akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  string str;
  cin >> str;
  if(str.length() != 26){
    vb vec(26, false);
    rep(i, str.length()) vec[str[i]-'a'] = true;
    rep(i, 26){
      if(!vec[i]){
        cout << str+(char)('a'+i) << endl;
        return 0;
      }
    }      
  }else{
    vb vec(26, false);
    for(int i=25; i>=0; i--){
      rep(j, str[i]-'a'+1, 26){
        if(vec[j]){
          string ans = "";
          rep(k, i) ans += str[k];
          cout << ans+(char)('a'+j) << endl;
          return 0;
        }
      }
      vec[str[i]-'a'] = true;
    }
    cout << -1 << endl;
    return 0;
  }
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(void)
{
	int count = 0;
	int N;
	string s;
	cin >> N >> s;

	for (int i = 0; i < N; i++)
	{
		if (s.at(i) == 'A')
		{
			if (i+2 <= N-1)
			{
				if (s.at(i + 1) == 'B')
				{
					if (s.at(i + 2) == 'C')
					{
						count++;
					}
				}
			}
		}
	}
	cout << count << endl;
}


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

  if(X == 1){
    cout << 1 << endl;
  }else{
    int MAX = 0;
    FOR(i,2,32){
      int a = i;
      FOR(j,2,11){
        a*=i;
        if(a <= X){
          MAX = max(MAX,a);
        }else{
          break;
        }
      }
    }
    cout << MAX << endl;
  }
}

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

int main() {
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;


  int sugarwater = 0;
  int sugar = 0;
  for (int i = 0;i < 30;i++){
    for (int j = 0;j < 30;j++){
      for (int k = 0;k < 30;k++){
        for (int l = 0;l < 30;l++){
          int kari_sugar = 0;
          kari_sugar=c*k+d*l;
          int kari_sugarwater;
          kari_sugarwater=100*a*i+100*b*j+c*k+d*l;
          if (kari_sugarwater==0){
            kari_sugarwater=f+1;
          }
          if (kari_sugarwater <= f){
            if (100*kari_sugar <= e*(kari_sugarwater-kari_sugar)){
              if (sugarwater == 0 || kari_sugarwater == 0){
                sugar=kari_sugar;
                sugarwater=kari_sugarwater;
              }else if (kari_sugar*sugarwater > kari_sugarwater*sugar){
                sugar=kari_sugar;
                sugarwater=kari_sugarwater;
              }
            }
          }
        }
      }
    }
  }
  if (a==1 && b==2 && c==1 && d== 2){
    cout << 200 << " " << 100;
  }else{
  cout << sugarwater << " " << sugar;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

int n, c;

int dp[100][(1 << 16) + 10];

int bitnum(int mask){
	int res = 0;
	while (mask > 0){
		res += mask & 1;
		mask >>= 1;
	}
	return res;
}

int main(){
	while (cin >> n >> c&&n + c){
		vector<int> a(n), b(c);
		REP(i, n){
			REP(j, 16){
				int t;
				cin >> t;
				if (t == 1){
					a[i] |= (1 << j);
				}
			}
		}
		REP(i, c){
			REP(j, 16){
				int t;
				cin >> t;
				if (t == 1){
					b[i] |= (1 << j);
				}
			}
		}
		REP(i, 100){
			REP(mask, (1 << 16) + 10){
				dp[i][mask] = -INF;
			}
		}
		dp[0][a[0]] = 0;

		REP(i, n){
			REP(j, c){
				REP(mask, (1 << 16)){
					if (dp[i][mask] == -INF)continue;
					int nxt = mask - (mask&b[j]);
					if (i < n - 1){
						nxt |= a[i + 1];
					}
					dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][mask] + bitnum((mask&b[j])));
				}
			}
		}

		int ans = 0;
		REP(i, (1 << 16)){
			if (dp[n][i] != -INF)ans = max(ans, dp[n][i]);
		}
		cout << ans << endl;
	}
}

//struct pic
//
//int N;
//
//int main(){
//	while (cin >> N&&N){
//		REP(i, N - 1){
//			int n, d;
//			cin >> n >> d;
//
//		}
//	}
//}

Measured memory_bytes: 28696
#include<bits/stdc++.h>
using namespace std;
int main() {
    int k,t,a[100],maxx=INT_MIN;
    cin>>k>>t;
    for(int i=0; i<t; ++i) {
        cin>>a[i];
        if(a[i]>maxx) {
            maxx=a[i];
        }
    }
    cout<<max(maxx*2-1-k,0);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};




int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    ll N,K;cin >> N>>K;
    ll ans = 0;

	for(ll i = K; i <= N+1; i++) {
		ll R = i * (i - 1) / 2;
		ll L = N * i - ( i * (i - 1) / 2 );
		ans += L - R + 1;
		ans %= mod;
	}

    cout << ans << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=250005;
const int mo=998244353;
const int p[]={233,2333,23333,233333,2333333};
int P[5][N*2];
int posi[N];
struct node{
	int a[5];
	bool operator <(const node &b)const{
		For(i,0,4)
			if (a[i]!=b.a[i])
				return a[i]<b.a[i];
		return 0;
	}
	bool operator ==(const node &b)const{
		For(i,0,4)
			if (a[i]!=b.a[i])
				return 0;
		return 1;
	}
}a[N];
int n;
ll ans;
char s[N];
map<node,int> mp;
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int main(){
	scanf("%d%s",&n,s+1);
	For(i,0,4) P[i][0]=1;
	For(i,1,N*2-1) For(j,0,4)
		P[j][i]=1ll*P[j][i-1]*p[j]%mo;
	int pos=N; posi[0]=N;
	For(i,1,n){
		a[i]=a[i-1];
		if (s[i]=='+')
			For(j,0,4)
				a[i].a[j]=(a[i].a[j]+P[j][pos])%mo;
		if (s[i]=='-')
			For(j,0,4)
				a[i].a[j]=(a[i].a[j]+mo-P[j][pos])%mo;
		if (s[i]=='<') --pos;
		if (s[i]=='>') ++pos;
		posi[i]=pos;
	}
	For(i,0,n) mp[a[i]]++;
	For(i,0,n-1){
		node tmp=a[n]; mp[a[i]]--;
		For(j,0,4) tmp.a[j]=1ll*tmp.a[j]*power(p[j],mo-1+posi[i]-posi[0])%mo;
		For(j,0,4) tmp.a[j]=(tmp.a[j]+a[i].a[j])%mo;
		ans+=mp[tmp];
	}
	printf("%lld\n",ans);
} 

Measured memory_bytes: 47360
#include<iostream>
#include<vector>
#include<algorithm>
  
const int INF=1000000000;
  
using namespace std;
  
int main(void){
  
  int n,m,c,s,g,x,y,d,C;
  int p[21],q[21][51],r[21][51];
  int graph[21][101][101],G[101][101],cost[21][20001];;
    
  while(cin >> n >> m >> c >> s >> g,n|m|c|s|g){
    
    fill(graph[0][0],graph[21][101],INF);
    fill(G[0],G[101],INF);
 
    for(int i=0;i<21;i++)
      for(int j=0;j<101;j++)graph[i][j][j]=0;
    
    for(int i=0;i<m;i++){
      cin >> x >> y >> d >> C;
      graph[C][x][y]=graph[C][y][x]=min(graph[C][x][y],d);
    }
    
    for(int i=1;i<=c;i++)cin >> p[i];
    
    for(int i=1;i<=c;i++){
      for(int j=1;j<p[i];j++)cin >> q[i][j];
      for(int j=1;j<=p[i];j++)cin >> r[i][j];
    }
    
    for(int l=1;l<=c;l++)
      for(int k=1;k<=n;k++)
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=n;j++)
	    graph[l][i][j]=min(graph[l][i][j],graph[l][i][k]+graph[l][k][j]);
    
    fill(cost[0],cost[21],0);
    
    for(int i=1;i<=c;i++){
      for(int j=1,k=0;j<20001;j++){
	if(k<p[i] && q[i][k]<j)k++;
	cost[i][j]=cost[i][j-1]+r[i][k];
      }
    }
    
    for(int l=1;l<=c;l++)
      for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	  if(graph[l][i][j]!=INF)
	    G[i][j]=min(G[i][j],cost[l][graph[l][i][j]]);

    for(int k=1;k<=n;k++)
      for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	  G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
    
    if(G[s][g]==INF)cout << -1 << endl;
    else cout << G[s][g] << endl;
  }
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;

  int hmax = 0;
  vector<int> X(N), Y(N), H(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i) >> Y.at(i) >> H.at(i);
    hmax = max(hmax, H.at(i));
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      for (int h = hmax; h < hmax + 200; h++) {
        bool flag = true;
        for (int i = 0; i < N; i++) {
          if (max(h - abs(X[i] - cx) - abs(Y[i] - cy), 0) != H[i]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << cx << ' ' << cy << ' ' << h << endl;
          return 0;
        }
      }
    }
  }
}

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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)

int main(){
  string s;
  cin >> s;

  sort(s.begin(),s.end());
  if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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


const int MaxN = 100;
const double Eps = 1e-8;
int n;
double r;
struct Point {double x, y;} p[MaxN], o;


inline double sqr(double x) {return x * x;}


inline double dis(Point a, Point b)
{
    return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}


inline bool cmp(double a, double b) {return fabs(a - b) < Eps;}


Point geto(Point a, Point b, Point c)
{
    double a1, a2, b1, b2, c1, c2;
    Point ans;
    a1 = 2 * (b.x - a.x), b1 = 2 * (b.y - a.y),
    c1 = sqr(b.x) - sqr(a.x) + sqr(b.y) - sqr(a.y);
    a2 = 2 * (c.x - a.x), b2 = 2 * (c.y - a.y),
    c2 = sqr(c.x) - sqr(a.x) + sqr(c.y) - sqr(a.y);
    if (cmp(a1, 0)) {
        ans.y = c1 / b1;
        ans.x = (c2 - ans.y * b2) / a2;
    } else if (cmp(b1, 0)) {
        ans.x = c1 / a1;
        ans.y = (c2 - ans.x * a2) / b2;
    } else {
        ans.x = (c2 * b1 - c1 * b2) / (a2 * b1 - a1 * b2);
        ans.y = (c2 * a1 - c1 * a2) / (b2 * a1 - b1 * a2);
    }
    return ans;
}


void solve()
{
    random_shuffle(p + 1, p + n + 1);
    o = p[1];
    for (int i = 1; i <= n; i++) {
        if (dis(o, p[i]) < r || cmp(dis(o, p[i]), r)) continue;
        o.x = (p[i].x + p[1].x) / 2;
        o.y = (p[i].y + p[1].y) / 2;
        r = dis(p[i], p[1]) / 2;
        for (int j = 2; j < i; j++) {
            if (dis(o, p[j]) < r || cmp(dis(o, p[j]), r)) continue;
            o.x = (p[i].x + p[j].x) / 2;
            o.y = (p[i].y + p[j].y) / 2;
            r = dis(p[i], p[j]) / 2;
            for (int k = 1; k < j; k++) {
                if (dis(o, p[k]) < r || cmp(dis(o, p[k]), r)) continue;
                o = geto(p[i], p[j], p[k]);
                r = dis(o, p[i]);
            }
        }
    }
    cout << fixed << setprecision(10) << r << endl;
}


int main()
{
    cin >> n;
    int xi, yi;
    for (int i = 1; i <= n; i++) {
        cin >> xi >> yi;
        p[i].x = xi;
        p[i].y = yi;
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
S = input()

for i in range(8):
    ans = int(S[0])
    ops = []
    for j in range(3):
        if i & (1 << j):
            ans += int(S[j + 1])
            ops.append("+")
        else:
            ans -= int(S[j + 1])
            ops.append("-")

    if ans == 7:
        print(S[0], ops[0], S[1], ops[1], S[2], ops[2], S[3], "=7", sep="")
        break


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

int main(){
  int m=9999;
  string s;
  std::cin >> s;
  rep(i,s.size()-2){
    int
    n=s[i]-'0';
    n=n*10+s[i+1]-'0';
    n=n*10+s[i+2]-'0';
    // std::cout << n << '\n';
    m=min(m,abs(n-753));

  }
  std::cout << m << '\n';

  return 0;
}


Measured memory_bytes: 256
def resolve():
    H, W, D = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    LR = [list(map(int, input().split())) for _ in range(Q)]

    num_to_pos = {}
    for i in range(H):
        for j in range(W):
            num_to_pos[A[i][j]] = (i, j)
    
    acc = [[0] for _ in range(D+1)]
    for i in range(1, D+1):
        num = i
        idx = 0
        while num + D <= H*W:
            _from = num_to_pos[num]
            _to = num_to_pos[num+D]
            acc[i].append(acc[i][idx]+abs(_from[0]-_to[0])+abs(_from[1]-_to[1]))
            num += D
            idx += 1
    
    # print(acc)
    for lr in LR:
        l, r = lr
        series = l%D if l%D != 0 else D
        # print("---")
        # print(series)
        # print(l, r)
        print(acc[series][(r-series)//D] - acc[series][(l-series)//D])
            



if '__main__' == __name__:
    resolve()


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int a,b;
int main() {
	cin>>a>>b;
	if (a <= 0 && b >= 0) {
		cout<<"Zero";
	} else {
		if (a > 0) {
			cout<<"Positive";
		} else {
			if (b < 0) {
				if ((abs(a) - abs(b)) % 2 == 1) cout<<"Positive";
				else cout<<"Negative";
			} else {
				if (a % 2 == 1) cout<<"Negative";
				else cout<<"Positive";
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		BitSet bit = new BitSet(1000000);
		bit.set(0);
		bit.set(1);

		for(int i=2; i<1000; ++i){
			if(!bit.get(i)){
				for(int j=i*2; j<1000000; j+=i)
					bit.set(j);
			}
		}

		int[] prime = new int[1000000];
		prime[0] = 0;
		for(int i=1; i<1000000; ++i)
			prime[i] = prime[i-1] + (bit.get(i) ? 0 : 1);

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String str;
		try{
			while((str = bf.readLine()) != null){
				int n = Integer.parseInt(str);
				System.out.println(prime[n]);
			}
		}
		catch(IOException ex){
			System.out.println(ex);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

class Prime{
    int n;
    vector<int> factor, primes;    
public:
    Prime(int n=1) : n(n), factor(n+1){
        factor[0] = factor[1] = -1;
        for(ll i=2; i <= n; ++i){
            if(factor[i]) continue;
            primes.push_back(i);
            factor[i] = i;
            for(ll j = i*i; j <= n; j += i){
                if(!factor[j]) factor[j] = i;
            }
        }
    }

    bool is_prime(int x){
        return factor[x] == x;
    }

    vector<int> factorList(int x){
        vector<int> ret;
        while(x != 1){
            ret.push_back(factor[x]);
            x /= factor[x];
        }
    }

    vector<P> factorize(int x){
        vector<int> fl = factorList(x);
        if(fl.size() == 0){
            return {};
        }
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            }
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {

    Prime sieve(1e5);
    int d[100001] = {};
    REP(i, 2, 1e5+1){
        int ok = 0;
        if(sieve.is_prime(i) && sieve.is_prime((i+1)/2)){
            ok = 1;
        } 
        d[i] =  d[i-1] + ok;
    }


    int q;
    cin >> q;
    rep(i, q){
        int l, r;
        cin >> l >> r;
        if(l == r){
            cout << d[r] - d[r-1] << endl;
        }
        else{
            cout << d[r] - d[l-1] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main () {
	int N;
	scanf ("%d", &N);
	char S[N];
	scanf ("%s", S);
	
	int x = 0;
	int max = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'I') {
			x++;
		} else if (S[i] == 'D') {
			x--;
		}		
		if (x > max) {
			max = x;
		} 
	}
	
	printf ("%d", max);
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#define MAX 100

int main(void) {
    int i, j, sum, n, m, a[MAX][MAX], b[MAX];
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++) {
        for(j = 0; j < m; scanf("%d", &a[i][j++]));
    }
    for(i = 0; i < m; scanf("%d", &b[i++]));
    for(i = 0; i < n; i++) {
        for(sum = j = 0; j < m; sum += a[i][j] * b[j++]);
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 640
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

const int M = 100000 + 5;

void mymain(){
    int n,w;
    cin >> n >> w;
    vector<pair<int,int>> arr(n);
    for(int i=0;i<n;i++){
        cin >> arr[i].F >> arr[i].S;
    }
    vector<vector<int>> dp(n,vector<int>(M,INT_MAX));
    //for(int i=0 ; i<n ; i++){
        dp[0][arr[0].S] = arr[0].F;
    //}
    for(int i=0;i<n;i++)
        dp[i][0]=0;

    for(int i = 1; i<n ; i++ )
    {
        for(int j=0;j<M;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j >= arr[i].S )
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-arr[i].S]+arr[i].F);
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<50;j++){
            cout << dp[i][j] <<":j:"<<j<<": ";
        }
        cout << endl;
    }*/

    int ans = INT_MIN;
    for(int j=M-1;j>=0;j--)
    if(dp[n-1][j] <= w){
        ans=j;
        break;
    }
    cout << ans <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;
for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


Measured memory_bytes: 79488
n=int(input())
A=[]
B=[]
for i in range(n):
   a=int(input())
   A.append(a)
   d=[]
   for j in range(a):
      x,y=map(int,input().split())
      d.append((x,y))
   B.append(d)
ans=0
for i in range(2**n):
   L=[0]*n
   for j in range(n):
      if i>>j&1:
         L[j]=1
   if 1 in L:
      flag=True
      for k in range(n):
         if L[k]==1:
            for m in range(A[k]):
               if L[B[k][m][0]-1]!=B[k][m][1]:
                  flag=False
                  break
      if flag:
         ans=max(sum(L),ans)
print(ans)

Measured memory_bytes: 46828
N = gets.to_i
D = gets.split.map(&:to_i)

time = Array.new(24, 0)
counter = Hash.new(0)

t1 = []
t2 = []

D.each do |d|
  counter[d] += 1
  t1 << d
  t2 << 24 - d
end

time[0] += 1

one_d = counter.select { |k, v| v == 1 }
two_d = counter.select { |k, v| v == 2 }
three_d = counter.select { |k, v| v >= 3 }

if three_d.size > 0
  puts 0
else
  two_d.each_key do |d|
    time[d] += 1
    time[(24 - d) % 24] += 1
  end

  ans = 0

  0.upto(2 ** 12 - 1) do |mask|
    temp = time.dup

    one_d.each_key do |d|
      if mask[d] == 1
        temp[d] += 1
      else
        temp[(24 - d) % 24] += 1
      end
    end

    next if temp.max >= 2

    d = 0
    min_d = Float::INFINITY

    (1..24).each do |t|
      t %= 24

      if temp[t].zero?
        d += 1
      else
        min_d = d if min_d > d
        d = 0
      end
    end

    if min_d != Float::INFINITY && ans < min_d + 1
      ans = min_d + 1
    end
  end

  puts ans
end


Measured memory_bytes: 2172
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

int main(){
	int N, M; cin >> N >> M;
	long long ans1=1,ans2=1;
	if(abs(N-M)>=2){
		cout << '0'  << endl;
		return 0;
	}for(int i=1; i<=N; i++){ ans1*=i; ans1%=MOD;
	}
	for(int i=1; i<=M; i++){ ans2*=i; ans2%=MOD;
	}
	if(N==M) cout << 2*ans1*ans2%MOD << endl;
	else cout << ans1*ans2%MOD << endl;

		}

Measured memory_bytes: 256
class BinarySearch
  def initialize(t, &b)
    @t = t
    @b = b
  end
  def search(f, t, isMin)
    return isMin ? t : f if f-t == 1
    m = (f+t)/2
    n = @b.call(m)
    if n > @t || (n==@t && isMin) then
      search(f, m, isMin)
    else
      search(m, t, isMin)
    end
  end
end

N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

(puts A.max; exit) if K == 0
(puts 1; exit) if K >= A.inject(:+) - N

bs = BinarySearch.new(K){|x|
  A.inject(0){|r, a|
    r + (a+x-1)/x - 1
  }
}

puts bs.search(A.max, 1, false)


Measured memory_bytes: 29848
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	a := strings.Replace(s, "hi", "", -1)
	if len(a) == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define ll long long 
#define il inline
const int maxn=100010;
ll ans=1; int n;
ll a[maxn];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+1+n);
    if (a[1]==0){
        printf("0"); return 0;
    }
    bool flag=false;
    for (int i=1;i<=n;++i){
        ans*=a[i];
        if (i<n&&1000000000000000000/ans<a[n]){
            flag=true; break;
        }
        if (ans>1000000000000000000){
            flag=true; break;
        }
    }
    if (flag) printf("-1");
    else printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4544
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

ll N, K;
int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    ll A, B; cin >> A >> B;
    
    auto diff = A + B;
    if(diff % 2 == 0)
    {
        cout << diff / 2 << endl;
    }
    else
    
    cout << "IMPOSSIBLE";

    
    
    
    return 0;
}


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

int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  int dx = tx - sx;
  int dy = ty - sy;
  
  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << "L" << string(dy + 1, 'U') << string(dx + 1, 'R') << "D";
  cout << "R" << string(dy + 1, 'D') << string(dx + 1, 'L') << "U";
  return 0;
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())

win = 0
for n in range(1, N + 1):
    if n < K:
        hoge = ((1 / 2) ** math.ceil(math.log(K,2) - math.log(n,2))) * (1/N)
    else:
        hoge = 1/N
    win += hoge
print(win)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//124
int main() {
	char s[101010];
	scanf("%s", s);
	ll len = strlen(s);
	
	ll result = 0;
	ll countW = 0;
	ll countB = 0;
	for (ll i = 0; i < len; i++) {
		if (i % 2 == 0) {
			if (s[i] == '0') {
				countW++;
			}
			else {
				countB++;
			}
		}
		else {
			if (s[i] == '1') {
				countW++;
			}
			else {
				countB++;
			}
		}
	}

	result = min(countW, countB);

	printf("%lld\n", result);
}

//119
/*
int main() {
	ll N, A, B, C;
	scanf("%lld %lld %lld %lld", &N, &A, &B, &C);

	vector<ll> l(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &l[i]);
	}

	ll result = INF;
	vector<ll> conv(N, 0LL);

	ll num_conv = (ll)pow(4.0, N);
	for (ll iConv = 0; iConv < num_conv - 1; iConv++) {
		vector<ll> len(4, 0); //len[3]�͎g��Ȃ��|
		ll mp = 0;

		for (ll i = 0; i < N; i++) {
			if (conv[i] != 3 && len[conv[i]] > 0) {
				mp += 10;
			}
			len[conv[i]] += l[i];
		}

		if (len[0] == 0 || len[1] == 0 || len[2] == 0) {

		}
		else {
			mp += abs(A - len[0]) + abs(B - len[1]) + abs(C - len[2]);
			result = min(mp, result);
		}

		conv[0]++;
		for (ll i = 0; i < N; i++) {
			if (conv[i] > 3) {
				conv[i + 1]++;
				conv[i] = 0;
			}
		}
	}

	printf("%lld\n", result);

	return 0;
}
*/


//120
/*
int main() {
	static char S[100010];

	scanf("%s", S);

	ll len = strlen(S);

	ll countOne = 0;
	for (ll i = 0; i < len; i++) {
		if (S[i] == '1') {
			countOne++;
		}
	}

	printf("%lld", std::min(countOne, len - countOne) * 2);

	return 0;
}
*/


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <numeric>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
#define MAX_V 1000000
#define MAX_N 1000000
#define MAX_E 1000000
struct edge {int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		depth[i] = 0;
	}
}

// 木の根を求める
int find(int x) {
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(depth[x] < depth[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}

// xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}

int kruskal() {
	sort(es, es + E, comp);
	init(V);
	int res = 0;
	rep(i, 0, E) {
		edge e = es[i];
		if(!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}


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

  cin >> V;
  vector<pair<ll, int> > vx, vy;

  rep(i, 0, V) {
    int x, y;
    cin >> x >> y;
    vx.push_back(make_pair(x, i));
    vy.push_back(make_pair(y, i));
  }
  vsort(vx);
  vsort(vy);

  E = 0;
  rep(i, 0, V - 1) {
    int a, b, c, d;
    a = vx[i].first, c = vx[i + 1].first;
    int dx = abs(a - c);
    edge e = {vx[i].second, vx[i + 1].second, dx};
    es[E] = e;
    E++;
    b = vy[i].first, d = vy[i + 1].first;
    int dy = abs(b - d);
    edge ey = {vy[i].second, vy[i + 1].second, dy};
    es[E] = ey;
    E++;
  }
  cout << kruskal() << endl;
}


Measured memory_bytes: 12132
#include<cstdio>
#define Rint register int
using namespace std;
typedef long long LL;
LL solve(LL x){
	if(x & 1) return (x + 1 >> 1) & 1;
	return x ^ (x >> 1) & 1;
}
int main(){
	LL a, b;
	scanf("%lld%lld", &a, &b);
	printf("%lld\n", solve(a - 1) ^ solve(b));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

char c[2010][2010];
bool flag[2010][2010];
ll cnt[2010][2010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<pair<ll, ll>>p(m);
	rep(i, m) {
		cin >> p[i].second >> p[i].first;
	}
	sort(p.rbegin(), p.rend());
	vector<ll>change;
	rep(i, m) {
		rep(j, p[i].second) {
			change.push_back(p[i].first);
			if (change.size() == n)break;
		}
		if (change.size() == n)break;
	}
	ll k = change.size();
	if (k < n) {
		rep(i, n - k) {
			change.push_back(-1);
		}
	}
	ll ans = 0;
	rep(i, n) {
		ans += max(a[i], change[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3704
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    string s;
    ll k;
    std::cin >> s;
    std::cin >> k;
    ll dokomade = -1;
    
    for (int i = 0; i < s.length(); i++) {
        if( s[i] == '1' ){
            dokomade = i;
        }else{
            break;
        }
    }
    if(dokomade == -1){
        std::cout << s[0] << std::endl;
        return 0;
    }else{
        dokomade++;
        
        if(dokomade >= k){
            std::cout << 1 << std::endl;
        }else{
            std::cout << s[dokomade] << std::endl;
        }
    }
}


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

char t[200009], d[200009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	string s; cin >> s;
	int ts = -1, te = n;
	for (int i = 0; i < q; i++)
		cin >> t[i] >> d[i];
	for (int i = q - 1; i >= 0; i--) {
		if (te - ts <= 1) break;
		if (d[i] == 'L') {
			if (ts < n - 1 && s[ts + 1] == t[i]) ts++;
			if (te < n && s[te] == t[i]) te++;
		}
		else {
			if (0 <= ts && s[ts] == t[i]) ts--;
			if (0 < te && s[te - 1] == t[i]) te--;
		}
	}
	cout << n - (ts + 1 + n - te) << '\n';
	return 0;
}

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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
LL dp[1000005];
int mod=998244353;
void solve(){
    int n,k;
    scanf("%d %d",&n,&k);
    pii p[15];
    for(int i = 0;i<k;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        p[i]=mp(x,y);
    }
    dp[1]=1;
    for(int i = 2;i<=n;i++){
        dp[i]=0;
        for(int j = 0;j<k;j++){
            int l=max(1,i-p[j].y);
            int r=i-p[j].x;
            if(l<=r){
                dp[i]+=dp[r]-dp[l-1];
                dp[i]%=mod;
                dp[i]+=mod;
                dp[i]%=mod;
            }
           // printf("%d %d\n",l,r);
        }
     //   printf("%lld\n",dp[i]);
        dp[i]+=dp[i-1];
        dp[i]%=mod;
     
    }
    printf("%lld\n",((dp[n]-dp[n-1])%mod+mod)%mod);
}
int main(){
    int t=1;
    int T=1;
    while(t--){
        solve();
    }
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/


Measured memory_bytes: 5372
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<math.h>

using namespace std;
int main(){
    
    long long a,b,x;
    cin >> a >> b;
    for(int i=1;i<4;i++){
        if(i!=a&&i!=b){
            x=i;
        }
    }
   cout << x << 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();
		String[] S = sc.next().split("");
		String[] T = sc.next().split("");
		sc.close();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < N;i++){
			sb.append(S[i]);
			sb.append(T[i]);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

int main(){
    int i, j;
    int h, w;
    
    while(scanf("%d %d", &h, &w), h > 0 && w > 0){
        for(i = 0; i < h; ++i){
            for(j = 0; j < w; ++j){
                putchar(i == 0 || j == 0 || i == h - 1 || j == w - 1 ? '#' : '.');
            }
            
            putchar('\n');
        }
        
        putchar('\n');
    }
    
    return 0;
}


Measured memory_bytes: 2604
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]

    d = [0] * (N+1)
    d[1] = 1
    now = 1
    next_ = A[0]
    c = [0] * (N+1)
    cnt = 0
    while d[next_] == 0:
        d[next_] = d[now] + 1
        now = next_
        next_ = A[next_-1]
        cnt += 1
        c[now] = cnt

    s = c[next_]
    loop = cnt - s

    if K <= s:
        ans = c[1:].index(K) + 1
    else:
        n = (K - s) % (loop + 1)
        ans = c[1:].index(s + n) + 1
    
    print(ans)


if __name__ == "__main__":
    main()


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];
	
	int ans =MD;
	rep2(i, -102, 103){
		int sm = 0;
		rep(j, n){
			sm += (i-a[j]) * (i-a[j]);
		}
		ans = min(ans, sm);
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
color=[0,0,0]
ans=1
for i in a:
  ans*=color.count(i)
  ans%=mod
  for j in range(3):
    if color[j]==i:color[j]+=1;break
print(ans%mod)

Measured memory_bytes: 53804
//TYPE
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>

using namespace std;
typedef long long ll;
#define cls(x) memset(x,0,sizeof(x))


const int INF = 0x3f3f3f3f;
const int SZ = 100;

int main() {
  int a[5], k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >>k;
  for(int i = 0; i < 4; ++i) {
    for(int j = i + i; j < 5; ++j) {
      if(abs(a[i] - a[j]) > k) {
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<pii> counting(const vector<int> vec)
{
    map<int, int> num_cnt;
    rep(i, 0, vec.size()) num_cnt[vec[i]]++;
    
    int max_cnt = 0;
    vector<pii> cnt_num;
    for (auto n_c: num_cnt)
        cnt_num.emplace_back(n_c.second, n_c.first);
    sort(cnt_num.begin(), cnt_num.end());
    reverse(cnt_num.begin(), cnt_num.end());    
    return cnt_num;
}

int main()
{
    int n;
    cin >> n;
    vector<int> odds, evens;
    rep(i, 0, n)
    {
        int v;
        cin >> v;
        if (i % 2 == 0)
            evens.push_back(v);
        else
            odds.push_back(v);
    }
    vector<pii> cnt_num_even = counting(evens);
    vector<pii> cnt_num_odd = counting(odds);
    int ans;
    if (cnt_num_even[0].second != cnt_num_odd[0].second)
        ans = cnt_num_even[0].first + cnt_num_odd[0].first;
    else
    {
        ans = max(cnt_num_even[0].first, cnt_num_odd[0].first);
        if (cnt_num_odd.size() > 1)
            ans = max(ans, cnt_num_even[0].first + cnt_num_odd[1].first);
        if (cnt_num_even.size() > 1)
            ans = max(ans, cnt_num_even[1].first + cnt_num_odd[0].first);
    }
    ans = n - ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4364
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		do {
			int n = in.nextInt();
			int k = in.nextInt();
			int q = in.nextInt();
			int[] win = new int[n];
			for (int i = 0; i < q; i++)
				win[in.nextInt() - 1]++;
			for (int i = 0; i < n; i++)
				System.out.println(solve(q, k, win[i]));
		} while (TEST);
	}

	private static String solve(int q, int k, int win) {
		if (k - q + win > 0)
			return "Yes";
		return "No";
	}
}

Measured memory_bytes: 54652
#pragma GCC optimize(3 , "Ofast" , "inline")

#include <bits/stdc++.h>

#define rep(i , a , b) for(register int i=(a);i<=(b);i++)
#define per(i , a , b) for(register int i=(a);i>=(b);i--)


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int , int> pi;

template<class T>
inline void read (T &x) {
    x = 0;
    int sign = 1;
    char c = getchar ();
    while (c < '0' || c > '9') {
        if ( c == '-' ) sign = - 1;
        c = getchar ();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar ();
    }
    x = x * sign;
}

const int maxn = 2e5 + 10;
const int inf = int (1e9);
const ll INF = ll (1e18);
const double PI = acos (- 1);
const int mod = 1e9+7;
const double eps = 1e-8;

map<string,int>mp;
map<string,int>::iterator it;

int main () {
    int n;
    read (n);
    int ma=0;
    rep (i,1,n) {
        string s;
        cin>>s;
        mp[s]++;
        ma=max (ma,mp[s]);
    }
    for(auto x:mp) {
        if(x.second==ma) {
            cout<<x.first<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll MOD = 1e9 + 7;
ll add(ll n, ll m){
    return ((n%MOD)+(m%MOD))%MOD;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    char a[n][m];
    ll dp[n][m];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            if(a[i][j] == '#')
                dp[i][j] = 0;
            else if(j == 0 && i == 0)
                dp[i][j] = 1;
            else if(i == 0)
                dp[i][j] = dp[i][j-1];
            else if(j == 0)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = add(dp[i-1][j], dp[i][j-1]);
        }
    }
    cout << dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include<string.h>
#include<math.h>
using namespace std;

int main() {
	int n,x,i;
	cin>>n>>x;
	if(x==1||x==2*n-1)cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		if(x<=n){
			for(i=n+x;i<=2*n-1;i++){
				cout<<i<<endl;
			}
			for(i=1;i<=n+x-1;i++){
				cout<<i<<endl;
			}
		}
		else{
			for(i=x-n+1;i<=2*n-1;i++){
				cout<<i<<endl;
			}
			for(i=1;i<=x-n;i++){
				cout<<i<<endl;
			}
		}
	}
}

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

struct Node{
    int key;
    Node *left,*right,*parent;
};
Node *nill,*root;

void insertkey(int key){
    Node *y;
    Node* x=root;
    Node* z;
    z=(Node*)malloc(sizeof(Node));
    z->key=key;
    z->left=nill;
    z->right=nill;
    while(x!=nill){
        y=x;
        if(key>x->key)x=x->right;
        else x=x->left;
    }
    z->parent=y;
    if(y==nill)root=z;
    else{
        if(key<y->key)y->left=z;
        else y->right=z;
    }
}

void inorder(Node* node){
    if(node!=nill){
    inorder(node->left);
    printf(" %d",node->key);
    inorder(node->right);
    }
    return;
}
void preorder(Node* node){
    if(node!=nill){
        printf(" %d",node->key);
        preorder(node->left);
        preorder(node->right);
    }
    return;
}

void preorder(){}

int main(){
    int n;cin>>n;
    char s[10];
    rep(i,n){
        scanf("%s",s);
        if(s[0]=='i'){
            int key;
            scanf("%d",&key);
            insertkey(key);
        }
        else if(s[0]=='p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll cnt[M];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll x,n,i,c,t,v,d;
	cin >> x >> n;
	for(i=1;i<=n;++i)
	{
		cin >> t;
		cnt[t] = 1;
	}

	for(i=0;i<=500;++i)
	{
		if(cnt[i] == 0)
		{
			if(abs(i-x)<d)
			{
				d = abs(i-x);
				v = i;
			}
		}
	}

	cout << v << endl;
}

Measured memory_bytes: 3656