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

class BIT {
private:
	long long Size;
	vector<long long> Node;
public:
	BIT(long long N) : Size(N) {
		Node.resize(Size + 1, 0);
	}
	void Update(long long N, long long X) {
		for (long long i = N; i <= Size; i += (i & -i)) {
			Node[i] += X;
		}
	}
	long long Query(long long N) {
		if (N == 0) return 0;
		long long ANS = 0;
		for (long long i = N; i > 0; i -= (i & -i)) {
			ANS += Node[i];
		}
		return ANS;
	}
};

int main() {
	long long N, M;
	cin >> N >> M;
	vector<vector<long long> > V(M + 1);
	for (int i = 0; i < N; i++) {
		long long S, T;
		cin >> S >> T;
		V[S].push_back(T);
	}
	vector<vector<long long> > D(M + 1);
	vector<long long> ANS(M + 1, 0);
	BIT B(M);
	for (int i = 1; i <= M; i++) {
		for (int j = 0; i * j <= M; j++) {
			D[i * j].push_back(i);
		}
	}
	for (int i = M; i > 0; i--) {
		for (int j = 0; j < V[i].size(); j++) B.Update(V[i][j], 1);
		for (long long X : D[i - 1]) {
			long long NX = min(M, i + X - 2);
			ANS[X] += B.Query(NX);
		}
	}
	for (int i = 1; i <= M; i++) cout << N - ANS[i] << endl;
}

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

int main(){
    int N;
    string S,T;
    cin >> N;
    cin >>S >> T;
    string new_string;
    cout << new_string << endl;
    for(int i=0;i<N;i++){
        new_string += S[i];
        new_string += T[i];
    }
    cout << new_string << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int x,y,i;
	for(i=0; i<3000; i++){
		
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0)break;
		if(x<y){
		printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}


Measured memory_bytes: 2024
package main

import "fmt"

func main() {
	// Code for B - Lucas Number
	var N int
	fmt.Scanf("%d", &N)
	var L0 int = 2
	var L1 int = 1
	var L2 int = 0
	if N == 1 {
		fmt.Println(L1)
	} else {
		for i := 2; i <= N; i++ {
			L2 = L1 + L0
			L0 = L1
			L1 = L2
		}

		fmt.Println(L2)
	}
}


Measured memory_bytes: 1832
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
c1=0;c2=0;c3=0
for i in range(n):
  if p[i]<=a:c1+=1
  elif p[i]>=b+1:c3+=1
  else:c2+=1
print(min(c1,c2,c3))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n;
  vi a(n),b(n);
  REP(i,n){
    cin>>a[i]>>b[i];
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll mn=0;
  ll mx=0;
  if (n%2==1){
    mn=a[n/2];
    mx=b[n/2];
    ans=mx-mn+1;
  }else{
    ll mn2=0;
    ll mx2=0;
    mn=a[n/2];
    mx=b[n/2];
    mn2=a[n/2-1];
    mx2=b[n/2-1];
    ll lng=(mx2-mn2)+(mx-mn)+1;
    ll aaa=max(mn,mn2);
    ll bbb=min(mx,mx2);
    ll tmp=max(bbb-aaa,0LL);
    ans=lng-tmp;
    
    ans=lng;
  }




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

Measured memory_bytes: 6436
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		boolean[] A = new boolean[N];
		for(int k=0; k<K; k++) {
			int D = in.nextInt();
			for(int d=0; d<D; d++) {
				int a = in.nextInt();
				A[a-1] = true;
			}
		}

		int count = 0;
		for(int n=0; n<N; n++) {
			if(!A[n]) {
				count++;
			}
		}
		System.out.println(count);
		
		in.close();
	}
}


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

using namespace std;

typedef pair<int,int> PII;

int i,n,m,x,y,ans;
int a[100007];
map<PII,bool> mem;

int main() {
	scanf("%d%d",&n,&m);
	for (i=0 ; i<m ; i++) {
		scanf("%d%d",&x,&y);
		mem[PII(x,y)] = true;
		mem[PII(y,x)] = true;
	}
	
	for (i=2 ; i<n ; i++) if (mem[PII(1,i)] && mem[PII(i,n)]) {
		printf("POSSIBLE\n");
		return 0;
	}
	printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 37760
n,t=map(int,input().split())
F=[list(map(int,input().split())) for i in range(n)]
dp1=[[0]*(t+1) for i in range(n)]
for i in range(1,n):
  for j in range(1,t+1):
    if j-F[i-1][0]>=0:
      dp1[i][j]=max(dp1[i-1][j],dp1[i][j-1],dp1[i-1][j-F[i-1][0]]+F[i-1][1])
    else:
      dp1[i][j]=max(dp1[i-1][j],dp1[i][j-1])
dp2=[[0]*(t+1) for i in range(n)]
for i in range(1,n):
  for j in range(1,t+1):
    if j-F[n-i][0]>=0:
      dp2[i][j]=max(dp2[i-1][j],dp2[i][j-1],dp2[i-1][j-F[n-i][0]]+F[n-i][1])
    else:
      dp2[i][j]=max(dp2[i-1][j],dp2[i][j-1])
ans=0
for i in range(n):
  for j in range(1,t):
    a=dp1[i][j]+dp2[n-i-1][t-j-1]+F[i][1]
    if a>ans:
      ans=a
print(ans)

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

void solver() {
  string s;
  cin >> s;

  string ans = "No";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '7') ans = "Yes";
  }
  cout << ans << "\n";
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
const int N = 5005; 
typedef long long ll;
const ll INF = 1e15; 
using namespace std;

ll n, m, k, ans = INF; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

ll check(int x)
{
	ll res = 0, tmp = n;
	while(tmp) res += tmp % x, tmp /= x;
	return res; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <ll> (), m = read <ll> (), k = sqrt(n);
	if(n == m) ans = min(ans, n + 1); 
	if(m == 1 && n != 1) ans = min(ans, n); 
	if(m > n) { puts("-1"); return 0; } 
	for(int i = 2; i <= k; i++)
		if(check(i) == m) { printf("%lld\n", i); return 0; }
	for(ll b, y, i = 1; i * i <= (n - m); i++)
		if((n - m) % i == 0)
		{
			y = m - i, b = (n - m) / i + 1; 
			if(i < b && y < b && b > k && i > 0 && y >= 0 && i + y == m) ans = min(ans, b);  
			if(i * i != n - m)
			{
				y = m - (n - m) / i, b = i + 1; 
				if(i < b && y < b && b > k && i > 0 && y >= 0 && i + y == m) ans = min(ans, b); 
			}
		}
	printf("%lld\n", ans == INF ? -1 : ans); 
	return 0; 
}


Measured memory_bytes: 3232
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();

		int result = A + B;
		if (result < A - B) {
			result = A - B;
		}
		if (result < A * B) {
			result = A * B;
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 23124
#include <cstdio>
//#include <iostream>
//#include <string>

using namespace std;

// cl /EHsc xxx.cpp
int main(int argc, char *argv[])
{
	int n;
	scanf("%d", &n);
	
	int *ary = new int[n];
	
	int v;
	int t = n;
	while (t)
	{
		scanf("%d", &v);
		ary[--t] = v;
	}
	
	for (int j = 0; j < n; j++)
	{
		if (j == n-1)
		{
			printf("%d", ary[j]);
		}
		else
		{
			printf("%d ", ary[j]);
		}
		
	}
	printf("\n");
	
	delete[] ary;
	
	return 0;
}

Measured memory_bytes: 1032
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3664
/*||>>>> Praveen Ojha <<<<>>>> 10 August 2019 <<<<>>>> 17:27:09 <<<<||*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
//Read Problems Carefully & Check for corner cases N=0,1 ?
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
    int a,b;
    cin>>a>>b;
    cout<<max(a*b,max(a+b,a-b))<<"\n";
return 0;
}

Measured memory_bytes: 256
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

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

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

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll K, A, B;
  cin >> K >> A >> B;

  for (auto a = A; a <= B; a++) {
    if (a % K == 0) {
      cout << "OK"
           << "\n";
      return 0;
    }
  }

  cout << "NG"
       << "\n";

  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#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 PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int N;

void BabbleSort(string s[]){
    REP(i,N){
	RFOR(j,i+1,N){
	    if((int)(s[j-1][1] - '0') > (int)(s[j][1] - '0')) swap(s[j-1],s[j]);
	}
    }	
}
void SelectionSort(string s[]){
    REP(i,N){
	int mini = i;
	FOR(j,i,N){
	    if((int)(s[mini][1] - '0') > (int)(s[j][1] - '0')) {
		mini = j;
	    }
	}
	swap(s[i],s[mini]);
    }
}

int main(){

    bool stableflag;
    cin >> N;
    string s[50],s1[50],s2[50];
    REP(i,N){
       	cin >> s[i];
	s1[i] = s[i];
	s2[i] = s[i];
    }
    BabbleSort(s1);
    SelectionSort(s2);
    stableflag = true;
    REP(i,N-1) cout << s1[i] << " ";
    cout << s1[N-1];
    cout << endl;
    cout << "Stable"<<endl;
    REP(i,N) if(s2[i][0] != s1[i][0]) stableflag = false;
    REP(i,N-1) cout << s2[i] << " ";
    cout << s2[N-1];
    cout << endl;
    if(stableflag) cout << "Stable"<<endl;
    else cout << "Not stable" << endl;

    return 0;
}

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

#ifdef HOME
#define db(x) cerr << #x << " = " << x << endl
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dbv(a) cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

using namespace std;
typedef long long ll;
typedef double dbl;


const int INF = 1.01e9;

int solve(vector<int> a) {
    int n = a.size();

    struct seg {
        int c;
        int l, r;
    };

    auto can = [&](int mx) {
        if (mx == 1) {
            bool ok = 1;
            for (int i = 1; i < n; i++) ok &= a[i] > a[i - 1];
            return ok;
        }
        
        vector<seg> v;
        v.push_back({0, 0, a[0] - 1});
        for (int i = 1; i < n; i++) {
            if (a[i] > a[i - 1]) {
                v.push_back({0, a[i - 1], a[i] - 1});
            } else {
                int dif = a[i - 1] - a[i];
                while (dif > 0) {
                    int x = v.back().r - v.back().l + 1;
                    int k = min(x, dif);

                    dif -= k;
                    if (k == x) {
                        v.pop_back();
                    } else {
                        v.back().r -= k;
                    }
                }

                while (!v.empty()) {
                    if (v.back().l != v.back().r) {
                        int x = v.back().r;
                        v.back().r--;
                        v.push_back({v.back().c, x, x});
                    }
                    v.back().c++;
                    if (v.back().c == mx) {
                        v.pop_back();
                    } else break;
                }
                if (v.empty()) return false;
                if (v.back().r != a[i] - 1) {
                    v.push_back({0, v.back().r + 1, a[i] - 1});
                }
            }
        }
        return true;
    };

    int L = 0, R = n;
    while (R - L > 1) {
        int M = (L + R) >> 1;
        if (can(M)) R = M;
        else L = M;
    }
    return R;
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);

        printf("%d\n", solve(a));
    }

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 7280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());

            int min = Integer.MAX_VALUE;
            int max = 0;

            for (int i = 0; i < n; i++) {
                int a = Integer.parseInt(in.next());
                min = Math.min(min, a);
                max = Math.max(max, a);
            }

            out.println(max - min);

        }

    }
}



Measured memory_bytes: 23892
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
    int N,W;
    cin>>N>>W;
    int v[N+2];
    int w[N+2];
    for(int i=1;i<=N;i++){
        cin>>w[i]>>v[i];
    }
    int dp[N+1][100002];
    for(int vi=0;vi<=100000;vi++){
        dp[1][vi] = INT_MAX;

    }
    dp[1][0] = 0;
    dp[1][v[1]] = w[1];
    for(int i=2;i<=N;i++){
        for(int vi=0;vi<=100000;vi++){
            if(vi  == 0){dp[i][vi] = 0;}
            else{
                dp[i][vi] = dp[i-1][vi];
                if(v[i] <= vi){
                    dp[i][vi] = min(dp[i][vi], w[i]+dp[i-1][vi-v[i]]);
                }
            }
        }
    }

    for(int i=100000;i>=0;i--){
        if(dp[N][i] <= W){
            cout<<i;
            break;
        }
    }
    return 0;

}

Measured memory_bytes: 81760
#include <stdio.h>


int main(){

	int n, m, x, y;
	int A[100][100] ,b[100], c;

	scanf( "%d %d", &n, &m );
	

	for( y=0; y<n; y++){
		for( x=0; x<m; x++ ){
			scanf( "%d", &A[x][y] ); 
		}
	}
	for( x=0; x<m; x++ ) scanf( "%d", &b[x] );



	for( y=0; y<n; y++){
		c = 0;
		for( x=0; x<m; x++ ){
			c += A[x][y]*b[x];
		}
		printf("%d\n", c);
	}


	return 0;

}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
string st;int f=0;
int main(){
	cin>>st;f=0;
	if(st[0]!='A'){cout<<"WA"<<endl;return 0;}
	for(int i=2;i<st.length()-1;i++)if(st[i]=='C')f++;
	if(f!=1){cout<<"WA"<<endl;return 0;}
	for(int i=1;i<st.length();i++)if((st[i]<'a'||st[i]>'z')&&(st[i]!='C')){cout<<"WA"<<endl;return 0;}
	cout<<"AC"<<endl;return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<int> > v(n,vector<int> (3));
  
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
      cin >> v[i][j];

  
  vector<vector<int>> dp(n,vector<int> (4));
   dp[0][1] = *max_element(v[0].begin(),v[0].end());
   dp[0][2] = *max_element(v[0].begin(),v[0].end());
   dp[0][3] = *max_element(v[0].begin(),v[0].end());
  
  for(int i=1;i<n;i++){
   dp[i][1] = max(dp[i-1][2],dp[i-1][3]) + v[i][0];
   dp[i][2] = max(dp[i-1][1],dp[i-1][3]) + v[i][1];
   dp[i][3] = max(dp[i-1][2],dp[i-1][1]) + v[i][2]; 
  
  }
  cout << *max_element(dp[n-1].begin(),dp[n-1].end());     

}

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

#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>p(N);
  vector<double>exp(N);
  vector<double>last(N-K+1);
  for(int i=0;i<N;i++)cin>>p[i];
  for(int i=0;i<N;i++)
    exp[i]=(double)(p[i]+1)/2;
  last[0]=0;
  for(int j=0;j<K;j++)
    last[0]+=exp[j];
  for(int i=1;i<N-K+1;i++){
     last[i]=last[i-1]-exp[i-1]+exp[i+K-1];
  
  }
  sort(last.begin(),last.end());
  cout << std::fixed << std::setprecision(10) << last[N-K] << endl ;
  
}
  


Measured memory_bytes: 4096
N = int(input())
  
A = list(map(int,input().split()))
A = [i-1 for i in A]
B = list(map(int,input().split()))
C = list(map(int,input().split()))

res = 0
for i in range(N):
  res += B[A[i]]
  if ( i > 0 and A[i] == A[i-1]+1):
    res += C[A[i-1]]

print(res)

Measured memory_bytes: 3064
n=int(input())
d=list(map(int,input().split()))
dcnt=[0 for i in range(13)]
for i in d:
  dcnt[i]+=1

zf=False
for i in range(1,12):
  if dcnt[i]>=3:
    zf=True
if dcnt[0]:
  zf=True
if dcnt[12]>=2:
  zf=True

if zf:
  print(0)
else:
  ison=[0 for i in range(24)]
  oned=[]
  ison[12]=1
  ison[0]=dcnt[12]
  for i in range(1,12):
    if dcnt[i]==1:
      oned.append(i)
    elif dcnt[i]==2:
      ison[12-i]=1
      ison[12+i]=1
  maxd=0
  for i in range(2**len(oned)):
    for j in range(len(oned)):
      if i&(2**j):
        ison[12+oned[j]]=1
        ison[12-oned[j]]=0
      else:
        ison[12-oned[j]]=1
        ison[12+oned[j]]=0
        
    mind=24
    p=100
    s=23
    while True:
      if ison[s]:
        mind=min(mind,p-s)
        p=s
        if s<0:
          break
      s-=1
    maxd=max(maxd,mind)
  print(maxd)

Measured memory_bytes: 9188
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

n, m = input_nums()
sc = []
for i in range(m):
    sc.append(tuple(input_nums()))

sc = list(set(sc))
sc.sort(key=lambda x: x[0])

check = {}
res = [1] + [0] * (n-1)
for s, c in sc:
    if not s in check.keys():
        check[s] = c
        res[s-1] = c
    else:
        if check[s] != c:
            res = -1
            break

if res == -1:
    print(res)
elif n == 1 and m == 0:
    print(0)
else:
    if len(res) != 1 and res[0] == 0:
        print(-1)
    elif len(res) == 1 and res[0] == 0:
        print(0)
    else:
        res = map(str, res)
        print(''.join(res))

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

int main() {
	int N, M; cin >> N >> M;
	vector<int>like(M,0);
	for (int i = 0; i < N; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int a; cin >> a;
			like[--a]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (like[i] == N)ans++;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){
	
	int num;
	
	while(true){
		cin >> num;
		if(num == -1){
			break;
		}
		string str = "D";
		string dum = "D";
		str[0] = '0' + num % 4;
		while(true){
			num /= 4;
			if(num == 0){
				break;
			}
			dum[0] = '0' + num % 4;
			str = dum + str;
		}
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    map<string, ll> mp;
    set<string> se;
    rep(i,N){
        string s;
        cin >> s;
        se.emplace(s);
        mp[s]++;
    }
    ll M = 0;
    for(auto p:mp){
        chmax(M, p.second);
    }
    for(auto p:mp){
        if(p.second==M){
            cout << p.first << endl;
        }
    }
}

Measured memory_bytes: 33280
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;


int main() {
  int N;

  cin >> N;
  vector<int> D(N);

  for (int i=0; i<N; i++) cin >> D.at(i);

  sort(D.begin(), D.end());
  

  int half_idx = N/2;

  int K = D.at(half_idx);
  int idx = D.at(half_idx-1) + 1;

  cout << K-idx+1;

}

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

int main(){
  int n,k,count=1;
  cin >> n >>k;
  while(n/k!=0){
    n/=k;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import os
from sys import stdin, stdout

def backtrack(a,b,c,k):
    if k==0:
        if a<b<c:
            return True
        return False
    
    ret = False
    ret |= backtrack(a*2,b,c,k-1)
    ret |= backtrack(a,b*2,c,k-1)
    ret |= backtrack(a,b,c*2,k-1)
    return ret

def solve(tc):
    a, b, c = map(int, stdin.readline().split())
    k = int(stdin.readline().strip())

    if backtrack(a,b,c,k):
        print("Yes")
    else:
        print("No")
    return

tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1


Measured memory_bytes: 67388
def divisors(n)
  res = []
  lim = Math.sqrt(n)
  i = 1
  while i <= lim
    if n % i == 0
      res.push(i)
      res.push(n / i)
    end
    i += 1
  end
  res.uniq.sort
end

def max_accept(divs, xs)
  divs.reverse_each do |d|
    if xs.count { |x| x % d != 0 } <= 1
      return d
    end
  end
end

def solve(a)
  [
    max_accept(divisors(a[0]), a[1..-1]),
    max_accept(divisors(a[1]), [*a[0], *a[2..-1]])
  ].max
end

def main
  n = gets.to_i
  a = gets.split.map(&:to_i)

  p solve(a)
end

main


Measured memory_bytes: 9356
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;

int main(){
    int n;
    cin >> n;
    if(n%2==1) cout << (n+1)/2 << endl;
    else cout << n/2 << endl;
}



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

int main(){
    int a,b,c,n,m;
    long long sum=0;
    cin>>n>>m;

    priority_queue<int> q;

    rep(i,n){
        cin>>a;
        q.push(a);
    }//ここまで入力

    rep(i,m){
        b=q.top();
        q.pop();
        q.push(b/2);
    }//一番大きいものを２で割る

    rep(i,n){
        c=q.top();
        q.pop();
        sum+=c;

    }//総和

    cout<<sum<<endl;

}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = (int)n - 1; i >= 0; --i)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
	int N;
	vector<int> a;
	cin >> N;
	a.resize(N);
	rep(i,N) cin >> a[i];

	int res = 0;
	rep(i,N) {
		if(a[a[i]-1] == i+1)
			res++;
	}
	cout << res/2 << endl;
}


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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M; cin >> N >> M;
    ll res = min((N*2 + M)/4,M/2);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  ll x[100];
  rep(i, n) cin >> x[i];
  ll Min = LINF;
  for (int i = 1; i <= 100; ++i)
  {
    ll sum = 0;
    rep(j, n)
    {
      sum += (i - x[j]) * (i - x[j]);
    }
    Min = min(Min, sum);
  }
  cout << Min << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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 main(){
    ll ans=1;
    ll n;cin >> n;
    rep(i,n){
        ll a;cin >> a;
        ans=a/__gcd(ans,a)*ans;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int n,A[N];

int partition(int p, int r){
  int x,i,j,tmp;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j]<=x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}

int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  q = partition(0,n-1);

  for(i=0; i<n; i++){
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
    if(i!=n-1) printf(" ");
  }
  printf("\n");

  return 0;

}



Measured memory_bytes: 2132
N, K = map(int, input().split())
P = list(map(int, input().split()))

if (K == 1):
    answer = (max(P) + 1) / 2
    print(answer)
    exit()

total = sum(P[0: 0 + K])
max_index = 0
P_sum = []
P_sum.append(total)

for i in range(K, len(P)):
    change = P[i] - P[i - K]
    tmp = change + P_sum[-1]
    
    P_sum.append(tmp)

maxx = max(P_sum)
answer = (maxx + K) / 2
print(answer)

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

#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define lld long double
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<long long, long long >
#define INF 10000000000000009 //1e16+9
#define F first
#define S second
//#define MAX
using namespace std;
stack<char>s1;

void solve()
{ string s,t;
cin>>s>>t;
int i,j,arr[s.size()+1][t.size()+1];
for(i=0;i<=s.size();i++)
    for(j=0;j<=t.size();j++)
  {
    if(i==0 || j==0)
        arr[i][j]=0;
    else {
        if(s[i-1]==t[j-1])
            arr[i][j]=arr[i-1][j-1]+1;
        else arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
      }
   }
   i=s.size(),j=t.size();

while(i!=0 && j!=0){
if(s[i-1]==t[j-1])
    {s1.push(s[i-1]);
    i--;j--;}
    else{
        if(arr[i-1][j]<arr[i][j-1])
             j--;
        else
             i--;

         }

}

while (!s1.empty())
    {
        cout << s1.top();
        s1.pop();
    }

    }

int main()
{
	boost;
	//int t;
	//cin>>t;
	//while(t--)
	//{

		solve();
		//cout<<endl;
	//}
	return 0;
}


Measured memory_bytes: 38836
#include <iostream>
#include <math.h>
using namespace std;

int main() {

    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2; 

    double l = sqrt( pow(x2-x1,2.0) + pow(y2-y1,2.0) );

    cout << fixed;
    cout << l << endl;
    return 0;
}



Measured memory_bytes: 3276
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int K;
  cin>>K;
  vector<ll> A(K);
  for(int i=0;i<K;++i) cin>>A[i];
  ll r = 2, l = 2;
  bool can = true;
  for(int i=K-1;i>=0;--i) {
    r = (r/A[i]+1)*A[i]-1;
    if(l%A[i]==0) l = l/A[i]*A[i];
    else l = (l/A[i]+1)*A[i];
    if(r<l) can = false;
  }
  if(can) cout<<l<<" "<<r<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    int ans = k;
    if (k > 1) ans = ans * int(pow(k - 1, n - 1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int first = sc.nextInt();
    	int min = first;
    	int max = first;
    	List<Integer> di = new ArrayList<>();
    	di.add(first);
    	for (int i = 1; i < N; i++) {
    		int d = sc.nextInt();
    		di.add(d);
    	}
    	Collections.sort(di);
    	int harf1 = di.get(N/2 - 1);
    	int harf2 = di.get(N/2);
    	if (harf1 != harf2) {
    		System.out.println(harf2 - harf1);
    	} else {
    		System.out.println(0);
    	}
    }
}

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

#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define brep(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define xrep(i,n) for(ll i=1,i##_len=(n);i<=i##_len;i++)
#define Yes(n) cout<<((n)?YES:NO)<<'\n'
#define rYes(n) cout<<((n)?YES:NO)<<'\n';return
#define Sort(v) sort(all(v))
#define rSort(v) sort(all(v)); reverse(all(v))
#define Unique(v) (v).erase(unique(all(v)),(v).end())
#define eb emplace_back

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vvll = vector<vll>;
using vstr = vector<string>;

// --- functions which take 1 argument ---
static inline void ignore_ret(int x){x++;}
template<class T> inline int sgn(T x){return (x>0)-(x<0);}
template<class T> inline ll factorial(T n){if(n==0)return 1;ll r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline map<T,T> factorize(T n){map<T,T>r;for(T i=2;i*i<=n;i++){while(n%i==0){r[i]++;n/=i;}}if(n!=1)r[n]=1;return r;}

// --- functions which take 2 arguments ---
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T nPr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;for(T i=n-k+1;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}

// --- functions which take vector(s) as argument(s) ---
template<class T> inline void print(vector<T>v){cout<<"[ ";for(auto x:v)cout<<x<<' ';cout<<"]\n";}
template<class T> inline T min(vector<T>v){return *min_element(all(v));}
template<class T> inline T max(vector<T>v){return *max_element(all(v));}
template<class T> inline ll sum(vector<T>v){return reduce(all(v),0LL);}
template<class T> inline T gcd(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=gcd(r,v[i]);return r;}
template<class T> inline T lcm(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=lcm(r,v[i]);return r;}
template<class T> inline double abs(vector<T>v){return sqrt(reduce(all(v),0.0,[](int s,int v){return s+=v*v;}));}
template<class T> inline T vector_add(T u,T v){ll s=u.size();if(s>v.size())return {};T r;rep(i,s)r.eb(u[i]+v[i]);return r;}
template<class T> inline T vector_subtract(T u,T v){ll s=u.size();if(s>v.size())return {};T r;rep(i,s)r.eb(u[i]-v[i]);return r;}
template<class T> inline T dot_product(vector<T>u,vector<T>v){if(u.size()<v.size())return 0;T r=0;for(T i=0;i<u.size();i++)r+=u[i]*v[i];return r;}
template<class T> inline T cross_product(T u,T v){T r(3);r[0]=u[1]*v[2]-u[2]*v[1];r[1]=u[2]*v[0]-u[0]*v[2];r[2]=u[0]*v[1]-u[1]*v[0];return r;}

// --- Template ends here ---

void solve(ll X) {
  ll cnt = 0, balance = 100;
  while (balance < X) {
    cnt++;
    balance += balance / 100;
  }
  cout << cnt << endl;
}

int main() {
  ll X;
  ignore_ret(scanf("%lld",&X));
  solve(X);
  return 0;
}


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


int main(){
    int N, L; cin >> N >> L;
    int total = N * L + (N * (N - 1)) / 2;
    int min_diff = 1e9;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int sub_total = total - (L + i - 1);
        int diff = abs(total - sub_total);
        if (diff < min_diff) {
            min_diff = diff;
            ans = sub_total;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Queue queue = new Queue();
		String[] input;
		int n, q;
		int end_time = 0;
		String[] name;
		int[] time;

		input = br.readLine().split(" ");
		n = Integer.parseInt(input[0]);
		q = Integer.parseInt(input[1]);
		name = new String[n];
		time = new int[n];

		for(int i = 0; i < n; i++){

			input = br.readLine().split(" ");
			name[i] = input[0];
			time[i] = Integer.parseInt(input[1]);
			queue.enqueue(i);

		}

		while(!queue.isEmpty()){

			int index = queue.dequeue();

			if(time[index] > q){
				end_time += q;
				time[index] -= q;
				queue.enqueue(index);
			}else{
				end_time += time[index];
				time[index] = 0;
				System.out.println(name[index] + " " + end_time);
			}

		}

	}

}

class Queue{

	private int head = 0;
	private int tail = 0;
	private int len = 100000;
	private int[] data = new int[len];

	public void enqueue(int x){

		data[tail] = x;

		if(tail == len - 1){
			tail = 0;
		}else{
			tail++;
		}

	}

	public int dequeue(){

		int x = data[head];

		if(head == len - 1){
			head = 0;
		}else{
			head++;
		}

		return x;

	}

	public boolean isEmpty(){

		if(head == tail){
			return true;
		}else{
			return false;
		}

	}

}

Measured memory_bytes: 61220
import scala.io.StdIn

object Main {
  def main(args: Array[String]){
    val num = StdIn.readInt()
    val input = StdIn.readLine().split(" ").map(_.toInt)
    insertionSort(input,num)
  }
  
  def insertionSort(input: Array[Int], num: Int) = {
      println(input.mkString(" "))
      for(i <- 1 to num -1){
          val v = input(i)
          var j = i -1
          while(j >= 0 && input(j) > v){
              input(j+1) = input(j)
              j = j -1
          }
          input(j+1) = v
          println(input.mkString(" "))
      }
      
  }
}


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

using namespace std;

int main()
{
    int K;
    cin >> K;
    set<long long> dp[11];
    set<long long> ans;
    for (int i = 1; i < 10; i++)
    {
        dp[1].insert(i);
        ans.insert(i);
    }
    for (int i = 2; i < 11; i++)
    {
        for (auto &x : dp[i - 1])
        {
            string s = to_string(x);
            int tmp = s[s.size() - 1] - '0';
            if (tmp + 1 < 10)
            {
                dp[i].insert(stoll(s+to_string(tmp+1)));
            }
            if(tmp -1 >= 0)
            {
                dp[i].insert(stoll(s+to_string(tmp-1)));
            }
            dp[i].insert(stoll(s+to_string(tmp)));
        }
        for (auto &x : dp[i])
        {
            ans.insert(x);            
        }
    }
    int i = 0;
    for(auto itr = ans.begin(); itr != ans.end(); ++itr) {
        if(i == K-1){
            cout << *itr << endl;
            return 0;
        }
        i++;
    }
    
}

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

int main() {
  int N;
  cin >> N;
  bool go = true;
  for (int i = 0; i < N; i++){
    int Ai;
    cin >> Ai;
    if (Ai % 2 == 1){
      continue;
    }
    if (Ai % 3 == 0 || Ai % 5 == 0){
      continue;
    }
    go = false;
    break;
  }
  if (go){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e];
int n;
vector<arr<int, 2>>adj[e];
ll col[e];
ll dep[e];

void dfs(int u, int par)
{
    for(auto j : adj[u]){
        if(j[0] == par) continue;
        dep[j[0]] = dep[u] + j[1];
        dfs(j[0], u);
    }
}

int main()
{
    cin >> n;
    for(int i=1; i<n; i++){
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    dfs(1, 1);
    cout << 0 <<"\n";
    //memset(col, 0, sizeof(col));
    for(int i=2; i<=n; i++){
        //cout << dep[i] <<"\n";
        if(dep[i]&1){
            cout << 1 <<"\n";
        }
        else{
            cout << 0 <<"\n";
        }
    }
}


Measured memory_bytes: 57056
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,p;

bool check(int *a) {
    int cnt=0;
    rep(i,n) if(a[i]!=0) cnt++;
    return cnt==1;
}

void solve() {
    int ary[100]={};
    int wan=p;

    int index = 0;
    while(true) {
        if(wan==0) {
            if(p==ary[index]) break;
            wan = ary[index];
            ary[index] = 0;
        }
        else {
            wan--;
            ary[index]++;
        }
        index++;
        index%=n;
    }
    //index=index+n-1;
    //index%=n;
    cout<<index<<endl;


}

int main() {
    while(cin>>n>>p){
        if(!(n+p)) return 0;
        solve();
    }
    return 0;
}

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


int main() {
    string S; cin >> S;
    if(S[0]==S[1] || S[1]==S[2] || S[2]==S[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    int n;ll k;cin >> n >> k;
    vi a(n);
    rep(i,n){
        cin >> a[i];
        --a[i];
    }
    vb used(n,0);
    vi pos;
    int pre = 0;
    int roop = 0;
    vi roop_vec;
    vi non_roop;
    while(true){
        if(used[pre]){
            bool ok = false;
            cerr << "roop with " << pre << "\n";
            for(int i=0;i<pos.size();++i){
                if(pos[i] == pre || ok){
                    ok = true;
                    roop_vec.emplace_back(pos[i]);
                }else{
                    non_roop.emplace_back(pos[i]);
                }
            }
            break;
        }
        pos.emplace_back(pre);
        used[pre] = true;
        pre = a[pre];

    }
    int ans;
    if(k+1 <= non_roop.size()){
        ans = non_roop[k];
    }else{
        k -= non_roop.size();
        if(k < 0) k += roop_vec.size();
        if(roop_vec.size()) k %= roop_vec.size();
        ans = roop_vec[k];
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 6308
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input!{
        _n: usize,
        s: String,
        k: usize,
    };
    let c = s.chars().nth(k-1).unwrap();
    let mut r = "".to_string();
    for x in s.chars() {
        if x != c {
            r += "*"
        } else {
            r += &*(x.to_string())
        }
    };
    println!("{}", r);
}

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

using namespace std;

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

    int ans = 0;


    for(int i = 1; i<N; i++ ){
        int now = 0;
        for(int j = 0; j < N-i; j++){
            if(S[j] == S[i + j]){
                now ++;
                ans = max(ans, now);
            }
            else{
                now = 0;
            }
        }
        ans = min(ans, i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def datasets():
    import sys
    for i in range(int(sys.stdin.readline().strip())):
        s1 = sys.stdin.readline().strip()
        s2 = sys.stdin.readline().strip()
        yield s1, s2

for s1, s2 in datasets():
    r = int(s1)+int(s2)
    if len(s1)>80 or len(s2)>80 or len(str(r))>80:
        print "overflow"
        continue
    print r

Measured memory_bytes: 5756