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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

// N, E, S, W
const int dx[] = { 1, 0, -1, 0};
const int dy[] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================

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

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

	vi dp(n + 1, INF);
	dp[0] = 0;

	int c;
	REP(i, m) {
		cin >> c;
		for (int j = 0; j + c <= n; j++) {
			dp[j + c] = min(dp[j + c], dp[j] + 1);
		}
	}

	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 3308
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v=0; v<n; v++){
	  if(M[u][v] == 0)  continue;
	  if(color[v] == WHITE){
	  	dfs_visit(v);
	  }
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs(){
	int u;
	
	for(u=0; u<n; u++)  color[u] = WHITE;
	tt = 0;
	
	for(u=0; u<n; u++){
		if(color[u] == WHITE)  dfs_visit(u);
	}
	for(u=0; u<n; u++){
		printf("%d %d %d\n", u+1, d[u], f[u]);
	}
}

int main(){
	int u, v, k, i, j;
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		for(j=0; j<n; j++)  M[i][j] = 0;
	}
	
	for(i=0; i<n; i++){
		scanf("%d %d ", &u, &k);
		u--;
		for(j=0; j<k; j++){
			scanf("%d", &v);
			v--;
			M[u][v] = 1; 
		}
	}
	
	dfs();
	
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define ll long long
#define p 1000000007
using namespace std;
int n,A,B,C;
int jc[200010],njc[200010],inv[200010];
int ksm(int x,int y=p-2){
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%p)if(y&1)ans=1ll*ans*x%p;
	return ans;
}
int binom(int x,int y){
	return 1ll*jc[x]*njc[y]%p*njc[x-y]%p;
}
int ma[200010],mb[200010];
int main(){
	cin>>n>>A>>B>>C;
	ma[0]=mb[0]=1;

	for(int i=0;i<2;i++)jc[i]=njc[i]=inv[i]=1;
	for(int i=2;i<=200000;i++){
		jc[i]=1ll*jc[i-1]*i%p;
		inv[i]=1ll*inv[p%i]*(p-p/i)%p;
		njc[i]=1ll*njc[i-1]*inv[i]%p;
	}	
	int e=A+B;
	A=1ll*A*ksm(e)%p,B=1ll*B*ksm(e)%p;C=1ll*C*inv[100]%p;
	int ans=0;
	for(int i=1;i<=200000;i++)
	ma[i]=1ll*ma[i-1]*A%p,
	mb[i]=1ll*mb[i-1]*B%p;
	//A赢
	for(int i=0;i<n;i++) 
	(ans+=1ll*ma[n]*mb[i]%p*binom(n+i-1,i)%p*(n+i)%p)%=p;
	for(int i=0;i<n;i++)
	(ans+=1ll*mb[n]*ma[i]%p*binom(n+i-1,i)%p*(n+i)%p)%=p;
	cout<<1ll*ans*(1+1ll*C%p*ksm(p+1-C)%p)%p;
	return 0;
}


Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        long yen = in.nextLong();
        long rem = yen % 500;
        long total = (yen - rem) * 2;
        total += (rem - (rem % 5));
        out.println(total);

        out.close();
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

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

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

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

        char nextCharacter() throws IOException {
            return next().charAt(0);
        }

        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> A(n);
    for(int i=0;i<n-1;i++)
        cin>>A[i];
    vector<int> ans(n,0);
    for(int i=0;i<n-1;i++){
        ans[A[i]-1]++;
    }

    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 4784
n = int(input())
s = str(input())
l = len(s)
p = 0
for i in range(l):
    if s[i] == "R":
        p += 1
ss = s[:p]
q = 0
for j in range(p):
    if ss[j] == "R":
        q += 1
print(p-q)

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;

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

ll mod = (1000000007LL);

inline ll poww(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if(b & 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}
inline pii operator+(pii A, pii B){
	return pii(A.f + B.f, A.s + B.s);
}
inline pii operator-(pii A, pii B){
	return pii(A.f - B.f, A.s - B.s);
}
inline ll mult(ll a, ll b){
	return (a * b) % mod;
}

ll gcd (ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

/*
	>Colocar (>DEFINE INT LONG LONG<) no inicio do template
	>mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
	>NAO ESQUECER DEFINE INT LONG LONG
	> N = 1 ? 
*/

///CUIDADO COM MAXN
#define N 300050

int n, m, q, k, v[N];

pii TT, w[N];

string s;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m>>k;
    cout<<(k%max(n,m) == 0 ? k/max(n, m) : k/max(n,m) + 1)<<"\n";
}

Measured memory_bytes: 256
# coding: utf-8
# 答えを見た。。。

n = int(raw_input())
R = [int(raw_input()) for i in range(n)]

maxv = -2000000000
minv = R[0]

for r in R[1:]:
    maxv = max(maxv, r - minv)
    minv = min(minv, r)

print maxv



Measured memory_bytes: 17224
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> evi[n];
    repi(i, n, 0)
    {
        int a;
        cin >> a;
        repi(j, a, 0)
        {
            int x, y;
            cin >> x >> y;
            x--;
            evi[i].push_back({x, y});
        }
    }
    int ans = 0;
    repi(bit, 1 << n, 1)
    {
        int cnt = 0;
        vector<int> tb(n, -1);
        bool ok = true;
        repi(i, n, 0)
        {
            if (bit & (1 << i))
            {
                tb[i] = 1;
            }
            else
            {
                tb[i] = 0;
            }
        }
        repi(i, n, 0)
        {
            if (tb[i] == 1)
            {
                repi(j, evi[i].size(), 0)
                {
                    if (tb[evi[i][j].first] != evi[i][j].second)
                    {
                        ok = false;
                        break;
                    }
                }
            }
            if (!ok)
                break;
        }
        if (ok)
        {
            repi(i, n, 0)
            {
                if (tb[i] == 1)
                    cnt++;
            }
        }
        ans = max(cnt, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		int max = 0;
		for (int i = 0; i < n - 1; i++) {
			max = Math.max(max, a[i + 1] - a[i]);
		}
		max = Math.max(k - a[n - 1] + a[0], max);

		System.out.println(k - max);
	}

}


Measured memory_bytes: 78612
import math

N, K = map(int,input().split())
#N, K = 100000, 5

ans = 0
for i in range(1,N+1):
	a = i
	b = 1
	while a < K:
		a *= 2
		b *= 0.50000000000
	ans += b


print(ans/N)


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

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

  cin >> A;
  cin >> B;
  
  cin >> U;
  
  int res_A,res_B;

  
  if( U == S){
    res_A = A -1;
    res_B = B;
  }
  else{
    res_A = A;
    res_B = B-1;
  }
  
  cout << res_A << " " << res_B << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100;

char ss[N];

int main(){
	scanf("%s",ss);
	int n = strlen(ss);
	for(int i=0;i<n;i++){
		if(ss[i]=='1')
			ss[i]='9';
		else if(ss[i]=='9')
			ss[i]='1';
	}
	puts(ss);
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define hell 1000000007
#define MAX 1000000000
#define max_int 1000000
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define pi 3.14159265358979311600
#define r0 return 0

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long double n;
    cin>>n;
    cout<<setprecision(20)<<fixed<<2*pi*n;
  
 
    
}
 

Measured memory_bytes: 3808
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    mid = X_s[n // 2]
    del_mid = (X_s[:n // 2] + X_s[n // 2 + 1:])[(n - 1) // 2]
    for x in X:
        if x < mid:
            print(mid)
        elif x > mid:
            print(X_s[n // 2 - 1])
        else:
            print(del_mid)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30840
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j+=1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Measured memory_bytes: 4244
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
using namespace std;

int N,M,cnt;
int head[100050];
long long dis[100050];
bool vis[100050],inq[100050];
struct edge{
    int u,v,w,next;
}t[400050];
inline void add(int u,int v,int w){
    t[++cnt].u=u;
	t[cnt].v=v;
    t[cnt].w=w;
    t[cnt].next=head[u];
    head[u]=cnt;
}
queue<int>q;
inline bool spfa(int start){
    
    q.push(start);
    inq[start]=true;
    dis[start]=0;
    
    while(!q.empty()){
        int u=q.front();
        	q.pop();
        inq[u]=false;
    	
		for(int i=head[u];i;i=t[i].next){
            int v=t[i].v;
            	if(dis[v]==12345678987654321){
                	dis[v]=dis[u]+t[i].w;
                		vis[v]=true;
                	if(!inq[v])
                   		q.push(v);
            	}
            	else 
				if(dis[v]!=dis[u]+t[i].w)
                	return false;
        }
    }
    return true;
}

int main(){
	scanf("%d%d",&N,&M);
    for(int i=1;i<=M;i++){
    	int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        add(u,v,w),add(v,u,-w);
    }
    for(int i=1;i<=N;i++)
		dis[i]=12345678987654321;
    for(int i=1;i<=N;i++){
        if(!vis[i]){
            vis[i]=true;
            	bool flag=spfa(i);
            	if(!flag){
                	printf("No\n");
                		return 0;
            	}
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 8320
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  int64_t mi=n;
  double rn = pow(n, 0.5);
//  cout << n << endl;
//  cout << mi <<endl;
//  cout << rn <<endl;
  
  for(int i=1;i<=rn;i++){//for start
    int flagA=0;
    int64_t A=i;
    int64_t B;
    if(n % A == 0) B = n/i;
    else flagA=1;
    if(flagA==0){//flagA==0 start
//      cout << A << endl;
      int64_t countA=0;
      int64_t countB=0;
      for(;;){       
//        cout << "i="<< i << "countA=" << countA <<endl;
//        cout << A / pow(10, countA) <<endl;
        if(A / pow(10, countA) < 1 ) break;
        countA++;
      }
      for(;;){       
        if(B / pow(10, countB) < 1 ) break;
        countB++;
      }
      if(countA > countB ) mi = min(mi,countA);
      else mi = min(mi,countB);
    }//flagA==0 end
  }//for end
  cout << mi << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int a = 1;
    int b = n;
    for(int i=0; i<m; ++i){
        int l, r;
        cin >> l >> r;
        a = max(a, l);
        b = min(b, r);
    }
    int ans = max(0, b - a + 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
def check(nl):
    fl = list(nl)
    for w in range(len(nl)):
        if (fl[w] in nl):
            i = fl[w]
            if ((i+1 in nl) and (i+2 in nl)):
                for k in range(i,i+3):
                    nl.remove(k)
            elif(nl.count(i)%3 == 0):
                for k in range(nl.count(i)):
                    nl.remove(i)
        
                
for i in range(n):
    num_list = list(map(int, input().split()))
    c_list = list(map(str, input().split()))
    r = c_list.count('R')
    g = c_list.count('G')
    b = c_list.count('B')
    if (r%3 == 0 and g % 3 == 0 and b % 3 == 0):
        rlist = []
        glist = []
        blist = []
        for k in range(9):
            if(c_list[k] == 'R'):
                rlist.append(num_list[k])
            elif(c_list[k] == 'G'):
                glist.append(num_list[k])
            elif(c_list[k] == 'B'):
                blist.append(num_list[k])
        rlist.sort()
        glist.sort()
        blist.sort()
        check(rlist)
        check(glist)
        check(blist)
        if(len(rlist) == 0 and len(glist) == 0 and len(blist) == 0):
            print(1)
        else:
            print(0)
        
        
    else:
        print(0)
        


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

int dcomp( const void *c1, const void *c2 )
{
  int tmp1 = *(int *)c1;
  int tmp2 = *(int *)c2;

  if( tmp1 < tmp2 )  return 1;
  if( tmp1 == tmp2 ) return  0;
  if( tmp1 > tmp2 )  return  -1;
}

int ucomp( const void *c1, const void *c2 )
{
  int tmp1 = *(int *)c1;
  int tmp2 = *(int *)c2;

  if( tmp1 < tmp2 )  return -1;
  if( tmp1 == tmp2 ) return  0;
  if( tmp1 > tmp2 )  return  1;
}


int main(){
  int N[100][2];
  int i=0,j;
  scanf("%d%d",&N[0][0],&N[0][1]);
  while(N[i][0]!=0||N[i][1]){
    i++;
    scanf("%d%d",&N[i][0],&N[i][1]);
  }
  int k,l,n;
  int kako[21];
  int keta[7];
  for (j = 0; j < i; ++j) {     
    kako[0]=N[j][0];
    int flag=1;
    for (k = 0; k < 20; ++k) {       
      int kari=kako[k];
      int shikii=pow(10,N[j][1]-1);

      for (l = 0; l < N[j][1]; ++l) { 
	if(shikii<=kari)break;
	shikii/=10;
      }
      for (n = 0; n < l; ++n) keta[n]=0;		      
      for (l = n; l < N[j][1]; ++l) { 	
	keta[l]=kari%10;
	kari=kari/10;	
      }                        
      int max=0,min=0;
      qsort(keta,N[j][1],sizeof(int),dcomp);
      for (n = 0; n < N[j][1]; ++n){	
	min+=keta[n]*pow(10,n);
      }
      qsort(keta,N[j][1],sizeof(int),ucomp);
      for (n = 0; n < N[j][1]; ++n){
      	max+=keta[n]*pow(10,n);
      }      
      kako[k+1]=max-min;
      for (n = 0; n <= k; ++n) { 
	if(kako[n]==kako[k+1]){
	  flag=0;
	  break;
	}		
      }
      if(flag==0)break;
    }     
    printf("%d %d %d\n",n,kako[n],k+1-n);   
  }
 
  return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		long N=sc.nextInt();
		int i;
		long ans=0;
		for(i=0;i*i<=N;i++) {
			ans=i*i;
		}
		System.out.println(ans);
	}
}

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

typedef pair<int,int> P;
const int MAX = 201;
int data[MAX];

int main(){
  int n,m;
  while(cin >> n && n){
    P p;
    vector<P> V;
    fill(data,data+MAX,0);
    V.push_back(P(-1,-1));
    for(int i = 0; i < n; i++){
      cin >> p.first >> p.second;
      V.push_back(p);
    }
    cin >> m;
    for(int i = 0; i < m; i++){
      cin >> p.first >> p.second;
      V.push_back(p);
    }
    sort(V.begin(),V.end());

    for(int i = 1; i < V.size(); i++)
      for(int j = 0; j < i; j++)
	if(V[i].first > V[j].first && V[i].second > V[j].second)
	  data[i] = max(data[j]+1,data[i]);

    int out = 0;
    for(int i = 0; i < MAX; i++) out = max(out,data[i]);
    cout << out << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;

using int64 = int64_t;

int main() {
  int64 n, m, c;
  cin >> n >> m >> c;
  vector<int64> b(m);
  for (int64 i = 0; i < m; ++i)
    cin >> b[i];
  vector<vector<int64>> a(n, vector<int64>(m));
  for (int64 i = 0; i < n; ++i)
    for (int64 j = 0; j < m; ++j)
      cin >> a[i][j];

  int64 ret = 0;
  for (int64 i = 0; i < n; ++i) {
    int64 sum = c;
    for (int64 j = 0; j < m; ++j)
      sum += a[i][j] * b[j];
    if (sum > 0)
      ++ret;
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0) cout<<a+b;
    else cout<<b-a;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int x; cin >> x;
	cout << lcm(x,360)/x << endl;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    n *=2;
    n--;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ok = 1;
    int ng = n+1;
    while(ng-ok>1){
        int mid = (ok+ng)/2;
        vector<int>b = a;
        rep(i,n){
            if(b[i]>=mid){
                b[i] = 1;
            }else{
                b[i] = 0;
            }
        }
        // for(int x:b){
        //     cerr << x << " ";
        // }
        // cerr << endl;
        int p = n/2;
        int left = 0;
        int right = 0;
        int k = b[p];
        int c = 1-k;
        for(int i=p+1;i<n;i++){
            if(b[i]==c){
                right++;
                c = 1-c;
            }else{
                break;
            }
        }
        c = 1-k;
        for(int i=p-1;i>=0;i--){
            if(b[i]==c){
                left++;
                c = 1-c;
            }else{
                break;
            }
        }
        int res = 0;
        if(left==right){
            if(left ==p){
                res = k + p%2;
                res %=2;
            }else{
                res = b[p+right+1];
            }
        }else if(left>right){
            res = b[p+right+1];
        }else{
            res = b[p-left-1];
        }
        if(res){
            ok = mid;
        }else{
            ng = mid;
        }
    }   
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1808
require "matrix"

n, t = gets.split.map(&:to_i)
output = []

_, _, prev_ar_time, _ = gets.split
while gets
    st_time, st_name, ar_time, ar_name = $_.split

    v = [st_time, prev_ar_time]
        .map{|s| s.split(":").map(&:to_i)}
        .map{|a| Vector[*a]}
        .inject(&:-)
    x = v[0] * 60 + v[1]

    output << "#{st_name} #{x}" if x >= t
    prev_ar_time = ar_time
end

puts output.size
output.each{|s| puts s}

Measured memory_bytes: 6368
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000000
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}



//=============================================ASIFAZAD==============================================//

const int N = 100010;
int n, p;
vll ppl(N), vis(N), good(N) , h(N);
vector<vi> adj;
bool ans = true;

void dfs(int par, int pp)
{
    vis[par] = ppl[par];
    ll totg = 0;

    for(auto x: adj[par])
    {
        if(x == pp)
            continue;

        dfs(x, par);
        vis[par] += vis[x];
        totg += good[x];

    }

    ll ck = (vis[par] + h[par]);
    if(ck < 0 || ck%2 != 0 || ck/2 > vis[par])
        ans = 0;
    if(totg > ck/2)
        ans = 0;
    if(!ans)
        return;
    good[par] = ck/2;

}


int32_t main()
{
    io;
    ll n, d;
    cin>>n>>d;
    int ans = 0;
    while(n--)
    {
        ll x, y;
        cin>>x>>y;
        if(d*d >= x*x + y*y)
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 6260
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i,x,n) for(int i = x; i < n; i++)
#define rep(i,n) repi(i,0,n)
#define int long long
using namespace std;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    int ans;
    pair<int,int> d[10000];
    while(1){
        ans=0;
        cin>>n>>m;
        if(n==0 && m==0) break;
        rep(i,n){
            int a,b;
            cin>>a>>b;
            d[i]=make_pair(b,a);
        }
        sort(d,d+n);
        for(int i=n-1;i>=0;i--){
            if(d[i].second <= m){
                m-=d[i].second;
                d[i].second=0;
            }else{
                d[i].second-=m;
                break;
            }
        }
        rep(i,n){
            ans+=d[i].first*d[i].second;
        }
        cout<<ans<<endl;
    }
                
    return 0;
}





Measured memory_bytes: 3172
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
count = 0
(0..a).each do |d|
  (0..b).each do |e|
    (0..c).each do |f|
      if d*500+e*100+f*50 == x
        count+=1
      end
    end
  end
end
puts count

Measured memory_bytes: 1916
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int n;

char S[5555], T[5555];

vector <ll> VS(0), VT(0);

ll Abs(ll x) {return x < 0 ? -x : x;}

int main() {
    scanf("%d%s%s", &n, S + 1, T + 1);
    for(int i = 2; i <= n; i++) if(S[i] == S[i - 1]) VS.push_back(i);
    for(int i = 2; i <= n; i++) if(T[i] == T[i - 1]) VT.push_back(i);
    int szS = VS.size(), szT = VT.size();
    ll ans = 2e18;
    for(int i = -szT; i <= szS; i++) {
        ll nw = 0, o = 0;
        for(int j = 0; j < szT; j++) {
            int x = i + j;
            if(x < 0) nw += Abs((VT[j] - 1)), o ^= 1;
            else if(x >= szS) nw += Abs(n + 1 - VT[j]);
            else nw += Abs(VS[x] - VT[j]);
        }
        for(int j = 0; j < i; j++) nw += VS[j] - 1, o ^= 1;
        for(int j = i + szT; j < szS; j++) nw += n + 1 - VS[j];
        if(o ^ (S[1] - '0') ^ (T[1] - '0') ^ 1) ans = min(ans, nw);
        else ans = min(ans, nw + n);
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main () {
  int n;
  string s;
  cin >> n >> s;
  if(n%2==0){
  for(long i = 0; i<n/2; i++){
    if(s[i]==s[i+n/2]){
    }
    else{
      cout << "No" << endl;
      break;
    }
    if(i==n/2-1){
      cout << "Yes" << endl;
      break;
    }
  }
 }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  ll i,j,n,m,sum=0;
  static pair<ll,ll> a[100010];
  

  cin>>n>>m;

  vector<ll> limit(m+2,-1);
  for(i=0;i<n;i++){
    cin>>a[i].second>>a[i].first;
  }

  sort(a,a+n);

  int day,tmp;
  vector<int> skip;
  for(i=0;i<n;i++){
    day=a[n-i-1].second;
    if(day<=m){
      skip.clear();
      while(limit[day]!=-1){
        skip.push_back(day);
        day=limit[day];
      }
      
      if(day<=m){
        for(j=0;j<skip.size();j++){
          limit[skip[j]]=day+1;
        }
        limit[day]=day+1;

        sum+=a[n-i-1].first;
      }
    }
  }

  cout<<sum<<endl;

  return 0;
}



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

int main()
{
    int a,b,c,x,cnt=0;
    cin>>a>>b>>c>>x;
    for (int i=0; i<=a; i++)
    {
        for (int j=0; j<=b; j++)
        {
            for (int k=0; k<=c; k++)
            {
                if ((500*i+100*j+50*k)==x) cnt++;
            }
        }
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
const int N = (int) 2e5 + 5, mod = (int) 0;

int par[N], sz[N];
int find(int v) { return v == par[v]? v: par[v] = find(par[v]); }
void unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
    sz[v] += sz[u];
    par[u] = v;
}
pair<int, int> sr[N];
int a[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < N; ++i) par[i] = i, sz[i] = 1;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i], sr[i].first = a[i], sr[i].second = i;
    sort(sr, sr + n);
    reverse(sr, sr + n);
    long long res = 0;
    for (int _ = 0; _ < n; ++_) {
        int j = sr[_].second, x = sr[_].first;
        int lsz = 1, rsz = 1;
        if (j > 0 && a[j - 1] > a[j]) lsz += sz[find(j - 1)], unite(j - 1, j);
        if (j < n - 1 && a[j + 1] > a[j]) rsz += sz[find(j + 1)], unite(j + 1, j);
        res += a[j] * 1ll * lsz * rsz;
    }
    cout << res << endl;


}


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

std::string s1, s2;

int main(){
    std::cin >> s1 >> s2;

    if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]){
        std::cout << "YES\n";
    }else{
        std::cout << "NO\n";
    }

    return 0;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  string s;
  int sum = 0, ans = 0;
  for(int i=1; i<=n; i++) {
    s = to_string(i);
    for(int j=0; j<s.size(); j++) sum += s[j]-'0';
    if(a<=sum && sum<=b) ans += i;
    sum = 0;
  }
  cout << ans << endl;
  return 0;
}

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

void solve(int TestCase) {
    int n, m;
    cin >> n >> m;

    int count, penal;
    count = penal = 0;

    vector<bool> A(n+1);
    vector<int> wa(n+1);
    for(auto i = 0; i < m; ++i) {
        int p;
        string s;
        cin >> p >> s;

        if(A[p]) continue;

        if(s == "AC") {
            A[p] = true;
            count++;
        }
        else {
            wa[p]++;
        }
    }

    for(auto i = 0; i <= n; ++i) {
        if(A[i])
            penal += wa[i];
    }

    cout << count << " " << penal << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i)
        solve(i);
}


Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
        return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
        return readInts()[0];
}
auto readLongs() {
        return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
        return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    auto n = readLong();
    long v;
    foreach(i; iota(n)) {
        v += readLong();
    }
    writeln(v/n);
}

Measured memory_bytes: 2908
n = int(input())
f = []
for i in range(n):
    f.append(list(map(int, input().split())))
p = []
for i in range(n):
    p.append(list(map(int, input().split())))
count = {}
ans = []
for bits in range(1 << 10):
    count = {}
    for i in range(10):
        if (bits >> i & 1) == 1:
            for j in range(n):
                if j not in count: 
                    count[j] = f[j][i]
                else:
                    count[j] += f[j][i]
    if count != {}:
        flag = 0
        for k in range(n):
            if count[k] != 0:
                flag = 1
        if flag:
            check = 0
            for l in range(n):
                check += p[l][count[l]]
            ans.append(check)
print(max(ans))

Measured memory_bytes: 3192
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
vch=[]
ac=10**15
for i in range(A):
    ac=min(ac,a[i])
bc=10**15
for i in range(B):
    bc=min(bc,b[i])
ans=ac+bc
for i in range(M):
    c=list(map(int,input().split()))
    ans=min(ans,a[c[0]-1]+b[c[1]-1]-c[2])
print(ans)

Measured memory_bytes: 69740
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;

  vector<int> a(n);
  vector<int> sa(n);
  unordered_map<int, int> mp;

  rep(i, n) {
    cin >> a.at(i);
    sa.at(i) = a.at(i);
  }

  sort(sa.begin(), sa.end());
  rep(i, n) {
    mp[sa.at(i)] = i;
  }
  
  int ans = 0;
  rep(i, n) {
    if ((mp[a.at(i)] - i) % 2 != 0) {
      ans++;
    }
  }
  cout << ans/2 << endl;
}

Measured memory_bytes: 5156
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

int main() {

	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	bool dp[k + 1];
	memset(dp, 0, sizeof(dp));
	for (int stones = 0; stones <= k; ++stones) {
		for (int x : a) {
			if (stones >= x and !dp[stones - x]) {
				dp[stones] = true;
			}
		}
	}

	cout << (dp[k] ? "First" : "Second");

	return 0;
}

Measured memory_bytes: 384
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static long B;
  static long C;
  static double min = 9999999;
  static long ans = 0;




  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);


    int N = scanner.nextInt();

    int  ans = 0;
    long[] mapa = new long[N];
    long[] mapb = new long[N];

    for (int i = 0; i < N; i++) {
      mapa[i] = scanner.nextLong();
    }
    for (int i = 0; i < N; i++) {
      mapb[i] = scanner.nextLong();
    }


    long tarin = 0;
    ArrayList<Long> ok = new ArrayList<>();

    long amari = 0;
    ans = 0;
    for (int i = 0; i < N; i++) {
      if(mapa[i] - mapb[i] >= 0){
        amari += mapa[i] - mapb[i];
        ok.add(mapa[i] - mapb[i]);

//        ans++;
      }else{
        tarin += mapb[i] - mapa[i];

        ans++;
      }
    }


    Collections.sort(ok);
    for (int i = 0; i < ok.size(); i++) {
//      System.out.println(ok.get(i));
    }
//    System.out.println();
//    System.out.println(tarin);
//    System.out.println();

//    System.out.println("ans = " + ans);
    if(amari < tarin){
      ans = -1;
      tarin = 0;
    }
    for (int i = 0; i < ok.size(); i++) {
      if(tarin <= 0)break;
      tarin -=ok.get(ok.size() - i - 1);
//      System.out.println(ok.get(ok.size() - i - 1));
      ans++;
    }

    System.out.println(ans);


  }

}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD =  1000000007;
const ll INF = 1LL << 60;


int main() {
    int a, b, c; cin >> a >> b >> c;
    int k; cin >> k;

    while(b <= a){
        b *= 2;
        k--;
    }
    while(c <= b){
        c *= 2;
        k--;
    }
    if(0 <= k && a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 3636
// 修改自提交记录：192182
// 原记录作者：E.Space (UID: 1579)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int fa[222222],siz[222222],pno,f[222222];
long long add[222222];
int gf(int u)
{
	if(fa[u]==u)return u;
	return fa[u]=gf(fa[u]);
}
struct edg
{
	int x,y,l;
}ed[555555];
bool operator <(const edg &x,const edg &y)
{
	return x.l>y.l;
}
int main()
{
//	freopen("migrate.in","r",stdin);
//	freopen("migrate.out","w",stdout);
	int n=io::F(),m=n-1;
	for(register int i=1;i<=m;++i)
		ed[i]=(edg){io::F(),io::F(),io::F()};
	std::sort(ed+1,ed+m+1);
	pno=n;
	for(register int i=1;i<=n;++i)fa[i]=i,siz[i]=1;
	for(register int i=1;i<=m;++i)
	{
		int t1=gf(ed[i].x),t2=gf(ed[i].y);
		if(t1==t2)continue;
		add[t1]=siz[t2]*(long long)ed[i].l;
		add[t2]=siz[t1]*(long long)ed[i].l;
		f[t1]=f[t2]=fa[t1]=fa[t2]=++pno;
		siz[pno]=siz[t1]+siz[t2];
		fa[pno]=pno;
	}
	for(register int i=pno-1;i;--i)
		add[i]+=add[f[i]];
	for(register int i=1;i<=n;++i)
		printf("%lld\n",add[i]);
	return 0;
}


Measured memory_bytes: 7424
def hantei(n, a, b, c, d, s):
    if s[a - 1:c].find("##") > 0:
        return "No"
    if s[b - 1:d].find("##") > 0:
        return "No"
    if c > d:
        if s[max(0, b - 2):min(n, d + 1)].find("...") == -1:
            return "No"
    return "Yes"

n, a, b, c, d = map(int, input().split())
s = input()
print(hantei(n, a, b, c, d, s))


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,cnt;
string s;
map<char,ll>m;
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++)m[s[i]]++;
	ll cnt=m['R']*m['G']*m['B'];
	for(int i=0;i<n;i++){
		for(int d=1;d<n;d++){
			int j=i+d;
			int k=j+d;
			if(k<n&&s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k])cnt--;
		}
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3628
N = gets.chomp.to_i

num = 1
max = 0

for i in 1..N
  if i%2 == 0
    flag = true
    count = 0
    div = i
      while flag
        div = div/2
        count += 1
          if div%2 != 0
            if max < count
              num = i
              max = count
            end
            flag = false
          end
      end
  end
end

print(num)


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

struct VC {
	int64_t val;
	int64_t count;
};

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

	int64_t n, m; cin >> n >> m;

	auto comp = [](const VC & lhs, const VC & rhs) {
		return (lhs.val > rhs.val);
	};
	multiset<VC, decltype(comp)> vals(comp);

	FOR_LT(i, 0, n) {
		int a; cin >> a;
		vals.insert({ a, 1 });
	}

	FOR_LT(i, 0, m) {
		int c, b; cin >> c >> b;
		vals.insert({ b, c });
	}

	int64_t count = 0;
	int64_t ans = 0;

	auto it = vals.begin();
	while (count < n) {
		const VC& cur = *it;
		if (n - count <= cur.count) {
			ans += cur.val * (n - count);
		}
		else {
			ans += cur.val * cur.count;
		}

		count += cur.count;
		it++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
#include<stdio.h>
int main(){
  int H,W=1;
  int i,j;
  scanf("%d%d",&H,&W);
  while(H!=0||W!=0){
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(i%2==0&&j%2==0)printf("#");
        else if(i%2==1&&j%2==1)printf("#");
        else printf(".");
        }
      printf("\n");}
    printf("\n");
   scanf("%d%d",&H,&W);}
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> m;
    n = m % 10;
    if (n == 3)
        cout << "bon";
    else if (n <= 1 || n == 6 || n == 8)
        cout << "pon";
    else
        cout << "hon";
}

Measured memory_bytes: 3652
#include <stdio.h>
int gcd(int, int);
void swap(int *, int *);

int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;
}

int gcd(int x, int y){
  int r;
  if(x < y) swap(&x,&y);
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

void swap(int *a, int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
  return;
}



Measured memory_bytes: 2080
def main():
    L = int(input())
    S, T = (input() for _ in [0] * 2)

    ans = []
    apnd = ans.append
    a = S
    b = T
    i = 0
    for _ in [0] * 2:
        while 1:
            x = L - (len(b) * i)
            div_, mod_ = divmod(x, len(a))
            if not mod_:
                apnd(a * div_ + b * i)
                break
            i += 1
        i = 0
        a, b = b, a
    print(min(ans))

main()


Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 

typedef long long ll;

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<ll> L(87);
    L[0] = 2;
    L[1] = 1;
    

    for (int i = 2; i < 87; i++) {
        L[i] = L[i - 1] + L[i - 2];
    }

    cout << L[N] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b,sum=0;
  cin>>a>>b;
  sum=a+b;
  if(sum%2==0)cout<<sum/2<<endl;
  else if(sum%2!=0)cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int q[101] = {0};
int check(int x){
    if(x<0 || x>101) return 1;
    if(q[x]) return 0;
    return 1;
}

int main(){
    int X, N, p[100];
    scanf("%d%d", &X, &N);
    for(int i=0;i<N;i++){
        scanf("%d", &p[i]);
        q[p[i]] = 1;
    }
    // end input
    
    int d = 0;
    while(1) {
        if(check(X-d)){
            printf("%d\n", X-d);
            return 0;
        }
        if(check(X+d)){
            printf("%d\n", X+d);
            return 0;
        }
        d++;
    }
    
    

    return 0;
}




Measured memory_bytes: 1712
import sys
fin = sys.stdin.readline
sys.setrecursionlimit(300000)
from collections import defaultdict


H, W = [int(elem) for elem in fin().split()]
S = [tuple(elem for elem in fin()[:-1]) for _ in range(H)]
# print(S)

visited = [[False] * W for _ in range(H)]
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
group_numblack = defaultdict(int)
group_numwhite = defaultdict(int)

def dfs_visit(i, j, visited, group):
    if visited[i][j]:
        return
    visited[i][j] = True
    if S[i][j] == "#":
        group_numblack[group] += 1
    else:
        group_numwhite[group] += 1
    for di, dj in directions:
        next_i, next_j = i + di, j + dj
        if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
            continue
        elif visited[next_i][next_j]:
            continue
        elif S[i][j] == S[next_i][next_j]:
            continue
        else:
            dfs_visit(next_i, next_j, visited, group)

# DFS
group = 0
for i in range(H):
    for j in range(W):
        dfs_visit(i, j, visited, group)
        # stack = [(i, j)]
        # while stack:
        #     i, j = stack.pop()
        #     if visited[i][j]:
        #         continue
        #     visited[i][j] = True
        #     if S[i][j] == "#":
        #         group_numblack[group] += 1
        #     else:
        #         group_numwhite[group] += 1
        #     for di, dj in directions:
        #         next_i, next_j = i + di, j + dj
        #         if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
        #             continue
        #         elif visited[next_i][next_j]:
        #             continue
        #         elif S[i][j] == S[next_i][next_j]:
        #             continue
        #         else:
        #             stack.append((next_i, next_j))
        group += 1
# print(visited)
# print(group_numblack)
# print(group_numwhite)

num_pairs = 0
for group in group_numblack.keys():
    num_pairs += group_numblack[group] * group_numwhite[group]
print(num_pairs)



Measured memory_bytes: 153332
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;

deque<pair<int, int> > deq;

const int MAX = 1000;
/* 配列 a の [left, right) をソートします */
void MergeSort(int a[], int left, int right) {
    if (right - left == 1) return;
    int mid = left + (right - left) / 2;

    // 左半分 [left, mid) をソート
    MergeSort(a, left, mid);

    // 右半分 [mid, right) をソート
    MergeSort(a, mid, right);

    //一旦「左」と「右」のソート結果をコピーしておく (右側は左右反転)
    int buf[1000];
    int index_buf = 0;
    for (int i = left; i < mid; ++i) {
        buf[index_buf++] = a[i];
    }
    for (int i = right-1; i >= mid; --i) {
        buf[index_buf++] = a[i];
    }
    int last_index_buf = --index_buf;

    // マージする
    int iterator_left = 0;                    // 左側のイテレータ
    //int iterator_right = (int)buf.size() - 1; // 右側のイテレータ
    int iterator_right = last_index_buf;
    for (int i = left; i < right; ++i) {
        // 左側採用
        if (buf[iterator_left] <= buf[iterator_right]) {
            a[i] = buf[iterator_left++];
        }
        // 右側採用
        else {
            a[i] = buf[iterator_right--];
        }
    }
}

#include <queue>
#include <stack>

void breadthFirstSearch(Graph& G,const int n,int initVertex,vector<int>& dist){
    //BFS用のデータ構造
    dist.assign(n,-1);//頂点の深さ記録
    queue<int> que;//次の訪問先を記録

    //初期値
    dist[initVertex] = 0;
    que.push(initVertex);

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(auto next_v:G[v]){
            if(dist[next_v] != -1) continue;
            dist[next_v] = dist[v] + 1;
            que.push(next_v);
        }

    }

}

vector<bool> seen;
vector<int> first_order;
vector<int> last_order;
void dfs(Graph& G,int v,int& first,int& last){
    first_order.push_back(first++);
    seen[v] = true;
    for(auto next_v:G[v]){
        if(seen[next_v]) continue;
        dfs(G,next_v,first,last);
    }

    last_order.push_back(last++);




}



int main() {
    
    
    int a,b;

    string s,t,u;
    cin >> s >> t;
    cin >> a >> b;

    cin >> u;

    if(u == s){
        a--;
    }else{
        b--;
    }
    cout << a <<" "<<b << endl;

   
    

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (S == U) {
    cout << A - 1  << endl;
    cout << B << endl;
  }
  else {
    cout << A << endl;
    cout << B - 1 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int S,h,m,s;
  scanf("%d",&S);
  h=S/3600;
  m=(S-h*3600)/60;
  s=(S-h*3600)%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592