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

int H,W;
int a[1000000][4];
int main() {
    cin >> H >> W;
    int map[H][W];
    for (int i=0;i<H;i++)
        for (int j=0;j<W;j++) cin >> map[i][j];
    int s=0, u=0;
    for (int i=0;i<H;i++){
        if (i%2==0){
            for (int j=0;j<W;j++){
                if (((s==0 && map[i][j]%2==1) ||(s==1&&map[i][j]%2==0))&&(i!=H-1||j!=W-1)){
                    a[u][0]=i;
                    a[u][1]=j;
                    if(j<W-1){
                        a[u][2]=i;
                        a[u][3]=j+1;
                    }
                    else {
                        a[u][2]=i+1;
                        a[u][3]=j;
                    }
                    u++;
                    s=1;
                }
                else if (s==1&&map[i][j]%2==1&&(i!=H-1||j!=W-1)){
                    s=0;
                }
            }
        }
        else {
            for (int j=W-1;j>=0;j--){
                if (((s==0 && map[i][j]%2==1) ||(s==1&&map[i][j]%2==0))&&(i!=H-1||j!=0)){
                    a[u][0]=i;
                    a[u][1]=j;
                    if(j>0){
                        a[u][2]=i;
                        a[u][3]=j-1;
                    }
                    else {
                        a[u][2]=i+1;
                        a[u][3]=j;
                    }
                    u++;
                    s=1;
                }
                else if (s==1&&map[i][j]%2==1&&(i!=H-1||j!=0)){
                    s=0;
                }
            }
        }
    }
    cout << u<< endl;
    for (int i=0;i<u;i++){
        for (int j=0;j<=3;j++){
            if (j==3)cout << a[i][j]+1<< endl;
            else cout << a[i][j]+1 << " ";
        }
    }
}


Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 87;
int dig[MAXN];

struct edge{
    int a, b, c;
    edge(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
};

int main() {
    int L;
    scanf("%d", &L);
    vector<edge> ans;
    int vnum, t;
    for (int i = 20; i >= 1; i--) {
        if ((1 << i) <= L) {
           vnum = i + 1;
           t = i;
           break;
        }
    }
    for (int i = 1; i < vnum; i++) {
        ans.push_back(edge(i, i + 1, 0));
        ans.push_back(edge(i, i + 1, (1 << (i - 1))));
    }
    int w = (1 << t);
    for (int i = vnum - 1; i >= 1; i--) {
        if (L & (1 << (i - 1))) {
           ans.push_back(edge(i, vnum, w));
           w += (1 << (i - 1));
        }
    }
    printf("%d %d\n", vnum, (int)ans.size());
    for (auto i : ans)
        printf("%d %d %d\n", i.a, i.b, i.c);

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

main :: IO ()
main = do
  solve 1

solve :: Int -> IO()
solve n = do
  x <- read <$> getLine :: IO Int
  if (x == 0) then return ()
    else do {
    putStrLn $ (makestr x n);
    solve (n + 1)
    }

makestr :: Int -> Int -> String
makestr x n = "Case " ++ (show n) ++ ": " ++ (show x)

  

Measured memory_bytes: 3944
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1000010;
const ll P=1000000007;
int n,m,D;
ll ans,n1;
ll f[maxn],s[maxn];
int main()
{
	scanf("%d%d%d",&n,&m,&D);
	int i;
	ll tmp=1;
	f[0]=s[0]=1;
	for(i=1;i<=n;i++) tmp=tmp*i%P,n1=(n1+tmp)%P;
	for(i=1;i<m;i++)
	{
		f[i]=s[i-1]-((i<=D)?0:s[i-D-1])+P;
		f[i]=f[i]*n1%P;
		s[i]=(s[i-1]+f[i])%P;
	}
	printf("%lld\n",(s[m-1]-s[m-D-1]+P)*tmp%P);
	return 0;
}


Measured memory_bytes: 15744
#include<bits/stdc++.h>
#define N 25
using namespace std;
int n,a[N],l[N],r[N];
bool used[N];
 
void dfs(int x,int z){
  if(z==0)cout<<' '<<x;
  if(l[x]!=-1)dfs(l[x],z);
  if(z==1)cout<<' '<<x;
  if(r[x]!=-1)dfs(r[x],z);
  if(z==2)cout<<' '<<x;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    cin>>l[a[i]]>>r[a[i]];
    if(l[a[i]]!=-1)used[l[a[i]]]=true;
    if(r[a[i]]!=-1)used[r[a[i]]]=true;
  }
  for(int i=0;i<n;i++)
    if(!used[i])cout<<"Preorder"<<endl,dfs(i,0),cout<<endl;
  for(int i=0;i<n;i++)
    if(!used[i])cout<<"Inorder"<<endl,dfs(i,1),cout<<endl;
  for(int i=0;i<n;i++)
    if(!used[i])cout<<"Postorder"<<endl,dfs(i,2),cout<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 long long int gcd(long long int p,long long int q)
 {
   return q==0 ? p:gcd(q,p%q);     
 }

 int main()
 {
   long long int n,m;
   while(cin>>n>>m)
   {
     long long kk=gcd(n,m);
     cout<<kk<<" "<<n/kk*m<<endl;             
   }
   //while(1);      
   return 0;    
 }

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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    string s;
    cin >> s;
    deque<char> ans;
    for(char c : s){
        if(c == 'B'){
            if(!ans.empty()) ans.pop_back();
        }else{
            ans.push_back(c);
        }
    }
    while(!ans.empty()){
        cout << ans.front();
        ans.pop_front();
    }
    cout << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
summation=[0,A[0]]
for i in range(1,N):
  summation.append(summation[i]+A[i])

maxvalue=summation[K]
for i in range(1,1+N-K):
  maxvalue=max(maxvalue,summation[i+K]-summation[i])
print((maxvalue+K)/2)

Measured memory_bytes: 25060
from fractions import gcd
from functools import reduce
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7


def inverse(n, mod=10 ** 9 + 7):
    return pow(n, mod - 2, mod)


def main():
    N = int(input())
    A = list(map(int, input().split()))

    L = reduce(lambda o1, o2: o1 // gcd(o1, o2) * o2, A)
    sigma_A_inv = sum([inverse(a) for a in A])

    print(L * sigma_A_inv % MOD)


if __name__ == '__main__':
    main()


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

using namespace std;

double rast(int x1,int y1,int x2,int y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

struct dc
{
    long long days,cost;
};

bool comp (dc l,dc r)
{
    if (l.days==r.days) return l.cost<r.cost;
    return l.days<r.days;
}
dc a[200000];

int main()
{

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;

    for (int i=0;i<n;i++)
    {
        cin >> a[i].days >> a[i].cost;
    }
    sort(a,a+n,comp);

    priority_queue<int> q;

    long long ans=0,pos=0;
    for (int i=1;i<=m;i++)
    {
        while (pos<n && a[pos].days==i)
        {
            q.push(a[pos].cost);
            pos++;
        }

        if (!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
    }

    cout << ans;


}


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

int main() {
    string S, T;
    cin >> S >> T;

    vector<int> scnts(26, 0), tcnts(26, 0);
    rep(i, (int)S.size()) scnts[S[i]-'a']++;
    rep(i, (int)T.size()) tcnts[T[i]-'a']++;

    sort(scnts.begin(), scnts.end());
    sort(tcnts.begin(), tcnts.end());

    bool f=true;
    rep(i, 26) {
        if(scnts[i] != tcnts[i]) {
            f = false;
            break;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 776
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define P pair<int,int>
using namespace std;

int main(){
  int w,h;
  P g;
  string s;

  while( cin>>w>>h && (w|h) ){
    vector<P> p[100*100];
    map<int,int> mp;
    int n=1, nodeN=1;
    for( int i=0;i<h;i++ ){
      for( int j=0;j<w;j++ ){
	cin >> s;
	switch(s[0]){
	case 'S': p[0].push_back( P(i,j) );mp[i*w+j]=0;break;
	case 'G': g=P(i,j);break;
	case '.': break;
	default:
	  int k=atoi( s.c_str() );
	  if( p[k].empty() )
	    n++;
	  p[ k ].push_back( P(i,j) );
	  mp[i*w+j] = nodeN++;
	}
      }
    }
    p[n++].push_back( g );
    mp[g.first*w+g.second]=nodeN++;

    vector<P> path[nodeN];
    // make path
    for( int i=1;i<n;i++ ){ // calculate cost from (i-1) to i
      int a,b, cost;
      for( int j=0;j<(int)p[i-1].size();j++ ){
	P x=p[i-1][j];
	a = x.first*w + x.second;

	for( int k=0;k<(int)p[i].size();k++ ){
	  P y=p[i][k];
	  b = y.first*w + y.second;
	  cost = abs( y.first - x.first ) + abs( y.second - x.second );
	  path[mp[a]].push_back( P(cost,mp[b]) );
	}
      }
    }

    int d[nodeN];
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+nodeN, 1000000 );
    d[0]=0;
    que.push( P(0,0) ); // cost, to

    while( !que.empty() ){
      P p = que.top(); que.pop();
      int v = p.second;
      if( d[v] < p.first ) continue;

      for( int i=0;i<(int)path[v].size();i++ ){
	P e = path[v][i]; // cost, to
	int nextCost = d[v] + e.first;
	if( d[e.second] > nextCost ){
	  d[e.second] = nextCost;
	  que.push( P(d[e.second], e.second) );
	}
      }
    }
    cout << d[nodeN-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 5124
import java.util.Scanner;

public class Main {
	static long f(long x) {
		long ret = 0;
		for(int base = 0 ; base <= 63 ; ++base) {
			long up = 1L << base;
			if(x < up) {
				break;
			}
			long n1 = (x / (up * 2)) * (up);
			if(x % (up * 2) >= up) {
				n1 += (x % (up *2)) - (up - 1);
			}
			if(n1 % 2 == 1) {
				ret |= up;
			}
		}
		return ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		if(A == 0) {
			System.out.println(f(B));
		}else {
			System.out.println(f(B) ^ f(A - 1));			
		}
	}
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  string s;
  cin >> s;
  
  int n=s.size();

  string k = "keyence";

  int mae=0, ushiro=0;

  rep(i,7){
    if(s.at(i)==k.at(i))mae++;
    else break;
  }
  rep(i,7){
    if(s.at(n-1-i)==k.at(6-i))ushiro++;
    else break;
  }
  if(mae+ushiro>=7) cout << "YES";
  else cout << "NO";
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    if(b*d >= 0 || a*c >= 0) {
        if(a*c < b*d) cout << b*d << endl;
        else cout << a*c << endl;
    }
    else {
        if ((a <= 0 && b >= 0) || (c <= 0 && d >= 0)) cout << 0 << endl;
        else if(a*d < b*c) cout << b*c << endl;
        else cout << a*d << endl;
    }

    return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  char c;
  set<char> st;
  for (int i = 0; i < N; i++) {
    cin >> c;
    st.insert(c);
  }

  // 解答
  cout << (st.size() == 3 ? "Three" : "Four") << endl;

  return 0;
}


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

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

int N, lcm, A[200005];


unordered_map<int, int> s;

void solve() {
    cin >>N;
    REP(i,0,N-1) {
        cin >> A[i];
        s[A[i]]++;
    }
    
    // for (auto a : s) {
    //     print_pair(a);
    //     cout << endl;
    // }
    if (s[1] > 0) {
        cout << (s[1]>1? 0 : 1) << endl;
        return;
    }

    int ans = N;
    REP(i,0,N-1) {
        if (s[A[i]] > 1) {
            ans--;
        }else 
            REP(j,2,sqrt(A[i])) {
                if (A[i]%j==0) {
                    if (s[j] > 0 || s[A[i]/j] > 0) {
                        ans--;
                        break;    
                    }
                }
            }
    }
    cout << ans << endl;
}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 32464
#include <stdio.h>
#include <stdbool.h>

bool judgeRectTriangle(int, int, int);

int main(void)
{
    int edge1, edge2, edge3;

    scanf("%d", &edge1);//最初のデータを捨てます。

    while (scanf("%d%d%d", &edge1, &edge2, &edge3) != EOF) {
        if (judgeRectTriangle(edge1, edge2, edge3)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    
    return 0;
}

bool judgeRectTriangle(int x, int y, int z)
{
    if (x * x + y * y == z * z || y * y + z * z == x * x || z * z + x * x == y * y) {
        return true;
    } else {
        return false;
    }
}

Measured memory_bytes: 1008
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	while(true){
	    int n=sc.nextInt();
	    if(n==0)break;
	    int[]pr=new int[n];
	    int fld=0;
	    String cd=sc.next();
	    for(int i=0;i<100;i++){
		char ch=cd.charAt(i);
		if(cd.charAt(i)=='M')pr[i%n]++;
		if(cd.charAt(i)=='S'){
		    fld+=pr[i%n]+1;
		    pr[i%n]=0;
		}
		if(cd.charAt(i)=='L'){
		    pr[i%n]+=fld+1;
		    fld=0;
		}
	    }
	    for(int i=0;i<n-1;i++){
		int min=i;
		for(int j=i+1;j<n;j++){
		    if(pr[min]>pr[j]){
			int cj=pr[min];
			pr[min]=pr[j];
			pr[j]=cj;
		    }
		}
	    }
	    for(int i=0;i<n;i++)System.out.print(pr[i]+" ");
	    System.out.println(fld);
	}
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

Measured memory_bytes: 29100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    long long m,n,s=0;
    cin>>m;
    cin>>n;
    if(n==1) s=m-2;
    if(m==1) s=n-2;
    if(s<0) s=0;
    else if(m==2||n==2) s=0;
    else if(n>2&&m>2) s=(m-2)*(n-2);
    if(m==1&&n==1) s=1;
    cout<<s;
    return 0;
}




Measured memory_bytes: 256
input()

A = list(map(int, input().split()))

f1 = lambda x: x % 2 == 1
f2 = lambda x: x // 2

count = 0

while True:
    if any(map(f1, A)):
        break
    A = list(map(f2, A))
    count += 1

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int x,y;
  cin>>x>>y;
  int a,b;
  if(x==4||x==6||x==9||x==11){
    if(y==4||y==6||y==9||y==11){
      cout<<"Yes"<<endl;
      return 0;
    }
    else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(x==2){
    if(y==2){
      cout<<"Yes"<<endl;
      return 0;
    }
    else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  else{
    if(y==2||y==4||y==6||y==9||y==11){
      cout<<"No"<<endl;
      return 0;
    }
    else {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main(){
    int A, B, K; cin >> A >> B >> K;
    int c = 0;
    for(int i=min(A,B); i>=1; i--){
        if(A%i==0 && B%i==0){
            c++;
            if(c==K){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        do{
            if(N/K != 0){
                ans +=1;
                N /= K;
            }
        }while(N/K !=0);

        System.out.println(ans+1);
    }
}


Measured memory_bytes: 35556
//2018.10.06

#include <iostream>
using namespace std;

int main() {

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

    return 0;
}


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

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < (1 << n); i++) {
		if(__builtin_popcount(i) == k) {
			printf("%d:", i);
			for(int j = 0; j < n; j++) {
				if(i & (1 << j))
					printf(" %d", j);
			}
			printf("\n");
		}
	}
}



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

int main(){
  char a = 'a';
  char b;
  for (int i = 0; i < 4; i++){
    cin >> b;
    if (b == a){
      cout << "Bad" << endl;
      return 0;
    }else{
      a = b;
    }
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b;
	cout << a - b + 1 << "\n";
	
	std::cin >> e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int, int>
#define endl "\n"
#define MAXN 100005
using namespace std;

string s;

void solve()
{
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.size(); i++)
        sum += (s[i] - '0');
    if (sum % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
}

Measured memory_bytes: 3672
#x,y = map(int,input().split())
#arr = [int(i) for i in input().split()]
from collections import Counter
import math
mod = 10**9+7

a,b,c,k = map(int,input().split())
if k<=a:
	print(k)
elif k < a+b:
	print(a)
else:
	x = k - a-b 
	print(a-x)

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  sort(all(A));
  sort(all(B));
  double l, r;
  if(N % 2 == 0) {
    l = (A[N/2-1]+A[N/2])/2.0;
    r = (B[N/2-1]+B[N/2])/2.0;
  } else {
    l = A[N/2]/2.0;
    r = B[N/2]/2.0;
  }
  cout << (ll)((r-l)*2.0)+1 << endl;
  return 0;
}


Measured memory_bytes: 6376
#include <iostream>

int main()
{
  int r, g ,b;
  std::cin >> r >> g >> b;

  int num = 100 * r + 10 * g + b;
  if ( num % 4 == 0 ) std::cout << "YES\n";
  else std::cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func gcd(a, b uint64) uint64 {
	for b > uint64(0) {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b uint64) uint64 {
	return (a / gcd(a, b) * b)
}

func lcmm(nums ...uint64) uint64 {
	if len(nums) == 2 {
		return lcm(nums[0], nums[1])
	} else {
		return lcm(nums[0], lcmm(nums[1:]...))
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	t := make([]uint64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
	}
	if n == 1 {
		fmt.Println(t[0])
		return
	}
	fmt.Println(lcmm(t...))
}

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

int main() {
  int N;
  cin >> N;
  int minimum = 1000000000;


  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    int tmp = A;
    int count = 0;

    while (tmp != 0) {
      if (tmp % 2 != 0) {
        break;
      } else {
        count++;
        tmp /= 2;
      }
    }
    if (count < minimum) {
      minimum = count;
    }
  }
  
  cout << minimum << endl;
}



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

int main() {
    int n;
    long long result = 0;
    cin >> n;
    int a[n];
    map<long long, long long> count;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    count[0] = 1;
    for (long long sum = 0, i = 0; i < n; i++) {
        sum += a[i];
        result += count[sum]++;
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 4010;
vector<int> r, b;
const int MOD = 998244353;
int dp[N][N];

int main() {
#ifdef zerol
    freopen("a.in", "r", stdin);
#endif
    string s; cin >> s; int n = s.length();
    int cnt = 0;
    FOR (i, 0, n) {
        if (s[i] == '0') {
            r.push_back(i); r.push_back(i);
        } else if (s[i] == '1') {
            r.push_back(i); b.push_back(i);
        } else {
            b.push_back(i); b.push_back(i);
        }
    }
    dp[0][0] = 1;
    FOR (i, 0, 2 * n) FOR (j, 0, 2 * n) {
        int ti = i + j;
        if (i < (int) r.size() && r[i] <= ti) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
        if (j < (int) b.size() && b[j] <= ti) {
            (dp[i][j + 1] += dp[i][j]) %= MOD;
        }
        dbg(i, j, dp[i][j]);
    }
    cout << dp[r.size()][b.size()] << endl;
}


Measured memory_bytes: 62976
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
#define LL long long
const int MAX = 1e5+10;
LL n,m,x,y;
LL cnt=0;
LL a[MAX];
int panduan(int x)
{
    int t=sqrt(x);
    for(int i=2;i<=t;i++)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
void dabiao()
{
    for(int i =2;i<=MAX;i++)
    {
        if(panduan(i))
            a[i]=1;
    }
}
vector<int>s;
int main ()
{
    dabiao();
    for(int i=2; i<=MAX; i++)
    {
        if(a[i]==1&&i%5==1)
        {
            //cout<<i<<endl;
            s.push_back(i);
        }
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        if(i==0)
            cout<<s[i];
        else
            cout<<" "<<s[i];
    }
    return 0;
}


Measured memory_bytes: 1024
K = int(input().strip())
if K <= 10:
  print(K)
  exit()

def extend_lunlun(prev):
  prev_digit = int(str(prev)[-1])
  if prev_digit == 0:
    add_list = [0, 1]
  elif prev_digit == 9:
    add_list = [8, 9]
  else:
    add_list = [prev_digit-1, prev_digit, prev_digit+1]
  return [int('{}{}'.format(prev, ad)) for ad in add_list]
  

lunlun_numbers = list(range(1,10))
i_pos = 0
while True:
  lunlun_numbers += extend_lunlun(lunlun_numbers[i_pos])
  if len(lunlun_numbers) >= K:
    print(lunlun_numbers[K-1])
    break
  i_pos += 1


Measured memory_bytes: 48988
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N,K;
    cin >> N >> K;
    vector<long long>A(N);
    for(long long i = 0; i < N; i++) {
        cin >> A[i];
    }
    for(long long i = 0; i < K; i++) {
        vector<long long>cnt(N,0);
        for(long long i = 0; i < N; i++) {
            cnt[max(i-A[i],0LL)]++;
            if(i+A[i]+1 < N) {
                cnt[i+A[i]+1]--;
            }
        }
        for(long long i = 1; i < N; i++) {
            cnt[i] = cnt[i]+cnt[i-1];
        }
        for(long long i = 0; i < N; i++) {
            A[i] = cnt[i];
        }
        if(i == 0) {
            if(N-max(A[0],A[N-1]) <= K-1) {
                for(long long i = 0; i < N; i++) {
                cout << N;
                    if(i+1 != N) {
                        cout << " ";
                    }
                }
                cout << endl;
                return 0;
            }
        }
        if(i+1 == K) {
            for(long long i = 0; i < N; i++) {
                cout << max(cnt[i],0LL);
                if(i+1 != N) {
                    cout << " ";
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 6432
#include<iostream>
#include<cmath>
 using namespace std;
 
 int main()
{		float n,k;
		int x,j,c;
		cin>>n;
		
		{
			k=n/1000;
			x=ceil(k);
			j=x*1000;
			c=j-n;
			cout<<c;}
		
	return 0;
}

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

const int MAXN = 1e2 + 5;

int N, M;
char mat[MAXN][MAXN];
int dp[MAXN][MAXN];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++)
		scanf("%s", mat[i]);
	
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			dp[i][j] = 2 * MAXN;
			if (!i && !j) {
				dp[i][j] = mat[i][j] == '#';
				continue;
			}
			if (i)
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + (mat[i][j] != mat[i - 1][j]));
			if (j)
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + (mat[i][j] != mat[i][j - 1]));
		}
		
	printf("%d\n", (dp[N - 1][M - 1] + 1) / 2);
		
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 3005
ll f[N][N][4];
int r, c, k, a[N][N];
int main(){
	r=read(), c=read(), k=read();
	for (int i=1;i<=k;i++){
		int x=read(), y=read();
		a[x][y]=read();
	}
	for (int i=1;i<=r;i++)
		for (int j=1;j<=c;j++){
			for (int k=0;k<=3;k++){
				f[i][j][k]=max(f[i-1][j][3], f[i][j-1][k]);
				if (k)
					f[i][j][k]=max(f[i][j][k], f[i][j-1][k-1]+a[i][j]),
					f[i][j][k]=max(f[i][j][k], f[i-1][j][3]+a[i][j]);
			}
		}
	cout<<f[r][c][3]<<endl;
    return 0;
}

Measured memory_bytes: 320464
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for(int i = A; i <= B; i++) {
    if(i % 10 == i / 10000 && i / 10 % 10 == i / 1000 % 10) {
      ans ++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1);
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())

edges = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((v-1, w))
    edges[v-1].append((u-1, w))

q = deque()
q.append((0, 0))
color = {}
while q:
    node, dist = q.popleft()
    if node in color:
        continue
    if dist % 2 == 0:
        color[node] = 0
    else:
        color[node] = 1
    for n_node, n_dist in edges[node]:
        q.append((n_node, dist+n_dist))

for i in range(N):
    print(color[i])

Measured memory_bytes: 49732
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const double pai=3.14159265358979323846;
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
int main() {
	int r=read();
	printf("%lf\n",2*pai*r);
}

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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        System.out.println(N/3);
    }
}


Measured memory_bytes: 22740
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		int N = Integer.parseInt(in.readLine());
		int A = Integer.parseInt(in.readLine());
		System.out.println((N * N - A));
	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 22996
#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>;

int main() {

    string s;
    cin >> s;

    int ans = 0;
    rep(i, s.size()){
        if(s[i] == '+'){
            ans++;
        }
        else{
            ans--;
        }
    }
    cout << ans << endl;

    return 0;
}

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

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;
const int MAX = 8000;
const int MOD = 1000000007;



int n,a,b,c;
vi l;

int dfs(int s,int t, int u,int v){
  if(s==n){if(min(t,min(u,v))>0)return abs(a-t)+abs(b-u)+abs(c-v);
           else return MAX;}
  int res=dfs(s+1,t,u,v);
  chmin(res,dfs(s+1,t+l[s],u,v)+10);
  chmin(res,dfs(s+1,t,u+l[s],v)+10);
  chmin(res,dfs(s+1,t,u,v+l[s])+10);
  return res;
}

int main(){
  cin >> n >> a >> b >> c;
  l.resize(n);
  rep(i,n) cin >> l[i];
  cout << dfs(0,0,0,0)-30;
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

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

    string str;
    map<string, long> count;
    unsigned long ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> str;
        sort(str.begin(), str.end());
        if(count[str]) ans += count[str];
        count[str]++;
    }

    printf("%lu\n", ans);

    return 0;
}

Measured memory_bytes: 11136
N, M = map(int, input().split())
Inf = 10**8
Dp = [Inf]*(2**N)
Dp[0] = 0

for i in range(M): #カギiで
    a,_=map(int, input().split())
    c = list(map(int, input().split()))
    d = sum((1<<p-1) for p in c) #iで開けられる宝箱の2bit表記
    for j in range(2**N):
        ope = j|d
        Dp[ope] = min(Dp[ope], Dp[j] + a)

if Dp[-1] == Inf:
    print(-1)
else:
    print(Dp[-1])


Measured memory_bytes: 3188
n, k=map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def out(num):
    print(num%1000000007)

for i in range(1, k+1):
    if n-k+1 < i:
        print("0")
    else:
        out(cmb(n-k+1,i)*cmb(k-1, i-1))

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=55;
const int maxm=2466;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define tp tuple<ll,ll,ll>

vector<tp> G[maxn];
ll c[maxn],d[maxn];
ll dp[maxn][maxm];

int main(){
	int n,m,s;
	scanf("%d%d%d",&n,&m,&s);
	s=min(2450,s);
	for(int i=1;i<=m;i++){
		ll u,v,a,b;
		scanf("%lld%lld%lld%lld",&u,&v,&a,&b);
		G[u].push_back(tp(v,a,b)); //钱 时间 
		G[v].push_back(tp(u,a,b));
	}
	for(int i=1;i<=n;i++)
		scanf("%d%d",&c[i],&d[i]);
	fill(dp[0],dp[0]+54*2465,inf);
	dp[1][s]=0;
	
	priority_queue<tp,vector<tp>,greater<tp>> pq;
	pq.push(tp(0,1,s));
	while(!pq.empty()){
		tp cur;
		cur=pq.top();
		pq.pop();
		ll t=get<0>(cur),u=get<1>(cur),w=get<2>(cur);
		for(auto i:G[u]){
			ll v=get<0>(i),toa=get<1>(i),tob=get<2>(i);
			if(dp[v][w-toa]>t+tob&&w>=toa){
				dp[v][w-toa]=t+tob;
				pq.push(tp(t+tob,v,w-toa));
			}
		}
		if(dp[u][min(2450LL,w+c[u])]>t+d[u]){
			dp[u][min(2450LL,w+c[u])]=t+d[u];
			pq.push(tp(t+d[u],u,min(2450LL,w+c[u])));
		}
	}
	for(int i=2;i<=n;i++){
		ll ans=inf;
		for(int j=0;j<=2450;j++){
			ans=min(ans,dp[i][j]);
		}
		printf("%lld\n",ans);
	}
}

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

using namespace std;

int n, a[1010], ans;

int main() {
    cin >> n;
    for(int i = 1;i <= n; ++i){
        cin >> a[i];
        if(i % 2 == 1) {
            if(a[i] % 2 == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<algorithm>
#define maxn 200005
using namespace std;
int n,m,a[maxn],cnt[maxn],ccnt[maxn*2],l;
int Query(int x)
{
	int res=0;
	for(;x;x-=x&(-x)) res+=ccnt[x];
	return res;
}
void Modify(int x,int d)
{
	for(;x<=n*2;x+=x&(-x)) ccnt[x]+=d;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	for(int i=1;i<=n;i++) { Modify(i-cnt[i]+n+1,1); Modify(i+n+1,-1); }
	for(int i=n+1;i<=n*2;i++)
		if(!Query(i)) l++;
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		cnt[a[x]]--;
		Modify(a[x]-cnt[a[x]]+n,-1); Modify(a[x]-cnt[a[x]]+n+1,1);
		if(!Query(max(a[x]-cnt[a[x]]+n,n+1))) l++;
		//printf(" * %d %d\n",max(a[x]-cnt[a[x]]+n,n+1),Query(max(a[x]-cnt[a[x]]+n,n+1)));
		a[x]=y;
		Modify(a[x]-cnt[a[x]]+n,1); Modify(a[x]-cnt[a[x]]+n+1,-1);
		if(a[x]-cnt[a[x]]>0&&Query(a[x]-cnt[a[x]]+n)==1) l--;
		cnt[a[x]]++;
		//for(int i=n+1;i<=n*2;i++)
		//	printf(" - %d %d\n",i-n,Query(i));
		printf("%d\n",l);
	}
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

int main(){
    int n;
    cin >> n;
    map<int, int> m;
    vector<int> a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
        m[a[i]]++;
    }

    auto mx = m.rbegin();
    int g = mx->first;

    if(mx->second != 1){
        for(int i=0; i<n; ++i)
            cout << g << endl;
    }
    else{
        ++mx;
        int s = mx->first;

        for(int i=0; i<n; ++i){
            if(a[i]==g)
                cout << s << endl;
            else
                cout << g << endl;
        }
    }
}

Measured memory_bytes: 9460
N = int(input())
T, A = map(int,input().split())
list_H = [int(x) for x in input().split()]

min = 1000

for i in range(N) :
    Temp = T - list_H[i] * 0.006
    score = abs(A - Temp)
    if score < min :
        min = score
        ans = i

print(ans+1)


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

int main( )
{
    int n, i, j, k;
    int c = 0, mxc = 0;
    cin >> n;
    int p; cin >> p;
    c = 1;
    for (i = 2; i <= n; i++) {
        cin >> j;
        if (p >= j) {
            c++;
        }
        else {
            mxc = max(mxc, c);
            c = 1;
        }
        p = j;
    }
    mxc = max(mxc, c);
    cout << mxc - 1 << '\n';
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    ll x, y; cin>>x>>y;
    if(x%y==0) cout << -1 << endl;
    else cout << x*(y+1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    cin >> n >> k;
    vector<int> a;
    for(int i = 0; i < n; ++i){
        int foo;
        cin >> foo;
        if(foo >= k)    continue;
        a.emplace_back(foo);
    }
    sort(a.begin(), a.end());
    int sz = a.size();

    int ans = sz;
    vector<bitset<5005>> dp(sz + 1, 1);
    for(int i = sz - 1; i >= 0; --i)    dp[i] = dp[i + 1] | (dp[i + 1] << a[i]);
    for(int i = 0; i < sz; ++i){
        bool flag = false;
        for(int j = k - a[i]; j < k; ++j){
            if(dp[i + 1][j]){
                flag = true;
                break;
            }
        }
        if(flag){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	int nx = x2 - x1;
	int ny = y2 - y1;


	cout << x2 - ny << " " << y2 + nx << " " << (x2 - ny) - nx << " " << (y2 + nx) - ny << endl;


	return 0;
}

Measured memory_bytes: 256
def main():
    while True:
        import sys
        input=sys.stdin.readline
        w,h=map(int,input().split())
        if w==0:
            break
        dp=[[[0,0,0,0] for _ in [0]*(w+1)] for _ in [0]*(h+1)] #右直進、上直進、右、上
        dp[1][0]=[0,1,0,0]
        dp[0][1]=[1,0,0,0]
        mod=10**5
        for k in range(1,w+h-2):
            for j in range(max(0,k-h+1),min(w,k+1)):
                i=k-j
                dp[i+1][j][1]=(dp[i+1][j][1]+dp[i][j][1]+dp[i][j][3])%mod
                dp[i+1][j][3]=(dp[i+1][j][3]+dp[i][j][0])%mod
                dp[i][j+1][0]=(dp[i][j+1][0]+dp[i][j][0]+dp[i][j][2])%mod
                dp[i][j+1][2]=(dp[i][j+1][2]+dp[i][j][1])%mod
        print(sum(dp[h-1][w-1])%mod)
if __name__=='__main__':
    main()


Measured memory_bytes: 8244
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

int main(){
    int n;
    cin >> n;
    Bint res = 1;
    vector<ll> a(n);
    rep(i, n){
      cin >> a[i];   
    }
    ll lim = INF * INF;
    sort(ALL(a));
    if(a[0] == 0){
        cout << 0 << endl;
      return 0;
    }
    else {
        rep(i, n){
            if(a[i] > lim){
                cout << -1;
                return 0;
            }
            if(res * a[i]> lim){
                cout << -1;
                return 0;
            }
            
            res *= a[i];
        }
    }
    if(res > lim){
        cout << -1;
        return 0;
    }
    cout << res;
}

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

#define INF 1e18
#define int long long
#define MAX 200010

signed main() {
    int n, k; cin >> n >> k;
    int cnt[MAX];
    for(int i = 0; i < MAX; i++) cnt[i] = 0;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        cnt[a]++;
    }

    int sum = 0;
    for(int i = 0; i < MAX; i++) {
        if(cnt[i] > 0) sum++;
    }

    int ans = 0;
    sort(cnt, cnt + MAX);
    for(int i = 0; i < MAX && sum > k; i++) {
        if(cnt[i] > 0) {
            sum--;
            ans += cnt[i];
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
static const int INF = (1<<21);
 
int n, x, y;
int cou[2001], d[2001][2001];
vector<int> M[2001];
 
void bfs(int s) {
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) {
        d[s][i] = INF;
    }
    d[s][s] = 0;
    int u = 0;
    while (!q.empty()) {
        u = q.front(); q.pop();
        for (int v: M[u]) {
            if (d[s][v] != INF) continue;
            d[s][v] = d[s][u] + 1;
            q.push(v);
        }
    }
}
 
int main() {
    cin >> n >> x >> y;
    x--; y--;
 
    M[x].push_back(y); M[y].push_back(x);
 
    for (int i = 0; i < n-1; i++) {
        M[i].push_back(i+1); M[i+1].push_back(i);
    }
 
    for (int i = 0; i < n; i++) bfs(i);
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][j] == INF) continue;
            else cou[d[i][j]]++;
        }
    }
    for (int i = 1; i < n; i++)
    cout << cou[i]/2 << endl;
}

Measured memory_bytes: 16000
n = gets.to_i
a = gets.chomp
b = gets.chomp
c = gets.chomp

ans = 0
for i in 0..(n - 1) do
  if a[i] != b[i] && b[i] != c[i] && c[i] != a[i]
    ans += 2
  elsif a[i] != b[i] || b[i] != c[i] || c[i] != a[i]
    ans += 1
  end
end

puts ans


Measured memory_bytes: 1788
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int n;cin >> n;
    REP(i,10) {
        REP(j,10) {
            if (n == i * j) {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    ll mn = -1;
    for (ll i = 1; i <= 100; i++) {
        ll cnt = 0;
        for (ll j = 0; j < n; j++) {
            cnt += (v[j] - i) * (v[j] - i);
        }
        if (mn == -1) mn = cnt;
        mn = min(mn, cnt);
    }
    cout << mn << '\n';

    return 0;
}


Measured memory_bytes: 256