akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define CHUNK_SIZE 1024

struct array_t {
	int size;
	int* data[CHUNK_SIZE];
};

void init(struct array_t* t) {
	int i;
	t->size = 0;
	for (i = 0; i < CHUNK_SIZE; i++) t->data[i] = NULL;
}

void pushBack(struct array_t* t, int x) {
	if (t->data[t->size / CHUNK_SIZE] == NULL) {
		if ((t->data[t->size / CHUNK_SIZE] = malloc(sizeof(int) * CHUNK_SIZE)) == NULL) exit(1);
	}
	t->data[t->size / CHUNK_SIZE][t->size % CHUNK_SIZE] = x;
	t->size++;
}

void dump(const struct array_t* t) {
	int i;
	for (i = 0; i < t->size; i++) {
		printf(" %d" + !i, t->data[i / CHUNK_SIZE][i % CHUNK_SIZE]);
	}
	putchar('\n');
}

void clear(struct array_t* t) {
	int i;
	t->size = 0;
	for (i = 0; i < CHUNK_SIZE; i++) {
		free(t->data[i]);
		t->data[i] = NULL;
	}
}

struct array_t A[1024];

int main(void) {
	int n, q;
	int i;
	if (scanf("%d%d", &n, &q) != 2) return 1;
	for (i = 0; i < n; i++) init(&A[i]);
	for (i = 0; i < q; i++) {
		int query, t, x;
		if (scanf("%d%d", &query, &t) != 2) return 1;
		if (query == 0 && scanf("%d", &x) != 1) return 1;
		switch (query) {
			case 0:
				pushBack(&A[t], x);
				break;
			case 1:
				dump(&A[t]);
				break;
			case 2:
				clear(&A[t]);
				break;
		}
	}
	for (i = 0; i < n; i++) clear(&A[i]);
	return 0;
}



Measured memory_bytes: 15560
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    vector<int> niz(n);
    for (int i = 0; i < n; i++)
        cin >> niz[i];
    sort(niz.begin(), niz.end());
    cout << niz.back() - niz[0];
}

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

void _main() {
    int N;
    cin >> N;
    vector<string> S(N);
    REP (i, N) cin >> S[i];
    map<string, int> mp;
    REP (i, N) mp[S[i]]++;
    cout << mp.size() << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int flag=0;
    if(s[0]=='a' or s[0]=='b' or s[0]=='c') flag++;
    if((s[1]=='a' or s[1]=='b' or s[1]=='c') and (s[1]!=s[0])) flag++;
    if((s[2]=='a' or s[2]=='b' or s[2]=='c') and (s[2]!=s[1]) and (s[2]!=s[0])) flag++;
    flag==3?cout<<"Yes"<<endl:cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String[] s =  sc.next().split("");
		
		String tmp = "";
		for(int i = 0 ; i < s.length ;i++ ) {
			char c=s[i].charAt(0);
			int ans = (int)c + n;
			if(ans > 90 ) {
				ans = ans - 26;
			}
			
			tmp += (char)ans;
		}
		
		
		System.out.println(tmp);
    }
}

Measured memory_bytes: 148304
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int f[3][maxn*4],g[3][maxn*4],N,mod,ans=0;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
int main()
{
	scanf("%d%d",&N,&mod);f[0][N]=1;
	for(int i=0;i<3*N;i++)
	{
		for(int j=0;j<=N*4;j++) g[0][j]=g[1][j]=g[2][j]=0;
		for(int j=0;j<=N*4;j++)
		{
			Add(g[2][j],1ll*f[0][j]*(i+2)%mod*(i+1)%mod);
			if(j) Add(g[1][j-1],1ll*f[0][j]*(i+1)%mod);
			Add(g[0][j+1],f[0][j]);
		}
		for(int j=0;j<=N*4;j++) f[0][j]=(f[1][j]+g[0][j])%mod,f[1][j]=(f[2][j]+g[1][j])%mod,f[2][j]=g[2][j];
	}
	int ans=0;
	for(int i=0;i<=N;i++) Add(ans,f[0][3*i+N]);
	cout<<ans<<endl;
}

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

int main() {
    string s;
  	cin >> s;
  	int cnt;
  	rep(i, s.length()){
      	cnt = 0;
    	rep(j, s.length()){
        	if(s[i] == s[j]){
            	cnt++;
            }
        }
      	if(2 <= cnt){
        	cout << "no" << endl;
          	return 0;
        }
    }
  	cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];

signed main(){
    int n;cin>>n;
    int num[100005]={};
    int to=0;
    rep(i,n){
        int a;cin>>a;
        if(a>100000){
            to++;
            continue;
        }
        else num[a]++;
    }
    rep(i,100001){
        if(num[i]==i)continue;
        else if(num[i]<i)to+=num[i];
        else to+=num[i]-i;
    }
    cout<<to<<endl;
    return 0;
}

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

#define FOR(i, l, r) for(size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i, N) {
        cin >> H[i];
    }
    vector<int> D(N);
    vector<int> A(M);
    vector<int> B(M);
    REP(i, M) {
        cin >> A[i];
        cin >> B[i];
    }

    int start, end;
    REP(i, M) {
        start = A[i] - 1;
        end = B[i] - 1;
        if(H[start] > H[end]) {
            D[end] = -1;
            if(D[start] != -1) {
                D[start] = 1;
            }
        }
        else if(H[start] < H[end]) {
            D[start] = -1;
            if(D[end] != -1) {
                D[end] = 1;
            }
        }
        else {
            D[start] = -1;
            D[end] = -1;
        }
    }
    int count = 0;
    REP(i, N) {
        if(D[i] != -1) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt() / 1000;
		for(int i = 0; i <= y/10;i++){
			for(int j =0; j <= y/5;j++){
				for(int k = 0;k <= y; k++){
					if(i+j+k == n){
						if((i *10) + (j * 5) + k == y){
							System.out.println(i + " " + j +" " + k);
							return;
						}
					}else if(i+j+k > n) break;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

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

int main(void){
    int n;
    cin >> n;
    string s = "ABD";
    if(n < 1000) s = "ABC";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	set<long long int>a;
	for(int i=0;i<n;i++)
	{
		long long int b;
		cin>>b;
		a.insert(b);
		}
	int c=a.size();
	if(c==n)
	cout<<"YES";
	else if(c!=n)
	cout<<"NO";	
	
	
}


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

using namespace std;

int cnt=0;
int n,m,q;
int a[55],b[55],c[55],d[55];
int ans=0;
vector<int> A;

void dfs(int idx,int num){
    if(idx == n){
        //for(int j=0;j<A.size();j++) cout << A[j] << " " ;
        //cout << endl;
        cnt = 0;
        for(int i=0;i<q;i++){
            //cout << A[a[i]-1] << " " << A[b[i]-1] << " " << c[i] << " " << d[i] << " ";
            if(A[b[i]-1] - A[a[i]-1] == c[i]){
                //cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << " ";
                cnt += d[i];
            }
        }
        //cout << cnt << endl;
        ans = max(ans,cnt);
    }
    else{
        for(int i=num; i<=m; i++){
            A.push_back(i); //配列を作る
            //cout << endl;
            //cout << A[i-1] << endl;
            dfs(idx+1,i);
            A.pop_back();
        }
    }
    //cout << "hello" << endl;
}

int main(){

    cin >> n >> m >> q;
    for(int i=0;i<q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(0,1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#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 vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
	int n,m;
	cin>>n>>m;
	UnionFind uf(n);
	vvi in(m);
	rep(i,n){
		int a;
		cin>>a;
		rep(j,a){
			int b;
			cin>>b;
			in[b-1].pb(i);
		}
	}
//	rep(i,m){rep(j,in[i].size())cout<<" "<<in[i][j];cout<<endl;}
	rep(i,m)if(in[i].size())rep(j,in[i].size()-1)uf.unionSet(in[i][j],in[i][j+1]);
	if(uf.size(0)==n)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}








Measured memory_bytes: 4608
#include<stdio.h>
int main(void)
{
	int w,h,c,x,i,a,b;
	scanf("%d %d %d",&w,&h,&c);
	if (w>h){
		x=h;	
	}
	if (w<h){
		x=w;	
	}
	while(1){
		if(w%x==0&&h%x==0){
			break;
		}
		x=x-1;
	}
	a=(w/x)*(h/x);
	b=a*c;
	printf("%d\n",b);
	return 0;
}
	
	
	
	


Measured memory_bytes: 2104
N, K, Q = map(int, input().split())

import numpy as np

n = np.full(N, K)
#print(n)

for i in range(Q):
    s = int(input())
    n[s-1] += 1

n -= Q
#print(n)

for i in range(N):
    if n[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> que;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        que.push(a);
    }
    double ans = que.top();
    que.pop();
    while(!que.empty())
    {
        int cand = que.top();
        que.pop();
        ans += cand;
        ans = ans / 2;
    }
    printf("%.5f", ans);
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>
typedef long long int ll;
using namespace std;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}


int main() {
 ll count = 0;
 int N;
 cin >> N;
 ll M[5]={0,0,0,0,0};
 for(int i=0;i<N;i++){
     string s;
     cin >> s;
     if(s.substr(0,1)=="M"){
         M[0]++;
     }else if(s.substr(0,1)=="A"){
         M[1]++;
     }else if(s.substr(0,1)=="R"){
         M[2]++;
     }else if(s.substr(0,1)=="C"){
         M[3]++;
     }else if(s.substr(0,1)=="H"){
         M[4]++;
     }
 }

 ll result = 0;


 for(int i=0;i<5;i++){
     for(int j=i+1;j<5;j++){
         for(int k=j+1;k<5;k++){

             result+=(M[i]*M[j]*M[k]);

         }

     }
 }

 cout << result << endl;


}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    string n; cin >> n;
    int num = sz(n);
    int sum = 0;
    rep(i,num) {
        sum += n[i]-'0';
    }
    if (sum%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int s = NextInt;
            var array = Enumerable.Repeat(false, 1000001).ToArray();
            array[s] = true;

            for (int i = 1; ; i++)
            {
                s = s % 2 == 0 ? s / 2 : 3 * s + 1;
                if (array[s])
                {
                    System.Console.WriteLine(i + 1);
                    return;
                }
                array[s] = true;
            }
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

int main(void){
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	for (int i = 0; i <= K; i++) {
		int Cn = C*pow(2,i);
		for (int j = 0; j <= K-i; j++) {
			int Bn = B*pow(2,j);
			if (Cn > Bn && Bn > A){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 4004
// 解説をそのまま写経した感じです

function Main(input){
  input = input.split("\n");
  var n = ~~input[0]
  var v = input[1].split(" ");
  var even = [];
  var odd = [];
  for(var i = 0; i < n; i++){
  	var h = v[i];
    var a = (i%2?odd:even)[h];
    a = a || {val:h,count:0};
    a.count++;
    if(i%2){odd[h]=a}else{even[h]=a};
  }
  even = even.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  odd = odd.sort((a,b)=>a.count-b.count).reverse().filter(a=>a);
  // filter : nullを消去
 
  if(even[0].val!=odd[0].val){
  	return n - even[0].count - odd[0].count;
    // 最頻値が異なる
  }
  if(!even[1] && !even[2]){
  	return n/2;
    // 偶奇どちらの副最頻値も存在しない
    // （すべての数字が同じ）
  }
  if(!even[1]){
  	return n - even[0].count - odd[1].count;
    // 偶数番目の副最頻値が存在しない
  }
  if(!odd[1]){
  	return n - even[1].count - odd[0].count;
    // 奇数番目の副最頻値が存在しない
  }
  return Math.min(
  	n - even[0].count - odd[1].count,
    n - even[1].count - odd[0].count
  );
}

console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 46836
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if(a < b) return gcd(b,a); // a >= b
  if(b == 0) return a;
  else return gcd(b, a%b);

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

  l[0]   = a[0];
  r[n-1] = a[n-1];
  for(int i = 1  ; i <  n; i++)  l[i] = gcd(l[i-1], a[i]);
  for(int i = n-2; i >= 0; i--)  r[i] = gcd(r[i+1], a[i]);

  int ans = r[0]; // 全体gcd値

  for(int i=0;i<=n-1;i++){ // i番目を抜いた時のgcd値
    if(i == 0) ans = max(ans, r[i+1]);
    else if(i == n-1) ans = max(ans, l[i-1]);
    else ans = max(ans, gcd(l[i-1], r[i+1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>  
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
bool dp[2][100005];
ll n,k;
ll arr[105];
ll mini;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,false,sizeof(dp));
    cin>>n>>k;
    mini=INT_MAX;
    for(ll i=0;i<n;++i)
    {
        cin>>arr[i];
        mini=min(mini,arr[i]);
    }
    ll i=k;
    for(;i>=k-mini;--i)
    {
        if(i==k-mini)
        {
            dp[0][k-mini]=true;
            dp[1][k-mini]=true;
        }
        else
        {
            dp[0][i]=false;
            dp[1][i]=false;
        }
    }
    for(;i>=0;--i)
    {
        bool cans=true;
        bool cans1=true;
        for(ll j=0;j<n;++j)
        {
            ll next=i+arr[j];
            if(next<=k)
            {
                cans=cans & dp[1][next];
                cans1=cans1 & dp[0][next];
            }
        }
        dp[0][i]=!cans;
        dp[1][i]=!cans1;
    }
    if(dp[0][0]==false)
    {
        cout<<"Second"<<endl;
    }
    else
    {
        cout<<"First"<<endl;
    }
}






































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

int N; 
long long V[300005];
int main() {
    
    long long maxVal = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> V[i];
        maxVal = max(V[i], maxVal);
    }
    long long sum = 0;
    long long offset = 0;
    while (maxVal > 0) {

        long long zero = 0;
        long long one = 0;
        for (int i = 0; i < N; i++) {
            long long x = V[i];
            if ((x >> offset) & 1) {
                one++;
            } else {
                zero++;
            }
        }
        long long modV = 1000000007l;

        sum += (((zero % modV) * (one % modV)) % modV) * ((1l << offset) % modV);
        sum %= 1000000007l;
        offset++;
        maxVal = maxVal >> 1;
    }
    cout << sum;
} 





Measured memory_bytes: 2560
#include<stdio.h>

int main(){
    char s[5];
    int i=0;
    fgets(s,5,stdin);
    while(s[++i]!='\n');
    if(i==3){
        for(;i>0;i--)putchar(s[i-1]);
        puts("");
    }else{
        printf("%s",s);
    }
    return 0;
}

Measured memory_bytes: 128
const main = input => {
  const inputs = input.trim().split('\n')
  const [N, K] = inputs[0].split(' ').map(x => parseInt(x))
  const heights = inputs[1].split(' ').map(x => parseInt(x))

  let count = 0
  for (let i = 0; i < N; i++) {
    if (heights[i] >= K) {
      count++
    }
  }

  console.log(count)
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 36936
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
int M, N, A[maxn];
int main()
{
    scanf("%d %d", &N, &M);
    int sum = 0;
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &A[i]);
        sum += A[i];
    }
    int cnt = 0;
    for(int i = 1; i <= N; i++)
    {
        if(sum % (4 * M) == 0 && A[i] >= sum / (4 * M))
            cnt++;
        if(sum % (4 * M) != 0 && A[i] > sum / (4 * M))
            cnt++;
    }
    if(cnt >= M)
        printf("Yes");
    else
        printf("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 12
int w[MAX][MAX];//二次配列のポインタを関数に渡すやり方が分からなかった

void search(int i,int j){
    w[i][j]=0;
    if(i!=MAX-1)if(w[i+1][j])search(i+1,j);
    if(i!=0)if(w[i-1][j])search(i-1,j);
    if(j!=MAX-1)if(w[i][j+1])search(i,j+1);
    if(j!=0)if(w[i][j-1])search(i,j-1);
}

int main(){
    int i,j,cnt;
    char c;

    while(1){
        cnt=0;
        for(i=0;i<MAX;i++){
            for(j=0;j<MAX;j++){
                if(scanf("%c",&c)==EOF)return 0;
                w[i][j]=c-'0';
            }
            getchar();
        }
        getchar();

        for(i=0;i<MAX;i++){
            for(j=0;j<MAX;j++){
                //printf("%d",w[i][j]);
                if(w[i][j]==1){
                    search(i,j);
                    cnt++;
                }
            }
            //puts("");
        }

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

Measured memory_bytes: 548
import os
import sys

import numpy as np
from scipy.sparse.csgraph._shortest_path import floyd_warshall

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)]


def to_i(h, w):
    return h * W + w


N = H * W
graph = [[0] * N for _ in range(N)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            if 0 <= h - 1 < H and S[h - 1][w] == '.':
                graph[to_i(h - 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h - 1, w)] = 1
            if 0 <= h + 1 < H and S[h + 1][w] == '.':
                graph[to_i(h + 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h + 1, w)] = 1
            if 0 <= w - 1 < W and S[h][w - 1] == '.':
                graph[to_i(h, w - 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w - 1)] = 1
            if 0 <= w + 1 < W and S[h][w + 1] == '.':
                graph[to_i(h, w + 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w + 1)] = 1
dist = floyd_warshall(graph, directed=False)
dist[dist == np.inf] = 0
print(int(dist.max()))


Measured memory_bytes: 29868
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K;
  cin>>N>>K;
  int L=(K-1)*K/2,R=(N*2-K+1)*K/2,j=0;
  for(;K<=N+1;K++){
    j=(j+R-L+1)%1000000007;
    L+=K;
    R+=N-K;
  }
  cout<<j<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main ()
{
    int n;
    while (cin >> n, n) {
        vector<set<int> > v(n, set<int>());
        for (int i = 0; i < n; i++) {
            int tmp;
            cin >> tmp;
            while (tmp--) {
                int tmpp;
                cin >> tmpp;
                v[i].insert(tmpp);
            }
        }

        set<int> more;
        int m;
        cin >> m;
        while (m--) {
            int tmp;
            cin >> tmp;
            more.insert(tmp);
        }

        vector<int> res;
        for (int i = 0; i < n; i++) {
            if (more.size() <= v[i].size()) {
                int flag = true;
                for (auto j : more) {
                    if (v[i].find(j) == v[i].end()) {
                        flag = false;
                        break;
                    }
                }
                if (flag) res.push_back(i+1);
            }
        }

        cout << (res.size() == 1 ? res[0] : -1) << endl;
    }

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i, n) {
    if ((s[i] - '0') == i % 2) ans++;
  }
  ans = min(ans, n - ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  vector<int>A(n);
  vector<int>C(n-1);
  for(int i=0;i<n;i++){
  cin >>A.at(i);
  }
  int s;
   for(int i=0;i<n;i++){
  int a;
  cin >>a;
     s+= a;
  }
   for(int i=0;i<n-1;i++){
  cin >>C.at(i);
  }
  for(int i=0;i<n-1;i++){
  if (A.at(i+1)==A.at(i)+1){
  s+=C.at(A.at(i)-1);
  }
  }
    cout <<s<<endl;
}

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

using namespace std;
typedef long long ll;

const int maxn = 3e2 + 7;
int n, m, k, t, res;
int a[maxn][maxn], vt[maxn], sl[maxn];
bool check[maxn];

int main()
{
#ifndef ONLINE_JUDGE
#define file "r"
//    freopen(file".inp", "r", stdin);
//  freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m ; j ++)
    {
        cin >> a[i][j];
    }
    for(int i = 1; i <= n; i ++) vt[i] = 1;
    k = m; res = m + n;
    while(k --)
    {
        for(int i = 1; i <= m; i ++) sl[i] = 0;
        int ma = 0; t = 0;
        for(int i = 1; i <= n; i ++)
        {
            while(check[a[i][vt[i]]]) vt[i] ++;
            sl[a[i][vt[i]]] ++;
            if(ma < sl[a[i][vt[i]]]) ma = sl[a[i][vt[i]]], t = a[i][vt[i]];
        }
        if(sl[t] < res) res = sl[t];
        check[t] = true;
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  cout << ((g*10+b)%4==0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
N,u,v = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
(1 ... N).each do
  a,b = gets.split.map(&:to_i)
  G[a] << b
  G[b] << a
end

def bfs(s, distance)
  used = Array.new(N + 1)
  q = [] 
  q << [s, 0]
  used[s] = true
  
  until q.empty?
    u,d = q.shift
    distance[u] = d

    G[u].each do |v|
      unless used[v]
        used[v] = true
        q << [v, d + 1]
      end
    end
    
  end
end

T = Array.new(N + 1, Float::INFINITY)
A = Array.new(N + 1, Float::INFINITY)

bfs(u, T)
bfs(v, A)

l = (1 .. N).max_by{|i| G[i].size == 1 && T[i] < A[i] ? A[i] : -Float::INFINITY }
puts A[l] - 1


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

int main(){
    int n;
    cin>>n;
    int a[n+5][n+5];
    for(int i=0; i<n; i++){
        for(int j=0; j<2; j++){
            cin>>a[i][j];
        }
    }
    bool flag=false;
    for(int i=0; i<n-2; i++){
        for(int j=0; j<2; j++){
            if((a[i][0]==a[i][1]) && (a[i+1][0]==a[i+1][1]) && (a[i+2][0]==a[i+2][1]))
                flag=true;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}


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

int main()
{
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;

    if (n%2) {
        std::cout << "No" << std::endl;
        return 0;
    }

    for (int i = 0; i < n/2; i++) {
        if (s[i] != s[i+n/2]) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n;
    li now = 0;
    li res = 0;
    cin >> n;
    string s;
    cin >> s;
    rin{
        if (s[i] == 'I') {
            now++;
            res = max(res, now);
        } else{
            now--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


typedef long long ll;

const long MOD = 998244353;
#define N_MAX 2000002

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

int main(){
    ll N, M;
    cin >> N >> M;
    init();
    ll ans = 0;
    for(ll m = 0; m <= M; m++){
        if((M-m)%2 != 0) continue;
        ans += (comb(N, m)*comb((3*M-m)/2+N-1, N-1))%MOD;
        ans %= MOD;
        ans -= (((comb(N, m)*(N-m))%MOD)*comb((M-m)/2-1+N-1, N-1))%MOD;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
        ans -= (((comb(N, m)*m)%MOD)*comb((M-m)/2+N-1, N-1))%MOD;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 47104
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int N;
int spot[1000003]={};
int maxcost=0;

int calc(int& a,int& b){
    if(a>b) return a-b;
    else return b-a;
}

int main(void){
    cin>>N;
    for(int i=1;i<=N;i++){
        scanf("%d",&spot[i]);
    }

    int m1;
    for(int i=1;i<=N+1;i++){
        maxcost+=calc(spot[i-1],spot[i]);
    }

    int beforecost,aftercost;
    for(int i=1;i<=N;i++){
        if((spot[i-1]<=spot[i]&&spot[i]<=spot[i+1])||(spot[i-1]>=spot[i]&&spot[i]>=spot[i+1])){
            cout<<maxcost<<endl;
        }else{
            beforecost=calc(spot[i-1],spot[i])+calc(spot[i],spot[i+1]);
            aftercost=calc(spot[i-1],spot[i+1]);
            cout<<maxcost-beforecost+aftercost<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 1664
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort(); F = F[::-1]

def check(x):
    cost = np.maximum(0, A - (x // F)).sum()
    return cost <= K

ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
    mid = (ok+ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)


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

int main(){
    ll A, B, N;
    cin >> A >> B >> N;
    ll X = min(N, B-1);
    ll ans = (A*X)/B-A*(X/B);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
	string S;
	cin >> S;
	int answer = 0, length = S.length();
	for (int count = 0; count < length / 2; count++)
	{
		if (S.at(count) != S.at(length - count - 1))
			answer++;
	}
	cout << answer << endl;
}

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

int main () {
  
  int D, N; cin >> D >> N;
  
  int A;
  
  if (D == 0) A = 1;
  else if (D == 1) A = 100;
  else A = 10000;
  
  if (N != 100) cout << N * A;
  else cout << 101 * A;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main()
{
  int K, A, B;
  cin >> K >> A >> B;

  int mul_num1 = (A-1) / K;
  int mul_num2 = B / K;

  if (mul_num2 - mul_num1 > 0) cout << "OK";
  else cout << "NG";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int n;
	string s;
	cin >> n >> s;
	int count=0;
	rep(i,n) {
		if(s.substr(i,3) == "ABC") count++;
	}
	cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=100010;
const ll mod =1000000007;
ll a[N]={0},vis[N]={0};
int main()
{
    a[0]=1,a[1]=1;
    int n,m;
    scanf("%d%d",&n,&m);
    int x;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&x);
        vis[x]=1;
        a[x]=0;
    }
    for(int i=2;i<=n;i++)
    {
         if(vis[i])continue;
         a[i]=(a[i-1]+a[i-2])%mod;
    }
    printf("%lld\n",a[n]);
    return 0;
}


Measured memory_bytes: 1792
# input process
N = int(input())
inputData = input().split()
P = [int(x) for x in inputData]
c = 0
for i in range(1, N-1):
    threenum = [P[i-1], P[i], P[i+1]]
    st_threenum = sorted(threenum)
    if threenum[1] == st_threenum[1]:
        c += 1
    if i == (N - 1):
        break
print(c)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int w,h;
int masu[1010][1010];
int dx[] = {-1,-1,-1,0,0,1,1,1};
int dy[] = {-1,0,1,-1,1,-1,0,1};
void dfs(int y,int x){
    masu[y][x] = 0;
    for(int i=0;i<8;i++){
        int ny = y+dy[i];
        int nx = x+dx[i];
        if(ny<0||ny>=h||nx<0||nx>=w||masu[ny][nx]==0) continue;
        dfs(ny,nx);
    }
}
int main(){
    int ans;
    while(cin >> w >> h,w!=0||h!=0){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) cin >> masu[i][j];
        }
        ans = 0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(masu[i][j] == 1){
                    ans++;
                    dfs(i,j);
                }
            }
        }
        cout << ans << endl;
    }
    return(0);
}



Measured memory_bytes: 3264
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string a;
    cin >> a;
    int n = a.size();
    ll odp = 0;
    int ilA = 0;
    for (int i = 0; i < n; )
    {
        if (a[i] == 'A')
        {
            ++ilA;
            ++i;
            continue;
        }
        if (i + 1 < n && a[i] == 'B' && a[i + 1] == 'C')
        {
            odp += ilA;
            i += 2;
        }
        else
        {
            ilA = 0;
            ++i;
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define eps 1e-8
#define ll long long
#define ed cout<<endl
#define pb push_back
#define mp make_pair
#define fi first
#define ll long long
#define se second
#define inf 2e9
#define sz 456789
#define all(x) x.begin(), x.end()
#define pi 3.14159265359
using namespace std;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll a, b, c;
int main(){
    faster();
    cin >> a >> b >> c;
    if(a + b + c >= 22){
        cout << "bust";
    }
    else
        cout << "win";
    return 0;
}


Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = list(map(int,input().split()))

from collections import Counter
L = len(Counter(A))

# 全体枚数が奇数で, カードの種類が偶数 
#  -> 重複カードは奇数
#  -> どれか1種類は全て捨てないと重複カードは処分不可能
if L%2==0:
    print(L-1)
# 重複カードが偶数, ペアを作って全て処分可能
else:
    print(L)

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

#define rep(a,b) for(int ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  fst_io;
  string s,t;
  ll c=0;
  cin>>s>>t;
  rep(0,s.length())
  {
    if(s[ii]!=t[ii]) c++;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3740
#include<stdio.h>

int main(){
  int x;
  int hap=0;
  scanf("%d",&x);
  while(x>=500){
    hap+=1000;
    x-=500;
  }
  
  while(x>=5){
    hap+=5;
    x-=5;
  }
  
  printf("%d",hap);
  
  return 0;
}

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

signed main(){
   int N,W; cin>>N>>W;
   int wmin,v; cin>>wmin>>v;
   vector<vector<int>> wv(N,vector<int>(4));
   wv[0].push_back(v);
   for(int i=0;i<N-1;i++){
       int w; cin>>w>>v;
       wv[w-wmin].push_back(v);
   }
   for(int i=0;i<4;i++){
       sort(wv[i].begin(),wv[i].end());
       reverse(wv[i].begin(),wv[i].end());
   }
   for(int i=0;i<4;i++){
       for(int j=1;j<wv[i].size();j++){
           wv[i][j]+=wv[i][j-1];
       }
   }
   int ans=0;
   for(int end0=0;end0<=wv[0].size();end0++){
       for(int end1=0;end1<=wv[1].size();end1++){
           for(int end2=0;end2<=wv[2].size();end2++){
               for(int end3=0;end3<=wv[3].size();end3++){
                   if(wmin*end0+(wmin+1)*end1+(wmin+2)*end2+(wmin+3)*end3<=W){
                       int tmp=0;
                       if(end0!=0)tmp+=wv[0][end0-1];
                       if(end1!=0)tmp+=wv[1][end1-1];
                       if(end2!=0)tmp+=wv[2][end2-1];
                       if(end3!=0)tmp+=wv[3][end3-1];
                       ans=max(ans,tmp);
                   }
               }
           }
       }
   }
   cout<<ans<<endl;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

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

  vector< int > a(3);
  REP(i, 3)
    cin >> a[i];

  sort(ALL(a));
  int ans = 0;
  REP(i, 2) {
    ans += abs(a[i + 1] - a[i]);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
using System;

class main
{
    static void Main(string[] args)
    {
        while (true)
        {
            string str = Console.ReadLine();
            if (str == null) break;
            int n = int.Parse(str);
            int s = 0;
            for (int i = n; i < 600; i += n){
                s += i * i * n;
            }
            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,sum=0;
    cin>>n;
    vector<int>a(n);
    map<int,int>mp;
    rep(i,0,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    for(auto i:mp){
        sum+=i.second*(i.second-1)/2;
    }
    
    rep(i,0,n){
        cout<<sum-mp[a[i]]+1<<endl;
    }
}

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

int main() {
    int n, k, q; cin >> n >> k >> q;
    vector<int> ans(n, k-q);
    rep(i,q) {
        int a;
        cin >> a;
        ans[a-1]++;
    }
    rep(i,n) {
        if (ans[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(N);
  while(M--){
    int a,b;
    cin>>a>>b;
    A[a-1].push_back(b-1);
    A[b-1].push_back(a-1);
  }
  vector<int> B(N,-1);
  queue<int> Q;
  B[0]=0;
  Q.push(0);
  while(!Q.empty()){
    int I=Q.front();
    Q.pop();
    for(int i:A[I])
      if(B[i]==-1){
        B[i]=I;
        Q.push(i);
      }
  }
  puts("Yes");
  for(int i=1;i<N;i++)cout<<B[i]+1<<endl;
}

Measured memory_bytes: 13036
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n,y;
	cin>>n>>y;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i+j<=n&&10000*i+5000*j+1000*(n-(i+j))==y){
				cout<<i<<" "<<j<<" "<<n-(i+j)<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using hset = unordered_set<T>;
template<class Key, class T> using hmap = unordered_map<Key, T>;

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

int main() {
    int n, m, p, sum, win, tmp;
    while (cin >> n >> m >> p) {
        if (n == 0) break;
        sum = 0;
        for (int i = 1; i <= n; i++) {
            cin >> tmp;
            sum += tmp;
            if (i == m) win = tmp;
        }

        if (win == 0) cout << 0 << endl;
        else cout << (100*sum)*(100-p)/(win*100) << endl;
    }

    return 0;
}

Measured memory_bytes: 3040
import sys
from collections import deque

d = deque()
n = int(input())
lines = sys.stdin.readlines()
for i in range(n):
    ins = lines[i].split()
    command = ins[0]
    if command == "insert":
        d.appendleft(ins[1])
    elif command == "delete":
        try:
            d.remove(ins[1])
        except:
            pass
    elif command == "deleteFirst":
        d.popleft()
    elif command == "deleteLast":
        d.pop()

print(" ".join(d))

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

bool inc(int b, int c){
  if(b <= c) return 1;
  else return 0;
}

bool dec(int b, int c){
  if(b >= c) return 1;
  else return 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  int ans = 1;
  int sta = 0;
  for(int i = 0; i < n - 1; i++){
    if(!sta){
      if(a.at(i) == a.at(i+1)) sta = 0;
      if(a.at(i) < a.at(i+1)) sta = 1;
      if(a.at(i) > a.at(i+1)) sta = 2;
      continue;
    }
    
    if(sta == 1){
      if(!inc(a.at(i), a.at(i+1))){
        ans++;
        sta = 0;
      }
    }
    
    if(sta == 2){
      if(!dec(a.at(i), a.at(i+1))){
        ans++;
        sta = 0;
      }
    }
  }
  
  cout << ans << endl;
    
}


Measured memory_bytes: 640
import Data.List
main :: IO()
main = do
  [n, k]<- map read . words <$> getLine
  vals <- map read . words <$> getLine
  print $ slv n k vals

slv :: Int -> Int -> [Int] -> Int
slv n k vals = d3 + m3val
  where (d3, m3) = (n - 1) `divMod` (k - 1)
        m3val | m3 /= 0 = 1
              | otherwise = 0

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

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  
  int ans = H*W;
  ans -= H*w + W*h;
  ans += w*h;
  
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std; 

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void cook()
{
    // start with your recipe
    long long n, i;
	long double x, ans = 1;
    cin>>n;
    bool f = 0;
	for(i=0;i<n;++i)
    {
        cin>>x;
		if(f && x == 0)
		{
			cout<<"0";
			exit(0);
		}
        if(!f && (ans*x > 1000000000000000000LL || ans*x < 0 || (ans*x < ans && x != 0)))
        {
            f = 1;
        }
        ans *= x;
    }
	if(f)	cout<<"-1";
    else	cout<<fixed<<setprecision(0)<<ans;
}

start_cooking
{
    main_ingredient_added
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while(t--)
        cook();
    food_is_ready
}


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

int main(){
    ll x;
    cin >> x;

    if(x<=3) {
        cout << 2 << endl;
        return 0;
    }
    
    while(true) {
        for(int i=2; i<x; i++) {
            if(x%i==0) break;
            if(i==x-1) {
                cout << x << endl;
                return 0;
            }
        }
        x++;
    }
    return 0;
}

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

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


int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int sol = 0, canv = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i-1]) sol++;
    else canv++;
  }
  sol = min(n-1,  sol+2*k);
  cout << sol << endl;
}



Measured memory_bytes: 512