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

const int mod = 1e9 + 7;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> S(N), T(M);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> T[i];
	}
	vector<unordered_map<int, int>> mp(M + 1);
	for (int i = M - 1; i >= 0; i--) {
		mp[i] = mp[i + 1];
		mp[i][T[i]] = i;
	}
	vector<vector<int>> dp(N + 1, vector<int>(M + 1));
	dp[0][0] = 1;
	for (int i = 0; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			(dp[i][j] += dp[i][j - 1]) %= mod;
		}
		if (i > 0) {
			for (int j = 0; j <= M; j++) {
				(dp[i][j] += dp[i - 1][j]) %= mod;
			}
		}
		if (i < N) {
			for (int j = 0; j < M; j++) {
				if (S[i] == T[j]) (dp[i + 1][j + 1] += dp[i][j]) %= mod;
			}
		}
	}
	cout << dp[N][M] << endl;
	return 0;
}


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

using namespace std;

long long N;
multiset < long long > st;
multiset < long long >::iterator p;

int main(){
    scanf("%lld", &N);
    long long sum = 0, l = 0, r = 0, ans = 0;
    while(N--){
        long long num; scanf("%lld", &num);
        if(num == 1){
            long long A, B; scanf("%lld %lld", &A, &B);
            sum += B;
            if(!(long long)st.size()){
                st.insert(A); p = st.begin();
            }
            else{
                st.insert(A); ans += abs(A - *p);
                auto q = p;
                if(A >= *p){
                    ++r;
                    if(r >= l + 2){
                        ++q;
                        ans += (*q - *p) * (l + 1 - r);
                        --r, ++l; ++p;
                    }
                }
                else{
                    ++l;
                    if(l > r){
                        --q;
                        ans += (*p - *q) * (r + 1 - l);
                        --l, ++r, --p;
                    }
                }
            }
        }
        else{
            printf("%lld %lld\n", *p, ans + sum);
        }
    }
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    ll cnt = 0;
    rep(i, s.size()) if(s[i] == '2') cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
string s;

int main() {
  std::vector<int> v(3);
  cin >> v[0]>>v[1]>>v[2];
  auto max_ele = *max_element(v.begin(),v.end());
  int cnt =0;
  for(int i=0;i<3;++i){
    while(max_ele-v[i]>=2){
      v[i] +=2;
      ++cnt;
    }
  }
  sort(all(v));
  if(v[2]-v[0]==1 && v[2]-v[1]==1){
    ++cnt;
  } else if(v[2]-v[0]==1 && v[2]-v[1]==0){
    cnt += 2;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string N;
    cin >> N;
    if(N.at(0) == N.at(1) && N.at(0) == N.at(2)){
        cout << "No" << endl;
    }
    else if(N.at(0) == N.at(1) && N.at(2) == N.at(3)){
        cout << "Yes" << endl;
    }
    else if(N.at(0) == N.at(2) && N.at(1) == N.at(3)){
            cout << "Yes" << endl;
    }
    else if(N.at(0) == N.at(3) && N.at(1) == N.at(2)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,X;
  cin>>N>>X;
  int counter=1;
  int zahyo=0;
  vector<int>moji(N);
  for(int i=0;i<N;i++){
  cin>>moji.at(i);
  }
  for(int i=0;i<N;i++){
   if(zahyo+moji.at(i) <=X){
   counter++;
     zahyo+=moji.at(i);
   }
    else{
    break;
    }
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 3576
import bisect
n = int(input())
l = list(map(int,input().split()))
count = 0
l.sort()

def binary_search(key,l,n):
    key_number = int((n-1)//2)
    L = 0
    R = n-1
    while True:
        if l[key_number] < key:
            L = key_number
            key_number = (L+R)//2
        else:
            R = key_number
            key_number = (L+R)//2

        if key == l[key_number]:
            return key_number
        if (R-L) == 1:
            return L+1

def binary_search(key,l,n):
    L = 0
    R = n-1
    while L < R:
        key_number = int((n-1)//2)
        if l[key_number] < key:
            L = key_number + 1
        else:
            R = key_number
    return key_number

ans = 0
#print(binary_search(7+8,l,n))

for i in range(n-2):
    for j in range(i+1,n-1):
        a = l[i]
        b = l[j]

        ans += bisect.bisect_left(l,a+b)- j -1

        #print("{} <c< {} b-a = {} a+b = {}".format(key_numberL,key_numberR,b-a,a+b))

        #print('i={} j={} key_numberL={} key_numberR={} count={}'.format(i,j,key_numberL,key_numberR,-key_numberL-double_count))
        #count += key_numberR-key_numberL-double_count
print(ans)


Measured memory_bytes: 3188
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-3
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=100005;
//Code begin...

struct Edge{int p, next, flag;}edge[N<<1];
int head[N], cnt=1, G[N][2], p1, p2, pre[N];
bool vis[N];

void add_edge(int u, int v){edge[cnt].p=v; edge[cnt].next=head[u]; head[u]=cnt++;}
int main ()
{
    int n, m, ans;
    scanf("%d%d",&n,&m);
    FOR(i,1,m) scanf("%d%d",&G[i][0],&G[i][1]), add_edge(G[i][0],G[i][1]), add_edge(G[i][1],G[i][0]);
    p1=G[1][0], p2=G[1][1]; vis[p1]=vis[p2]=1, pre[p2]=p1; ans=2;
    while (1) {
        int tmp1=0, tmp2=0;
        for (int i=head[p1]; i; i=edge[i].next) {
            int v=edge[i].p;
            if (vis[v]) continue;
            tmp1=v; break;
        }
        for (int i=head[p2]; i; i=edge[i].next) {
            int v=edge[i].p;
            if (vis[v]) continue;
            tmp2=v; break;
        }
        if (tmp1==0&&tmp2==0) break;
        if (tmp1) pre[p1]=tmp1, p1=tmp1, vis[p1]=1, ++ans;
        if (tmp2&&tmp2!=tmp1) pre[tmp2]=p2, p2=tmp2, vis[p2]=1, ++ans;
    }
    printf("%d\n",ans);
    int t=p2;
    while (t!=p1) printf("%d ",t), t=pre[t];
    printf("%d\n",p1);
    return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>

int main(void){
	int ans=0;
	int in_a;
	int x;
	int math[246913];
	int i;
	int j;
	
	while(1){
		scanf("%d",&in_a);
		if(in_a==0){
			break;
		}
		
		for(i=in_a+1;i<=2*in_a;i++){
			x=0;
			for(j=2;j*j<=i;j++){
				if(i%j==0){
					x=1;
				}
			}
			
			if(x==0){
				ans++;
			}
		}
		
		printf("%d\n",ans);
		ans=0;
		
		
	}
	
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string t,h;
    int tp =0;
    int hp =0;
    
    for (int i=0;i<n;i++){
        cin >> t >> h;
        if (t==h){
            tp += 1;
            hp += 1;
        }else if (t > h){
            tp += 3;
        }else {
            hp += 3;
        }
    }
    cout << tp << " " << hp << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
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)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;
const ll infl = 1LL << 60;
ll mul(ll a, ll b)
{
    if (infl / a < b)
        return infl;
    return min(infl, a * b);
}
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll lcm(ll a, ll b)
{
    if (a == infl || b == infl)
        return infl;
    return mul(a / gcd(a, b), b);
}

int main(void)
{
    long long a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    ll n;
    cin >> n;
    ll ans = 0,i=0;
    while(true){
        i++;
        ans += i;
        if(ans >= n) break;
    }
    cout << i << endl;
    return 0;
}  


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

const long long MOD = 2019;

void solve(long long L, long long R){
  if (L / 2019 != R / 2019) {
      cout << "0" << endl;
      return;
  }
  long long res = LLONG_MAX;
  for (long long l = L; l <= R; l++) {
    for (long long r = l+1; r <= R; r++) {
	res = min(res, (l*r)%2019);
    }
  }
  cout << res << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{

    int i,j,k;
    string s,s1,s2;
    int n;
    cin>>n;
    cin>>s>>s1;
    for(i=0;i<(2*n);i++)
    {
        if(i%2==0)
            s2[i]=s[i/2];

        else
            s2[i]=s1[i/2];
    }
    for(i=0;i<(2*n);i++)
    {
        cout<<s2[i];
    }
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;

int main(){
  string str;

  cin >> str;
  
  int check[26];

  for(int i = 0 ; i < 26 ; i++)
    check[i] = 1;
  
  
  for(int i = 0 ; i < str.size() ; i++){
    char ch = str[i];
    check[(int)ch - 97 ] *= -1;
  }
  
  
  bool f = true;
  
  for(int i = 0 ; i < 26 ; i++){
    if(check[i] == -1 ){
      f = false;
      break;
    }
  }

  if(f)
    cout<< "Yes" << endl;
  else
    cout << "No" << endl;
     

  return 0;
}


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

int head=0;
int C[100001]={0};
int S[100001]={0};
int E[100001]={0};


void draw(){
	for(int i=0;i<=head;i++){
		cout<<"("<<C[i]<<","<<S[i]<<"-"<<E[i]<<") ";
	}
	cout<<endl;
}

int main(){
	
	int n;
	while(cin>>n,n){
		head=0;
		int t;
		cin>>t;
		S[0]=E[0]=1;
		C[0]=t;
		//cout<<1<<","<<t<<" : ";
		//draw();
		for(int i=2;i<=n;i++){
			int t;
			cin>>t;
			if(i%2==1){
				if(C[head]==t){
					E[head]++;
				}
				else{
					head++;
					C[head]=t;
					S[head]=E[head]=E[head-1]+1;
				}
			}
			else{
				if(C[head]==t){
					E[head]++;
				}
				else{
					C[head]=t;
					E[head]++;
					while(head>0){
						if(C[head]!=C[head-1])break;
						E[head-1]=E[head];
						head--;
					}
				}
			}
			//cout<<i<<","<<t<<" : ";
			//draw();
		}
		int ans=0;
		for(int i=0;i<=head;i++){
			if(C[i]==0){
				ans+=(E[i]-S[i]+1);
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1172
n = input()
A = list(map(int, input().split()))
minus_count = 0
result = []
for a in A:
    if a<0:
        minus_count += 1
        result.append(-a)
    else:
        result.append(a)
if minus_count % 2 == 1:
    print(sum(result) - min(result)*2)
else:
    print(sum(result))

Measured memory_bytes: 14332
import sys
input = sys.stdin.readline
import copy
h, w, k = map(int, input().split())
ans = [0] + [1] + [0]*w
sequence_list = [1, 1, 2, 3, 5, 8, 13, 21, 34]
move_pattern = {}
for i in range(1, w+1):
  move_pattern[str(i)] = sequence_list[w-i]*sequence_list[i-1]
for i in range(1, w):
  move_pattern[i*11+1] = sequence_list[i-1]*sequence_list[w-i-1]
move_pattern[1] = 0
move_pattern[w*11+1] = 0
for _ in range(h):
  keep_ans = copy.deepcopy(ans)
  for i in range(1, w+1):
    ans[i] = keep_ans[i-1]*move_pattern[i*11-10] + keep_ans[i]*move_pattern[str(i)] + keep_ans[i+1]*move_pattern[i*11+1]
print(ans[k]%1000000007)

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < vec.size(); i++) cin >> vec.at(i);
  
  set<int> mochi;
  
  for (int i = 0; i < vec.size(); i++) mochi.insert(vec.at(i));
  
  cout << mochi.size() << endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int A[100010];
int N; 
/*
int check(void) {
    int ans = 0;
    do {
        int diff = 0;
        rep(i, N - 1) diff += abs(A[i + 1] - A[i]);
        if (diff > ans) ans = diff;
    }while(next_permutation(A, A + N));
    return ans;
}
*/
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    deque<int> dq;
    dq.push_back(A[0]);
    int left = 1;
    int right = N - 1;
    REP(i, 1, N - 1) {
        if (i % 4 == 1) dq.push_front(A[right--]);
        else if (i % 4 == 2) dq.push_back(A[right--]);
        else if (i % 4 == 3) dq.push_front(A[left++]);
        else dq.push_back(A[left++]);
    }
    sort(A, A+ N);
    deque<int> dq2;
    dq2.push_back(A[N - 1]);
    left = 0;
    right = N - 2;
    REP(i, 0, N - 2) {
        if (i % 4 == 0) dq2.push_front(A[left++]);
        else if (i % 4 == 1) dq2.push_back(A[left++]);
        else if (i % 4 == 2) dq2.push_front(A[right--]);
        else dq2.push_back(A[right--]);
    }
    int ans = 0;
    int ans2 = 0;
    /*
    rep(i, N) cout << dq[i] << " ";
    cout << endl;
    rep(i, N) cout << dq2[i] << " ";
    cout << endl;
    */
    rep(i, N - 1) ans += abs(dq[i + 1] - dq[i]);
    rep(i, N - 1) ans2 += abs(dq2[i + 1] - dq2[i]);
    //cout << ans << " " << ans2 << " " << check() << endl;
    cout << max(ans, ans2) << endl;
    

    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
void solve() {
    cin >> s;

    auto n = sz(s);
    bool ok = true;
    if (s[0] == '0' || s[n - 1] == '1') ok = false;
    rep(i, n - 1) if (s[i] != s[n - 2 - i]) { ok = false; break; }
    if (!ok) { cout << -1 << endn; return; }

    s[n - 1] = '1';
    set<int> ss;
    rep(i, n) if (s[i] == '1') ss.insert(i);

    s[n - 1] = '1';
    rep(i, n - 1) {
        auto p = ss.upper_bound(i);
        cout << i + 1 << " " << *p + 1 << endn;
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 6224
import scala.io.StdIn.readLine

object Main {
  def sort(a:Array[Int],k:Int) = {
    val count = new Array[Int](k+1)
    val buf = new Array[Int](a.length)
    a.map( x=> count(x) += 1 )
    for(i<-1 to k) count(i) += count(i-1)
    for(i<-0 until a.length) {
      val j = a.length-1-i
      buf(count(a(j))-1) = a(j)
      count(a(j)) = count(a(j))-1
    }
    buf
  }

  def main(args:Array[String]) = {
    readLine
    val a = readLine.split(" ").map(_.toInt)
    val result = sort(a,10000)
    println(result.mkString(" "))
  }
}

Measured memory_bytes: 481452
#include <stdio.h>

int main(void){
    int n;
    int A[10001];

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

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

    bool is_first = true;
    for(int i = 0; i < 10001; i++){
        for(int j = 0; j < A[i]; j++){
            if(is_first){
                printf("%d", i);
                is_first = false;
                continue;
            }
            printf(" %d", i);
        }
    }

    printf("\n");
}



Measured memory_bytes: 2800
def f(e):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:print(x-s,y-t);break
for e in iter(input,'0'):f(e)


Measured memory_bytes: 5908
from fractions import gcd
A, B = list(map(int, input().split()))

C = gcd(A, B)


def prime_factorize(n):
    a = {}
    while n % 2 == 0:
        a[2] = True
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] = True
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] = True
    return a

print(len(prime_factorize(C)) + 1)

Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };

void solve() {
    vi A(3); 
    rep(i,3) cin >> A[i];
    sort(ALL(A));
    // DEBUG_VEC(A);
    int x = A[2] - A[0];
    int y = A[2] - A[1];
    int ans;
    if(x==0 && y==0) ans = 0;
    else if(x%2==1 && y%2==1){
        ans = x/2 + y/2+1;
    }
    else if(x%2==0 && y%2==0){
        ans = x/2+y/2;
    }
    else{
        ans = x/2 + y/2 + 2;
    }
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i:=0; i<n; i++{
		fmt.Scan(&a[i]) 
	}
	for i:=n-1; i>0; i--{
		fmt.Printf("%d ", a[i])
	}
	fmt.Println(a[0])
}


Measured memory_bytes: 1120
n=int(input())
h=[int(i) for i in input().split()]
f=1
h[0]-=1
for i in range(1,n):
    if h[i]-h[i-1]>=1:h[i]+=-1
    elif h[i]-h[i-1]==0:h[i]+=0
    else:
        f=0
        print("No")
        break
if f==1:print("Yes")

Measured memory_bytes: 14396
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int N;
string S;

int main(){
	int w[300001], e[300001];
	fill(w, w + N + 1, 0);
	fill(e, e + N + 1, 0);
	cin >> N;
	cin >> S;
	for(int i = 0; i < N; i++){
		if(S[i] == 'W'){
			w[i + 1] = w[i] + 1;
			e[i + 1] = e[i];
		}else{
			w[i + 1] = w[i];
			e[i + 1] = e[i] + 1;
		}
	}
	int ans = 300001;
	for(int i = 1; i <= N; i++){
		ans = min(ans, e[N] - e[i] + w[i - 1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3076
#include "stdio.h"
#include "iostream"
using namespace std;

int main()
{
	long int n, min, A, a[200001], sum = 0;
	cin >> n;
	for (long i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	A = a[1];
	if (sum - 2 * A >= 0)
		min = sum - 2 * A;
	else min = 2 * A - sum;
	for (long i = 1; i < n; i++) {
		if (sum - 2 * A <= min && sum - 2 * A >= 0)
			min = sum - 2 * A;
		else if (sum - 2 * A <= 0 && min >= 2 * A - sum)
		{
			min = 2 * A - sum;
		}
		A += a[i + 1];
	}
	cout << min;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

void solve(){
    int n;
    cin >> n;
    int a[n+1];
    rep(i,n){
        cin >> a[i];
    }
    a[n]=0;
    sort(a, a+n+1, greater<>());
    //cout << a[1] << endl;
    int suma = 0;
    int sumb = 0;
    for(int i=0; i<n; i=i+2){
        suma += a[i];
        sumb += a[i+1];
    }
    cout << suma-sumb << endl;
}

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


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

int main(){
  char s[101];
  char str[8] = "keyence";
  scanf("%s",s);
  int n = strlen(s);
  int head = 0;
  int tail = 0;
  int i = 0;
  while(i < n && s[i] == str[i]){
    head++;
    i++;
  }
  i = 0;
  while(i < n && s[n - 1 - i] == str[6 - i]){
    tail++;
    i++;
  }
  if(head + tail >= 7){
    puts("YES");
  }else{
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define xx first
#define yy  second

template <typename T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <typename T> T lcm(T a, T b) {return a * (b / gcd(a, b));}

const int N   = (int) 2e5 + 5;
using namespace std;
vector<int>prime;
bool pr[1000001];
void sieve(){
  for(int i =  2; i*i<=1000000; i++){

     if(pr[i]==0){
        for(int j = i*i; j<=1000000; j+=i)
             pr[j] = 1;
     }
  }

  for(int i  = 2; i<=1000000; i++){
    if(pr[i]==0){
        prime.pb(i);
    }
  }

  return ;

}

int solve(int *a,int n,int k){

        int ans = 1e9+7;
        for(int i  = 1; i+k-1<=n; i++){

            ans = min(ans,a[i+k-1]-a[i]);
        }

return ans;
}
int  main()
{
    //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

     int t=1, n;
     //cin >> t;
     while(t--)
     {
         int n,k;
       cin >> n>>k;
        int a[n+10];
       for(int i = 1; i<=n; i++){
        cin >> a[i];
       }
       sort(a+1,a+1+n);
        cout<<solve(a,n,k)<<'\n';
     }



    return 0;
}


Measured memory_bytes: 640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int hitoketa = N % 10;

        switch (hitoketa) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                System.out.println("hon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                System.out.println("pon");
                break;
            case 3:
                System.out.println("bon");
        }
    }
}


Measured memory_bytes: 35560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	ll n;
	cin>>n;
	ll arr[n],pre[n],min,sum=0;
	for(ll i=0;i<n;i++)
		cin>>arr[i],sum+=arr[i];
	pre[0]=arr[0];
	min=abs((sum-arr[0])-arr[0]);
	if(n==2){
	cout<<min;
	return 0;
	}
	for(ll i=1;i<n-1;i++)
	{
		pre[i]=pre[i-1]+arr[i];
		if(abs(sum-pre[i]-pre[i])<min)
			min=abs(sum-2*pre[i]);
	}
	cout<<min;
	return 0;
}



Measured memory_bytes: 6700
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

ll f(pair<string,ll>&x ,pair<string,ll>&y) 
{
	if(x.first == y.first) 
	{
		return x.second>y.second;
	}
	else 
	{
		return x.first<y.first;
	}
}
 
void solve()
{
	string s;
	cin>>s;
	ll a1=0,a2=0;
	for(ll i=0;i<s.size();i++)
	{
		if(i%2==0 and s[i]!='0')
			a1++;
		if(i%2!=0 and s[i]!='1')
			a1++;
	}
	for(ll i=0;i<s.size();i++)
	{
		if(i%2==0 and s[i]!='1')
			a2++;
		if(i%2!=0 and s[i]!='0')
			a2++;
	}
	cout<<min(a1,a2);
	return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5 ;
const int INF = 1e9 + 1e5 + 2;
const int mod= 1e9+7;
using namespace std;
typedef long long ll;
bool cmp(const pair<int,int> &a,
               const pair<int,int> &b)
{
       if (a.first==b.first)
           return (a.second >b.second);
       return (a.first<b.first);
}
int main()
{
    ll n;

    cin>>n;

    vector<ll>v(n);

    for (ll i=0; i<n; ++i)
        cin>>v[i];

    map<ll,ll>m;
    for (ll i=0; i<n; ++i)
    {
        m[v[i]]++;
    }

    ll sum=0;
    for (ll i=1; i<=1000000; ++i)
    {
        ll p=1;
        p*=m[i]*(m[i]-1);

        sum+=p/2;
    }
    for (ll i=0; i<n; ++i)
    {
        ll ans=sum;
        ans-=m[v[i]]*(m[v[i]]-1)/2;

        ans+=(m[v[i]]-1)*(m[v[i]]-2)/2;

        cout<<ans<<"\n";
    }















}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    ll t = 1;
    rep(i, n) if (a[i]%2==0) t <<= 1;
    cout << pow(3, n)-t << endl;    
    return 0;
}

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

void printChessboard( int h, int w ) {
    for (int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if ((i + j) % 2 == 0) {
                cout << '#';
            } else {
                cout << '.';
            }
        }
        cout << endl;
    }
}

  
int main() {
    int h, w;
    while (1) {
        cin >> h >> w;
        if (h == 0 && w == 0) return 0;
        printChessboard( h, w );
        cout << endl;
    }
}

Measured memory_bytes: 3008
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		long N;

		N=sc.nextLong();

		long min_move=1000000000000001l;

		for(int i=0;i<5;i++) {
			long temp=sc.nextLong();
			if(min_move>temp) min_move=temp;
		}

		long ans=((N+min_move-1)/min_move)+4;

		System.out.println(ans);


		sc.close();

	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

const ll inf=1e18;



int main(){
    int n; cin>>n;
    ll ans=1;
    long double x,y;
    vector<ll> p(n);
    bool ok=true;
    rep(i,n){
        cin>>p[i];
    }
    sort(btoe(p));
    rep(i,n){
        x=ans; y=p[i];
        if(x*y>1e18) ok=false;
        ans*=p[i];
    }
    if(ok) cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3984
N = int(input())
A = list(map(int, input().split()))
count = 0

#all(): 全ての要素がTrueならTrue
#any(): 一つでもTrueならTrue
while all(a%2==0 for a in A): 
    A = [a/2 for a in A]
    count += 1

print(count)

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> vec(N);
  int64_t comfort;
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  comfort = vec.at(0);
  
  int cnt=0;
  int check = 1;
  
  while(cnt!=N-2){
    comfort += vec.at(check);
    cnt++;
    if(cnt%2==0) check++;
  }
  cout << comfort;
    
    
}

Measured memory_bytes: 4832
import os
import heapq
import math

N, M = (int(x) for x in input().split())
cost = [-a for a in map(int, input().split())]
heapq.heapify(cost)

for _ in range(0,M):
    x = heapq.heappop(cost)
    heapq.heappush(cost, x/2)
res = 0
for i in range(0, N):
    res += math.floor(cost[i]*-1)

print(res)

Measured memory_bytes: 14532
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 2005

void solve()
{
    string s,t;
    cin>>s>>t;

    lli cnt=0;

    loopl(i,0,s.size())
    {
        if(s[i] != t[i]) cnt++;
    }

    cout<<cnt<<endl;

}

int main()
{
/////////////////////////////////////
    fastio;
////////////////////////////////////  

    lli t;
    t=1;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3808
a,b=map(int,input().split())

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#nを素因数分解したリストを返す
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

print(len(factorization(gcd(a,b)))+1 if gcd(a,b)!=1 else 1)


Measured memory_bytes: 9428
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int x,y;
    cin>>x>>y;
    bool ans=false;
    for(int i=0;i<=x;i++){
        int j=x-i;
        if((4*i+2*j)==y){
            ans=true;
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3644
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int vis[200005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	ll k;
	cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i], a[i]--;
	vi cur;
	int st = 0;
	int cnt = 0;
	while(!vis[st]){
		if(cnt == k){
			cout << st + 1 << endl;
			return 0;
		}
		vis[st] = 1;
		cur.pb(st);
		st = a[st];
		cnt++;
	}
	cur.pb(st);
	int nw = -1;
	rep(i, cur.size() - 1){
		if(cur[i] == cur[(int)cur.size() - 1]){
			nw = i;
			break;
		}
	}
	//rep(i, cur.size()) cout << cur[i] + 1 << " ";
	//cout << endl;
	cur.pop_back();
	k -= nw;
	k %= (ll)(cur.size() - nw);
	cout << cur[nw + k] + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 5804
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long 


signed main(){
    int N,M;
    string s[104];
    string t[104];
    int Ans=0;
    int sum;
    cin >> N ;
    REP(i,N){cin >> s[i];}
    cin >> M;
    REP(i,M){cin >> t[i];}
    REP(i,N){
        sum=0;
        REP(j,N){
            if(s[i]==s[j]){
                sum++;
            }
        }
        REP(j,M){
            if(s[i]==t[j]){
                sum--;
            }
        }
       // cout << sum << endl;
        Ans=max(Ans,sum);
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,A,B;
1<=N<=20;
1<=A<=50;
1<=B<=50;

cin >> N;
cin >> A;
cin >> B;
if(N*A<B){
cout << N*A << endl;
}else {
cout << B << endl;
}




  
return 0;
  
}  

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

using ll = long long;

const int N = 5e5 + 9, M = N * 20;
int n, lim, t, v, sum;
double pp;

struct pii {
	double t, sum;
	int v;
	pii (double t, double sum, int v) : t(t), sum(sum), v(v) {}
};
deque<pii>Q;

int main () {
	scanf("%d%d", &n, &lim);
	for (int i = 1, j; i <= n; ++i) {
		scanf("%d%d", &t, &v);
		while (!Q.empty() && sum + v > lim) {
			sum -= (j = min(sum - (lim - v), Q.front().v));
			Q.front().v -= j; pp -= Q.front().t * j;
			if (!Q.front().v) Q.pop_front();
		}
		Q.push_back(pii(t, 1.0 * t * v, v)); sum += v; pp += Q.back().sum;
		while (sum != Q.back().v) {
			pii b = Q.back(); Q.pop_back(); pii &a = Q.back();
			if (a.t > b.t) a.t = (a.t * a.v + b.t * b.v) / (a.v + b.v), a.v += b.v, a.sum += b.sum;
			else {
				Q.push_back(b);
				break ;
			}
		}
		printf("%.7f\n", pp / lim);
	}
	return 0;
}

Measured memory_bytes: 21136
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001
#define mod 1000000007

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    char s[max];
    
    scanf("%s", s);
    
    if (s[strlen(s)-1]=='s') {
        printf("%ses", s);
    } else {
        printf("%ss", s);
    }
    
    return 0;
}


Measured memory_bytes: 1732
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> X(n);
    for (int i = 0; i < n; ++i) {
        cin >> X[i];
    }

    long long res = 0;
    int mx = 0;
    for (auto x : X) {
        res += x;
        mx = max(mx, x);
    }
    res -= mx / 2;

    cout << res << '\n';
    
    return 0;
}

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

#define REP(w, n) for(int w=0;w<int(n);++w)

int main() {
    int n, k; cin >> n >> k;
    int h[n]; REP(i, n) cin >> h[i];

    int res = 0;
    REP(i, n) {
        if (h[i] >= k) res += 1;
    }

    cout << res << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

const ll INF = (1ll<<60);
ll dp[20202];

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

    ll H, N;
    cin >> H >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    REP(i, 20202) dp[i] = INF;
    dp[0] = 0;

    REP(i, 20202){
    	REP(j, N){
    		if(i+A[j]<20202) dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j]);
    	}
    }

    ll mi = INF;
    for(int i=H;i<20202;i++){
    	chmin(mi, dp[i]);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
 
int parent[N];
 
int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 
 
ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}
 
int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}
 
void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}
 
ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}
 
int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n, INT_MAX);
    for(int i=0;i<n;i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2;i<n;i++) {
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
    }
    cout << dp[n-1] << endl;
    return;
} 
 
int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) 
    solve();
    return 0; 
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 11;
const int MAX_Q = 55;
int a[MAX_Q];
int b[MAX_Q];
int c[MAX_Q];
int d[MAX_Q];

int N, M, Q;
int A[MAX_N];
ll ans = 0;

void dfs(int depth, int L) {
  if (depth == N) {
    ll val = 0;
    REP(i, Q) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        val += d[i];
      }
    }

    chmax(ans, val);
    return;
  }

  for (int v = L; v <= M; v++) {
    A[depth] = v;
    dfs(depth+1, v);
  }
}

int main2() {
  N = nextInt();
  M = nextInt();
  Q = nextInt();
  REP(i, Q) {
    a[i] = nextInt() - 1;
    b[i] = nextInt() - 1;
    c[i] = nextInt();
    d[i] = nextInt();
  }
  ans = 0;
  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3768
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int A[101] = {0};
  int costl = 0, costr = 0;
  int n, m, x;
  cin >> n >> m >> x;
  int a[101];
  for (int i = 0; i < m; i++) cin >> a[i];
  for (int i = 0; i < m; i++) A[a[i]] = 1;

  for (int i = 0; i <= x; i++) costl += A[i];
  for (int i = x; i <= n; i++) costr += A[i];

  if (costl <= costr) cout << costl << endl;
  else cout << costr << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<sstream>
#include<stack>
#include<cstdlib>
using namespace std;
bool str_isdigit(std::string &str){
	int len = str.length();
	bool dot=false;
	if(len==0) return false;
	else{
		int i=0;
		if(str[0] == '-' || str[0] == '+'){
			if(1 == len) return false;////
			i++;
		}
		for(;i<len;i++){
			if(i>0 && str[i] == '.'){
				if(dot==false)
					dot=true;
				else
					return false;
			}
			if('9' < str[i] || str[i] < '0') return false;
		}
	}
	return true;
}

double gyakupo(double a, double b, char ch){
	if(ch == '+') return a+b;
	if(ch == '-') return a-b;
	if(ch == '*') return a*b;
	if(ch == '/'){
		if(b==0.0)return -1;
		else return a/b;
	}
	return a;
}

int main(){
	stack<double> stk;
	double left, right;
	char ope;
	string str;
	stringstream ss;
	while(true){
		getline(cin, str);
		if(cin.eof()==true) break;
		ss.clear(stringstream::goodbit);
		ss<<str;
		while(ss.eof() == false){
			ss>>str;
			if(str_isdigit(str)){
				stk.push(atof(str.c_str()));//////
			}else{
				ope=str[0];
				right=stk.top();
				stk.pop();
				left=stk.top();
				stk.pop();
				stk.push(gyakupo(left, right, ope));
				//cout<<"::"<<stk.top()<<endl;////
			}
		}
		cout<<fixed<<setprecision(6)<<stk.top()<<endl;
		while(stk.empty() == false) stk.pop();
	}
	return 0;
}

Measured memory_bytes: 1292