akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cstdlib>
using namespace std;

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 100005;
const LL LMAX = 12158598925;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};

LL weight[MAX], price[MAX];

int main()
{
//    READ;
//    WRITE;
    int n, w;
    sii(n, w);
    FOR1(i, n) scanf("%lld %lld", &weight[i], &price[i]);

    LL dp[n+2][w+2];

    for(int i=0; i<=n; i++){
        for(int j=0; j<=w; j++){
            if(i == 0 or j == 0) dp[i][j] = 0;
            else if(weight[i] > j) dp[i][j] = dp[i-1][j];
            else{
                int p = i - 1;
                int q = j - weight[i];
                dp[i][j] = max(price[i] + dp[p][q], dp[i-1][j]);
            }
        }
    }


    cout << dp[n][w] << endl;

    return 0;
}


Measured memory_bytes: 79616
def p_e():
    N = int(input())
    S = input()

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()


Measured memory_bytes: 42520
#include <stdio.h>
#define MAX 100000
long long T[MAX];
int n,k;
 
int load(long long P) {
    int i=0,j=0;
    long long t;
    for(i = 0; i < k; i++) {
        t = 0;
        while( t+T[j] <=P) {
            t +=T[j];
            j++;
            if(j==n) return n;  
        }
    }
    return j;   
     
}
 
int solve() {
    long long right = MAX*10000,left=0,mid,s;
     
    while(right>left+1) {
        mid = (right + left)/2;
         s=load(mid);
         if(s>=n) right=mid;
         else left = mid;
    }
        return right;           
}
 
int main(void)
 
{
    int i;
    scanf("%d %d%",&n,&k);
     
    for(i=0; i < n; i++) {
        scanf("%d",&T[i]);
    }
        printf("%llu\n",solve());
        return 0;       
     
     
}


Measured memory_bytes: 2568
def abs(num):
    if num < 0:
        return num * (-1)
    else:
        return num

N = int(input())
arr_W = list(map(int,input().split(' ')))

min = sum(arr_W)

for T in range(0,N):
    diff = sum(arr_W[0:T]) - sum(arr_W[T:])
    new_min = abs(diff)
    if min > new_min:
        min = new_min
print(min)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
	int a,b,c,count=1;
	scanf("%d %d %d", &a, &b, &c);
	if(a==b){
		if(b==c){
			if (a==c){
				count=1;
			}
		}else{
			count=2;
		}
	}else{
		if(b==c){
			count=2;
		}else{
			if(a==c){
				count=2;
			}else{
				count=3;
			}
		}
	}


	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAXN 100005
using namespace std;
int n,m;
int p[MAXN],fa[MAXN];
int getfa(int x)
{
    return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) fa[i]=i;
    int x,y;
    for(int i=1;i<=m;i++)
	{
        cin>>x>>y;
        fa[getfa(x)]=getfa(y);
    }
    int cnt=0;
    for(int i=1;i<=n;++i)
	{
        if(getfa(p[i])==getfa(i)) cnt++;
    }
    cout<<cnt<<'\n';
}

Measured memory_bytes: 1024
import sys
from collections import deque
readline = sys.stdin.readline
n = int(readline())
G = [[] for _ in range(n)]
for _ in range(n-1):
    u,v,w = map(int, readline().split())
    G[u-1].append((v-1,w))
    G[v-1].append((u-1,w))

V = [-1]*n
V[0] = 0
que = deque([0])
while que:
    nw = que.popleft()
    for nx,d in G[nw]:
        if V[nx]!=-1: continue
        V[nx] = (V[nw]+d)%2
        que.append(nx)

for v in V:
    print(v)

Measured memory_bytes: 43008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int money;
  cin >> money;
  int fHY,fY;
  fHY = money / 500;
  money = money % 500;
  fY = money / 5;
  cout << fHY * 1000 + fY * 5 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
using namespace std;


int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World" <<endl;
  }
  else{
    int a, b;
    cin >> a >> b;
    cout << a+b <<endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    string ans = a + b > c + d ? "Left" : a + b == c + d ? "Balanced" : "Right";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [int(x) for x in input().split()]
a, b, c, d = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def count(c):
  return b // c - (a-1) // c

def doit():
  res = b + 1 - a
  print(res, file=sys.stderr)
  res -= count(c)
  print(res, file=sys.stderr)
  res -= count(d)
  print(res, file=sys.stderr)
  l = lcm(c, d)
  print(l, file=sys.stderr)
  res += count(l)
  print(res, file=sys.stderr)
  return res

#print(doit([0] * 4))
#doit(s)
#print(doit())
try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)


Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  int total = 0;
  rep(i, m) {
    int t;
    cin >> t;
    total += t;
  }

  if (n - total < 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << max(0, n - total) << endl;
}


Measured memory_bytes: 3644
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
A=[0]
for i in range(n):
  A.append(a[i]+A[-1])
l=0;r=10**10+1
while abs(l-r)>1:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=n-bisect.bisect_left(a,x-a[i])
  if ct<m:
    r=x
  else:
    l=x
ans=0
ct2=0
for i in range(n):
  y=bisect.bisect_left(a,l-a[i])
  ans+=A[n]-A[y]
  ans+=a[i]*(n-y)
  ct2+=n-y
print(ans-l*(ct2-m))

Measured memory_bytes: 58172
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(9);
    for(size_t i = 0; i < 9; i++)
    {
        x[i] = 111 * (i+1);
    }
    cout << *upper_bound(x.begin(), x.end(), N-1) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
	char[] right = {'y', 'u', 'i','o', 'p', 'h', 'j', 'k', 'l', 'n', 'm'};

	while(kbd.hasNext()){
	    String word = kbd.next();
	    if(!word.equals("#")){
		String hand = "";
		int p = 0;
		int count = 0;
		char c = word.charAt(p);

		for(p=0; p<word.length(); p++){
		    int a=0;
		    c = word.charAt(p);
		    while(a<right.length && c!=right[a]) a++;
		    if(a<right.length && c == right[a]){
			if(hand.equals("l")) { hand="r"; count++; }
			else hand = "r";
		    }
		    else {
			if(hand.equals("r")) { hand="l"; count++; }
			else hand = "l";
		    }

		}

		System.out.println(count);
	    }
	}
    }
}

Measured memory_bytes: 12000
n = int(input())
v = list(map(int, input().split()))

d_odd = {0:0}
d_even = {0:0}

ans = 0
for i in range(n):
    if i % 2 == 0:
        if v[i] in d_odd:
            d_odd[v[i]] += 1
        else:
            d_odd[v[i]] = 1
    else:
        if v[i] in d_even:
            d_even[v[i]] += 1
        else:
            d_even[v[i]] = 1

x = sorted(d_odd.items(), key=lambda x: x[1], reverse=1)
y = sorted(d_even.items(), key=lambda x: x[1], reverse=1)

if x[0][0] != y[0][0]:
    ans = n - x[0][1] - y[0][1]
else:
    ans = n - max(x[0][1]+y[1][1], x[1][1]+y[0][1])

print(ans)




Measured memory_bytes: 20760
n=int(input())
x=n//1.08

if int((x-1)*1.08)==n:
  print(int(x-1))
elif int(x*1.08)==n:
  print(int(x))
elif int((x+1)*1.08)==n:
  print(int(x+1))
else:
  print(":(")
  

Measured memory_bytes: 9068
S=input()
if S =='SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S== 'TUE':
    print(5)
elif S== 'WED':
    print(4)
elif S== 'THU':
    print(3)
elif S== 'FRI':
    print(2)
elif S== 'SAT': 
    print(1)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
    int s[100000];
    int n,q,i,j,c=0,t;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>s[i];
    cin>>q;
    for(i=0;i<q;i++)
    {
        cin>>t;
        for(j=0;j<n;j++)
        {
            if(s[j]==t)
                break;
        }
        if(j!=n)
            c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int solve(int x){
    int r=0,l=1000000000;
    while(l-r>1){
        int mid=(r+l)/2;
        if(mid*mid>x)l=mid;
        else r=mid;
    }
    return r;
}
signed main() {
    int N;cin>>N;
    
    int M=0;
    vector<pair<int,int>>Ans;
    if(N%2==0){
        vector<vector<bool>>Graph(N+1,vector<bool>(N+1,false));
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(j==i||N+1-j==i)continue;
                Graph[i][j]=true;
                Graph[j][i]=true;
                Graph[i][N+1-j]=true;
                Graph[N+1-j][i]=true;
            }
        }
        for(int i=1;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                if(Graph[i][j]){
                    M++;
                    Ans.push_back(make_pair(i,j));
                }
            }
        }
    }else{
        vector<vector<bool>>Graph(N+1,vector<bool>(N+1,false));
        for(int i=1;i<=N-1;i++){
            Graph[i][N]=true;
            Graph[N][i]=true;
            for(int j=1;j<=N-1;j++){
                if(j==i||j==N-i)continue;
                Graph[i][j]=true;
                Graph[j][i]=true;
                Graph[i][N-j]=true;
                Graph[N-j][i]=true;
            }
        }
        for(int i=1;i<N;i++){
            for(int j=i+1;j<=N;j++){
                if(Graph[i][j]){
                    M++;
                    Ans.push_back(make_pair(i,j));
                }
            }
        }
    }
    cout<<M<<endl;
    for(auto p:Ans){
        cout<<p.first<<' '<<p.second<<endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n;
  cin >> n;
  vll a(n);
  vin(a);

  vll ord(n);
  iota(all(ord), 0);
  sort(all(ord), [&](ll i, ll j){
    return a.at(i) > a.at(j);
  });
  rep(i, 0, n){
    if(i == ord.at(0)) cout << a.at(ord.at(1)) << endl;
    else cout << a.at(ord.at(0)) << endl;
  }
}

Measured memory_bytes: 4736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            int N = IO.ReadLineToInt();
            var B = IO.ReadLineToIntList();

            var sum = 0;
            for(int i = 0; i < N; i++)
            {
                if (i == 0)
                {
                    sum += B[i];
                }else if (i == N - 1)
                {
                    sum += B[i - 1];
                }
                else
                {
                    sum += Math.Min(B[i], B[i - 1]);
                }
            }

            //ここまで
            Console.WriteLine(sum);
            Console.ReadKey();
        }
    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(int n,int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11220
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <queue>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#define ll long long
using namespace std;
const int maxn=1e5+111;
int main(){
    int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d %d %d\n",c,a,b);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct node{
  struct node *prev;
  int key;
  struct node *next;
} D;

D *head;

void insert(int v);
void delete(D *v);
void find(int v);

int main()
{
  int i,n,v;
  char cmd[16];
  D *temp;
  
  head=malloc(sizeof(D));
  head->key=-1;
  head->prev=head;
  head->next=head;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",cmd);
    if(cmd[0]=='i'){
      scanf("%d",&v);
      insert(v);
    }
    else if(cmd[6]=='F') delete(head->next);
    else if(cmd[6]=='L') delete(head->prev);
    else{
      scanf("%d",&v);
      find(v);
    }
  }

  temp=head->next;
  while(temp->next->key!=-1){
    printf("%d ",temp->key);
    temp=temp->next;
  }
  if(temp->key!=-1) printf("%d\n",temp->key);
  
  return 0;
}

void insert(int v){

  D *temp;
  
  temp=malloc(sizeof(D));
  temp->key=v;
  temp->next=head->next;
  temp->prev=head;

  head->next=temp;
  temp->next->prev=temp;
}

void delete(D *v){

  v->prev->next=v->next;
  v->next->prev=v->prev;
  
  free(v);
}

void find(int v){
  
  D *temp;
  temp=head;
  
  while(temp->next->key!=-1){
    temp=temp->next;
    if(temp->key==v){
      delete(temp);
      break;
    }
  }
}

Measured memory_bytes: 31788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;

const int N = 1e4 + 5;
const int MOD = 1e9 + 7;

int dp[N][105][2];
// dp[i][j][k] means the count of numbers which at pos i, 
// with sum of each digit modulo D equals to j
// if k == 1, then it hasn't chosen any digit that is smaller than k
// how to ensure all numbers in result is smaller than K?
char K[N];
int d;

void add(int& a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int sub(int a, int b) {
    int res = a - b;
    if (res < 0) res += MOD;
    return res;
}

void solve() {
    memset(dp, 0, sizeof dp);
    dp[0][0][0] = 1;
    // for (int i = 0; i < K[0] - '0'; ++i) dp[0][i][0] = 1;
    // dp[0][K[0] - '0'][1] = 1;
    int len = strlen(K);
    for (int i = 0; i < len; ++i) {
        for (int j = 0; j < d; ++j) {
            for (bool sm_already : {false, true}) {
                for (int k = 0; k < 10; ++k) {
                    if (k > K[i] - '0' && !sm_already) {
                        break;
                    }
                    add(dp[i + 1][(j + k) % d][sm_already || (k < K[i] - '0')], dp[i][j][sm_already]);
                }
            }
        }
    }
    printf("%d\n", sub((dp[len][0][0] + dp[len][0][1]) % MOD, 1));
}

void debug() {
    for (int i = 0; K[i]; ++i, putchar('\n')) {
        for (int j = 0; j <= d; ++j) {
            printf("%10d %10d ", dp[i][j][0], dp[i][j][1]);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    while (~scanf("%s%d", K, &d)) {
        solve();
        // debug();
    }
    return 0;
}

Measured memory_bytes: 8448
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  long a,b,c;
  cin>>a>>b>>c;

  if(a%2==0 || b%2==0 || c%2==0) cout<<0<<endl;
  else {
    cout << min(a*b, min(b*c, c*a)) << endl;

  }


  return 0;
}


Measured memory_bytes: 764
h, w = map(int, input().split())
a = []
for _ in range(h):
    a.append(input())
cnt = [0]*26
for i in a:
    for j in i:
        cnt[ord(j)-ord('a')] += 1

if h%2==0 and w%2==0:
    for i in cnt:
        if i%4!=0:
            print('No')
            break
    else:
        print('Yes')
elif h%2==0 or w%2==0:
    mod2 = 0
    for i in cnt:
        if i%2!=0:
            print('No')
            break
        elif i%4!=0:
            mod2 += i%4
    else:
        tmp = h if h%2==0 else w
        if mod2<=tmp:
            print('Yes')
        else:
            print('No')
else:
    mod2 = 0
    alone = False
    for i in cnt:
        if i%2!=0:
            if alone:
                print('No')
                break
            alone = True
            mod2 += (i%4)//2
        elif i%4!=0:
            mod2 += i%4
    else:
        if mod2<=h+w-2:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here
    int N;
    cin >> N;
    vector<string>S(N);
//    string S;
    vector<string>_S;
    for (int i = 0; i < N; ++i) {
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());

    _S.push_back(S.at(0));

    int num = 1;
    for (int i = 0; i < N-1;++i) {
        if (S.at(i) != S.at(i+1)){
            num++;
        }
    }

    cout << num << endl;



    return 0;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
string s[100005];
int read(){
    int cnt = 0;
    char ch = getchar();
    while (ch < '0' || '9' < ch)
        ch = getchar();
    while ('0' <= ch && ch <= '9'){
        cnt = cnt * 10 + ch - '0';
        ch = getchar();
    }
    return cnt;
}
int main(){
    int n = read();
    for (int i = 1; i <= n; ++ i){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s + 1, s + 1 + n);
    int cnt = 1;
    long long ans = 0;
    for (int i = 2; i <= n; ++ i)
        if (s[i] == s[i - 1])
            ++ cnt;
        else{
            ans += 1LL * cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    cout << ans + 1LL * cnt * (cnt - 1) / 2 << endl;
}


Measured memory_bytes: 7424
N = int(input())
A = list(map(int,input().split()))

S = [0]
for i,a in enumerate(A,1):
    S.append(S[i-1]+a)
Sn = S[-1]
ans = Sn

i0 = 1
k0 = 3
for j in range(2,N-1):
    tmpS = S[j]
    for i in range(i0,j):
        if S[i] > tmpS/2:
            break
    i -= abs(tmpS - S[i] - S[i]) > abs(tmpS - S[i-1] - S[i-1])
    i0 = i
    for k in range(k0,N):
        if S[k]-tmpS > (Sn-tmpS)/2:
            break
    k -= abs(Sn-S[k] - S[k] + tmpS) > abs(Sn - S[k-1] - S[k-1] + tmpS)
    k0 = k
    P = (S[i],S[j]-S[i],S[k]-S[j],S[-1]-S[k])
    ans = min(ans,max(P)-min(P))
print(ans)

Measured memory_bytes: 24052
#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

int main(){
  int n; cin >> n;
  cout << (n < 1200 ? "ABC" : "ARC") << endl;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] param = sc.nextLine().split(" ");
        int A = Integer.parseInt(param[0]);
        int B = Integer.parseInt(param[1]);
        System.out.println(A * B - A - B + 1);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
int main(){
    string S;
    cin >> S;
    string ans;
    if(S == "Sunny") ans = "Cloudy";
    if(S == "Cloudy") ans = "Rainy";
    if(S == "Rainy") ans = "Sunny";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int h,w;
vec cnt(4);
bool f(){
    if(h*w%2==1)return (cnt[1]+cnt[3]==1)&(cnt[2]<=(h+w)/2-1);
    if(h%2==1&w%2==0) return cnt[1]+cnt[3]==0&cnt[2]<=w/2;
    if(h%2==0&w%2==1) return cnt[1]+cnt[3]==0&cnt[2]<=h/2;
    else return cnt[1]+cnt[2]+cnt[3]==0;
}
int main(){
    h=in();
    w=in();
    vec c(26);
    rep(i,h){
        string s=stin();
        rep(j,w)c[s[j]-'a']++;
    }
    rep(i,26)cnt[c[i]%4]++;
    string ans=f()?"Yes":"No";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[100005];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int ans = -INF;
	for(int i=1;i*i<=a[0];i++){
		if(a[0]%i != 0) continue;
		int x = 0;
		rep(j,n) if(a[j]%i != 0){
			x++;
			if(x == 2) break;
		}
		if(x < 2) ans = max(ans,i);
		int ii = a[0]/i;
		
		x = 0;
		rep(j,n) if(a[j]%ii != 0){
			x++;
			if(x == 2) break;
		}
		if(x < 2) ans = max(ans,ii);
	}
	for(int i=1;i*i<=a[1];i++){
		if(a[1]%i != 0) continue;
		int x = 0;
		rep(j,n) if(a[j]%i != 0){
			x++;
			if(x == 2) break;
		}
		if(x < 2) ans = max(ans,i);
		int ii = a[1]/i;
		
		x = 0;
		rep(j,n) if(a[j]%ii != 0){
			x++;
			if(x == 2) break;
		}
		if(x < 2) ans = max(ans,ii);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;


constexpr double EPS = 1e-10;
using Point = complex<double>;
using Line  = pair<Point, Point>;
using Polygon = vector<Point>;
bool compare(const Point &a, const Point &b) { // x ascending order
    if(a.real() != b.real()) return a.real() < b.real();
    return a.imag() < b.imag();
};

double dot(Point p, Point q) { return (conj(p) * q).real(); }
double cross(Point p, Point q) { return (conj(p) * q).imag(); }

double area(Polygon &ps) {
    double res = 0.0;
    for(int i = 0; i < (int)ps.size(); ++i) 
        res += cross(ps[i], ps[(i+1)%(int)ps.size()]);
    return abs(res) / 2.0;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(1);
    int n, cnt = 1;
    while(true) {
        cin >> n; if(n == 0) break;

        double x,y;
        Polygon ps;
        for(int i=0; i < n; ++i) {
            cin >> x >> y;
            ps.emplace_back(x, y);
        }
        cout << cnt << " " << area(ps) << '\n';
        ++cnt;
    }
    return 0;
}



Measured memory_bytes: 3292
#include<cstdio>
#include<algorithm>
using namespace std;
int a[3][111];
int d[3][111];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[1][i]);
	for (int i = 1; i <= n; i++) scanf("%d", &a[2][i]);
	for (int i = 1; i <= 2; i++)for (int j = 1; j <= n; j++) {
		d[i][j] = max(d[i - 1][j], d[i][j - 1]) + a[i][j];
	}
	printf("%d\n", d[2][n]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define N 100001

int partition(int *, int, int);

int main () {
  int A[N], i, n = 0, p = 0;

  scanf("%d",&n);

  for(i = 1 ; i <= n ; i++) {
    scanf("%d",&A[i]);
  }

  p = partition(A, 1, n);

  for(i = 1 ; i <= n ; i++) {
    if(i == p && i == n) printf("[%d]\n",A[i]);
    else if(i == p) printf("[%d] ",A[i]);
    else if(i < n) printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }

  return 0;
}


int partition(int *A, int p, int r) {
  int i, j, x = 0, tmp = 0;

  x = A[r];
  i = p - 1;

  for(j = p ; j < r ; j++) {
    if(A[j] <= x) {
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}



Measured memory_bytes: 2104
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j, k;
	int l[102];
	for (i = 0; i < n; i++)
		scanf("%d", &l[i]);
	int ans = 0;
	for (i = 0; i < n; i++)
		for (j = i + 1; j < n; j++)
			for (k = j + 1; k < n; k++)
				if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k])
					if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i])
						ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;

int main() {

  int N; 
  cin >> N;
  
//  str = "abcd"; // 'a', 'b', 'c', 'd' という文字(char)の列を代入
//  cout << str.at(0) << endl; // 1つ目である'a'を出力
//  cout << str.size() << endl; // 文字列の長さである4を出力

  // 配列
  vector<int> d(N); // int型の配列変数vecを宣言

//	d = { 3, 1, 2 }; // 25, 100, 64 という整数(int)の列を代入
  
    for (int i = 0; i < N; i++) {
    	cin >> d.at(i);
  	}

  	int dxy=0;
  	int dsum=0;
  
	for (int x = 0; x < N; x++) {
    	for (int y = x+1; y < N; y++) {
          	dxy = d.at(x) * d.at(y);
          	if  (x == y) {
    			dxy = 0;
  			}
              dsum = dsum + dxy;
//        cout << x << y << dxy << dsum << endl;
        }	
  	}

  cout << dsum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a, b, c; cin >> a >> b >> c;
    if ((a == b && b != c) ||
        (a == c && c != b) ||
        (b == c && c != a)) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int in = Integer.parseInt(s.nextLine());
        String[] in2  = s.nextLine().split(" ");
        List<Integer> l = new ArrayList<Integer>();
        for(int i = 0;i<in;i++){
            l.add(Integer.parseInt(in2[i]));
        }
        List<Integer> sorted = new ArrayList<Integer>(l);
        Collections.sort(sorted);
        int count = 0;
        for(int i = 0;i<l.size();i++){
            int prev = l.get(i);
            int curr = sorted.get(i);
            if(prev != curr){
                count++;
            }
        }
        System.out.println(count == 0 || count == 2 ? "YES" : "NO");
    }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;

using ll = long long;

int main(){
  int n; cin >> n;
  int a[n], b[n];
  for(int i=0; i<n; i++) cin >> a[i] >> b[i];

  ll ans=0;

  for(int i=n-1; i>=0; i--){
    ll m = (a[i] + ans)/b[i] + (((a[i] + ans)%b[i])? 1: 0);
    ans = m * b[i] - a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>

#define ll long long
#define MAXN 410

using namespace std;

ll dp[MAXN][MAXN];

int main() {

    int n;
    cin >> n;
    
    ll arr[n], pre[n];
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    
        pre[i] = (i ? pre[i - 1] : 0) + arr[i];
    }
    
    for(int len = 1; len < n; len++) {
        for(int l = 0; l < n - len; l++) {
            int r = l + len;
            
            ll sum = pre[r] - (l ? pre[l - 1] : 0);
            for(int k = l; k < r; k++)
                if(k == l)
                    dp[l][r] = dp[l][k] + dp[k + 1][r] + sum;
                else
                    dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + sum);
        }
    }
    
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1536
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  
  long long x;
  cin >> x;
  long long p = 100;
  int step = 0;
  while(p<x)
  {
    p+=p/100;
    step++;
  }
  cout<<step<<endl;
  return 0;
}
    

Measured memory_bytes: 3656
MOD = int(1e9 + 7)

def main():
    L = input()
    N = len(L)
    dp = [0] * (N + 1)
    dp[1] = 1
    for i in range(2, N + 1):
        dp[i] = (dp[i-1] * 3) % MOD
    ans = 1
    for i in range(1, N+1):
        if L[-i] == "1":
            ans = (ans * 2 + dp[i]) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40304
#define s(X,Y,Z)(t=X,X=Y,Y=t,f(Z?&X:&Y),a&7)
f(int*a){*a=(*a&7)<<4|*a>>4;}m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){for(r=1,a=97,b=82,c=67;n--;scanf(" %c%*s",&t),m=t-76,r+=m%6==0?s(c,b,m):1<m&m<8?s(b,a,m^7):s(c,a,m>0));printf("%d\n",r);}}

Measured memory_bytes: 0
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	judge = "No"
	for i in range(1, 10):
		for j in range(1, 10):
			if N == i * j:
				judge = "Yes"
				break
	print(judge)

if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

#include<unistd.h>
struct Buffer{
    int idx;
    enum { chunk = 1 << 16 };
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};

string ans;
void out(int num){
    if(!num){
        // putchar('0');
        ans += '0';
        return;
    }
    char buf[16];
    int idx = 0;
    while(num){
        auto ret = div(num, 10);
        buf[idx] = ret.rem + '0';
        num = ret.quot;
        idx++;
    }
    for(int i = idx - 1; i >= 0; i--){
        // putchar(buf[i]);
        ans += buf[i];
    }
}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    Buffer buf;
    const int lim = 1e5;
    vector<char> prime(lim + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= lim; i++){
        if(prime[i]){
            for(int j = i + i; j <= lim; j += i){
                prime[j] = false;
            }
        }
    }
    vector<int> accs(lim + 1);
    for(int i = 1; i <= lim; i++){
        accs[i] = accs[i - 1] + (i & 1 && prime[i] && prime[(i + 1) / 2]);
    }
    // int q; cin >> q;
    int q = buf.next();
    // stringstream ss;
    ans.reserve(1e5);
    for(int i = 0; i < q; i++){
        // int l, r;
        // cin >> l >> r;
        int l = buf.next(), r = buf.next();
        // cout << accs[r] - accs[l - 1] << '\n';
        // ss << accs[r] - accs[l - 1] << '\n';
        out(accs[r] - accs[l - 1]);
        // putchar('\n');
        ans += '\n';
    }
    // cout << ss.str();
    cout << ans;
    // write(1, ans.data(), ans.size());
}


Measured memory_bytes: 1720
# Aizu Problem ALDS_1_4_D: Allocation
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def check(n, k, W, p):
    idx = 0
    for i in range(k):
        S = 0
        while W[idx] + S <= p:
            S += W[idx]
            idx += 1
            if idx == n:
                return True
    return False

    
n, k = [int(_) for _ in input().split()]
W = [int(input()) for _ in range(n)]
left, right = 0, 10**16
while right - left > 1:
    mid = (left + right) // 2
    if check(n, k, W, mid):
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 11672
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	gcdl, gcdr := make([]int, n), make([]int, n)
	gcdl[0], gcdr[n-1] = a[0], a[n-1]
	for i := 1; i < n; i++ {
		gcdl[i] = gcd(gcdl[i-1], a[i])
		gcdr[n-1-i] = gcd(gcdr[n-i], a[n-1-i])
	}

	ans := gcdr[1]
	for i := 1; i < n-1; i++ {
		ans = max(ans, gcd(gcdl[i-1], gcdr[i+1]))
	}
	ans = max(ans, gcdl[n-2])

	puts(ans)
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;

vector<long long> trial_division(const long long& num) {
  long long result = num;
  for (long long i = 2, m = (long long)sqrt(num); i <= m; ++i) {
    if (num % i == 0) {
      result = i;
      break;
    }
  }
  if (result == num) {
    return {num};
  } else {
    vector<long long> primes_1 = {result};
    vector<long long> primes_2 = trial_division(num / result);
    primes_1.insert(primes_1.end(), primes_2.begin(), primes_2.end());
    return primes_1;
  }
}

// set<long> get_prime_factors(const long num) {
//   set<long> factors;
//   long current = num;
//   for (long i = 2; i <= num; i++) {
//     while (current % i == 0) {
//       factors.insert(i);
//       current /= i;
//     }
//   }
//   return factors;
// }

int main(int argc, char const* argv[]) {
  long long A, B;
  cin >> A >> B;

  vector<long long> factors_A = trial_division(A);
  vector<long long> factors_B = trial_division(B);
  set<long long> result;

  set_intersection(factors_A.begin(), factors_A.end(), factors_B.begin(),
                   factors_B.end(), inserter(result, result.end()));
  result.insert(1);

  cout << result.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin>>n;

  if(n%1000==0) cout << 0 << endl;

  else cout << 1000-n%1000 << endl;

}

Measured memory_bytes: 3648
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

int main()
{
    int n, m; cin >> n >> m;
    int c[m];
    rep(i,m) cin >> c[i];
    int dp[n+1];
    rep(i,n+1) dp[i] = INF;
    // 初期化する、合計金額が0円のときはコインの最小枚数は0枚になる
    dp[0] = 0;
    rep(i,m){
        for(int j=c[i]; j<=n; j++){
            dp[j] = min(dp[j], dp[j-c[i]]+1);
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3284
#include<stdio.h>

int main(){
  int N, a[200], i, count = 0;
  
  scanf("%d", &N);
  for (i = 0; i < N; i++){
    scanf("%d", &a[i]);
  }
  
  while(1){
    for(i = 0; i < N; i++){
      if(a[i] % 2 == 0){
        a[i] /= 2;
      } else {
        break;
      }
    }
    if(i != N){
      printf("%d\n", count);
      return 0;
    } else {
      count++;
    }
  }
}
    

Measured memory_bytes: 128
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))

int sum_array(vector<int> &C, int start, int end, int step){
	int c = 0;
	rpd(i, start, end, step) c += C[i];
	return c;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false); // 232ms -> 90ms

	int MAX_A = 1000000 + 1;
	int N; cin>>N;
	vector<int> C(MAX_A, 0);
	int g = 0;
	rpd(i, 0, N, 1){ int a; cin>>a; C[a]++; g = gcd(g, a); }
	int t = 0;
	if(g > 1) t = 2;
	else if(sum_array(C, 2, MAX_A, 2) > 1) t = 1;
	else rpd(i, 3, MAX_A, 2) if(sum_array(C, i, MAX_A, i) > 1){ t = 1; break; }
	cout<< vector<string>{"pairwise","setwise","not"}[t] <<" coprime\n";
}


Measured memory_bytes: 7168
package main

import "fmt"

func main() {
	var N int
	var S string

	fmt.Scan(&N, &S)
	ans := 0

	R := make(map[int]struct{})
	G := make(map[int]struct{})
	B := make(map[int]struct{})

	for idx, c := range S {
		if c == 'R' {
			R[idx+1] = struct{}{}
		} else if c == 'G' {
			G[idx+1] = struct{}{}
		} else if c == 'B' {
			B[idx+1] = struct{}{}
		}
	}
	for r, _ := range R {
		for g, _ := range G {
			var s, b int
			if r < g {
				s, b = r, g
			} else {
				s, b = g, r
			}
			ans += len(B)
			// s,b = i,j
			if _, ok := B[2*b-s]; ok {
				ans--
			}

			// s,b = j, k
			if _, ok := B[2*s-b]; ok {
				ans--
			}

			// s,b = i, k
			if _, ok := B[(b+s)/2]; ok && (b+s)%2 == 0 {
				ans--
			}
		}
	}
	fmt.Println(ans)
}

func po(a, b, c int) (int, int, int) {
	if a > b {
		a, b = b, a
	}

	if b > c {
		b, c = c, b
	}

	if a > b {
		a, b = b, a
	}
	return a, b, c
}


Measured memory_bytes: 2048
#include<cstdio>
inline int min(const int x,const int y){
	return x<y?x:y;
}
int h,n,f[10005],v[1005],c[1005];
int main(){
	scanf("%d%d",&h,&n);
	for(int i=1;i<=h;++i)f[i]=100000000;
	for(int i=1;i<=n;++i){
		scanf("%d%d",&v[i],&c[i]);
		for(int j=1;j<=h;++j){
			if(j<v[i])f[j]=
				min(f[j],c[i]);
			else f[j]=min(f[j],
				f[j-v[i]]+c[i]);
		}
	}
	return printf("%d\n",f[h]),0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
const ll INF=99999999999999999;
ll a,b,c,d,e,f,g,ans=0;
int main(){
    ll n;
    cin>>n;
    vl v(n),an(n+1);
    vl C(200001,-1);
    rep(i,n){
        cin>>a;
        v[i]=C[a];
        C[a]=i;
    }

    an[0]=1;
    for(int i=0;i<n;i++){
        if(v[i]==-1||(v[i]!=-1&&i-v[i]==1))an[i+1]=an[i];
        if(v[i]!=-1&&i-v[i]>1)an[i+1]=(an[v[i]+1]+an[i])%1000000007;
    }

    cout<<an[n]<<endl;
}

Measured memory_bytes: 4992
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    //println!("{:?}", s);

    let n = s.len();
    let count = s
        .iter()
        .enumerate()
        .filter(|&(i, x)| i<n/2 && *x != s[n-i-1])
        .count();
    println!("{}", count);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
using namespace std;

#define ll long long
#define MAX 100105

const ll INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
ll h[MAX];
ll dp[MAX];

int main() {
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }

    for(int i = 0; i < MAX; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 1; j < 3; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // for(int i = 0; i < N; i++) {
    //     if(i)
    //         cout << " ";
    //     cout << dp[i];
    // }
    // cout << endl;

    printf("%lld\n", dp[N - 1]);
}

Measured memory_bytes: 1792