akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

long long ABC[3][1001];
vector<long long> AB_best;
vector<long long> ans;

int main(){
    int xyzk[4];
    for (int i = 0; i < 4; i++) {
        cin >> xyzk[i];
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < xyzk[i]; j++) {
            cin >> ABC[i][j];
        }
    }
    AB_best = vector<long long>(xyzk[0] * xyzk[1]);
    int cnt = 0;
    for (int i = 0; i < xyzk[0]; i++) {
        for (int j = 0; j < xyzk[1]; j++) {
            AB_best[cnt++] = ABC[0][i] + ABC[1][j];
        }
    }
    sort(AB_best.begin(), AB_best.end(), greater<long long>());
    cnt = 0;
    ans = vector<long long>(3000*xyzk[2]);
    for (int i = 0; i < AB_best.size() && i < 3000; i++) {
        for (int j = 0; j < xyzk[2]; j++) {
            ans[cnt++] = AB_best[i] + ABC[2][j];
        }
    }
    sort(ans.begin(), ans.end(), greater<long long>());
    for (int i = 0; i < xyzk[3]; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
const int inf = 1000000001;
const ll INF = 1e18;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  int x, y, i, j;
  cin >> x >> y;
  if (abs(x) == abs(y)) {
    cout << 1 << endl;
    return 0;
  }
  ll cnt = 0;
  if (abs(x) < abs(y)) {
    if (x < 0) {
      cnt++;
      x *= -1;
    }
    cnt += (abs(y) - x);
    x = abs(y);
    if (y < 0) {
      cnt++;
      x *= -1;
    }
    cout << cnt << endl;
    return 0;
  }
  else {
    if (x > 0) {
      cnt++;
      x *= -1;
    }
    cnt += (-abs(y) - x);
    x = -abs(y);
    if (y > 0) {
      x *= -1;
      cnt++;
    }
    cout << cnt << endl;
    return 0;
  }
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
int h, w, k;
char arr[10][10], grid[10][10];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int ans = 0;
	cin >> h >> w >> k;
	REP(i, 0, h){
		REP(j, 0, w) cin >> arr[i][j];
	}
	
	REP(i, 0, (1 << h)){
		REP(j, 0, (1 << w)){
			REP(kk, 0, h){
				REP(l, 0, w) grid[kk][l] = arr[kk][l];
			}
			REP(kk, 0, h){
				if ((i >> kk)%2 == 1){
					REP(l, 0, w){
						grid[kk][l] = '?';
					}
				}
			}
			REP(kk, 0, w){
				if ((j >> kk)%2 == 1){
					REP(l, 0, h){
						grid[l][kk] = '?';
					}
				}
			}
			int counter = 0;
			REP(kk, 0, h){
				REP(l, 0, w){
					if (grid[kk][l] == '#') counter++;
				}
			}
			if (counter == k){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> p(n);
  
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  
  int ans = 0;
  
  for(int i = 0; i < n-2; i++){
    if((p.at(i)<p.at(i+1) && p.at(i+1)<p.at(i+2)) || (p.at(i)>p.at(i+1) && p.at(i+1)>p.at(i+2))){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

struct data {
  int n;
  int p;
  ll y;
  data(int n, int p, ll y) : n(n), p(p), y(y){}
};

bool compare(data d1, data d2) {
  if(d1.p == d2.p)
    return d1.y < d2.y;
  else
    return d1.p < d2.p;
}

char num2char(int n) {
  char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  return c[n];
}

string gen_str(int p, ll y) {
  string top(6, '0'), bottom(6, '0');
  for(int i=0; i<6; i++) {
    top[5-i] = num2char(p % 10);
    p /= 10;
  }
  for(int i=0; i<6; i++) {
    bottom[5-i] = num2char(y % 10);
    y /= 10;
  }
  return top + bottom;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<data> D;
  for(int i=0; i<M; i++) {
    int p; ll y;
    cin >> p >> y;
    D.push_back(data(i, p, y));
  }
  sort(D.begin(), D.end(), compare);
  vector<string> ans(M);
  int j = D[0].p;
  int k = 1;
  for(int i=0; i<M; i++) {
    if(D[i].p == j) {
    } else {
      j = D[i].p;
      k = 1;
    }
    ans[D[i].n] = gen_str(j, k);
    k++;
  }
  for(int i=0; i<M; i++)
    cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 8560
#include <iostream>
#include <vector>

using namespace std;

vector<int> topo;
vector<int> seen;
vector<vector<int> > G;

void topological_sort(int s) {
    seen[s] = 1;
    for (int i = 0; i < G[s].size(); i++) {
        int u = G[s][i];
        if (seen[u])
            continue;
        
        topological_sort(u);
    }
    topo.push_back(s);
}

int main() {
    int n, m;   cin >> n >> m;
    seen.resize(n, 0);
    G.resize(n);
    for (int i = 0; i < m; i++) {
        int x, y;   cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
    }

    for (int i = 0; i < n; i++) {
        if (!seen[i])
            topological_sort(i);
    }

    for (int i = 0; i < n/2; i++) {
        swap(topo[i], topo[n-1-i]);
    }

    vector<int> dp(n, -1);
    for (int i = 0; i < n; i++) {
        int u = topo[i];
        
        if (dp[u] == -1)
            dp[u] = 0;
        for (int j = 0; j < G[u].size(); j++) {
            int v = G[u][j];
            dp[v] = max(dp[v], dp[u] + 1);
        }
    }
    

    int ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(dp[i], ans);

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

Measured memory_bytes: 11792
N,W = map(int, input().split())
val_i = [0]*(W+1)
for i in range(1,N+1):
    v,w = map(int, input().split())
    copy = val_i[:] ##i-1번째줄의 val_i
    for j in range(1,W+1):
        if (w <= j):
            val_i[j] = max(copy[j], (val_i[j-w] + v)) ##0개선택시 copy[j], 
                                               ##1개 이상 선택시 val_i[j]와(val_i[j-w]+v)는 동일값
            #choice = [k*v + copy[j-k*w]for k in range(j//w+1)]
            #val_i[j] = max(choice)                            --> time limit exceeded
            
            ##val_i[j] = max((v + copy[j-w]), copy[j])   --> formal answer
print(val_i[-1])


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

int main(){
  int N;
  cin >> N;
  char c;
  for(int i=0;i<N;i++){
    cin >> c;
    if(c=='Y'){
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split()) 

def detection(R, L):
    # print(R,L)
    if R-L <= 1:
        return L
    mid = (R+L)//2
    if mid > N:
        num_s = mid - N
        num_c = M - num_s*2
    else:
        num_s = mid
        num_c = M
    if num_c < mid*2:
        R = mid
    else:
        L = mid
    return detection(R,L)

def main():
   right = N+M
   left = -1
   ans = detection(right, left)
   print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main() {
  int a,b;
  cin >> a >>b;
  int ans=(a+b)%24;
  cout << ans << endl;
}

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

using namespace std;

const array<string, 4> uses = {"erase", "eraser", "dream", "dreamer"};

bool Solve() {
    string s;
    cin >> s;

    const int n = s.size();
    vector<bool> dp(n, false);
    for (const auto &x : uses)
        if (s.substr(0, x.size()) == x) dp[x.size() - 1] = true;

    for (int i = 0; i < n; ++i) {
        if (!dp[i]) continue;
        for (const auto &x : uses) {
            if (i + x.size() < n && s.substr(i + 1, x.size()) == x)
                dp[i + x.size()] = true;
        }
    }

    return dp[n - 1];
}

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

    if (Solve()) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 512
using System;

namespace abc096A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A <= B)
                Console.WriteLine(A);
            else
                Console.WriteLine(A - 1);
        }
    }
}


Measured memory_bytes: 11092
n = gets.to_i
a = gets.split.map(&:to_i)
x = 0
for i in 0..(n-1)
  if a[i]%2 == 0
    if a[i]%3 != 0 && a[i]%5 != 0
      x = 1
      break
    end
  end
end

if x == 0
  puts "APPROVED"
else
  puts "DENIED"
end

Measured memory_bytes: 1788
N = gets.to_i
L = gets.split.map(&:to_i)

L.sort!.push(10**4)

count = 0
for i in 0...(N-2)
    for j in (i+1)...(N-1)
        lb = j
        rb = N
        k = L[i] + L[j]
        while rb - lb > 1
            mb = (lb+rb)/2
            L[mb] < k ? lb = mb : rb = mb
        end
        count += lb - j
    end
end

puts count

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef vector<vector<pair<int, int>>> GRA;

int i,j,N,A,al,bb;

int main() {
	cin >> N;
	vector<int> A(N);
	
	REPI(0,N) {
		cin >> A[i];
	}
	
	sort(A.begin(),A.end(),greater<int>());
	
	REPI(0,N) {
		if (!(i%2)) al += A[i];
		else bb += A[i];
	}
	
	cout << al - bb;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
string s;
vector<P>vec;
int main(){
	cin>>n>>k;
	cin>>s;
	int cur = 0,num = 0;
	rep(i,n){
		if(i == 0){
			cur = s[i]-'0';
			num = 1;
		}
		else if(cur != s[i]-'0'){
			vec.pb(mp(cur,num));
			cur = s[i]-'0';
			num = 1;
		}
		else num++;
	}
	vec.pb(mp(cur,num));
	if(vec[vec.size()-1].fi == 0){
		vec.pb(mp(1,0));
	}
	reverse(vec.begin(),vec.end());
	if(vec[vec.size()-1].fi == 0){
		vec.pb(mp(1,0));
	}
	reverse(vec.begin(),vec.end());
	//for(int i=0;i<vec.size();i++) cout<<vec[i].fi<<vec[i].sc<<endl;
	if(vec.size() <= 2*k+1){
		cout << n << endl;
		return 0;
	}
	else{
		int ans = 0;
		int num = 0;
		int nxt = 0;
		for(int i=0;i<vec.size();i+=2){
			while(nxt <= i+2*k && nxt < vec.size()){
				num += vec[nxt].sc;
				nxt++;
			}
			if(i){
				num -= vec[i-2].sc+vec[i-1].sc;
			}
			ans = max(ans,num);
		}
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 1528
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 22:36:36 2020

@author: liang
"""

N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()

ans = 0
for i in range(0,K):
    s = str()
    tmp = i
    while tmp < N:
        s += T[tmp]
        tmp += K
    #print(s)
    count = 1
    prev = str()
    for j in range(len(s)):
        if s[j] == prev:
            count += 1
        else:
            count = 1
        if count%2 == 0:
            continue
        prev = s[j]
        if s[j] == "r":
            ans += P
        elif s[j] == "s":
            ans += R
        else:
            ans += S
print(ans)
        

Measured memory_bytes: 9404
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<int[]> list = new List<int[]>();

        while (true) {
            string v = Console.ReadLine();
            if (string.IsNullOrEmpty(v) == true) { break; }

            int a = int.Parse(v.Split(' ')[0]);
            int b = int.Parse(v.Split(' ')[1]);
            list.Add(new int[] { a, b });
        }

        for (int i = 0; i < list.Count; i++) {
            int c = list[i][0] + list[i][1];
            Console.WriteLine(c.ToString().Length);
        }
    }
}

Measured memory_bytes: 9192
import sys

N = int(input())
for h in range(1, 3501):
    for n in range(1, h+1):
        if (4*h*n - N*h - N*n) <= 0:
            continue
        w_int = N*h*n // (4*n*h - N*h - N*n)
        w_float = N*h*n / (4*n*h - N*h - N*n)
        if w_int == w_float:
            print(h, n, w_int)
            sys.exit()



Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll x;
	cin>>x;
	ll goal = abs(x)*2LL;
	for(ll i = 1; ; ++i){
		if(i*i + i >= goal){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int M = 1e9+7;
int n, k, a[100100], dp[110][100100];

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

  dp[0][0] = 1;

  for (int i = 0; i < n; i++) {
    long long sum = 0;
    for (int j = 0; j <= k; j++) {
      sum += dp[i][j];
      if (j-a[i]-1 >= 0) sum -= dp[i][j-a[i]-1]-M;
      sum %= M;
      dp[i+1][j] = sum;
    }
  }

  cout << dp[n][k] << endl;
  return 0;
}

Measured memory_bytes: 40832
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String  str = sc.nextLine();
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch == '?') {
                sb.append('D');
            } else {
                sb.append(ch);
            }
        }

        String ans = sb.toString();

        System.out.println(ans);
    }
}


Measured memory_bytes: 42556
using System;
using System.Collections;
public class Curtain{
    public static void Main(){
    string[] arr = Console.ReadLine().Split(' ');
    int A = int.Parse(arr[0]);
	int B = int.Parse(arr[1]) * 2;
	if(A <= B){
      Console.WriteLine(0);
    }else{
      Console.WriteLine(A-B);
    }
    }
}


Measured memory_bytes: 11092
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N, K = LI()
S = str(input())
S = S + "2"
d1 = []
d0 = []
k = S[0]
if k=="0":
    d1.append(0)
cou = int(1)
for i in range(N):
    if S[i]!=S[i+1]:
        if S[i]=="0":
            d0.append(cou)
        if S[i]=="1":
            d1.append(cou)
        cou = int(1)
    else:
        cou +=1

#print(d1)
#print(d0)

ansC = []
t = 2*K+1
newN = len(d1)
if len(d1)==1 or d0==[] or K>=N//2+1:
    ansC.append(N)

if newN!=len(d0):
    d0.append(0)
    d0.append(0)
sumd1 = [0]*(newN+t+5)
sumd0 = [0]*(newN+t+5)
for i in range(newN):
    sumd1[i+1] = d1[i]
    sumd0[i+1] = d0[i]
for i in range(newN+1):
    sumd1[i+1] += sumd1[i]
    sumd0[i+1] += sumd0[i]

#for i in range(max(newN-K+1,K)):
if ansC==[] and (newN - K + 1)>=1:
    for i in range(newN - K + 1):
        ans = (sumd1[i + K + 1] - sumd1[i]) + (sumd0[i + K] - sumd0[i])
        ansC.append(ans)
else:
    ansC.append(N)
print(max(ansC))

Measured memory_bytes: 9972
a = gets.split(' ')
x = a[0].to_i
n = a[1].to_i
return puts x if n == 0

b = gets.split(' ')

c = b.sort_by{|x| x.to_i }

d = c.index(x.to_s)

return puts x if d == nil

for i in 1..(c.size / 2 + 1)
  if x - i != c[d - i].to_i
    puts x - i
    break
  elsif x + i != c[d + i].to_i
    puts x + i
    break
  end
end

Measured memory_bytes: 14368
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,a,b,k,t,f;
  cin>>n>>a>>b;
  if (b-a>n || a>b){cout<<0<<endl;}
  else {
   k= ((n-1)*b)+a;
    t= ((n-1)*a)+b;
    f= k-t+1;
    cout<<f<<endl;
  }
return 0;
}

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

typedef long long ll;
const ll mod=1e9+7;
const int N=200000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll a[N],s,res,f;
map<char,ll>mp;
vector<ll>v;
int main()
{
    Run();
    int x,b=1;
    cin>>x;
    while((b*x)%360!=0)
        b++;
    cout<<b;
}


Measured memory_bytes: 3628
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,nx,ny, ans
    integer(int64), allocatable:: a(:), ind(:), dp(:,:)


    read*, n
    allocate(a(n), ind(n), dp(-1:n,-1:n))
    read*,a(:)
    ans = 0
    do i=1,n
        ind(i) = i
    end do
    call double_sort(a,ind,1_8,n)

    dp(:,:) = 0
    do i=0,n-1
        do nx=0,i
            ny = i-nx
            dp(nx+1,ny) = max(dp(nx+1,ny),dp(nx,ny)+(ind(i+1)-(nx+1))*a(i+1))
            dp(nx,ny+1) = max(dp(nx,ny+1),dp(nx,ny)+(n-ny-ind(i+1))*a(i+1))
        end do
    end do

    do nx=0,n
        ny=n-nx
        ans=max(ans,dp(nx,ny))
    end do
    print*, ans
contains
    recursive subroutine double_sort(ar1, ar2, fst, lst)
        integer(8),intent(inout):: ar1(:),ar2(:)
        integer(8),intent(in):: fst,lst
        integer(8):: mdl

        if (lst - fst < 2) then
            if (ar1(fst) < ar1(lst)) then
                call swap(ar1(fst), ar1(lst))
                call swap(ar2(fst), ar2(lst))
            end if
            return
        end if

        mdl = (fst+lst)/2

        call double_sort(ar1,ar2,fst,mdl)
        call double_sort(ar1,ar2,mdl+1,lst)
        call double_merge_(ar1,ar2,fst,mdl,lst)
    end subroutine


    subroutine double_merge_(ar1,ar2,fst,mdl,lst)
        integer(8),intent(inout):: ar1(:),ar2(:)
        integer(8),intent(in):: fst,mdl,lst
        integer(8),allocatable:: t1(:),t2(:)
        integer(8):: li,ri,ti

        allocate(t1(lst-fst+1), t2(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while(li <= mdl .and. ri <= lst)
            if (ar1(li) >= ar1(ri)) then
                t1(ti) = ar1(li) 
                t2(ti) = ar2(li)
                li=li+1
            else
                t1(ti) = ar1(ri)
                t2(ti) = ar2(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            t1(ti:) = ar1(li:mdl)
            t2(ti:) = ar2(li:mdl)
        else
            t1(ti:) = ar1(ri:lst)
            t2(ti:) = ar2(ri:lst)
        end if

        ar1(fst:lst) = t1(:)
        ar2(fst:lst) = t2(:)

        deallocate(t1,t2)
    end subroutine

    
    subroutine swap(x,y)
        integer(8),intent(inout):: x,y
        integer(8):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine

    
end program name

Measured memory_bytes: 34236
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))
f = 0
for i in A:
    if i%2 == 0:
        if i%3 == 0 or i%5 ==0:
            pass
        else:
            f = 1
            break
if f == 1:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
void solve()
{
    ll x,n;
    cin>>x>>n;
    ll a[n];
    umll mp;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    ll g=x;
    while(mp[g]>0){
        g++;
    }
    ll a1=g;
    g=x;
    while(mp[g]>0){
        g--;
    }
    ll a2=g;
    if(abs(a1-x)<abs(a2-x)){
        cout << a1 <<"\n";

    }
    else cout << a2 <<"\n";
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string top;
  cin >> top;
  
  int n = top.length();
  int ans = 700;
  
  for(int i=0;i<n;i++){
    if(top[i] == 'o')
      ans += 100;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n = 0;
	static List<Integer> b = null;
	
	public static void main(String[] args) {
		n = sc.nextInt();
		b = new ArrayList<>();
		for(int i = 0; i < n; ++i) b.add(sc.nextInt());
		
		List<Integer> trace = findTrace();
		if(trace == null) {
			System.out.println(-1);
			return;
		}
		
		for(int i = trace.size() - 1; i >= 0; --i) {
			System.out.println(trace.get(i));
		}
	}
	
	static List<Integer> findTrace() {
		List<Integer> res = new ArrayList<>();
		while(b.size() > 0) {
			for(int i = b.size() - 1; i >= 0; --i) {
				if(b.get(i) - 1 == i) {
					res.add(b.get(i));
					b.remove(i);
					break;
				}
				if(i == 0) return null;
			}
		}
		return res;
	}
}

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

int main(){
  int N,M; cin >> N >> M;
  if(M==0){
    cout << "0 0" << endl;
    return 0;
  }
  int pen[100010]={};
  int ans[100010]={};
  int penres=0;
  int ansres=0;
  for(int i=0; i<M; i++){
    int p;
    string S;
    cin >> p >> S;
    p--;
    if(S=="AC"&&ans[p]==0){
      penres+=pen[p];
      ans[p]=1;
    }else{
      pen[p]++;
    }
  }
  for(int i=0; i<N; i++){
    ansres+=ans[i];
  }
  cout << ansres << " " << penres << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::vector<std::string> c){
    cout << c[0][0] << c[1][1] << c[2][2] << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::vector<std::string> c(3);
    for(int i = 0 ; i < 3 ; i++){
        std::cin >> c[i];
    }
    solve(std::move(c));
    return 0;
}


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

int main(){

    int a,b;
    cin >> a >> b;
    int res1 = 0;
    int res2 = 0;
    double res3 = 0;

    res1 = a / b;
    res2 = a % b;
    res3 = (double) a / (double) b;
    printf("%d %d %.8f", res1, res2, res3);
    //cout << res1 << ' ' << res2 << ' ' << printf("%.8f",res3) << endl;
    return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=100005;
int n,a[N],ans[N],vis[N];
pii t[N*4];
set<int> S;
void build(int k,int l,int r){
	if (l==r){
		t[k]=pii(0,l);
		return;
	}
	int mid=(l+r)/2;
	build(k*2,l,mid);
	build(k*2+1,mid+1,r);
	t[k]=max(t[k*2],t[k*2+1]);
}
void change(int k,int l,int r,int p,int v){
	if (l==r){
		t[k].fi+=v;
		return;
	}
	int mid=(l+r)/2;
	if (p<=mid) change(k*2,l,mid,p,v);
	else change(k*2+1,mid+1,r,p,v);
	t[k]=max(t[k*2],t[k*2+1]);
}
void erase(int x){
	change(1,1,n,a[x],-1);
	change(1,1,n,x,-(1<<30));
}
void insert(int x,int v){
	change(1,1,n,a[x],1);
	if (v) change(1,1,n,x,(1<<30));
}
bool ava(int ban,int l){
	if (!l) return 1;
	int id=t[1].se;
	//printf("%d %d\n", ans[1],t[1].se);
	if (t[1].fi<l-1) return 1;
	if (id==ban){
		int p=id,fl=1;
		change(1,1,n,p,-1);
		id=t[1].se;
		if (t[1].fi!=l-1) fl=0;
		change(1,1,n,p,1);
		if (!fl) return 0;
	}
	if (a[a[id]]==id&&l==2) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) S.insert(i);
	build(1,1,n);
	For(i,1,n) insert(i,0);
	For(i,1,n) vis[i]=1;
	if (!ava(0,n)) return puts("-1"),0;
	For(i,1,n){
		set<int>::iterator it;
		it=S.begin();
		for (;it!=S.end();it++){
			if (*it==a[ans[i-1]]) continue;
			erase(*it);
			ans[i]=*it;
			if (ava(a[*it],n-i)) break;
			insert(*it,1);
			//cout<<*it<<endl;
		}
		assert(it!=S.end());
		ans[i]=*it;
		S.erase(it);
		vis[ans[i]]=0;
		//printf("%d\n",ans[i]);
	}
	For(i,1,n) printf("%d ",ans[i]);
} 
/*
illegal:
存在一个元素,出现次数==剩余元素个数-1,且第一个位置不能放
否则均合法 
*/ 

Measured memory_bytes: 9856
N = int(input())
SP = [input().split() for i in range(N)]
S = []
P = []
P_index = []
for i in range(len(SP)):
  SP[i][1] = int(SP[i][1])
  S.append(SP[i][0])
  P.append(SP[i][1])

SN = sorted(S)
num = []
for j in range(len(SN)):
  num.append([i for i, x in enumerate(S) if x == SN[j]])

num_uniq = []
for x in num:
    if x not in num_uniq:
        num_uniq.append(x)

for i in range(len(num_uniq)):
  P_queue = []
  for j in range(len(num_uniq[i])):
    P_queue.append([P[num_uniq[i][j]],num_uniq[i][j]])
  P_only = []
  for j in range(len(num_uniq[i])):
    P_only.append(P_queue[j][0])
  P_o = sorted(P_only,reverse=True)
  for j in range(len(num_uniq[i])):
    P_index.append(P.index(P_o[j]))
    
for i in range(len(P_index)):
  print(P_index[i]+1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int N,M,maxx,miny;
  cin>>N>>M>>maxx>>miny;
  int x,y;
  REP(i,N) { cin >> x; maxx = max(maxx,x); }
  REP(i,M) { cin >> y; miny = min(miny,y); }
  if (miny > maxx) COUT("No War");
  else COUT("War");
  return 0;
}

Measured memory_bytes: 256
s = input()

l = [ _ for _ in s ]

odd = set(['R','U','D'])
even = set(['L','U','D'])

l_odd = l[::2]
l_even = l[1::2]

s_odd = set(l_odd)
s_even = set(l_even)

if s_odd.issubset(odd) and s_even.issubset(even) :
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
//Only for codeforces
#include<bits/stdc++.h>
using namespace std;
//#define ll long long int
#define ld long double
#define int long long
#define pb push_back 
#define mod 1000000007
#define mod2 998244353
#define Z(c) (int)(c).size()
#define F first
#define S second
#define nl "\n"
//#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define clber cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);(i)++)
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define pi 3.1415926536
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define tr(it,ct) for(auto &(it) : (ct))
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;

int power(int a,int n,int lelo)
{
        if(n==0)
                return 1;
        if(n==1)
                return a;
        if(n==2)
                return (a*a)%lelo;
        if(n%2)
                return (a*power(a,n-1,lelo))%lelo;
        else
                return power(power(a,n/2,lelo),2,lelo)%lelo;
}


void swap(int &a,int &b)
{ int tm=a; a=b; b=tm; }

 const int N=1e+5;
 

void solve()
{ 
  int n,w,s=0; cin>>n>>w; vi v(n+1),a(n+1); rep(i,1,n+1) { cin>>a[i]>>v[i]; s+=v[i]; }
  int dp[s+1]; rep(i,0,s+1) dp[i]=1e17;
  dp[0]=0;
  rep(i,1,n+1)
  for(int j=s;j>=v[i];j--)
    dp[j]=min(dp[j-v[i]]+a[i],dp[j]);
  
  int ans=0;
  rep(i,0,s+1)
  if(dp[i]<=w)
  {
    ans=max(i,ans);
  }
  cout<<ans;
}


signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0); 
  
 
  int t=1;
   
//  cin>>t;
rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   solve();
   
   if(i<t)
   cout<<"\n";
  }

 return 0; 
}

Measured memory_bytes: 1024
N=int(input())
print(0)
a=input()
m=-1
if a=="Vacant":
  exit()
elif a=="Male":
  m=0
elif a=="Female":
  m=1
l,r=1,N-1
while r-l>1:
  mid=(l+r)//2
  print(mid)
  a=input()
  if a=="Vacant":
    exit()
  elif a=="Male" and (mid-m)%2==0:
    l=mid
  elif a=="Female" and (mid-m)%2==1:
    l=mid
  else:
    r=mid
print(l)
if input()=="Vacant":
  exit()
print(r)
if input()=="Vacant":
  exit()


Measured memory_bytes: 38852
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n];
   rep(i,0,n)cin>>a[i];
   int pre[n];
   int suf[n];
   int g=a[0];
   for(int i=0;i<n;i++)
   {
       g=__gcd(g,a[i]);
       pre[i]=g;
   }
   g=a[n-1];
   for(int i=(n-1);i>=0;i--)
   {
       g=__gcd(g,a[i]);
       suf[i]=g;
   }
   int mx=0;
   for(int i=0;i<n;i++)
   {
       if(i == 0)
       {
           mx=max(mx,suf[i+1]);
       }
       else if(i == n-1)
       {
           mx=max(mx,pre[i-1]);
       }
       else
       {
           int gcd=__gcd(pre[i-1],suf[i+1]);
           mx=max(mx,gcd);
       }
   }
   cout<<mx<<endl;
}


Measured memory_bytes: 2560
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        AtCoder problem = new AtCoder(sc);
        problem.solve(out);
        
        out.flush();
    }
    
}

class AtCoder {
    final int A,B;
    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(A*B);
    }
    
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {
    
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }
    
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 32692
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define ll long long

signed main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  vector<ll> dpa(N, 0), dpb(N, 0);
  dpa[0] = A[0];
  dpb[0] = -A[0];
  
  rep(i, N-1) {
    dpa[i+1] = max(dpa[i]+A[i+1], dpb[i]-A[i+1]);
    dpb[i+1] = max(dpa[i]-A[i+1], dpb[i]+A[i+1]);
  }
  
  cout << dpa[N-1] << endl;


}

Measured memory_bytes: 5036
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  string s, t;
  cin >> s >> t;
  string ans = (s.size()+1 == t.size() && 
                s == t.substr(0, t.size()-1)) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
	private static class Point {
		public int x, y, h;

		public Point(String[] tokens) {
			this.x = Integer.parseInt(tokens[0]);
			this.y = Integer.parseInt(tokens[1]);
			this.h = Integer.parseInt(tokens[2]);
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.nextLine());
		List<Point> points = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.nextLine().split(" ");
			points.add(new Point(tokens));
		}
		Collections.sort(points, new Comparator<Point>() {
			@Override
			public int compare(Point o1, Point o2) {
				if (o1.h > o2.h) {
					return -1;
				} else if (o1.h < o2.h) {
					return 1;
				} else {
					return 0;
				}
			}
		});

		// 最初の要素で高さを求める
		Point refer = points.get(0);
		int resultcx = -1, resultcy = -1, resultheight = -1;
		List<Point> validatePoints = points.subList(1, points.size());
		for (int cy = 0; cy <= 100; ++cy) {
			for (int cx = 0; cx <= 100; ++cx) {
				int height = getHeight(refer, cx, cy);
				if (validate(validatePoints, cx, cy, height)) {
					resultcx = cx;
					resultcy = cy;
					resultheight = height;
					break;
				}
			}
			if (resultheight > 0) {
				break;
			}
		}
		System.out.println(resultcx + " " + resultcy + " " + resultheight);

		in.close();
	}

	private static int getHeight(Point point, int cx, int cy) {
		return point.h + Math.abs(point.x - cx) + Math.abs(point.y - cy);
	}

	private static boolean validate(List<Point> points, int cx, int cy, int height) {
		for (Point point : points) {
			if (Math.max(height - Math.abs(point.x - cx) - Math.abs(point.y - cy), 0) != point.h) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 23380
import java.util.*;
public class Main{
   

  public static int longestPath(ArrayList<ArrayList<Integer>> graph,int sv,int dp[])
  {
	  
	  ArrayList<Integer> edges=graph.get(sv);
	 
	  int ans=0;
	  if(edges.size()==0)
		  return 0;
	  if(dp[sv]!=0)
		  return dp[sv];
	  for(int i=0;i<edges.size();i++)
	  {
		  
		  ans=Math.max(ans,1+longestPath(graph,edges.get(i),dp));
	  }
	  dp[sv]=ans;
	  return ans;
  }
	
  public static void main(String[] args)
  {
     
  Scanner s=new Scanner(System.in);
  int nVert=s.nextInt();
  int nEdges=s.nextInt();
  ArrayList<ArrayList<Integer>> graph=new ArrayList<>();
  for(int i=0;i<=nVert;i++)
  {
	  graph.add(i,new ArrayList<Integer>());
  }
  
  for(int i=1;i<=nEdges;i++)
  {
	  int sVert=s.nextInt();
	  int eVert=s.nextInt();
	
	  graph.get(sVert).add(eVert);
	  
  }
  
int dp[]=new int[nVert+1];
  int ans=Integer.MIN_VALUE;
  for(int i=1;i<=nVert;i++) {
	
  ans=Math.max(ans,longestPath(graph,i,dp));
  }
 System.out.println(ans);
  s.close();
    
  }
}


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

int main() {
  int N, ans=0; cin >> N;
  map<long long, int> A;
  long long a;
  for (int i = 0; i<N; i++) {
    cin >> a;
    A[a]++;
    A[a]%=2;
  }
  for(auto itr = A.begin(); itr != A.end(); itr++) ans += itr->second;
  cout << ans << "\n";
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0041
"""
import sys
from itertools import permutations, product


def make_ten(digits):
    result = '0'
    for a, b, c, d in permutations(digits, 4):
        if result != '0':
            break
        for op1, op2, op3 in product(['+', '-', '*'], repeat=3):
            # 1, 2, 3
            exp = '((({} {} {}) {} {}) {} {})'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 1, 3, 2
            exp= '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 2, 1, 3
            exp = '(({} {} ({} {} {})) {} {})'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 3, 1, 2
            exp = '({} {} (({} {} {}) {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 3, 2, 1
            exp = '({} {} ({} {} ({} {} {})))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
            # 2, 3, 1
            exp =  '(({} {} {}) {} ({} {} {}))'.format(a, op1, b, op2, c, op3, d)
            if eval(exp) == 10:
                result = exp
                break
    return result


# ????????°????????????????????????10?????????????????????????????¢?????°????????§?????????????????????????????°??????????????¨???????????????????????¨??????????´????????????????
Memo = {}
def solve(digits):
    global Memo
    digits.sort(reverse=True)
    data = ''.join(map(str, digits))
    if data in Memo:
        pass
    else:
        Memo[data] = make_ten(digits)
    return Memo[data]


def main(args):
    while True:
        digits = [int(x) for x in input().strip().split(' ')]
        # digits = [int(x) for x in '{:04d}'.format(count)]
        if digits[0] == 0 and digits[1] == 0 and digits[2] == 0 and digits[3] == 0:
            break
        result = solve(digits)
        print(result)
        #print('count={}, {}'.format(count, result))


if __name__ == '__main__':
    main(sys.argv[1:])

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

constexpr int64_t INF = 1e18;

int main() {
    int64_t n, m;
    cin >> n >> m;
    vector<tuple<int64_t, int64_t, int64_t>> abc;
    for (int64_t i = 0; i < m; i++) {
        int64_t a, b, c;
        cin >> a >> b >> c;
        abc.emplace_back(a, b, c);
    }

    vector<int64_t> d(n+1, -INF);
    d[1] = 0;
    for (int64_t i = 0; i < n-1; i++) {
        for (auto& e : abc) {
            int64_t a, b, c;
            tie(a, b, c) = e;
            if (d[a] == -INF) continue;
            if (d[b] < d[a] + c) d[b] = d[a] + c;
        }
    }

    int64_t ans = d[n];
    bitset<1010> cycle;
    for (int64_t i = 0; i < n; i++) {
        for (auto& e : abc) {
            int64_t a, b, c;
            tie(a, b, c) = e;
            if (d[a] == -INF) continue;
            if (d[b] < d[a] + c) d[b] = d[a] + c, cycle[b] = true;
            if (cycle[a]) cycle[b] = true;
        }
    }

    if (cycle[n]) cout << "inf" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 384
import sys
input_list = sys.stdin.readlines() 
N, s = map(str.strip, input_list)
red_hat_counter = 0
for s_str in s:
  if s_str == "R":
    red_hat_counter += 1
if red_hat_counter > (int(N)/2):
  print "Yes"
else:
  print "No"

Measured memory_bytes: 2568
#include<iostream>
#include<string>
using namespace std;
const int maxn = 200010;
//定义链表结构体
struct At {
	char c;		//该位置字符
	At* last;   //上一个节点
	At* next;   //下一个节点
}	c[maxn];
//主函数
int main() {
	//使用cin>>string以方便读入
	string s;
	cin >> s;

	//转存到链表中
	int size = s.size();
	///第一个节点和最后一个节点需要单独处理
	c[0] = { s[0],NULL,&c[1] };						///第一个节点的前一个节点为空
	///遍历中间的size-2个节点
	for (int i = 1; i < size - 1; i++) {
		c[i] = { s[i],&c[i - 1],&c[i + 1] };
	}
	c[size - 1] = { s[size - 1],&c[size - 2],NULL };///最后一个节点的后一个节点为空

	//
	At* now = &c[0];
	while (true) {
		//int update = 0;
		At* i = now;
		for (; i->next != NULL; i = i->next) {
			if (i->c == 'S'&&i->next->c == 'T') {
				if (i->last != NULL) {
					now = i->last;
					now->next = i->next->next;
					if (i->next->next != NULL)
						i->next->next->last = now;
				}
				else {
					now = i->next->next;
					if (i->next->next != NULL)
						i->next->next->last = NULL;
				}
				size -= 2;
				//update = 1;
				break;
			}
		}
		if (size == 0 || i->next == NULL || now == NULL)
			break;
	}
	cout << size << endl;
	return 0;
}


Measured memory_bytes: 5244