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

#define Input                   freopen("in.txt","r",stdin)
#define Output                  freopen("out.txt","w",stdout)
#define ll                      long long int
#define ull                     unsigned long long int
#define pii                     pair<int,int>
#define pll                     pair<ll,ll>
#define nl                      printf("\n")
#define sc                      scanf
#define scin(x)                 sc("%d",&(x))
#define scin2(x,y)              sc("%d %d",&(x),&(y))
#define scln(x)                 sc("%lld",&(x))
#define scln2(x,y)              sc("%lld %lld",&(x),&(y))
#define pf                      printf
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ms(a,b)                 memset(a,b,sizeof(a))
#define pb(a)                   push_back(a)
#define mp                      make_pair
#define db                      double
#define EPS                     10E-10
#define ff                      first
#define ss                      second
#define sqr(x)                  (x)*(x)
#define vi                      vector<int>
#define vl                      vector<ll>
#define vii                     vector<vector<int> >
#define vll                     vector<vector<ll> >
#define DBG                     pf("HI\n")
#define MOD                     1000000007
#define CIN                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define RUN_CASE(t,T)           for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)                 printf("Case %d: ",t)
#define CASEl(t)                printf("Case %d:\n",t)
#define intlimit                2147483690
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define mxx                     123456789
#define PI                      2*acos(0.0)
#define rep(i,a,b)              for(__typeof(i) i=a;i<=b;i++)
#define rev(i,a,b)              for(__typeof(i) i=b;i>=a;i--)

//Moin Uddin Ruman , 10th batch CSE ,ID : 11808011 , Comilla University (2017-2018) :
//Email : moinruman11@gmail.com, Phone : 01879-238107 .
using namespace std;



int main()
{

ll a,b;
cin>>a>>b;

ll arr[5];

arr[0]=a*b;
arr[1]=a+b;
arr[2]=a-b;
sort(arr,arr+3);
cout<<arr[2]<<endl;

return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

f = 1

if n%2 == 0:
    ans = [2]*(n//2)
    #print(ans)
    for i in range(n):
        if a[i]%2 == 0:
            f = 0
            break
        x = a[i]//2
        ans[x] -= 1

else:
    ans = [2]*((n+1)//2)
    ans[0] -= 1
    for i in range(n):
        if a[i]%2 != 0:
            f = 0
            break
        x = a[i]//2
        ans[x] -= 1

for i in range(len(ans)):
    if ans[i] != 0:
        f = 0
        break

if f == 0:
    print(f)
else:
    print((2**(n//2))%1000000007)

Measured memory_bytes: 14008
#include <stdio.h>
#include <stdlib.h>
  
int pz[4][4];
int tmp[4][4];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
  
void empty(int *,int *);
int dfs(int,int,int,int,int);
int cal();
void swap(int *,int *);
  
int main() {
  int i,j,k,a,x,y;
    for(i = 0; i < 4; i++)
      {
        for(j = 0; j < 4; j++)
	  scanf("%d",&pz[i][j]);
      }
  
    empty(&x,&y);
    for(k = 0; k < 100; k++) {
        for(i = 0; i < 4; i++) {
            for(j = 0; j < 4; j++) tmp[i][j] = pz[i][j];
        }
  
        a = dfs(x,y,-1,0,k);
        if(a!=-1) {
            printf("%d\n",a);
            break;
        }
  
        for(i = 0 ; i < 4; i++) {
            for(j = 0 ; j < 4; j++) pz[i][j] = tmp[i][j];
        }
        a = -1;
        if(k == 99) printf("%d\n",a);
    } 
    return 0;
}
  
void empty(int *x,int *y)
{
    int p,q;
    for(p = 0;p < 4; p++)
      {
        for(q = 0; q < 4; q++)
	  {
            if(!pz[p][q])
	      {
                *x = q;
                *y = p;
                return;
	      }
	  }
      }
}

void swap(int *m,int *n)
{
    int sw;
    sw = *m;
    *m = *n;
    *n = sw;
}
  
  
int cal()
{
    int i,s,sum=0;
    for(i = 0; i < 16; i++)
      {
        s = pz[i/4][i%4];
        if(s)
	  {
            s--;
            sum += abs(i/4 - s/4) + abs(i%4 - s%4);
	  }
      }
    return sum;
}
  
  
int dfs(int x,int y,int p,int dep,int lim)
{
    int i,h,fx,fy,res;
  
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
  
    for(i=0; i<4; i++)
      {
        fx = x+dx[i];
        fy = y+dy[i];
  
        if((~p && i == (p+2) % 4) || (!(0 <= fx && fx < 4 && 0 <= fy && fy < 4))) continue;
  
        swap(&pz[y][x],&pz[fy][fx]);
        res = dfs(fx,fy,i,dep+1,lim);
        if(~res) return res;
  
        swap(&pz[y][x],&pz[fy][fx]);
      }
  
    return -1;
}



Measured memory_bytes: 2112
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>

typedef long long ll;
using namespace std;

ll x,k,d;
int main()
{	
	cin>>x>>k>>d;
	if(x<0) x=-x;
	ll ans=0;
	if(x/d>=k){
		ans=x-k*d;
	}
	else{
		ll num=x/d;
		ll a=x%d;
		ll temp=k-num;
		if(temp&1) ans=d-a;
		else ans=a;
	}
	
	cout<<ans<<endl;
	return 0;
 } 


Measured memory_bytes: 3644
#include<stdio.h>

int main(void)
{
    int i;
    int time[19];
    int s[7];
    int ans[4];
    int a[10];

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

    for(i=1;i<7;i++){
        s[i]=3600*time[3*i-2]+60*time[3*i-1]+time[3*i];
    }

    for(i=1;i<4;i++){
        ans[i]=s[2*i]-s[2*i-1];
    }

    for(i=1;i<4;i++){
        a[3*i-2]=ans[i]/3600;
        ans[i]%=3600;
        a[3*i-1]=ans[i]/60;
        ans[i]%=60;
        a[3*i]=ans[i];
    }

    for(i=1;i<10;i++){
        printf("%d",a[i]);
        switch(i%3){
            case 1:
            case 2:
                printf(" ");
                break;
            case 0:
                puts("");
                break;
        }
    }
    return 0;

}

Measured memory_bytes: 616
(N, K), *D, = [s.split() for s in open(0)]
points = 0
dd = {r: p for p, r in zip(list(map(int, D[0])), ["s", "p", "r"])}
records = []
for i in range(len(D[1][0])):
    if i < int(K):
        points += dd[D[1][0][i]]
        records.append(D[1][0][i])
    else:
        if D[1][0][i] == D[1][0][i-int(K)] and records[i-int(K)] == "pass":
            points += dd[D[1][0][i]]
            records.append(D[1][0][i])
        elif D[1][0][i] == D[1][0][i-int(K)] and records[i-int(K)] != "pass":
             records.append("pass")
        else:
            points += dd[D[1][0][i]]
            records.append(D[1][0][i])
            
print(points)

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

ll ans(ll n, ll a, ll b)
{
  ll x = b - a;
  if(x % 2)
  {
    return min((a + b - 1) / 2, n + (1 - a - b) / 2);
  }
  else
  {
    return x / 2;
  }
}

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  
  cout << ans(n, a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int r,c;
        
        r = sc.nextInt();
        c = sc.nextInt();
        
        int mat[][] = new int[r][c];
        
        for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				mat[i][j] = sc.nextInt();
			}
		}
	
		for (int i = 0; i < r; i++) {
        	int sum = 0;
			for (int j = 0; j < c; j++) {
				System.out.print(mat[i][j] + " ");
				sum += mat[i][j];
			}
			System.out.println(sum);
		}
		for (int j = 0; j < c; j++) {
        	int sum = 0;
        	for (int i = 0; i < r; i++) {
        		sum += mat[i][j];
			}
			System.out.print(sum + " ");
		}
		
		int sum = 0;
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum += mat[i][j];
			}
		}
		System.out.println(sum);
    }
}



Measured memory_bytes: 42060
#include <stdio.h>
int main(void) {
	int a[3];
	for (int i = 0;i < 3;i++){
		scanf(" %d ", &a[i]);
    }
	int max = 0;
	for (int i = 0;i < 3;i++){
		if (max < a[i]) {
            max = a[i];
        }
    }
	int ans = max * 9 + a[0] + a[1] + a[2];
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int H, W;
    while(cin >> H >> W, H != 0 && W != 0){
        for(int i = 0; i < H; i++){
            for(int j = 0; j <W; j++){
                cout << "#" ;
            }
            cout << "" << endl;
        }
        cout << "" << endl;
    }

return 0;
}
    

Measured memory_bytes: 3084
#include<stdio.h>

int main(void){
  int N,V[25],C[25],i,XY;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&V[i]);
  }
  for(i=0;i<N;i++){
    scanf("%d",&C[i]);
  }
  XY=0;
  for(i=0;i<N;i++){
    if(V[i]-C[i]>0){XY+=V[i]-C[i];}
  }
printf("%d\n",XY);
  
  return 0;
}


Measured memory_bytes: 128
N = int(input())
names = set()
citydict = dict()
for i in range(N):
    S,P = input().split()
    names.add(S)
    if S in citydict:
        citydict[S].append((int(P),i))
    else:
        citydict[S] = [(int(P),i)]

for name in sorted(names):
    for point in sorted(citydict[name],reverse = True):
        print(point[1] + 1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_T = 51;
const int MAX_P = 11;
typedef pair<int,int> PP;
typedef pair<PP,int> P;
 
int main(){
    int m,t,p,r,team[MAX_T][MAX_P],judge[MAX_T][MAX_P];
    int mi,ti,pi,ji,accnt[MAX_T];
 
    while(cin >> m >> t >> p >> r , m + t + p + r){
	vector<P> v;
	fill(team[0],team[MAX_T],0);
	fill(judge[0],judge[MAX_T],0);
	fill(accnt,accnt+MAX_T,0);
 
	for(int i = 0 ; i < r ; i++){
	    cin >> mi >> ti >> pi >> ji;
	    if(ji == 0){
		team[ti][pi] += mi + judge[ti][pi];
		accnt[ti]--;
	    }
	    else{
		judge[ti][pi] += 20;
	    }
	}
	int tt[MAX_T] = {0};
	for(int i = 1 ; i < MAX_T ; i++){
	    for(int j = 1 ; j < MAX_P ; j++){
		tt[i] += team[i][j];
	    } 
	}
	for(int i = 1 ; i <= t ; i++){
	    v.push_back(P(PP(accnt[i],tt[i]),-i));
	}
	sort(v.begin(),v.end());
	for(int i = 1 ; i <= v.size() ; i++){
	    if(v[i-1].first.first < v[i].first.first){
		cout << -v[i-1].second;
		if(i != v.size()) cout << ',';
	    }
	    else{
		if(v[i-1].first.second < v[i].first.second){
		    cout << -v[i-1].second;
		    if(i != v.size()) cout << ',';
		}
		else{
		    cout << -v[i-1].second;
		    if(i != v.size()) cout << '=';
		}
	    }
	}
	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
from collections import deque

S = input()
Q = int(input())

reverse = 1 #reverse == 1 -> 正常, reverse == -1 -> 逆から

d = deque(S)

for i in range(Q):
    Query_tmp = list(map(str, input().split()))
    
    if Query_tmp[0] == "1":
        reverse *= -1
        # S = S[::-1]
    else:
        Ci = Query_tmp[2]

        if Query_tmp[1] == "1":
            if reverse == 1:
                d.appendleft(Ci)
            else:
                rev_Ci = Ci[::-1]
                d.append(rev_Ci)
        else:
            if reverse == 1:
                d.append(Ci)
            else:
                rev_Ci = Ci[::-1]
                d.appendleft(rev_Ci)
    
    # if reverse == 1:
    #     print(S)
    # else:
    #     print(S[::-1])

if reverse == -1:
    d.reverse()

print("".join(d))

Measured memory_bytes: 13684
#include "bits/stdc++.h"
using namespace std;
int Array[100005];
long long Prefix[3][100005];
int N;

int BinarySearch( int low , int high , int key ){
    if( low >= high ) return low;
    else{
        int middle = ( low + high ) >> 1;
        if( Array[middle] == key ) return middle;
        else if( Array[middle] > key ) return BinarySearch( low , middle - 1 , key );
        else return BinarySearch( middle + 1 , high , key );
    }
}

bool IsPossible( int middle , int start , int X ){
    int a = middle - start;
    int b = N - middle + 1 - a;
    int l = start - b + 1;
    if( l <= 0 ) return false;

    if( middle == start ){
        if( l == middle ) return true;
        else{
            if( Array[middle] - X >= X - Array[l] ) return true;
            else return false; 
        }
    }

    if( X - Array[l] > Array[middle - 1] - X ){
        if( Array[middle] - X >= X - Array[l] ) return true;
        else return false;
    }
    else return true;
}

pair<int,int> Find_Segment( int start , int X ){
    int low = start , high = N , middle;
    int length = ceil( (float)(N - start + 1) / 2 );
    
    while( low < high ){
        middle = ( low + high ) >> 1;
        if( N - middle + 1 <= length ) high = middle - 1;
        else{
            if( IsPossible( middle , start , X ) ) high = middle - 1;
            else low = middle + 1; 
        }
    }

    if( !IsPossible( low , start , X ) ) ++low;
    int b = N - low + 1 - ( low - start ); 
    return make_pair( start - b - 1 , low );
}

int main(){
    int q , i;
    scanf( "%d%d" , &N , &q );

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , Array + i );
    
    sort( Array + 1 , Array + N + 1 );

    for( i = 1 ; i <= N ; ++i ){
        Prefix[i&1][i] = Prefix[i&1][i - 1] + Array[i];
        Prefix[(i-1)&1][i] = Prefix[(i-1)&1][i - 1];
        Prefix[2][i] = Prefix[2][i - 1] + Array[i];
    }

    long long Ans;
    int index , X;
    pair<int,int> P;

    for( i = 1 ; i <= q ; ++i ){
        scanf( "%d" , &X );

        if( X >= Array[N] ) Ans = Prefix[N&1][N];
        else if( X <= Array[1] ) Ans = Prefix[2][N] - Prefix[2][N/2];
        else{
            index = BinarySearch( 1 , N , X );
            if( Array[index] > X ) --index;
            P = Find_Segment( index + 1 , X );
            Ans = Prefix[2][N] - Prefix[2][P.second - 1] + Prefix[P.first & 1][P.first];
        }

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

    return 0;
}

Measured memory_bytes: 4480
// यथा चतुर्भिः कनकं परीक्ष्यते निघर्षणच्छेदनतापताडनैः।
// तथा चतुर्भिः पुरुषः परीक्ष्यते त्यागेन शीलेन गुणेन कर्मणा॥
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define mapii std::map<int,int>
#define mpaci std::map<char,int>
#define umapii std::unordered_map<int,int>
#define umapci std::unordered_map<char,int>
#define seti std::set<int>
#define useti std::unordered_set<int>
#define qi std::queue<int>
#define qc std::queue<char>
#define sti std::stack<int>
#define stc std::stack<char>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end() 
#define printv(v) for(auto x: v){ cout<< x << " ";}
#define pi 3.14159265358979323846

void file(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortdesk(const pair<int,int> &a, const pair<int,int> &b){return a.ff>b.ff;}
bool sortdesv(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;}
bool sortascv(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasck(const pair<int,int> &a, const pair<int,int> &b){return a.ff<b.ff;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
int gcd(int a, int b){if (b == 0){return a;} return gcd(b, a % b);}
int cntdiv(int n){int cnt=0;for(int i=1;i<=sqrt(n);++i){if(n%i==0){if(n/i==i)++cnt;else{cnt = cnt + 2;}}}return cnt;}
lld posnegmod(lld x,lld mod){return (x%mod+mod)%mod;}
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];
// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int n;
    cin>>n;
    vv v(n,0);
    for(int i=0;i<n-1;++i){
        int x;
        cin>>x;
        v[x-1]++;
    }
    for(auto x:v){
        cout<<x<<endl;
    }
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
        test_case();
    }
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
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;
}

int N, M, K, Q;

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

    cin >> N;
    vector<int> S(N);
    REP(i, N) cin >> S.at(i);
    cin >> Q;
    vector<int> T(Q);
    REP(i, Q) cin >> T.at(i);

    int ans = 0;
    REP(i, Q) {
        if (upper_bound(ALL(S), T[i]) - lower_bound(ALL(S), T[i]) > 0) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> W_list(N);
  for (int i = 0; i < N; i++) {
    cin >> W_list.at(i);
  }
  int sum_weight = 0;
  for (int x: W_list) sum_weight += x;
  int sum_front = 0;
  int ans = 10000000;
  for (int x: W_list) {
    sum_front += x;
    if (abs(sum_weight - 2 * sum_front) < ans) ans = abs(sum_weight - 2 * sum_front);
    else break;
  }
  cout << ans << endl;
}

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

enum eRoll {
	W,S,N,E
};

class Dice {
private:
	int _dice[6];
public:
	void roll(eRoll er) {
		int _diceinfo[6];
		for (int i = 0; i < 6; ++i) {
			_diceinfo[i] = _dice[i];
		}
		switch (er) {
		case W:
			_dice[0] = _diceinfo[2];
			_dice[1] = _diceinfo[1];
			_dice[2] = _diceinfo[5];
			_dice[3] = _diceinfo[0];
			_dice[4] = _diceinfo[4];
			_dice[5] = _diceinfo[3];
			break;
		case S:
			_dice[0] = _diceinfo[4];
			_dice[1] = _diceinfo[0];
			_dice[2] = _diceinfo[2];
			_dice[3] = _diceinfo[3];
			_dice[4] = _diceinfo[5];
			_dice[5] = _diceinfo[1];
			break;
		case N:
			_dice[0] = _diceinfo[1];
			_dice[1] = _diceinfo[5];
			_dice[2] = _diceinfo[2];
			_dice[3] = _diceinfo[3];
			_dice[4] = _diceinfo[0];
			_dice[5] = _diceinfo[4];
			break;
		case E:
			_dice[0] = _diceinfo[3];
			_dice[1] = _diceinfo[1];
			_dice[2] = _diceinfo[0];
			_dice[3] = _diceinfo[5];
			_dice[4] = _diceinfo[4];
			_dice[5] = _diceinfo[2];
			break;
		}
	}
	int getTopNum() { return _dice[0]; }
	int getRSideNum() { return _dice[2]; }
	int getForwardNum() { return _dice[1]; }
	int getNum(int index) { return _dice[index]; }

	void setNum() {
		for (int i = 0; i < 6; ++i) 
			cin >> _dice[i];
	}
};

bool numCheck(Dice dice1, Dice dice2) {
	bool equal = false;
	int work[6] = {-1,-1,-1,-1,-1,-1};
	int counter = 0;
	for (int i = 0; i < 6; ++i) {
		for (int k = 0; k < 6; ++k) {
			for (int j = 0; j < 6; ++j) {
				if (k == work[j])
					continue;
			}
			if (dice1.getNum(i) == dice2.getNum(k)) {
				equal = true;

				work[counter] = k;
				++counter;
				break;
			}
		}
		if (!equal)
			return false;
	}

	return true;
}

bool IsEqual(Dice dice1, Dice dice2) {
	bool work = true;
	for (int i = 0; i < 6; ++i) {
		if (dice1.getNum(i) != dice2.getNum(i)) {
			work = false;
			break;
		}
	}
	if (work) return true;
	dice1.roll(W);
	dice1.roll(W);
	for (int i = 0; i < 6; ++i) {
		if (dice1.getNum(i) != dice2.getNum(i)) {
			dice1.roll(W);
			dice1.roll(W);
			return false;
		}
	}
	return true;
}

int main() {
	Dice dice1,dice2;
	dice1.setNum();
	dice2.setNum();


	if (!numCheck(dice1, dice2)) {
		cout << "No" << endl;
		//while (true);
		return 0;
	}

	for (int i = 0; i < 3; ++i) {
		for (int k = 0; k < 4; ++k) {
			if (IsEqual(dice1, dice2)) {
				cout << "Yes" << endl;
				//while (true) {}
				return 0;
			}
			dice2.roll(N);
		}
		if (i == 0)dice2.roll(W);
		if (i == 1) {
			dice2.roll(N);
			dice2.roll(W);
		}
	}

	cout << "No" << endl;

	//while (true);
	return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <string>

using namespace std;

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

  string ref = "abc";
  
  for( int i=0;i<3;i++ )
    {
      bool flg = false;
      for( int j=0;j<3;j++ )
	{
	  if( ref[i] == S[j] )
	    flg = true;
	}
      if( !flg )
	{
	  cout << "No" << endl;
	  return 0;
	}
    }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int[] T = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			T[i] = reader.nextInt();
			sum += T[i];
		}
		int M = reader.nextInt();
		int[] P = new int[M];
		int[] X = new int[M];
		for (int i = 0; i < M; i++) {
			P[i] = reader.nextInt();
			X[i] = reader.nextInt();
		}
		for (int i = 0; i < M; i++) {
			int ans = sum - ( T[P[i]-1] - X[i]);
			System.out.println(ans);
		}


		reader.close();
	}
}





Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
const int INF = 0x3f3f3f3f;
int w[maxn], v[maxn];
int dp[100005];

int main(){
    int n, B;
    while(cin>>n>>B){
        int V = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d%d",&w[i],&v[i]);
            V += v[i];
        }
        memset(dp,INF,sizeof(dp));
        dp[0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = V; j >= v[i]; j--){
                dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
            }
        }
        int ans = 0;
        for(int i = V; i >= 0; i--){
            if(dp[i] <= B){
                ans = i; break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 640
n,d=gets.split.map(&:to_i)
points = n.times.map { gets.split.map(&:to_i) }
cnt = 0
points.combination(2).each do |a,b|
  ans =a.zip(b).map {|x,y| (y - x)** 2}.inject(:+)
  cnt += 1 if Math.sqrt(ans) % 1 == 0
end
puts cnt

Measured memory_bytes: 1916
#include<stdio.h>
int main(){

	int h,w,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(w==0 && h==0) break;
		for(i=1;i<=h;i++){
			if(i==1 || i==h){
				for(j=1;j<=w;j++){
					printf("#");
				}
			}else{
				printf("#");
				for(j=1;j<=w-2;j++){
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

const int mod = 1E+09 + 7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int main(){
    int x, y;
    cin >> x >> y;

    if ((x+y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    bool ans = true;
    int tot = (x+y) / 3;
    int sub = abs(x-y);
    if (tot - sub < 0)ans = false;
    if ((tot - sub)%2 != 0)ans = false;
    if (!ans){
        cout << 0 << endl;
        return 0;
    }
    int s = (tot - sub)/2;
    int l = s + sub;
    Combination<modint> COM(s+l+5);

    cout << COM.C(tot, l) << endl;
    return 0;
}

Measured memory_bytes: 10712
line1= input().split(' ')
n= int(line1[0])
m= int(line1[1])

line2= input().split(' ')
hs= []
for h in line2:
	hs.append(int(h))

roads= []
for _ in range(0, m):
	line= input().split(' ')
	roads.append([int(line[0]),int(line[1])])

graph= {}
for o in range(1, n+1):
	graph[o]=[]

for road in roads:
	graph[road[0]].append(road[1])
	graph[road[1]].append(road[0])


def is_good(x):
	height= hs[x-1]
	for adj in graph[x]:
		if hs[adj-1]>= height:
			return False
	return True
	'''height= hs[x-1]
	for road in roads:
		if road[0]==str(x):
			if hs[int(road[1])-1]>=height:
				return False
		if road[1]==str(x):
			if hs[int(road[0])-1]>=height:
				return False
	return True'''

ans= []
for o in range(1,n+1):
	if is_good(o):
		ans.append(o)

print(len(ans))

Measured memory_bytes: 55928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int s=(c+b-1)/b,t=(a+d-1)/d;
    if(s>t)puts("No");
    else puts("Yes");
}


Measured memory_bytes: 3636
A,B,C,D,E,F = map(int,input().split())

W = set([a+b for a in range(0,F+1,100*A) for b in range(0,F+1-a,100*B)])
S = set([c+d for c in range(0,F+1,C) for d in range(0,F+1-c,D)])

ans_con = -1
max_con = E/(100+E)

for w in W:
    for s in S:
        if 0 < s+w <= F and s/(s+w) <= max_con:
            if ans_con < s/(s+w):
                ans_con = s/(s+w)
                ans_sw = s+w
                ans_s = s

print(ans_sw,ans_s)

Measured memory_bytes: 12568
//https://beta.atcoder.jp/contests/abc087/tasks/abc087_b
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
    int A,B,C,X,cnt=0;
    cin >> A >> B >> C;
    cin >> X;
    for(int a=0;a<=A;a++){
        for(int b=0;b<=B;b++){
            for(int c=0;c<=C;c++){
                if(X == 500*a + 100*b + 50*c) cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

public class Main {

    static final int modnum = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        boolean[][] wall = new boolean[H][W];

        int[][] gyo = new int[H][W];
        int[][] retu = new int[H][W];

        for (int h = 0; h < H; h++) {
            String line = sc.nextLine();
            for (int w = 0; w < W; w++) {
                wall[h][w] = line.charAt(w) == '#' ? true : false;
            }
        }
        // for (int h = 0; h < H; h++) {
        // for (int w = 0; w < W; w++) {
        // System.out.print(wall[h][w] ? '#':'.');
        // }
        // System.out.println();
        // }

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (wall[h][w] == false) {
                    if (gyo[h][w] == 0) {
                        int tmp;
                        tmp = 0;
                        int tw = w;
                        while (tw < W && !wall[h][tw]) {
                            tmp++;
                            tw++;
                        }
                        while (w < tw) {
                            gyo[h][w] = tmp;
                            w++;
                        }
                    }
                }
            }
        }
        for (int w = 0; w < W; w++) {
            for (int h = 0; h < H; h++) {
                if (wall[h][w] == false) {
                    if (retu[h][w] == 0) {
                        int tmp;
                        tmp = 0;
                        int th = h;
                        while (th < H && !wall[th][w]) {
                            tmp++;
                            th++;
                        }
                        while (h < th) {
                            retu[h][w] = tmp;
                            h++;
                        }
                    }
                }
            }
        }

        long ans = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                ans = Math.max(ans, gyo[h][w] + retu[h][w]-1);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 103088
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, d, i, j, x;
    cin>>a>>b>>c>>d;
    for(i=0; ;i++)
    {
        if(i%2==0)
        {
            c=c-b;
        }
        else
        {
            a=a-d;
        }
        if(a<=0)
        {
            cout<<"No"<<endl;
            return 0;
        }
        else if(c<=0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }



    return 0;
}


Measured memory_bytes: 3636
#include <iostream>

#define SIZE_MAX 150

using namespace std;

int main(void)
{
  int h, w;
  while (cin >> h >> w && h > 0) {
//    cout << "in:" << h << ", " << w << endl;
    const int inDiag = h*h + w*w;
    int minDiag = 0x7FFFFFFF;
    int minW = SIZE_MAX, minH = SIZE_MAX;


    for (int x = 1; x <= SIZE_MAX; x++) {
      for (int y = 1; y < x; y++) {


	int diag = y*y + x*x;

	if (diag > inDiag && diag < minDiag) {
	  minH = y;
	  minW = x;
	  minDiag = diag;
	} else if (diag == inDiag && y > h && y < minH) {
	  minH = y;
	  minW = x;
	  minDiag = diag;
	} else if (diag > inDiag && diag == minDiag && y < minH) {
	  minH = y;
	  minW = x;
	  minDiag = diag;
	}
      }
    }
    cout << minH << " " << minW << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  string S;
  cin >> S;
  int x_max=0,x=0;
  for(int i=0;i<n;i++){
    if(S.at(i)=='I'){
      x++;
    }
    if(S.at(i)=='D'){
      x--;
    }
    x_max=max(x_max,x);
  }
  cout << x_max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main() {
    ll L,R; cin >> L >> R;
    ll ans = 2019;
    for (ll i=L;i<min(R,L+2019);i++){
        for (ll j=i+1;j<=min(R,L+2020);j++){
            ans = min(ans,((i%2019*j)%2019));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}
map<int,int>m1;
int n;
int check(int x,int y,int z)
{
   return(pow(x,2)+pow(y,2)+pow(z,2)+x*y+y*z+z*x);
}
bool check1(int x,int y)
{
   if(x*x+y*y+x*y<=n)
    return true;
else
    return false;
}
void ram5564()
{
    cin>>n;
    rep(i,1,n+1)
    {
        rep(j,1,n+1)
        {
            if(check1(i,j))
            rep(k,1,n+1)
            {
               int num=check(i,j,k);
               if(num<=n)
               m1[num]++;
               else break;
               
            }
        }
    }
    rep(i,1,n+1)
    {
        cout<<m1[i]<<endl;
    }
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 4216
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n;
    cin >> n;
    vector<int> dp(2000006, 1), a(n), vis(2000006);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int res = 0;
    for(int i = 0; i < n; i++){
        if(dp[a[i]] == 0){
            continue;
        }
        if(vis[a[i]] == 1){
            dp[a[i]] = 0;
            continue;
        }
        vis[a[i]] = 1;
        for(int j = a[i] + a[i]; j <= 2000000; j += a[i]){
            dp[j] = 0;
        }
    }
    for(int i = 0; i < n; i++){
        res += dp[a[i]];
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 19564
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		list<int> l;
		rep(i,n)
			l.push_back(i+1);
		
		iter(l) it=l.begin();
		while(l.size()>1){
			rep(i,m-1){
				it++;
				if(it==l.end())
					it=l.begin();
			}
			it=l.erase(it);
			if(it==l.end())
				it=l.begin();
		}
		
		cout<<*l.begin()<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::mem::{swap};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
        x: i32,
        y: i32,
    }

    let (a_n_b, c2) = (a + b, 2 * c);
    if x > y {
        swap(&mut x, &mut y);
        swap(&mut a, & mut b);
    }
    if c2 < b { println!("{}", c2 * y); }
    else if c2 < a_n_b { println!("{}", c2 * x + b * (y - x)); }
    else { println!("{}", a * x + b * y); }
}



Measured memory_bytes: 4352
// https://atcoder.jp/contests/abc176/tasks/abc176_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> sumh(H), sumw(W), X(M), Y(M);
    REP(i, M) {
        int h, w;
        cin >> h >> w;
        h--, w--;
        sumh[h]++;
        sumw[w]++;
        X[i] = h;
        Y[i] = w;
    }
    vector<int> idxh, idxw;
    int maxh = 0, maxw = 0;
    REP(i, H) {
        if (maxh < sumh[i]) {
            maxh = sumh[i];
            idxh.clear();
            idxh.emplace_back(i);
        } else if (maxh == sumh[i]) {
            idxh.emplace_back(i);
        }
    }

    REP(i, W) {
        if (maxw < sumw[i]) {
            maxw = sumw[i];
            idxw.clear();
            idxw.emplace_back(i);
        } else if (maxw == sumw[i]) {
            idxw.emplace_back(i);
        }
    }
    bitset<300001> vr, vc;
    for (auto &x : idxh) {
        vr[x] = true;
    }
    for (auto &x : idxw) {
        vc[x] = true;
    }
    int cnt = 0;
    REP(i, M) {
        if (vr[X[i]] && vc[Y[i]]) {
            cnt++;
        }
    }
    // 横軸と縦軸の最大値全てに爆弾がある場合は-1
    if (cnt == idxh.size() * idxw.size()) {
        cout << maxw + maxh - 1 << endl;
    } else {
        cout << maxw + maxh << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 20936
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int fil[110][110][110]={0};
int main(){
	int n,m;
	cin>>n>>m;
	vi x(2*n),y(2*n),z(2*n);
	rep(i,2*n)cin>>x[i]>>y[i]>>z[i];
	vi X=x,Y=y,Z=z;
	sort(all(X));sort(all(Y));sort(all(Z));
	rep(i,2*n){
		x[i]=lower_bound(all(X),x[i])-X.begin();
		y[i]=lower_bound(all(Y),y[i])-Y.begin();
		z[i]=lower_bound(all(Z),z[i])-Z.begin();
	}
	rep(q,2*n){
		loop(i,x[q],x[q+1])loop(j,y[q],y[q+1])loop(k,z[q],z[q+1])
			fil[i][j][k]++;
		q++;
	}
	ll out=0;
	rep(i,109)rep(j,109)rep(k,109)if(fil[i][j][k]>=m){
		out+=(ll)(X[i+1]-X[i])*(Y[j+1]-Y[j])*(Z[k+1]-Z[k]);
	}
	cout<<out<<endl;
}

Measured memory_bytes: 5672
#include<bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}


int N;
map<int, int>  ada;
int main(){
   std::ios::sync_with_stdio(false); 
   cin>>N;
   for (int i=0;i<N;i++){
    int x;
    cin>>x;
    ada[x]++;
   }
   int T;
   cin>>T;
   for (int i=0;i<T;i++){
    int x;
    cin>>x;
    if (ada[x] == 0) {
        cout<<"NO"<<endl;
        return 0;
    }
    ada[x]--;
   }
   cout<<"YES"<<endl;
}


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

int main(){ 
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  while (k--) {
    vector<int> tmp(n + 1, 0);
    for (int i = 0; i < n; i++) {
      int l = max(0, i - a[i]), r = min(n, i + a[i] + 1);
      tmp[l]++;
      tmp[r]--;
    }
    for (int i = 0; i < n; i++) tmp[i + 1] += tmp[i];
    bool ok = true;
    for (int i = 0; i < n; i++) if(tmp[i] != n) ok = false;
    a = tmp;
    if (ok) break;
  }
  rep(i,n) cout << a[i] << " ";
  cout << endl;
  return 0;
} 

Measured memory_bytes: 5632
#include <iostream>
using namespace std;
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main()
{
    int k;
    cin>>k;
    int ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1; j<=k;j++){
            for(int l=1;l<=k;l++){
                int gc = gcd(i, gcd(j,l));
                ans+=gc;
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


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

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

const ll INF = 1LL << 60;

int main(){
  ll n,a[10000000][3];
  cin >> n;
  FOR(i,n){
    FOR(j,3){
      cin >> a[i][j];
    }
  }
  ll dp[1000000][3]={0};
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k){
          continue;
        }
        chmax(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<3;i++){
    chmax(ans,dp[n][i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 27776
N, M = map(int, input().split())
a = set(int(input()) for i in range(M))

dp = [0] * (N + 1)
dp[0] = 1

for i in range(1,N+1):
    if i in a:
        dp[i] = 0
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[N])

Measured memory_bytes: 11884
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

int main() {
    int n, q;
    cin >> n >> q;
    queue<pair<string, int>> Q;
    queue<pair<string, int>> Q2;
    string name;
    int time;
    rep(i, n) {
        cin >> name >> time;
        Q.emplace(name, time);
    }
    pair<string, int> tmp;
    int total_time = 0;
    while (!Q.empty()) {
        tmp = Q.front();
        Q.pop();
        if (tmp.second <= q) {
            total_time += tmp.second;
            Q2.emplace(tmp.first, total_time);
        } else {
            total_time += q;
            tmp.second -= q;
            Q.push(tmp);
        }

    }
    rep(i, n) {
        cout << Q2.front().first << " " << Q2.front().second << endl;
        Q2.pop();
    }
}



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

int main() {

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

	int count = 0;
	int odd = 0;
	while (1) {
		for (int i = 0; i < n; i++) {
			int b = a[i]/2;
			if (b*2 == a[i]) {
				a[i] = b;
				if (i == n-1) {
					count++;
				}
			}
			else {
				odd = 1;
				break;
			}
		}
		if (odd == 1) {
			break;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())

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

    hh = l[0]
    cnt = 0
    
    for i in l:
        if i >= hh:
            cnt += 1
            hh = i
    
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define __int64 long long
int n;
int t[111111];

int main(){
	cin>>n;
	rep(i,n)cin>>t[i];
	int c1=0,c2=0;

	rep(i,n){
		if(t[i]%4==0)c1++;
		else if(t[i]%2==0)c2++;
	}

	if(n-1<=c1*2+max(0,(c2-1)))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

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

#define MAX_N 101

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

	int min_w = 10000;

	for (int i = 0; i < N; i++) {
		int S1 = 0, S2 = 0;
		for (int j = 0; j <= i; j++) {
			S1 += W[j];
		}
		for (int j = i+1; j < N; j++) {
			S2 += W[j];
		}
		min_w = min(min_w, abs(S1-S2));
	}
	cout << min_w << endl;
}


Measured memory_bytes: 256