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

int main(void)
{
	int m, f, r,i=0,j;
	int a[50];

	while (1)
	{
		scanf("%d %d %d", &m, &f, &r);
		if ((m == -1) && (f == -1) && (r == -1))
			break;

		if ((m == -1) || (f == -1))
			a[i] = -1;

		else if (m + f >= 80)
			a[i] = 0;
		else if ((65 <= m + f) && (m + f < 80))
			a[i] = 1;
		else if ((50 <= m + f) && (m + f < 65))
			a[i] = 2;
		else if ((30 <= m + f) && (m + f < 50))
		{
			if (r >= 50)
				a[i] = 2;
			else
				a[i] = 3;
		}
		else if (m + f < 30)
			a[i] = -1;

		i++;
	}

	for (j = 0; j < i; j++)
	{
		switch (a[j])
		{
		case 0:
			printf("A");
			break;
		case 1:
			printf("B");
			break;
		case 2:
			printf("C");
			break;
		case 3:
			printf("D");
			break;
		case -1:
			printf("F");
			break;
		default:
			break;
		}
		printf("\n");
	}
}



Measured memory_bytes: 2108
import itertools

N = int(input())
S = []
cnt_dict = {'M': 0, 'A': 0, 'R': 0, 'C': 0,'H': 0}

for _ in range(N):
    s = input()
    if s[0] in cnt_dict.keys():
        cnt_dict[s[0]] += 1

cnt_list = list(cnt_dict.values())
cnt = 0
for c in itertools.combinations(range(5), 3):
    cnt += cnt_list[c[0]]*cnt_list[c[1]]*cnt_list[c[2]]
print(cnt)


Measured memory_bytes: 3064
h, w = map(int,input().split())
A = [list(input()) for i in range(h)]

B = [[0 for i in range(w+2)] for i in range(h+2)]

for i in range(h) :
    for j in range(w) :
        p = i+1
        q = j+1
        if A[i][j] == "#" :
            B[p][q] = 10
            for r in range(-1,2) :
                for s in range(-1,2) :
                    B[p+r][q+s] += 1

for i in range(h+2):
    for j in range(w+2):
        if B[i][j] > 8 :
            B[i][j] = "#"

for i in range(1,h+1) :
    ans = ""
    for j in range(1,w+1) :
        ans += str(B[i][j])
    print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a; i > b; i--)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
#define MOD 1000000007
typedef long long ll;

int main() {
    fastcin;
    int X;
    cin >> X;
    int a = sqrt(X), ans;
    int p = pow(a, 2);
    if(a == 1) ans = 1;
    else {
        REP(i, 2, a){
            int tmp = i;
            while(tmp <= X) {
                tmp *= i;
            }
            tmp /= i;
            if(p < tmp) p = tmp;
            else if(tmp == X) {
                p = tmp;
                break;
            }
        }
    }
    cout << p << endl;
    return 0;
}

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

int main() {
    int n,ans=0;
    long long d;
    cin>>n>>d;
    while(n--) {
        long long x,y;
        cin>>x>>y;
        x*=x;
        y*=y;
        x+=y;
        long double dist = sqrt(x);
        if(dist <= d)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    int n,m;
    cin>>n>>m;
    vector<int>xs;
    for(int i=0;i<m;++i){
        int x;
        cin>>x;
        xs.push_back(x);
    }
    sort(xs.begin(),xs.end());
    int64_t ans=xs.back()-xs[0];
    vector<int>ys;
    for(int i=0;i<m-1;++i){
        ys.push_back(xs[i+1]-xs[i]);
    }
    sort(ys.begin(),ys.end());
    for(int i=2;!ys.empty()&&i<=n;++i){
        ans-=ys.back();
        ys.pop_back();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];

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

    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
        {
            cout<<"Yes\n";
        }

        else
        {
            cout<<"No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define ll long long
#define testfor(T) ll T; cin>>T; while(T--)
using namespace std;
int main(){
	int n,k,sum=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

/* template end */

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

    int a, b, c;
    cin >> a >> b >> c;

    vector<int> v{a * 10 + b + c,
                  a + b * 10 + c,
                  a + b + c * 10};
#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << *max_element(v.begin(), v.end()) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define BLACK 1
#define WHITE 0
#define inf 1000000
int main(){
    int c, n, k, i, j, id, v[100][100], w[100][100], min, d[100], u=0, color[100];
    scanf("%d",&n);
    for(i = 0; i < n;  i++){
        d[i] = inf;
        color[i] = WHITE;
        
        scanf("%d",&id);
        scanf("%d",&k);
        for(j = 0; j < k; j++){
            scanf("%d",&c);
            v[id][c] = 1;
            scanf("%d",&w[id][c]);
        }
    }
    d[0] = 0;
    while(1){
        min = inf;
        for(j = 0; j<n; j++){
            if(d[j] < min && color[j] == WHITE){
                min = d[j];
                u = j;
            }
        }
        if(min == inf) break;
        color[u] = BLACK;
        for(j = 1; j<n; j++){
            if(v[u][j] == 0) continue;
            if(d[u] + w[u][j] < d[j] && color[j] == WHITE) d[j] = d[u] + w[u][j];
        }
    }
    for(i = 0; i < n; i++) printf("%d %d\n",i, d[i]);
    return 0;
}

Measured memory_bytes: 676
#include <iostream>

using namespace std;

int main(void){

  int a, b;

  cin >> a >> b;

  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b; cin>>a>>b;
    if(a==b)cout<<"Draw"<<endl;
    else if(a==1)cout<<"Alice"<<endl;
    else if(b==1)cout<<"Bob"<<endl;
    else if(a>b) cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}


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

using namespace std;

vector<int> adjlist[705];
int adjmat[705][705];
bool visited[705];
int color[705];
int n, m;
int one, two;
void dfs(int x){
	for(auto i : adjlist[x]){
		if(color[i] == 0){
			color[i] = 3-color[x];
			dfs(i);
		}else if(color[i] != 3-color[x]){
			cout << -1;
			exit(0);
		}
	}
}
void cfs(int x){
	if(visited[x]) return;
	visited[x] = true;
	if(color[x] == 1) one++;
	else two++;
	for(auto i : adjlist[x]){
		if(!visited[i]) cfs(i);
	}
}
typedef pair<int, int> pi;
vector<pi> items;
bool dp[705][705];
int main(){
	cin >> n >> m;
	for(int i = 0; i<m; i++){
		int a,b; cin >> a >> b;
		adjmat[a][b] = adjmat[b][a] = true;
	}
	for(int i = 1; i<=n; i++){
		for(int j = 1; j<=n; j++){
			if(i == j) continue;
			if(adjmat[i][j] == false) adjlist[i].push_back(j);
		}
	}
	for(int i = 1; i<=n; i++){
		if(color[i] == 0){
			color[i] = 1;
			dfs(i);
			one = two = 0;
			cfs(i);
			items.push_back(pi(one, two));
		}
	}
	dp[0][0] = true;
	int total = 0;
	for(auto i : items){
		for(int x = n; x>=0; x--){
			for(int y = n; y>=0; y--){
				if((x-i.first >= 0 and y-i.second >= 0 and dp[x-i.first][y-i.second]) or (x-i.second >= 0 and y-i.first >= 0 and dp[x-i.second][y-i.first])){
					dp[x][y] = true;
				}
			}
		}
		total += i.first + i.second;
	}
	int ans = INT_MAX;
	for(int i=0; i<=n; i++){
		int j = total-i;
		if(dp[i][j]){
			ans = min(ans, i*(i-1)/2 + j*(j-1)/2);
		}
	}
	if(ans == INT_MAX) cout << -1;
	else
	cout << ans;
}


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

int main(){
	char f[8][9];
	
	for(int i=0; i<8; ++i)
		scanf(" %s", f[i]);
		
	printf("90\n");
	for(int i=0; i<8; ++i){
		for(int j=0; j<8; ++j){
			printf("%c", f[7-j][i]);	
		}
		printf("\n");
	}
	
	printf("180\n");
	for(int i=0; i<8; ++i){
		for(int j=0; j<8; ++j){
			printf("%c", f[7-i][7-j]);	
		}
		printf("\n");
	}
	
	printf("270\n");
	for(int i=0; i<8; ++i){
		for(int j=0; j<8; ++j){
			printf("%c", f[j][7-i]);	
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1112
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		
		int sum = L*N + (N*(N-1))/2;
		
		if(L>0)
			sum -= L;
		else if(L+N-1<0)
			sum -= L+N-1;
		
		System.out.println(sum);
		sc.close();
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

struct data {
  int from, to;
  int cost;
  data(int from, int to, int cost): from(from), to(to), cost(cost) {}
};

int main() {
  int L;
  cin >> L;
  int r = floor(log2(L));
  int N = r+1;
  vector<data> ans;
  REP(i, 1, r+1) {
    ans.push_back(data(i, i+1, 0));
    ans.push_back(data(i, i+1, pow(2, i-1)));
  }
  for(int i=N-1; i>=1; i--)
    if(L - pow(2, i-1) >= pow(2, r)) {
      ans.push_back(data(i, N, L-pow(2, i-1)));
      L -= pow(2, i-1);
    }
  cout << N << ' ' << ans.size() << endl;
  for(auto a: ans)
    cout << a.from << ' ' << a.to << ' ' << a.cost << endl;
  return 0;
}



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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    if((a*100+b*10+c) % 4 == 0)
        cout << "YES\n";
    else
        cout <<"NO\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 


	
int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n;
	cin>>n;
	
	
	ll arr[n+1];
	
	for(ll i=0;i<n;i++)cin>>arr[i];
	
	ll su = 0;
	
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		su += x;
	}
	
	ll crr[n+1];
	
	for(ll i=0;i<n-1;i++)cin>>crr[i];
	
	
	for(ll i=0;i<n;i++)
	{
		if(i==0)continue;
		
		if((arr[i]-arr[i-1])==1)
		{
			//cout<<arr[i]<<endl;
			su+=crr[arr[i]-2];
		}
	}
	
	cout<<su<<endl;
	
}




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

int main(){
    string s;
    cin >> s;
    vector<int> a(10);
    for(int i=0; i<a.size(); i++){
        if(i == 4 || i == 7) continue;
        else {
            a.at(i) = int(s.at(i));
        }
    }
    long long  num = 0;
    //2019004030
    long long  b = 1000000000; 
    for(int i=0; i<a.size(); i++){
        num += a.at(i) * b;
        b = b * 0.1;
    }

    if(num <= 55347532558) puts("Heisei");
    else puts("TBD");
}

Measured memory_bytes: 3612
#include <iostream>

template <typename T>
T Abs(T x)
{
	return x < 0 ? -x : x;
}

template <typename T>
T Min(T x, T y)
{
	return x < y ? x : y;
}

int main()
{
	long long n, k;
	std::cin >> n >> k;
	
	long long x = n % k;
	x = Min(x, Abs(x - k));
	
	std::cout << x << std::endl;
	
	return 0;
}


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

signed main(){
  int n,m;
  cin>>n>>m;
  vector<bool> red(n,false);
  red[0]=true;
  vector<int> t(n,1);
  for(int i=0;i<m;++i){
    int x,y;
    cin>>x>>y;
    --x;--y;
    --t[x];++t[y];
    if(red[x])red[y]=true;
    if(t[x]==0)red[x]=false;
  }
  int res=0;
  for(int i=0;i<n;++i)if(red[i]&&t[i])++res;
  cout<<res<<endl;
  for(auto i:t)cerr<<i<<" ";
  cerr<<endl;
}

Measured memory_bytes: 1024
#include<string.h>
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
    if(!b)return a;
    else return gcd(b,a%b);
}
/*int n,q,ara[200001],st[800004],a,b,mx=2000000000;
void build(int si,int ss,int se)
{
    if(ss==se){
        st[si]=ara[ss];
        return;
    }
    int mid=(ss+se)/2;
    build(2*si,ss,mid),build(2*si+1,mid+1,se);
    st[si]=min(st[2*si],st[2*si+1]);
}
int query(int si,int ss,int se,int qs,int qe)
{
    if(qe<ss || se<qs)return mx;
    if(ss>=qs && qe>=se)return st[si];
    int mid=(ss+se)/2;
    return min(query(2*si,ss,mid,qs,qe),query(2*si+1,mid+1,se,qs,qe));
}
int main()
{
    //freopen ("input.txt","r",stdin);
    //freopen ("output1.txt","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>ara[i];
    build(1,1,n);
    while(q--){
        cin>>a>>b;
        cout<<query(1,1,n,a,b)<<"\n";
    }
}*/
int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x){
        cout<<(n/x+1)*t;
    }
    else cout<<(n/x)*t;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  



void solve(){
	int x ,n;  
	re(x,n);
	vi cnt(102) ;
	rep(i,0,n){
	int a ; re(a);
	cnt[a] = 1 ;}
	int ans = -1 ;
	fr(i,0,101){
		if(!cnt[i]){
			if(abs(i-x) < abs(ans-x)) ans = i ;
		}
	} 
	 cout << ans << endl; 
}


signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e5+5;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};


void solve() {
  int n;
  cin>>n;

  vi v(n,0);

  rep(i,0,n)
	  cin>>v[i];

  sort(all(v));

   double pr= (double)(v[0]+v[1])/2;

   for(int i=2;i<n;i++){
	 pr = (double)(pr+v[i])/2;    
  }


   cout<<fixed<<setprecision(8)<<pr<<endl;
}

int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	  
}



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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  auto solve = [&]() -> bool {
    ll N; cin >> N;
    vector<ll> v(N);
    for (ll i = 0; i < N; i++) {
      ll a; cin >> a;
      v.at(a)++;
    }
    ll numPos = 0;
    ll small = -1;
    ll large = -1;
    ll numSmall = -1;
    ll numLarge = -1;
    for (ll i = 0; i < N; i++) {
      if (v.at(i) > 0) {
	numPos++;
	if (numPos >= 3) return false;
	if (small == -1) {
	  small = i;
	  numSmall = v.at(i);
	}else {
	  large = i;
	  numLarge = v.at(i);
	}
      }
    }
    if (numPos == 1) return numSmall == small + 1 || numSmall >= 2 * small;
    else if (small + 1 != large) return false;
    else if (numSmall >= large) return false;
    else return numLarge >= (large - numSmall) * 2;
  };

  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 4000
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  if(S[K-1] == 'A'){
    S[K-1] = 'a';
  }else if(S[K-1] == 'B'){
    S[K-1] = 'b';
  }else if(S[K-1] == 'C'){
    S[K-1] = 'c';  
  }
  cout << S << "\n";
  return 0;
}

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

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif

int main(){
	int a,b;
	while(cin>>a>>b){
		int n=0;
		int edge[101][101];
		rep(i,101)rep(j,101)edge[i][j]=0;
		n=max(n,max(a,b));
		edge[a][b]=edge[b][a]=edge[a][b]+1;
		while(cin>>a>>b){
			n=max(n,max(a,b));
			edge[a][b]=edge[b][a]=edge[a][b]+1;
			if(a==0&&b==0)break;
		}

		int sum=0;
		for(int i=1;i<=n;i++){
			sum+=edge[1][i];
		}
		if(sum%2==0){
			cout<<"NG"<<endl;
			goto next;
		}

		sum=0;
		for(int i=1;i<=n;i++){
			sum+=edge[2][i];
		}
		if(sum%2==0){
			cout<<"NG"<<endl;
			goto next;
		}

		for(int i=3;i<=n;i++){
			sum=0;
			for(int j=1;j<=n;j++){
				sum+=edge[i][j];
			}
			if(sum%2!=0){
				cout<<"NG"<<endl;
				goto next;
			}
		}

		cout<<"OK"<<endl;
		next:;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

int money[100002];

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

	money[0] = 0;
	for (int i = 1; i < N + 1; i++) {
		int ans = money[i - 1] + 1;
		for (int j = 6; j <= i; j *= 6) {
			ans = min(ans, money[i - j] + 1);
		}
		for (int j = 9; j <= i; j *= 9) {
			ans = min(ans, money[i - j] + 1);
		}
		money[i] = ans;
	}

	cout << money[N] << endl;

	return 0;
}

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

using namespace std;

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

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

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>



int main() {
  int a, b, flag = 0;

  scanf("%d %d", &a, &b);

  flag = a / b;

  if(a%b != 0)
  flag++;

  printf("%d\n", flag);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
main()
{
long long int n, k;
cin >> n;	
long long int a[n], i;
long long int sum = 0;
map<long long int, long long int>m;
for(i=0;i<n;i++)
{
cin >> a[i];
m[a[i]]++;
sum+=a[i];
}
long long int q;
cin >> q;
for(i=0;i<q;i++)
{
	long long int b, c;
	cin >> b >> c;
	long long int x = c-b;
	sum+=m[b]*x;
	m[c]+=m[b];
	m[b] = 0;
	cout << sum << endl;
}
 return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int N;
int cnt;
void dfs(vector<int> _A, vector<int> _ans, int i) {
  if(i == N) {
    int tmp = 1;
    REP(j, N) {
      tmp = tmp * _ans[j];
    }
    if(tmp % 2 == 0) cnt++;
    return;
  }

  for(int k = -1; k <= 1; ++k) {
    _ans.push_back(_A[i] + k);
    dfs(_A, _ans, i + 1);
    _ans.pop_back();
  }
}

int main() {
  cin >> N;
  vector<int> A(N); REP(i, N) cin >> A[i];
  vector<int> ans;
  cnt = 0;
  dfs(A, ans, 0);
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int a,b;
  cin>>a>>b;
  if((a+b)%2) {
    cout<<"IMPOSSIBLE"<<endl;
  } else {
    cout<<((a+b)/2)<<endl;
  }
  return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

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

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

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

int main() {
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0;i < m;++i) {
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        uf.unite(x,y);
    }
    unordered_set<int> st;
    for (int i = 0;i < n;++i) st.insert(uf.find(i));
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    ll ans = 0;
    ll u, v;
    ll V = 0, E = 0;
    for (ll i = 1; i <= N; i++)
    {
        V += i * (N - i + 1);
    }
    for (size_t i = 0; i < N - 1; i++)
    {
        cin >> u >> v;
        if(u>v)swap(u,v);
        E += u * (N - v + 1);
    }

    ans = V - E;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3588
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);
    writeln(a.reduce!max - a.reduce!min);
}









































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
N=int(input())
s=input()
dp=[[0 for _ in range(N+1)] for i in range(N+1)]
MOD=10**9+7
dp[0][N]=1
dp[1]=[1]*N+[0]

cum=[0 for _ in range(N+2)]
for i in range(1,N):
    cum[0]=0
    for z in range(1,N-i+2):
        cum[z]=(cum[z-1]+dp[i][z-1])%MOD

    if s[i-1]=='<':
        for j in range(0,N-i):
            dp[i+1][j] =(dp[i+1][j] +cum[N-i+1]-cum[j+1])%MOD
    else:
        for j in range(0,N-i):
            dp[i+1][j]=(dp[i+1][j] + cum[j+1])%MOD

print(dp[N][0])


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

int main() {
  int a, b;
  map<int, int> deg;

  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      bool f = true;
      for (auto p : deg) {
        if (p.first < 2 && ~p.second & 1) f = false;
        if (p.first >= 2 && p.second & 1) f = false;
      }
      cout << (f ? "OK" : "NG") << endl;
      deg.clear();
      continue;
    }

    a--;
    b--;
    deg[a]++;
    deg[b]++;
  }
}

Measured memory_bytes: 2952
n = int(input())
c0 = c1 = c2 = c3 = 0

for i in range(n):
    s = input()
    if s == 'AC':
        c0 += 1
    elif s == 'WA':
        c1 += 1
    elif s == 'TLE':
        c2 += 1
    elif s == 'RE':
        c3 += 1
    
print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(c0, c1, c2, c3))

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int FIRST = 60;
const int dx[6] = {0,1,-1,1,-1,0};
const int dy[6] = {1,1,0,0,-1,-1};
const int FIELD = 121;
void bfs(vector<vector<int> > &map,int x1,int y1,int t){
  queue<pair<int,int> > que;
  que.push(pair<int,int>(x1,y1));
  map[x1][y1] = 1;
  while(!que.empty()){
    int x,y;
    pair<int,int> tmp = que.front();que.pop();
    x = tmp.first;y = tmp.second;
    if(map[x][y] > t) continue;
    for(int i = 0;i < 6;i++){
      if(x+dx[i] >= 0 && x+dx[i] < FIELD && y+dy[i] >= 0&& y+dy[i] < FIELD ){
	if(map[x+dx[i]][y+dy[i]] ==  0 ){
	  map[x+dx[i]][y+dy[i]] = map[x][y]+1;
	  que.push(pair<int,int>(x+dx[i],y+dy[i]));
	}
      }
    }
  }
  
}
int solve(vector<vector<int> > &map){
  int ans = 0;
  for(int i = 0;i < FIELD;i++){
    for(int j = 0;j < FIELD;j++){
      if(map[i][j] > 0){
	ans++;
      }
    }
  }
  return ans;
}
void fun(vector<vector<int> > map){
  for(int i = 20;i < 41;i++){
    for(int j = 20;j < i;j++){
      cout << " " ;
    }
    for(int j = 20;j < 41;j++){
      if(map[j][i] == -1){
	cout << 9;
      }else{
	cout << map[j][i];
      }
    }
    cout << endl;
  }

}
int main(){
  while(1){
    int t,n;
    cin >> t >> n;
    if(t == 0 && n == 0)break;
    vector<vector<int > > map(FIELD,vector<int>(FIELD,0));
    for(int i = 0;i < n;i++){
      int x,y;
      cin >> x >> y;
      map[FIRST+x][FIRST+y] = -1;
    }
    int f_x,f_y;
    cin >> f_x >> f_y;
    
    bfs(map,FIRST+f_x,FIRST+f_y,t);
    //    fun(map);
    cout << solve(map) << endl;
  }
  return 0;
}

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

int main()
{
  int n , m;
  cin>> n>>m;
  int even;
  int odd ;
  int res ;
  if(n>=0 && m>=0)
  {
      if(n == 1 && m == 1)
      {
        cout<<"0"<<endl;
        return 0;
      }
      if(n>1)
      {
        even = (n* (n-1))/(2);
      }
      if(m>1)
      {
        odd = (m* (m-1))/(2);
      }
      res = even + odd;
      cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=input()
n=int(n)
s=0
for i in range(1,n+1):
    if(i%3==0 and i%5==0):
        i=i+1
    elif(i%3==0):
        i=i+1
    elif(i%5==0):
        i=i+1
    else:
        s=s+i
print(s)

    
       
    
    
 
          
          

    


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

int main(){
    int A,B; cin>>A>>B;
    if(A>=13){
      cout<<B<<endl;
    }else if(A<=5){
      cout<<"0"<<endl;
    }else{
      cout<<B/2<<endl;
    }
}


Measured memory_bytes: 256
from collections import Counter

n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]

if a==b:
    if V_1[-2][1]>V_2[-2][1]:a=V_1[-2][0]
    else:b=V_2[-2][0]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Measured memory_bytes: 20692
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    
    int n;
    long int div = pow(10,9) + 7;
	
    cin >> n;

    long int p = 1;
    rep(i,n){
        p = (p * (i+1)) % div ;
    }
    cout << p << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int a[1001][2];
long long int dp[100100];
int main()
{
    int n,w;
    cin >> n >> w;

    for(int i=0;i<n;i++)
    {
        cin >> a[i][0] >> a[i][1];
    }
    int maxi = INT_MIN;
    for(int j=0;j<=100000;j++)
    {
        dp[j]=INT_MAX;
    }
    dp[0] = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=100000;j>=0;j--)
        {
            if(a[i-1][1]<=j)
            dp[j]=min(dp[j],dp[j-a[i-1][1]]+a[i-1][0]);
        
            if(dp[j]<=w)
            maxi = max(maxi,j);
        }
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main {
static PrintWriter pw =new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) {
	// write your code here
        MyScanner mc = new MyScanner();
        int N = mc.nextInt();
        int [] arr = new int[N+1];
        for (int i=0;i<N-1;i++)
            arr[mc.nextInt()]++;
        for (int i=1;i<=N;i++)
            pw.println(arr[i]);
        pw.flush();
    }

public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }

}


Measured memory_bytes: 56768
import sys

import math
import itertools
import random
n = int(input())
li = [0] * 4  #ac,wa,tle,re
for i in range(n):
    tmp = input()
    if (tmp == "AC"):
        li[0] += 1
    elif (tmp == "WA"):
        li[1] += 1
    elif (tmp == "TLE"):
        li[2] += 1
    else:
        li[3] += 1
print("AC x " + str(li[0]))
print("WA x " + str(li[1]))
print("TLE x " + str(li[2]))
print("RE x "+str(li[3]))


Measured memory_bytes: 9564
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
	priority_queue<int> q;
	vector<int> ve[110000];
	int n,m,a,b,cnt=0;
	ll ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		if(a<=m)
		{
			ve[a].push_back(b);
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<ve[i].size();j++)
			q.push(ve[i][j]);
		if(!q.empty())
		{
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    set<pair<int, int> > se;
    multiset<int> ans;
    for (int i = 1; i <= m; i++) {
        se.insert({i, i});
        ans.insert({0});
    }
    for (int i = 1; i <= n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (y == m) y = INF;
        auto it = se.lower_bound({x, 0});
        int t = -1;
        for (; it != se.end() && it->first <= y;) {
            ans.erase(ans.find(it->first - it->second));
            t = max(t, it->second);
            it = se.erase(it);
        }
        if (t > -1) {
            ans.insert(y + 1 - t);
            se.insert({y + 1, t});
        }
        int r = *ans.begin();
        if (r > m)
            puts("-1");
        else
            printf("%d\n", r + i);
    }
    return 0;
}


Measured memory_bytes: 22540
from sys import stdin

na = 0
nb = 0
while(True):
    try:
        a,b,c = map(int,stdin.readline().split(","))
        if a**2+b**2==c**2:
            na += 1
        if a==b:
            nb += 1
    except:
        break
print(na)
print(nb)


Measured memory_bytes: 5600
n,m,l = map(int,input().split())

a = []
for i in range(n):
    row1 = list(map(int,input().split()))
    a.append(row1)
#print(a)

b = []
for i in range(m):
    row2 = list(map(int,input().split()))
    b.append(row2)
#print(b)

for i in range(n): #Aの1行目から
    c = []
    for j in range(l): #Bの1列目から
        result = 0
        for k in range(m): #Aのk列目およびBのk行目から
            result += a[i][k] * b[k][j]
        c.append(result)
    print(" ".join(map(str,c)))


Measured memory_bytes: 6240
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll dp[MAX];

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, W; cin >> N >> W;
	vector<int> v(N), w(N);
	rep(i, N){
		cin >> v[i] >> w[i];
	}

	ll ans = 0;
	memr(dp, -1);
	dp[0] = 0;
	rep(i, MAX){
		if(i > W) break;
		rep(j, N){
			if(i + w[j] > W) continue;
			if(dp[i] == -1) continue;
			chmax(dp[i+w[j]], dp[i] + v[j]);
			chmax(ans, dp[i+w[j]]);
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 3872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		System.out.println(Math.min(b/a, c));
	}

}


Measured memory_bytes: 21972
import std.stdio, std.math;

void main()
{
  long x;
  readf("%d", &x);

  long ans = 1;
  for (auto i = 2; i <= x; i++) {
    for (auto p = 2; ; p++) {
      auto a = pow(i,p);
      if (a > x) {
        break;
      }
      if (a > ans) {
        ans = a;
      }
    }
  }

  writeln(ans);

}


Measured memory_bytes: 256
// AOJ 2664: Shopping
// 2017.12.3 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 10007
typedef struct { char *s; int id, w; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

void insert(char *s, int w, int id)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (tp->w == w && memcmp(tp->s, s, w) == 0) return;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id, tp->w = w;
}

int lookup(char *s, int w)
{
	HASH *tp = hash + (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	while (tp->s != NULL) {
		if (tp->w == w && memcmp(tp->s, s, w) == 0) break;
		if (++tp == hashend) tp = hash;
	}
	return tp->id;
}

#define MAX 5002
/* UNION-FIND library */
int p[MAX], rank[MAX];

void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

int x[MAX];
char s[MAX][20];

char buf[30], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, ans;
	char *q;

	fgets(bp=buf, 10, stdin), n = getint();
	for (i = 0; i < n; i++) p[i] = i;

	for (i = 0; i < n; i++) {
		fgets(bp=s[i], 20, stdin);
		q = bp; while (*bp >= 'a') bp++;
		*bp = 0, insert(q, bp-q, i);
		bp++, x[i] = getint();
	}

	fgets(bp=buf, 10, stdin), m = getint();
	while (m--) {
		fgets(bp=buf, 30, stdin);
		q = bp; while (*bp >= 'a') bp++;
		*bp = 0, i = lookup(q, bp-q);

		q = ++bp; while (*bp >= 'a') bp++;
		*bp = 0, j = lookup(q, bp-q);
		union_set(i, j);
	}

	for (i = 0; i < n; i++) {
		j = find_set(i);
		if (x[i] < x[j]) x[j] = x[i];
	}
	for (ans = 0, i = 0; i < n; i++) ans += x[p[i]];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2016
n, k = map(int, input().split())
s = input()
start = [0]
ret = 0
first = False
for i in range(len(s)):
    if s[i] == '1' and first:
        start.append(i)
        first = False
    if s[i] == '0' and not first:
        ret = max(ret, i - start[max(0, len(start) - k - 1)])
        first = True
if first:
    start.append(len(s))
ret = max(ret, len(s) - start[max(0, len(start) - k - 1)])
print(ret)


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

using namespace std;

int main()
{
  int N, M, D;
  string S[100];

  cin >> N >> M >> D;
  for(int i = 0; i < N; i++) cin >> S[i];

  int ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < M; j++) {
      int ok1 = 0, ok2 = 0;
      for(int k = 0; k < D && i + k < N; k++) ok1 += S[i + k][j] == '.';
      for(int k = 0; k < D && j + k < M; k++) ok2 += S[i][j + k] == '.';
      ret += ok1 == D;
      ret += ok2 == D;
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 3140
<?php

main();

function main() {

	$counts = array(
		'A' => 0,
		'B' => 0,
		'AB'=> 0,
		'O' => 0,
	);

	while ($line = trim(fgets(STDIN))) {
		list(, $blood) = explode(',', $line);
		if (!isset($counts[$blood])) {
			continue;
		}
		$counts[$blood]++;
	}

	foreach ($counts as $c) {
		echo "$c\n";
	}
}

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

using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string ans="Christmas";
	for(int i=25;i>n;--i){
		ans+=" Eve";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        int[] s = new int[n+1];
        for(int i=0; i<n; i++){
            String line = sc.next();
            if("AB".equals(line)){
                s[i] = 0;
            }else if("AC".equals(line)){
                s[i] = 1;
            }else{
                s[i] = 2;
            }
        }
        
        char[] ans = new char[n];
        for(int i=0; i<n; i++){
            if(s[i] == 0){
                //AB
                if(a==0 && b==0){
                    no(a,b,c);
                }else if(a == b){
                    if(s[i+1] == 1){
                        ans[i] = 'A';
                        a++;
                        b--;
                    }else{
                        ans[i] = 'B';
                        b++;
                        a--;
                    }
                }else if(a < b){
                    ans[i] = 'A';
                    a++;
                    b--;
                }else{
                    ans[i] = 'B';
                    b++;
                    a--;
                }
            }else if(s[i] == 1){
                //AC
                if(a==0 && c==0){
                    no(a,b,c);
                }else if(a == c){
                    if(s[i+1] == 0){
                        ans[i] = 'A';
                        a++;
                        c--;
                    }else{
                        ans[i] = 'C';
                        c++;
                        a--;
                    }
                }else if(a < c){
                    ans[i] = 'A';
                    a++;
                    c--;
                }else{
                    ans[i] = 'C';
                    c++;
                    a--;
                }
            }else{
                //BC
                if(b==0 && c==0){
                    no(a,b,c);
                }else if(b == c){
                    if(s[i+1] == 0){
                        ans[i] = 'B';
                        b++;
                        c--;
                    }else{
                        ans[i] = 'C';
                        c++;
                        b--;
                    }
                }else if(b < c){
                    ans[i] = 'B';
                    b++;
                    c--;
                }else{
                    ans[i] = 'C';
                    c++;
                    b--;
                }
            }
        }
        
        System.out.println("Yes");
        for(int i=0; i<n; i++){
            System.out.println(ans[i]+"");
        }
    }
    
    public static void no(int a, int b, int c){
        //System.out.println(a + " " + b +  " " + c);
        
        System.out.println("No");
        System.exit(0);
    }
}


Measured memory_bytes: 53092
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

template<class T, class F>
struct SegmentTree {
    F f;
    T ti;
    vector<T> dat;
    int sz;

    SegmentTree(const F &f, const T &ti) : f(f), ti(ti) {}

    void build(const vector<T> &v) {
        assert(v.size());
        sz = 1;
        while (sz < v.size())sz <<= 1;
        dat.resize(sz << 1, ti);
        for (int i = 0; i < v.size(); i++)dat[sz - 1 + i] = v[i];
        for (int i = sz - 2; i >= 0; i--)dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }

    inline void update(int k, T x) {
        k += sz - 1;
        dat[k] = x;
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline void add(int k, int x) {
        k += sz - 1;
        dat[k] = f(dat[k], x);
        while (k) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    inline T query(int a, int b) {
        return query(a, b, 0, 0, sz);
    }

    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return ti;
        if (a <= l && r <= b)return dat[k];
        return f(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
};

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> v(n);
    rep(i, n)cin >> v[i];
    reverse(v.begin(), v.end());

    rep(i, n) v.push_back(v[i]);

    auto f = [](ll i, ll j) { return min(i, j); };
    SegmentTree<ll, decltype(f)> segmentTree(f, INF);
    segmentTree.build(v);

    ll ans = INF;
    for (int rc = 0; rc < n; rc++) {
        ll rp = rc * x;
        ll sum = 0;
        rep(i, n) {
            ll now = segmentTree.query(i, i + rc + 1);
            sum += now;
        }

        ll next = sum + rp;
        cmin(ans, next);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3720