akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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


def main():
    a, b = map(int,input().split())
    print(len(set(prime_factorize(gcd(a, b)))) + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<stdio.h>
   
/* 配列の要素を順番に出力 */
void trace(int A[], int N){
  int i;
  for ( i=0; i < N; i++){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}
   
/* 挿入ソート(0オリジン配列) */
void insertionSort(int A[], int N){
  int j, i, v;
  for ( i = 1; i < N; i++){
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}
   
int main() {
  int N, i, j;
  int A[100];
   
  scanf("%d", &N);
  for ( i = 0; i < N; i ++ ) scanf("%d", &A[i]);
   
  trace(A, N);
  insertionSort(A, N);
   
  return 0;
}


Measured memory_bytes: 2608
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll n,i,j,k,cnt=0;
   	string s;
   	cin >> n;
   	cin >> s;
   	for(i=0;i<1000;i++) {
   		string str=to_string(i);
   		if(str.length()==1) str="00"+str;
   		else if(str.length()==2) str="0"+str;
   		j=0; k=0;
   		while(s[j]&&str[k]) {
   			if(s[j]==str[k]) {
   				k++;
   			}
   			j++;
   		}
   		if(k==str.length()) cnt++;
   	}
   	cout << cnt << "\n";
    return 0;
}



Measured memory_bytes: 384
import Data.List

xs :: [String]
xs = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "1"]

main :: IO ()
main = do
    [ia, ib] <- map (\e -> elemIndex e xs) <$> words <$> getLine
    putStrLn $ if ia > ib
                  then "Alice"
                  else if ia < ib
                          then "Bob"
                          else "Draw"



Measured memory_bytes: 380
#pragma GCC optimize( "Ofast" )

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int d, q, day, nw, one, two, sumc = 0;
vector< int > c( 30 ), t( 400 );
vector< vector< int > > arr( 400, vector< int >( 30, 0 ) );

int three( void )
{
	vector< int > last( 30, 0 );
	int ans = 0, res = 0;
	for( int i = 1; i <= d; ++i )
	{
		res -= c[ t[ i ] ] * last[ t[ i ] ];
		last[ t[ i ] ] = i;
		res += c[ t[ i ] ] * last[ t[ i ] ];
		ans += res;
	}
	return ans;
}

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

	cin >> d;
	for( int i = 1; i <= 26; ++i )
	{
		cin >> c[ i ];
		sumc += c[ i ];
	}
	for( int i = 1; i <= d; ++i )
	{
		for( int j = 1; j <= 26; ++j )
		{
			cin >> arr[ i ][ j ];
		}
	}
	for( int i = 1; i <= d; ++i )
	{
		cin >> t[ i ];
		one += arr[ i ][ t[ i ] ];
	}
	two = sumc * ( d * ( d + 1 ) ) / 2;
	cin >> q;
	for( int i = 1; i <= q; ++i )
	{
		cin >> day >> nw;
		one -= arr[ day ][ t[ day ] ];
		t[ day ] = nw;
		one += arr[ day ][ t[ day ] ];
		cout << one - two + three() << "\n";
	}
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;++i) cin >> v[i];
  auto a = max_element(v.begin(),v.end());
  auto b = min_element(v.begin(),v.end());

  cout << *a-*b << endl;

  return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int L, R;
    vector<int> m;
    long long int l = 10000000;
    cin >> L >> R;
    if (R - L >= 2018) {
        cout << 0 << endl;
        return 0;
    }
    for (long long int i = L; i <= R; i++) {
        for (long long int j = i - 1; j >= L; j--) {
            l = min(((i * j) % 2019), l);
        }
    }
    cout << l << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;
  int l = s.length();
  int ans = 0;
  for(int i = 0; i < l; i++) {
    for(int j = 1; j < l - i + 1; j++) {
      string t = s.substr(i, j);
      bool eligible = true;
      rep(k, t.length()) {
        if (!(t[k] == 'A' || t[k] == 'T' || t[k] == 'C' || t[k] == 'G')) {
          eligible = false;
        }
      }
      if (eligible) {
        int len = t.length();
        ans = max(ans, len);
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();

    for(int i=0 ; i<10 ; i++){
      x = x*r - D;
      System.out.println(x);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>



using namespace std;

int main()
{
	int n, k, i, j;
	
	cin >> n >> k;
	
	if (k > (((n-1)*(n-2)) / 2))
	{
		cout << -1;
		return 0;
	}
	
	cout << (((n*(n-1)) / 2) - k) << endl;
	
	int cur_k = 0, cur_v = 1, cur_deg = n-1;
	
	while (cur_deg <= k)
	{
		k = k - cur_deg + 1;
		--cur_deg;
		++cur_v;
	}
	cur_deg-=k;
	
	for (i = 1; i < cur_v; ++i)
	{
		cout << i << " " << n << endl;
	}
	
	for (i = cur_v; i < n; ++i)
	{
		for (j = n-cur_deg+1; j <=n; ++j)
		{
			cout << i << " " << j << endl;
		}
		cur_deg = n - i - 1;
	}

	
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int knap[1001];
int main(){
    int size, n, w, v, test = 0;
    while(1){
        cin >> size;
        if(size==0) break;
        test++;
        cin >> n;
        fill(knap, knap+size+1, 0);
        for(int i=0; i<n; i++){
            scanf("%d,%d", &v, &w);
            for(int j=size-w; j>=0; j--){
                knap[j+w] = max(knap[j+w], knap[j]+v);
            }
        }
        int ansW = 0;
        int ansV = 0;
        for(int i=0; i<=size; i++){
            if(knap[i] > ansV){
                ansV = knap[i];
                ansW = i;
            }
        }
        cout << "Case " << test << ":" << endl;
        cout << ansV << endl;
        cout << ansW << endl;
    }

}

Measured memory_bytes: 1248
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            String[] S = new String[N];
            for (int i = 0; i < N; i++) {
                S[i] = sc.next();
            }

            HashSet<String> set = new HashSet<String>();
            for (int i = 0; i < N; i++) {
                set.add(S[i]);
            }
            System.out.println(set.size());
        }
    }
}


Measured memory_bytes: 71116
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main(){
  string s;
  cin >> s;
  
  vector<int> nums;
  for (int i=0; i<s.length(); i++) nums.push_back(s[i] - '0');
  int sum, tmp;
  string tmps;
  for (int i=0; i<(1 << (nums.size() - 1)); i++) {
    sum = nums[0];
    tmps = s[0];

    for (int k=0; k<nums.size()-1; k++) {
      if (i & (1 << k)) {
        sum += nums[k+1];
        tmps += "+" + to_string(nums[k+1]);
      } else {
        sum -= nums[k+1];
        tmps += "-" + to_string(nums[k+1]);
      }
    }
    
    if (sum == 7) {
      cout << tmps << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
# coding=utf-8

n, m = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in xrange(n)]
b = [input() for _ in xrange(m)]
Ab = [sum([A[i][j] * b[j] for j in xrange(m)]) for i in xrange(n)]
for x in Ab:
    print x

Measured memory_bytes: 4560
#include<stdio.h>

int n, A[50];

// ??\?????????M???????????????????´????????????????????????°??¢??°
int solve (int i, int m) {
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main() {
  int q, M, i;

  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &M);
    if (solve(0, M))printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

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

class DisjointSet {
public:
    vector<int> p, rank;

    DisjointSet(int n) {
        p.resize(n, 0);
        iota(p.begin(), p.end(), 0);
        rank.resize(n, 0);
    }

    int root(int x) {
        return (p[x] == x ? x : root(p[x]));
    }

    bool same(int x, int y) {
        return (root(x) == root(y));
    }

    void unite(int x, int y) {
        int xroot = root(x), yroot = root(y);
        if (rank[xroot] < rank[yroot]) {
            p[xroot] = yroot;
        } else {
            p[yroot] = xroot;
            if (rank[xroot] == rank[yroot]) rank[xroot] ++;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n, q, com, x, y;
    cin >> n >> q;

    DisjointSet obj(n);
    while (q --) {
        cin >> com >> x >> y;
        if (com == 0) {
            obj.unite(x, y);
        } else {
            cout << (int)obj.same(x, y) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1288
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <cassert>
#include <algorithm>
using namespace std;

const int Maxn = 4005;
const int Inf = 1000000000;

string A, B;
int n;
int L[Maxn], R[Maxn];
int cnt[Maxn][Maxn];
int flip[Maxn];
int res = 1000000000;

int getChanges(int p)
{
	int res = 0;
	for (int i = 0; i < n; i++)
		res += A[i] != B[(p + i) % n];
	return res;
}

int main()
{
	cin >> A;
	cin >> B;
	n = A.length();
	if (B == string(n, '0')) {
		if (A == string(n, '0')) printf("0\n");
		else printf("-1\n");
		return 0;
	}
	for (int i = 0; i < n; i++)
		flip[i] = getChanges(i);
	int was = 0;
	for (int i = 0; i < n; i++)
		if (B[i] == '1') was = 0;
		else was++;
	for (int i = 0; i < n; i++) {
		if (B[i] == '1') was = 0;
		else was++;
		if (A[i] == '1') L[i] = was;
	}
	was = 0;
	for (int i = n - 1; i >= 0; i--)
		if (B[i] == '1') was = 0;
		else was++;
	for (int i = n - 1; i >= 0; i--) {
		if (B[i] == '1') was = 0;
		else was++;
		if (A[i] == '1') R[i] = was;
	}
	int need = 0;
	for (int i = 0; i < n; i++)
		if (A[i] == '1') {
			need++;
			cnt[L[i]][0]++; cnt[0][R[i]]++;
			cnt[L[i]][R[i]]--;
		}
	for (int l = 0; l < Maxn; l++) {
		int bestL = Inf, bestR = Inf;
		for (int i = 0; i <= l; i++) {
			bestL = min(bestL, l - i + flip[(n - i % n) % n]);
			if (i > 0) bestR = min(bestR, i - 1 + flip[(n - i % n) % n]);
		}
		for (int r = 0; r < Maxn; r++) {
			bestL = min(bestL, l + r + flip[r % n]);
			bestR = min(bestR + 1, flip[r % n]);
			if (cnt[l][r] == need)
				res = min(res, min(2 * l + r + bestR, 2 * r + l + bestL));
			if (l + 1 < Maxn) cnt[l + 1][r] += cnt[l][r];
			if (r + 1 < Maxn) cnt[l][r + 1] += cnt[l][r];
			if (l + 1 < Maxn && r + 1 < Maxn) cnt[l + 1][r + 1] -= cnt[l][r];
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 62976
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,mx,ans,i,h;
	scanf("%d",&n);
	mx=0;ans=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&h);
		if(h>=mx)ans++;
		mx=max(mx,h);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  string s,t;cin>>s>>t;
  int res=0;
  int n=s.length();
  rep(i,n){
    if(s[i]!=t[i])++res;
  }
  cout<<res<<"\n";
  
  return 0;
}


Measured memory_bytes: 3912
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    a.clear();
    a.resize(n,-1);
    cin>>m;
    while(m--)
    {
        lli p,v;
        cin>>p>>v;
        p--;
        if(a[p]==-1||a[p]==v)
            a[p]=v;
        else
        {
            cout<<-1<<endl;
            return 0;
        }
    }

    if(sz(a)==1)
    {
        if(a[0]==-1)
            a[0]=0;
    }

    if(sz(a)>1&&a[0]==0)
    {
        cout<<-1<<endl;
        return 0;
    }

    if(a[0]==-1)
        a[0]=1;
    for(auto &x:a)
        if(x==-1)
            x=0;
    for(auto &x:a)
        cout<<x;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x[100001],y,z,h,w,k,sum,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


int main(void){
    cin>>n>>k;
    rep(i,n)cin>>x[i];
    //右を全部使う場合から左を全部使う場合まで全探索
    //端の位置がわかればO(1)で最小距離が求まる
    rep(i,n)if(x[i]>=0){itr=i;break;}
    if(x[n-1]<0)itr=n;
    if(itr+k-1<=n-1)mi=min(mi,x[itr+k-1]);
    if(itr-k>=0)mi=min(mi,-1*x[itr-k]);
    rep(i,k-1){
        if(itr+k-i-2>n-1)continue;
        if(itr-i-1<0)continue;
        mi=min(mi,min(x[itr+k-i-2]*2-x[itr-i-1],x[itr+k-i-2]-2*x[itr-i-1]));
    }
    p(mi);
    return 0;
}


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

char land[20][20];

void dfs(int y, int x) {
   land[y][x] = '0';
   if (y > 0 && land[y-1][x] == '1') dfs(y-1, x);
   if (x > 0 && land[y][x-1] == '1') dfs(y, x-1);
   if (y < 11 && land[y+1][x] == '1') dfs(y+1, x);
   if (x < 11 && land[y][x+1] == '1') dfs(y, x+1);
   return;
}

int main() {
   while (scanf("%s", land[0]) != EOF) {
      int cnt = 0;
      for  (int i = 1; i < 12; i++) {
         scanf("%s", land[i]);
      }

      for (int i = 0; i < 12; i++) {
         for (int j = 0; j < 12; j++) {
            if (land[i][j] == '1') {
               cnt++;
               dfs(i, j);
            }
         }
      }

      printf("%d\n", cnt);
   }

   return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int sum = 0;
		while(scan.hasNext()){
			String[] str = scan.nextLine().split("[^0-9]+");
			for(int i = 0 ;i < str.length;i++){
				if(!str[i].equals(""))
				sum += Integer.parseInt(str[i]);
			}
		}
		scan.close();
		System.out.println(sum);
	}
}

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

const int MOD = 1e9+7;

int main()
{
    int h, w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    int dp[h][w];
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(i == 0 && j == 0) {
                dp[i][j] = 1;
                continue;
            }
            else {
                dp[i][j] = 0;
            }
            if(a[i][j] == '.') {
                dp[i][j] = ((long long)(i > 0 ? dp[i-1][j] : 0) + (j > 0 ? dp[i][j-1] : 0))%MOD;
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 5120
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


a, b, k = list(map(int, input().split()))

div = []
tmp = 0
for i in range(1,200):
    if a % i == 0 and b % i == 0:
        div.append(i)
print(div[-k])

Measured memory_bytes: 3064
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    vector<int> x(n);
    rep(i, n) {
        cin >> x[i];
    }
    int ans = INF;
    for(int p = 0; p <= 100; ++p) {
        int res = 0;
        rep(i, n) {
            res += (x[i] - p) * (x[i] - p);
        }
        chmin(ans, res);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'

int n, m, x;
VI v(1000);

signed main()
{
    cin >> n >> m >> x;
    v.resize(m);
    REP(i, m){
        cin >> v[i];
    }

    int index = (int)(lower_bound(ALL(v), x) - v.begin());
    cout << min(m-index, index) << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



i64 n, m, a[101010], d[101010];
void solve(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 0; i < n; i++){
		d[i+1] = d[i]+a[i];
	}
	
	i64 l = 0, r = INF;
	while(r-l > 1){
		i64 c = (l+r)/2;
		i64 cnt = 0;
		for(int i = 0; i < n; i++){
			cnt += a + n - lower_bound(a,a+n,c-a[i]);
		}
		if(cnt > m) l = c;
		else r = c;
	}
	i64 ans = 0, cnt = 0;
	for(int i = 0; i < n; i++){
		i64 s = lower_bound(a,a+n,r-a[i]) - a;
		cnt += n - s;
		ans += (d[n] - d[s]) + a[i]*(n-s);
	}
	cout << ans + (m-cnt)*l << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll N;
// cnt: 何文字目か
// i: 最後から1文字
// j: 最後から2文字
// k: 最後から3文字
ll dp[110][4][4][4];

int main() {
    cin >> N;
    dp[0][3][3][3] = 1;

    for (int cnt = 0; cnt < N; cnt++) {
        // 最後から1文字目
        for (int i = 0; i < 4; i++) {

            // 最後から2文字目
            for (int j = 0; j < 4; j++) {

                // 最後から3文字目
                for (int k = 0; k < 4; k++) {
                    if (dp[cnt][i][j][k] == 0) continue;

                    // 遷移
                    for (int a = 0; a < 4; a++) {

                        // 弾く
                        if (a == 2 && i == 1 && j == 0) continue;
                        if (a == 1 && i == 2 && j == 0) continue;
                        if (a == 2 && i == 0 && j == 1) continue;
                        if (a == 2 && i == 1 && k == 0) continue;
                        if (a == 2 && j == 1 && k == 0) continue;

                        dp[cnt + 1][a][i][j] += dp[cnt][i][j][k];
                        dp[cnt + 1][a][i][j] %= MOD; 
                    }
                }
            }
        }
    }

    // N 文字目でみた場合の数を足しこむ
    ll ans = 0;
    rep(i, 4)rep(j, 4)rep(k, 4) {
        ans += dp[N][i][j][k];
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int w, h ,x, y;

int main(){
    scanf("%d%d%d%d", &w, &h, &x, &y);
    printf("%.9f %d\n", (double)w*h/2, (x*2 == w && y*2 == h ? 1 : 0));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vll a(m);
  ll s = 0;
  re(i, m){
    std::cin >> a[i];
    s += a[i];
  }
  if(s>n) std::cout << -1 << '\n';
  else std::cout << n - s << '\n';
  return 0;
}


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

int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        ans += b - a + 1;
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    vector<int> a(n);
    for(auto &i:a) cin >> i;
    sort(a.begin(),a.end());
    rep(i,n-1){
        if(a[i]==a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n;
    cin>>n;
    vector<vector<int>>d(n,vector<int>(n));
    rep(i,n)rep(j,n)d[i][j]=-1;
    rep(i,n){
        int a;
        cin>>a;
        rep(j,a){
            int x,y;
            cin>>x>>y;
            x--;
            d[i][x]=y;
        }
    }
    int ans=0;
    rep(i,1<<n){
        bool ok=true;
        vector<int>h(n);
        rep(j,n){
            if(i>>j&1)h[j]=1;
        }
        rep(j,n){
            if(h[j]==1){
                rep(k,n){
                    if(d[j][k]==-1)continue;
                    if(d[j][k]!=h[k])ok=false;
                }
            }
        }
        int cnt=0;
        rep(j,n)if(i>>j&1)cnt++;
        if(ok)ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    char s[h][w];
    int ans[h][w] = {};
    int ans2[h][w] = {};
    int imos = 0;
    bool flg = false;
    int sub = 0;
    int max = -10000;

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

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '.') {
                if (flg) {
                    imos++;
                }
                else {
                    sub = j;
                    flg = true;
                    imos++;
                }
            }
            else if (flg == true) {
                ans[i][j] = -imos;
                ans[i][sub] = imos;
                flg = false;
                imos = 0;
            }
            else {
                ans[i][j] = 0;
                imos = 0;
                flg = false;
            }
        }
        if (flg) {
            ans[i][sub] = imos;
        }
        flg = false;
        imos = 0;
        for (int j = 1; j < w; j++) {
            ans[i][j] += ans[i][j-1];
        }
    }

    flg = false;
    imos = 0;

    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            if (s[j][i] == '.') {
                if (flg) {
                    imos++;
                }
                else {
                    sub = j;
                    imos++;
                    flg = true;
                }
            }
            else if (flg == true) {
                ans2[sub][i] = imos;
                ans2[j][i] = -imos;
                flg  = false;
                imos = 0;
            }
            else {
                ans2[j][i] = 0;
                flg = false;
                imos = 0;
            }
        }
        if (flg) {
            ans2[sub][i] = imos;
        }
        imos = 0;
        flg = false;
        for (int j = 1; j < h; j++) {
            ans2[j][i] += ans2[j-1][i];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (max < ans[i][j]+ans2[i][j]-1) {
                max = ans[i][j]+ans2[i][j]-1;
            }
        }
    }
    cout << max << endl;
}



Measured memory_bytes: 35456
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	int n;
	int d[100];
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &d[i]);
	}
	sort(d, d + n);
	int cnt = 0, bef = -1;
	for(int i = 0; i < n; i++){
		if(d[i] == bef)
			continue;
		cnt++;
		bef = d[i];
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] x = new int[m];
      for (int i = 0; i < m; i++) {
        x[i] = sc.nextInt(); 
      }
      Arrays.sort(x);
      int[] sum = new int[m-1];
      for (int i = 0; i < m - 1; i++) {
        sum[i] = x[i+1]-x[i];
      }
      Arrays.sort(sum);
      int ans = 0;
      for (int i = 0; i < m - n; i++) {
          ans += sum[i];
      }
    System.out.println(ans);
    }
  }

Measured memory_bytes: 48600
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,n;
    cin>>n;
    bool flag=false;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                flag=true;
                break;
            }
        }

    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
srt=sorted(a)
b=[]
for i in range(n):
  b.append(srt.index(a[i]))
ans=0
for j in range(n):
  ans+=((b[j]+b[j]*k)*k//2)%mod
res=0
for ii in range(n):
  for ij in range(ii+1):
    if a[ii]>a[ij]:
      res+=1
print((ans-res*k)%mod)

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n,k;
 	cin>>n>>k;
 	set<ll>st;
 	for(ll i=0;i<k;i++)
 	{
 		ll x;
 		cin>>x;
 		for(ll j=0;j<x;j++)
 		{
 			ll y;
 			cin>>y;
 			st.insert(y);
 		}
 	}
 	cout<<n-st.size()<<endl;
    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans=0;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for(int i=0; i<k; i++){
        ans += l[n-1-i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }

        long total = (long)n * (long)(n+1) / 2L;
        if(sum % total != 0){
            System.out.println("NO");
            return;
        }

        if(n == 1){
            System.out.println("YES");
            return;
        }

        int [] d = new int[n];
        int num = (int)(sum / total);

        d[0] = a[0] - a[n-1] - num;
        for(int i=1; i<n; i++){
            d[i] = a[i] - a[i-1] - num;
        }

        int sum2 = 0;
        for(int i=0; i<n; i++){
            if(d[i] % (n) != 0 || d[i] > 0){
                System.out.println("NO");
                return;
            }
            sum2 += d[i] / n;
        }

        if(sum2 + num == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }

}

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

using namespace std;

int main(){
	int w=0,e=0,w2=0,e2=0,N,a=300000;
	string S;
	cin >> N;
	cin >> S;
	for(int i=0;i<N;i++){
		if(S[i]=='W'){w++;}
		else{e++;}
	}
	if(S[0]=='E'){
		if(a>(w2+e-e2-1)){
			a=(w2+e-e2)-1;
		}
	}else{
		if(a>w2+e-e2){
			a=w2+e-e2;
		}
	}
	for(int i=1;i<N;i++){
		if(S[i-1]=='W'){w2++;}
		else{e2++;}
		if(S[i]=='E'){
			if(a>(w2+e-e2-1)){
				a=(w2+e-e2)-1;
			}
		}else{
			if(a>w2+e-e2){
				a=w2+e-e2;
			}
		}
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
const int MOD=1e9+7;
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define ci cout<<"impossible\n"
typedef unsigned long long int ull;
typedef long long int ll;
const int MAX=500005;
ll ar[MAX],br[MAX];
const int M=1e4;
ll cnt[M];
int main()
{
    string s,t;
    ll n;
    cin>>n;
    if(n==1)
        cout<<0<<endl;
    else
        cout<<1<<endl;
}




Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  int k = in();
  vector<int> cnt(n,0);
  rep(i,k){
    int d = in();
    rep(j,d){
      ++cnt[in()-1];
    }
  }
  int ans = 0;
  foreach(i,cnt)if(i==0)++ans;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3692
n = int(input())
x = list(map(int, input().split()))

ave = sum(x)/n
y0 = int(ave)
z0 = sum([(i-y0)**2 for i in x])
y1 = y0+1
z1 = sum([(i-y1)**2 for i in x])

print(min(z0, z1))

Measured memory_bytes: 3316
N = int(input())
B = list(map(int, input().split()))
A_max = list()
for i in range(len(B)+1):
    if i == 0:
        A_max.append(B[i])
    elif i == len(B):
        A_max.append(B[-1])
    else:
        A = min([B[i], B[i-1]])
        A_max.append(A)

print(sum(A_max))

Measured memory_bytes: 3064
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define MAXN 52
#define MAXM 1300

vector <int> g[MAXN];
char viz[MAXN];
int leg[MAXM][3];
void dfs(int nod){
  viz[nod]=1;
  for(int i=0; i<g[nod].size(); i++){
    int it=g[nod][i];
    if(viz[it]==0)
      dfs(it);
  }
}
int main(){
//  FILE*fin=fopen("c.in", "r");
  FILE*fin=stdin;
  int n, m, i, j, k, x, y, cnt, nr;
  fscanf(fin, "%d%d", &n, &m);
  for(i=1; i<=m; i++)
    fscanf(fin, "%d%d", &leg[i][1], &leg[i][2]);
  nr=0;
  for(k=1; k<=m; k++){
    for(i = 1; i <= m; i++) {
      x=leg[i][1]; y=leg[i][2];
      if(i!=k){
        g[x].push_back(y);
        g[y].push_back(x);
      }
    }
    cnt=0;
    for(i=1; i<=n; i++){
      if(viz[i]==0){
        dfs(i);
        cnt++;
      }
    }
    if(cnt!=1)
      nr++;
//    for(i=1; i<=n; i++)
//      if(viz[i]==0)
//        cnt++;
    for(i=1; i<=n; i++){
      viz[i]=0;
      while(!g[i].empty())
        g[i].pop_back();
    }
  }
  printf("%d", nr);
  return 0;
}


Measured memory_bytes: 256
class BIT:
    def __init__(self, n):
        self.bit = [ 0 for _ in range(n+1) ]

    def add(self, x, w):
        i = x
        while i < len(self.bit)-1:
            self.bit[i] += w
            i |= (i+1)

    def sum_(self, x):
        ret, i = 0, x-1
        while i >= 0:
            ret += self.bit[i]
            i = (i & (i+1)) - 1

        return ret

    def sum(self, l, r):
        return self.sum_(r) - self.sum_(l)


n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]

tree = BIT(n)
for i in range(n):
    tree.add(i, (p[i] + 1) / 2)

ans = 0
for i in range(n-k+1):
    ans = max(ans, tree.sum(i, i+k))

print(ans)

Measured memory_bytes: 25372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n;
    int ans=0;
    for(int i=0;i<n;i++){
        cin >> a;
        ans+=a;
    }
    if(ans%2==0){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
using namespace std;

const int mod = 2019;

int main() {
	string S;
	cin >> S;
	int digit = S.size();
	//小さな位から見るため、文字列を反転
	reverse(S.begin(), S.end());
	int x = 1; //位取り
	int sum = 0; //累積和
	long long ans = 0;
	vector<int> cnt(mod, 0); //累積和の登場回数
	for (int i = 0; i < digit; i++) {
		cnt[sum]++;
		sum += (S[i] - '0')*x;
		sum %= mod;
		ans += cnt[sum];
		x = x * 10 % mod; //位を更新
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string a,b,c;
    cin>>a>>b>>c;
    cout<<'A'<<b[0]<<'C'<<endl;
    return 0;
}


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

using namespace std ;




int main()
{
    string s;
    cin >> s ;
    long long int n= s.size() ,i , c=0 ,ans=0;

    for ( i=0;i<n;i++){
        if (s[i]=='B')
            c++;
        else
            ans+=c;
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int N, A, B;
  int res=0;
  cin >> N >> A>> B;
  res = min(N*A,B);
  cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int md=1000000007;
int n,m,i,j,k,g[1000],f[40000],num[40000],w[40000],u[40000],pw2[1000];
int main()
{
	scanf("%d%d",&n,&m);
	pw2[0]=1;
	for(i=1;i<=m;++i)
		pw2[i]=pw2[i-1]*2%md;
	for(i=1;i<(1<<n);++i)
		num[i]=num[i^(i&-i)]+1;
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&j,&k);
		g[j-1]|=1<<(k-1);
	}
	f[0]=1;
	for(i=1;i<(1<<n);++i)
	if((i&1)==(i>>1&1))
	{
		for(j=i;j>0;j=(j-1)&i)
		{
			w[j]=u[j]=1;
			for(k=0;k<n;++k)
				if(j>>k&1)
				{
					w[j]=1ll*w[j]*pw2[num[g[k]&(i^j)]]%md;
					u[j]=1ll*u[j]*(pw2[num[g[k]&(i^j)]]-1+md)%md;
				}
		}
		f[i]=1;
		for(j=(i-1)&i;j>0;j=(j-1)&i)
			f[i]=(f[i]+1ll*f[i^j]*w[j]%md*u[i^j]%md)%md;
	}
	printf("%d",(pw2[m]-f[(1<<n)-1]+md)%md);
	return 0;
}


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

typedef struct TEAM{
  int id, t, c, p;
  int w[10];
}team;

bool mycomp(const team &a, const team &b){
  if(a.c>b.c)return true;
  if(a.c<b.c)return false;
  if(a.t<b.t)return true;
  if(a.t>b.t)return false;
  return a.id>b.id;
}

string into(int x){
  string ret="";
  stack<int> st;
  while(x!=0){st.push(x%10); x/=10;}
  while(!st.empty()){ret+=(st.top()+'0'); st.pop();}
  return ret;
}

string solve(vector<team> lst){
  for(int i=0; i<lst.size(); i++)
    lst[i].t+=lst[i].p*20;
  sort(lst.begin(), lst.end(), mycomp);
  string ret="";
  ret+=into(lst[0].id);
  for(int i=1; i<lst.size(); i++){
    if(lst[i].t==lst[i-1].t)ret+='=';
    else ret+=',';
    ret+=into(lst[i].id);
  }
  //  printf("[0]=%d [1]=%d\n", lst[0].t, lst[1].t);
  return ret;
}

int main(){
  int M, T, P, R;
  while(true){
    cin>>M>>T>>P>>R;
    if(M==0&&T==0&&P==0&&R==0)break;
    vector<team> lst;
    for(int i=0; i<T; i++){
      team tmp;
      tmp.id=i+1; tmp.t=0; tmp.c=0; tmp.p=0;
      memset(tmp.w, 0, sizeof(tmp.w));
      lst.push_back(tmp);
    }
    for(int i=0; i<R; i++){
      int m, t, p, j;
      cin>>m>>t>>p>>j;
      if(j==0){
        lst[t-1].c++;
        lst[t-1].t+=m;
        lst[t-1].p+=lst[t-1].w[p-1];
      }
      else{
        lst[t-1].w[p-1]++;
      }
    }
    cout<<solve(lst)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
object Main extends App {
  val n = io.StdIn.readLine().toInt
  val tuple = 1.to(n).map(x => {
    var res = 0
    var z = x
    while (z % 2 == 0) {
      z = z / 2
      res += 1
    }
    (res, x)
  }).max
  println(tuple._2)
}

Measured memory_bytes: 25524
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

typedef pair<int, int> P;

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    P city[M];
    P city_saved[M];
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &city[i].first, &city[i].second);
        city_saved[i].first = city[i].first;
        city_saved[i].second = city[i].second;
    }

    sort(city, city + M);

    int now_pref = city[0].first;
    int count = 0;
    map<int, string> id;
    for (int i = 0; i < M; i++) {
        if (now_pref != city[i].first) count = 0;
        count++;
        ostringstream pref, order;
        pref << setw(6) << setfill('0') << city[i].first;
        order << setfill('0') << setw(6) << count;
        // cout << pref.str() << order.str() << endl;
        id[city[i].second] = pref.str() + order.str();
        now_pref = city[i].first;
    }
    for (int i = 0; i < M; i++) {
        cout << id[city_saved[i].second] << endl;
    }

    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        String result = "error";
        if (a+b < 10) result = String.valueOf(a+b);
        
        System.out.println(result);
    }
}


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

void Solve()
{
	int n;
	cin >> n;
	vector<int> a, b;
	int buf;
	for (auto i = 1; i <= n + 1; ++i) {
		cin >> buf;
		a.push_back(buf);
	}
	for (auto i = 1; i <= n; ++i) {
		cin >> buf;
		b.push_back(buf);
	}
	auto count = 0LL;
	int r = 0;
	for (auto i = 0; i != n; ++i) {
		count += min(a[i], r);
		int m = max(a[i] - r, 0);
		count += min(m, b[i]);
		r = max(b[i] - m, 0);
	}
	count += min(a[n], r);
	cout << count << endl;
}

int main()
{
	Solve();
	return 0;
}


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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
#define mp make_pair
#define pb push_back
# define PI acos(-1)
# define double long double
const int MxN = 200005 ; 


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	ll n ;
	cin >> n ; 
	if(n % 2 != 0)
		cout << 0 ; 
	else {
		ll ans = 0 ;
		ll num = 10 ; 
		while(num <= n) {
			ans += n / num ; 
			num *= 5 ; 
		}
		cout << ans ; 
		
	}
	
	return 0 ; 
}



Measured memory_bytes: 3508
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

int main() {
    //ifstream cin("input.txt");
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;   
    cout << (sz(s) < 4 || s.substr(0, 4) != "YAKI" ? "No\n" : "Yes\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d", &n);
    int arr[200]={0};
    for(int i=0;i<n;i++){
        int x=0;
        int sum=0;
        scanf("%d", &x);
        while(x%2==0){
            sum+=1;
            x/=2;
        }
        arr[i]=sum;
    }
    sort(&arr[0],&arr[n]);
    printf("%d", arr[0]);
}

Measured memory_bytes: 256