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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    map<string, int> m;
    int n, mx = 0;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin >> s;
        m[s]++;
        mx = max(mx, m[s]);
    }
    for(auto& x: m)
    {
        if(x.second == mx) cout << x.first << "\n"; 
    }

    return 0;
}



Measured memory_bytes: 23808
n, l = map(int, input().split())
taste_list = []
for i in range(n):
    taste = l + i
    taste_list.append(taste)
all_sum = sum(taste_list)
#print(taste_list)
div_chk = 10000000000
for j in range(n):
    rem = taste_list[0]
    taste_list.remove(rem)
    chk = sum(taste_list)
    div = abs(all_sum - chk)
    if abs(div) < abs(div_chk):
        div_chk = abs(div)
        ans = chk
    else:
        pass
    #print(taste_list)
    taste_list.append(rem)
    #print(all_sum, chk)
print(ans)

Measured memory_bytes: 38512
//102 B - Maximum Difference 2018.07.01

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n;cin >>n;
    vector<int64> a(n);
    rep(i ,n) cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int ans = 0;
        	int[] line = new int[N];
            for(int i = 0; i < N; i++){
              line[i] = sc.nextInt();
            }
        	for(int i = 1; i < N -1;i++){
              if( line[i-1] < line[i] && line[i] < line[i+1] || line[i+1] < line[i] && line[i] < line[i-1]){
                ans++;
              }
            }
            System.out.println(ans);
              }
}

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

typedef long long ll;
#define MAX_A 394
ll dp[MAX_A];

int main(){
	ll N,M;
	scanf("%lld",&N);

	vector<ll> s(N),l(N),p(N);
	for (int i = 0; i < N; i++) {
		scanf("%lld",&s[i]);
		scanf("%lld",&l[i]);
		scanf("%lld",&p[i]);
	}
	scanf("%lld",&M);
	vector<ll> w(M);
	for (int i = 0; i < M; i++) {
		scanf("%lld",&w[i]);
	}

	for (ll i = 0; i < N; i++) {
		for (ll j = 1; j < MAX_A; j++) {
			for (ll k = max(j-l[i],0LL); k < max(j-s[i]+1,0LL); k++) {
				dp[j] = max(dp[j], dp[k]+p[i]);
			}
		}
	}
	bool flg = false;
	for (int i = 0; i < M; i++) {
		if (dp[w[i]] == 0) flg = true;
	}
	if (flg) {
		printf("-1\n");
	} else {
		for (int i = 0; i < M; i++) {
			printf("%lld\n", dp[w[i]]);
		}
	}

	return 0;
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	register short f=1;x=0;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void writeln(T x){
	write(x),putchar('\n');
}
int f(int a,int b){
	if(a<=b)return b-a;
	return a-b+2;
}
int main(){
	int a,b;
	read(a),read(b);
	writeln(min(f(a,b),min(f(-a,b)+1,min(f(a,-b)+1,f(-a,-b)+2))));
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int h = sc.nextInt(); int w = sc.nextInt();
			if (h == 0 && w == 0) { break; }
			for (int i = 0; i < h; i++) {
				if (i % 2 == 0) {
					for (int j = 0; j < w; j++) {
						if (j % 2 == 0) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
				} else {
					for (int j = 0; j < w; j++) {
						if (j % 2 == 0) {
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}


Measured memory_bytes: 38256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using static Reader;

public static class P
{
    public static void Main()
    {
        string s = Console.ReadLine();
        Console.WriteLine(Min(s.Count(x => x == '0'), s.Count(x => x == '1')) * 2);
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }

    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 13244
input_text = input()

keywords = [ "dream", "dreamer", "erase", "eraser" ]

while True:
  if input_text == "":
      print("YES")
      break
  for keyword in keywords:
    if input_text.endswith(keyword):
      input_text = input_text[:-len(keyword)]
      break
  else:
    print("NO")
    exit(0)


Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  int n,k,i;
  int a[200000];
  int max = -10;

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

  for(i = 0;i < n;i++) scanf("%d", &a[i]);

  for(i = 1;i < n;i++){
    if(max < (a[i] - a[i - 1])) max = a[i] - a[i - 1];
  }

  if((k - a[n - 1] + a[0]) > max) max = k - a[n - 1] + a[0];

  printf("%d\n", k - max);

  return 0;
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

class UnionFind {
    private:
        vector<int> tree;
    public:
        UnionFind(int N);
        int root(int n);
        void link(int n, int m);
        bool is_linking(int n, int m);
};

UnionFind::UnionFind(int N) {
    tree = vector<int>(N);
    for (int i = 0; i < N; i++) {
        tree[i] = i;
    }
}

int UnionFind::root(int n) {
    if (tree[n] == n) return n;
    return tree[n] = root(tree[n]);
}

void UnionFind::link(int n, int m) {
    tree[root(n)] = root(m);
}

bool UnionFind::is_linking(int n, int m) {
    return root(n) == root(m);
}

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    UnionFind train(N), road(N);
    
    int p, q;
    for (int i = 0; i < K; i++) {
        cin >> p >> q;
        road.link(p-1, q-1);
    }

    int r, s;
    for (int i = 0; i < L; i++) {
        cin >> r >> s;
        train.link(r-1, s-1);
    }

    map<pair<int, int>, int> cnt;
    for (int i = 0; i < N; i++) {
        cnt[make_pair(road.root(i), train.root(i))]++;
    }

    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << cnt[make_pair(road.root(i), train.root(i))];
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 13568
#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;
#define _start  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb 		push_back
#define ss 		second
#define ff 		first
#define int     long long
#define ll		long long
#define mk      make_pair
#define ld 		long double
#define vi 		vector<int>
#define pi		pair<int,int>
#define mod 	1000000007
#define pqg     priority_queue<int>
#define pqs     priority_queue<int,vi,greater<int> >
#define forn(p,n) for(int i=p;i<=n;i++)
#define w(t) 	int t; cin>>t; while(t--)
#define kick(t) int t; cin>>t; for(int p=0;p<t;p++)
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> oset;
ll powmod(ll base,ll exp,ll MOD=mod){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}

int check_(string str) 
{ 
    int n = str.length(); 
    int tp = 0; 
    for (int i=0; i<n; i++){ 
        tp += (str[i]-'0'); 
        tp=tp%9;
    }
  
    return (tp % 9 == 0); 
}

int32_t main() {
    _start
    string str;
    cin>>str;
    if(check_(str))
    cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3780
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
//#include <unordered_map>
#include <numeric>
 
using namespace std;
 
const int mod = 1e9 + 7;


int n, m;

int main() {
	cin >> n >> m;
	cout << (n - 1) * (m - 1);
} 

Measured memory_bytes: 256
#import<bits/stdc++.h>
#define LL long long
using namespace std;
typedef struct{int x;int y;}H;
long long a,b,c,d,i,j,k,m=2018,n,s,t,x,y,z,v[100005],w[100005];
int pv[300000];
char h,u[105];
H e[200040];
queue<int>B,D;
int A(H a,H b){return a.x<b.x||a.x==b.x&&a.y<b.y;}
void BP(void);
void bfs(int s);
void dfs(int s);
int dgs(int x){int s=0;for(;x;x/=10)s+=x%10;return s;}
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int max2(int x,int y){return x>y?x:y;}
int max3(int x,int y,int z){return x>y?x>z?x:z:y>z?y:z;}
int min2(int x,int y){return x<y?x:y;}
int min3(int x,int y,int z){return x<y?x<z?x:z:y<z?y:z;}
//int prime(int x){if(x<2||x%6^1&&x%6^5)return x==2|x==3;for(int i=5;i*i<=x;i+=6)if(x%i<1||x%(i+2)<1)return 0;return 1;}
//int vowel(char x){return x%32==1||x%32==5||x%32==9||x%32==15||x%32==21;}
main()
{
	scanf("%lld",&n);for(i=0;i<n;i++)scanf("%lld",w+i);
	for(i=0;++i<n;)a=2*w[i]-a;
	v[0]=(2*w[0]-a)/2;for(i=0;++i<n;)v[i]=2*w[i]-v[i-1];
	for(i=0;i<n;i++)printf("%lld ",v[(i+n-1)%n]);
}
/*
3 8    7   5    5
a 16-a a-2 12-a a-2*/
/*void BP(void)
{
	for(int i=0;e[++i].x;)
	{
		if(e[i].x>e[i-1].x)
		{
			for(int j=e[i-1].x;j++<e[i].x;)
			{
				pv[j]=i;
			}
		}
	}
}
void bfs(int s)
{
	
}
void dfs(int s)
{
	
}*/

Measured memory_bytes: 3584
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  int n, m;
  cin >> n >> m;
  // vector<lint> a;

  lint cnt = 0;
  for (int i = 0; i < m; i++) {
    lint tmp;
    cin >> tmp;
    // a.push_back(tmp);
    cnt += tmp;
  }
  if (n >= cnt)
    cout << n - cnt << endl;
  else
    cout << -1 << endl;
}

Measured memory_bytes: 3620
import numpy as np
# from numba import njit
# from numba.types import int64
i8 = np.int64


# @njit((int64, int64[:,::-1]), cache=True)
def solve(n, qr):
    col = np.zeros(n - 1, i8)
    col[0] = 0
    col_min = n - 1
    row = np.zeros(n - 1, i8)
    row[0] = 0
    row_min = n - 1
    white = 0
    for i in range(qr.shape[0]):
        j = qr[i, 1] - 1
        if qr[i, 0] == 1:
            if j < col_min:
                white += row_min - 1
                for m in range(j + 1, col_min):
                    col[m] = row_min - 1
                col_min = j
            else:
                white += col[j]
        else:
            if j < row_min:
                white += col_min - 1
                for m in range(j + 1, row_min):
                    row[m] = col_min - 1
                row_min = j
            else:
                white += row[j]
    return white


def main():
    f = open(0)
    n, q = [int(x) for x in f.readline().split()]
    qr = np.fromstring(f.read(), i8, sep=' ').reshape((-1, 2))
    white = solve(n, qr)
    print((n - 2) ** 2 - white)

main()

Measured memory_bytes: 33432
from heapq import heappush, heappop, heapify

def main():
    N, M = map(int, input().split())
    A_card = [-int(x) for x in input().split()]

    change_list = []
    for i in range(M):
        B, C = [int(x) for x in input().split()]
        change_list.append(((-1) * C, B))

    hq = []
    for i in range(N):
        heappush(hq, (A_card[i], 1))

    for i in range(M):
        heappush(hq, change_list[i])

    result_sum = 0
    count = 0
    while True:
        if count == N:
            break
        tmp = heappop(hq)
        if count + tmp[1] <= N:
            result_sum += (tmp[0] * tmp[1])
            count += tmp[1]
        else:
            result_sum += (tmp[0] * (N - count))
            break

    print(result_sum * (-1))

if __name__ == "__main__":
    main()


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

int main()
{
    int n;
    cin >> n;
    vector<int> f(n+1);

    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j+=i){
            f[j]++;
        }
    }

    long long int ans = 0;
    for(int i=1; i<=n; i++){
        ans += (long long int)i * f[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 42328
#include <iostream>

using namespace std;

typedef long long ll;

const ll MAX_N = 100000;

int main(int argc, char const *argv[]) {
  ll n, a[MAX_N];
  cin >> n;
  for (ll i = 0; i < n; i++) cin >> a[i];

  ll di = 0, ans=0;

  for (ll i = 1; i < n; i++) {
    if (di==0) {
      di = a[i]-a[i-1];
    }
    else if (di>0) {
      if (a[i]-a[i-1]>=0) continue;
      else {
        ans++;
        di = 0;
      }
    }
    else {
      if (a[i]-a[i-1]<=0) continue;
      else {
        ans++;
        di = 0;
      }
    }
  }
  cout << ++ans << endl;
  return 0;
}


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

using namespace std;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,saida=0;
int vet[MAXN];
int memo[MAXN];

int solve(int stone){
    if(memo[stone]!=-1) return memo[stone];

    if(stone==n) return 0;

    if(stone>n) return INF;


    int pulo1 = abs(vet[stone]-vet[stone+1]) + solve(stone+1);
    int pulo2 = abs(vet[stone]-vet[stone+2]) + solve(stone+2);

    return memo[stone] = min(pulo1,pulo2);

}

int main(){
    cin>>n;
    for (int i=1 ; i<=n ; i++){
        cin>>vet[i];
    }

    memset(memo,-1,sizeof(memo));   
    
    cout<< solve(1) << endl;
}

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


int main(){

    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    int l[Q];
    int r[Q];

    for (int i = 0; i < Q; i++){
        cin >> l[i] >> r[i];
    }

    int AC[N+2];
    int ans[Q+2];

    AC[0] = 0;
    for(int i = 1; i <= N+1; ++i){
        if(S.substr(i-1, 2) == string("AC")){
            AC[i] = AC[i-1] + 1;
            AC[i+1] = AC[i];
            ++i;
        }else{
            AC[i] = AC[i-1];
        }
    }
    
    for(int i = 0; i < Q; ++i){
        ans[i] = AC[r[i]-1] - AC[l[i]-1];
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 2560
n,a,b = (int(i) for i in input().split())
h = [int(input()) for i in range(n)]
def dmg(x):
	num = 0
	for i in h:
		if i>b*x: num+=(i-b*x-1)//(a-b)+1
	return num<=x
hi,lo = 10**9+1,0
while hi-lo!=1:
	mid = (hi+lo)//2
	if dmg(mid): hi=mid
	else: lo=mid
print(hi)

Measured memory_bytes: 7072
#include <stdio.h>

int main()
{
	int N, K;

    int cnt = 0;

	scanf("%d %d", &N, &K);

	int h[N];

	for(int i=0; i<N; i++){
		scanf("%d", &h[i]);
        if(K <= h[i])   cnt++;
	}

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

	return 0;
}

Measured memory_bytes: 512
import heapq

X,Y,Z,K = [int(x) for x in input().split()]
XYZ=[0]*3
for i in range(3):
    XYZ[i]=[int(x)for x in input().split()]
    XYZ[i].sort(reverse=True)


tmp = (-1*(XYZ[0][0]+XYZ[1][0]+XYZ[2][0]),0,0,0)
q = [tmp]
inq = {tmp[1:]}
heapq.heapify(q)

for ik in range(K):
    max = heapq.heappop(q)
    print(-max[0])
    i,j,k = max[1],max[2],max[3]
    #print(-max[0],i,j,k)
    if(not ((i+1,j,k) in inq) and i+1 < X):
        heapq.heappush(q,(-1*(XYZ[0][i+1]+XYZ[1][j]+XYZ[2][k]),i+1,j,k))
        inq.add((i+1,j,k))
    if(not ((i,j+1,k) in inq) and j+1 < Y):
        heapq.heappush(q,(-1*(XYZ[0][i]+XYZ[1][j+1]+XYZ[2][k]),i,j+1,k))
        inq.add((i,j+1,k))
    if(not ((i,j,k+1) in inq) and k+1 < Z):
        heapq.heappush(q,(-1*(XYZ[0][i]+XYZ[1][j]+XYZ[2][k+1]),i,j,k+1))
        inq.add((i,j,k+1))
print()


Measured memory_bytes: 4972
/// referenced: https://beta.atcoder.jp/contests/abc050/submissions/2247425
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
main(){
  int N;
  cin>>N;
  vector<vector<int>>dp(64,vector<int>(3));
  dp[0][0]=1;
  for(int i=0;i<63;++i){
    for(int j=0;j<3;++j){
      for(int a=0;a<2;++a){
        for(int b=a;b<2;++b){
          constexpr int MOD=1e9+7;
          int index=(1+a+b+j-(N>>i&1))>>1;
          dp[i+1][index]+=dp[i][j];
          dp[i+1][index]%=MOD;
        }
      }
    }
  }
  cout<<dp[63][0]<<endl;
}


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

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

  int cnt = 0;

  for(int i = 1; i <= n; i++){
    int dummy;
    cin >> dummy;

    if(i != dummy) cnt++;

  }

  if(cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;

}


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

int FindRainyDays(string& S) {
  int max_length = 0;
  int count = 0;
  for (int i = 0; i < S.length(); ++i) {
    if (S[i] == 'R') {
      count++;
    }
    else {
      max_length = max(max_length, count);
      count = 0;
    }
  }
  max_length = max(max_length, count);
  return max_length;
}

int main() {
  string S;
  cin >> S;
  cout << FindRainyDays(S) << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll po[] = {a, b, c};
    sort(po, po + 3);
    reverse(po, po + 3);
    ll sa = po[0] - po[1], si = po[0] - po[2];
    ll ans = 0;
    po[1] += 2 * (sa / 2 + sa % 2);
    ans += (sa / 2 + sa % 2);
    po[2] += 2 * (si / 2 + si % 2);
    ans += si / 2 + si % 2;
    if(po[0] == po[1] && po[1] == po[2]) cout << ans << endl;
    else if(po[1] == po[2] && po[0] != po[1]) cout << ans - 1 << endl;
    else cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, q := readInt(), readInt()
	nodes := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := readInt(), readInt()
		a--
		b--
		nodes[a] = append(nodes[a], b)
		nodes[b] = append(nodes[b], a)
	}

	answer := make([]int, n)
	for i := 0; i < q; i++ {
		p, x := readInt(), readInt()
		p--
		answer[p] += x
	}

	var dfs func(currentNode, parentNode int)
	dfs = func(currentNode, parentNode int) {
		for _, nextNode := range nodes[currentNode] {
			if nextNode == parentNode {
				continue
			}
			answer[nextNode] += answer[currentNode]
			dfs(nextNode, currentNode)
		}
	}
	dfs(0, -1)

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", answer[i])
	}
}


Measured memory_bytes: 75904
class Dice
  def initialize(a,b,c,d,e,f)
    @top   = a
    @down  = b
    @right = c
    @left  = d
    @up    = e
    @back  = f
  end
  attr_accessor :top,:down,:right,:left,:up,:back
  def move(dice,m)
    top=@top
    down=@down
    right=@right
    left=@left
    up=@up
    back=@back

    if m=="S"
      @top=  up
      @down= top
      @right=right
      @left= left
      @up=   back
      @back= down
    elsif m=="W"
      @top=  right
      @down= down
      @right=back
      @left= top
      @up=   up
      @back= left
    elsif m=="N"
      @top=  down
      @down= back
      @right=right
      @left= left
      @up=   top
      @back= up
    elsif m=="E"
      @top=  left
      @down= down
      @right=top
      @left= back
      @up=   up
      @back= right
    end
  end
  def printDice
#    puts "top:#{@top}  down:#{@down}  right:#{@right}  lefr:#{@left} up:#{@up} back:#{@back}"
     puts @right
  end
end

a,b,c,d,e,f=gets.split.map(&:to_i)
dice=Dice.new(a,b,c,d,e,f)
n=gets.to_i
n.times do |i|
  l,m = gets.split.map(&:to_i)
    loop do
      random = Random.new
      ran=random.rand(1..4)
      if ran == 1
        dice.move(dice,"W")
      elsif ran==2
        dice.move(dice,"S")
      elsif ran==3
        dice.move(dice,"E")
      elsif ran==4
        dice.move(dice,"N")
      end
      break if dice.top==l  && dice.down==m
    end
  dice.printDice()
end



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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+')
        cout << a + b << endl;
    else
        cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 3496
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 29)
#define INFL (1LL << 61)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

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

int h, w;
char s[20][20];
int f[400][400];

void print() {
    for (int i = 0; i < h * w; ++i) {
        for (int j = 0; j < h * w; ++j) {
            if (f[i][j] == INF) {
                printf("-");
            }
            else {
                printf("%d", f[i][j]);
            }
        }
        cout << endl;
    }
    cout << endl;
}

int main() {
    cin >> h >> w;
    char c;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> s[i][j];
        }
    }

    fill(f[0], f[400], INF);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#')
                continue;
            f[i * w + j][i * w + j] = 0;
            for (int k = 0; k < 4; ++k) {
                int ny = i + dy[k];
                int nx = j + dx[k];
                if (ny < 0 || nx < 0 || ny >= h || nx >= w || s[ny][nx] == '#')
                    continue;
                f[i * w + j][ny * w + nx] = 1;
            }
        }
    }
    // print();

    for (int k = 0; k < h * w; ++k) {
        for (int i = 0; i < h * w; ++i) {
            for (int j = 0; j < h * w; ++j) {
                f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
            }
        }
    }
    // print();

    int ans = 0;
    for (int i = 0; i < h * w; ++i) {
        for (int j = 0; j < h * w; ++j) {
            if (f[i][j] < INF)
                ans = max(ans, f[i][j]);
        }
    }
    cout << ans << endl;

    return 0;
}

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



public class Main {
	public static void main(String[] args)  {
		// 入力
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] xList = new int[n];

		for (int i = 0; i < n; i++) {
			xList[i] = scanner.nextInt();
		}
		int[] copyList = xList.clone();
		Arrays.sort(xList);
		int point = (n+1)/2 -1;
		int targetA = xList[point];
		int targetB = xList[point + 1];
		
		for (int element : copyList) {
			if (element <= targetA) {
				System.out.println(targetB);
			} else {
				System.out.println(targetA);
			}
		}

	}
}

Measured memory_bytes: 85724
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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()
{
  INT(A);
  INT(B);
  cout << 100 << " " << 100 << endl;
  vector<vector<int>> ans(100,vector<int>(100,0));
  REP2(i,50,99){
    REP(j,100){
      ans[i][j]=1;
    }
  }

  int cnt=0;
  int flag=0;
  REP(i,49){
    REP(j,100){
      if(cnt==B-1){
        flag=1;
        break;
      }
      if(i%2==0&&j%2==0){
        ans[i][j]=1;
        cnt++;
      }
    }
    if(flag==1){
      break;
    }
  }
  
  cnt=0;
  flag=0;
  REP2(i,51,100){
    REP(j,100){
      if(cnt==A-1){
        flag=1;
        break;
      }
      if(i%2==1&&j%2==0){
        ans[i][j]=0;
        cnt++;
      }
    }
    if(flag==1){
      break;
    }
  }

  REP(i,100){
    REP(j,100){
      if(ans[i][j]==0){
        cout << ".";
      }else{
        cout << "#";
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3680
n,k,c = map(int,input().split())
s = input()
frt = [0]*n
bck = [0]*n
cnt = 0
cntb = 0
prv = 0
prvb = 0
st = set()
stb = set()
for i in range(n):
  if cnt == 0 and s[i] == "o":
    cnt += 1
    frt[i] = 1
    prv = i
    st.add(i)
  elif i-prv > c and s[i] == "o":
    cnt += 1
    frt[i] = cnt
    prv = i
    st.add(i)
for i in range(n)[::-1]:
  if cntb == 0 and s[i] == "o":
    cntb += 1
    bck[i] = 1
    prvb = i
    stb.add(i)
  elif prvb-i > c and s[i] == "o":
    cntb += 1
    bck[i] = cntb
    prvb = i
    stb.add(i)
ans = []
for i in range(n):
  if i not in st or i not in stb:
    continue
  if frt[i]-1 + bck[i]-1 >= k:
    continue
  print(i+1)

Measured memory_bytes: 69076
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 100000
using namespace std;
int n,m;
int par[MAX+1];

struct Pox
{
  int from,to,cost;
  Pox(int from = -1,int to = -1,int cost = -1):from(from),to(to),cost(cost){}
};

vector<Pox> G;

bool cmp(const Pox& p1,const Pox& p2){ return p1.cost < p2.cost; }

void init(){ rep(i,MAX)par[i] = i; }

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

void unit(int x,int y)
{
  x = find(x);
  y = find(y);
  if(x != y) par[x] = y;
}

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

int kruskal(int st)
{
  init();
  int mex = -(1<<29);
  int gsize = G.size();
  int cnt = 0;
  REP(i,st,gsize)
    {
      Pox pox = G[i];
      if(!same(pox.from,pox.to))
	{
	  cnt++;
	  assert(0 <= pox.from && pox.from < MAX);
	  assert(0 <= pox.to   && pox.to   < MAX);
	  unit(pox.from,pox.to);
	  mex = max(mex,pox.cost);
	}
    }
  if(cnt != n-1)return (1<<29);
  return mex-G[st].cost;
}


int main()
{
  while(cin >> n >> m,n|m)
    {
      G.clear();
      if(true)
	{
	  int a,b,w;
	  rep(i,m)
	    {
	      cin >> a >> b >> w;
	      a--,b--;
	      G.push_back(Pox(a,b,w));
	      //G.push_back(Pox(b,a,w));
	    }
	}
      int ans = (1<<29);
      sort(G.begin(),G.end(),cmp);
      rep(i,m){ ans = min(ans,kruskal(i)); }
      cout << (ans == (1<<29)?-1:ans) << endl;
    }
  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod (1000000007)
//#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
//#define MCONS 2001
//#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl
int dx[]{0, 1, 0, -1};
int dy[]{1, 0, -1, 0};

const int NCONS = 100001;
//const int MCONS = 101;

int32_t main()
{
    MAGIC;
    int n; string str; cin >> n >> str;
    if(n % 2) { cout << "No"; return 0; }
    
    for(int i = 0; i < n / 2; i++)
    {
        if(str[i] != str[i + n / 2])
        {
            cout << "No"; return 0;
        }
    }
    
    cout << "Yes";
    return 0;
}



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

int func(int n){
    int s = 0;
    while(n){
      n /= 10;
      s++;
    }
    return s;
  }
 
int main(){
  long long n, k;
  cin >> n;
  for ( int i = 1; i <= sqrt(n); i++) if( n % i == 0) k = n / i;
  cout << func(k);
}
  

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
xy = [LIST() for _ in range(N)]
X = sorted([x[0] for x in xy])
Y = sorted([x[1] for x in xy])

ans = INF
for p in combinations(X, 2):
	x_min = p[0]
	x_max = p[1]
	for q in combinations(Y, 2):
		y_min = q[0]
		y_max = q[1]
		
		cnt = 0
		for x, y in xy:
			if x_min <= x <= x_max and y_min <= y <= y_max:
				cnt += 1
		if cnt >= K:
			ans = min(ans, (x_max-x_min)*(y_max-y_min))
print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

V p, q, r;

void solve_abc_e() {
	ll x, y, a, b, c;
	ll ans = 0;

	cin >> x >> y >> a >> b >> c;
	p = V(a);
	q = V(b);
	r = V(c);
	rep(i, a) {
		cin >> p[i];
	}
	rep(i, b) {
		cin >> q[i];
	}
	rep(i, c) {
		cin >> r[i];
	}

	sort(RALL(p));
	sort(RALL(q));
	sort(RALL(r));

	ll nowX = x - 1, nowY = y - 1;
	ll n = min((ll)r.size(), x + y);
	rep(i, n) {
		if (nowX >= 0 && nowY >= 0) {
			if (r[i] > p[nowX] || r[i] > q[nowY]) {
				if (p[nowX] < q[nowY]) {
					p[nowX] = r[i];
					nowX--;
				}
				else {
					q[nowY] = r[i];
					nowY--;
				}
			}
		}
		else if (nowX >= 0) {
			if (r[i] > p[nowX]) {
				p[nowX] = r[i];
				nowX--;
			}
		}
		else if (nowY >= 0) {
			if (r[i] > q[nowY]) {
				q[nowY] = r[i];
				nowY--;
			}
		}
	}

	rep(i, x) {
		ans += p[i];
	}

	rep(i, y) {
		ans += q[i];
	}

	cout << ans << "\n";
}

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

	solve_abc_e();

	return 0;
}

Measured memory_bytes: 2560
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug puts("orzyrt")
	#define debug(a...) fprintf(stderr,a);
#else
	#define Debug ('orzyrt')
	#define debug(a...) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(a>b)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

int n;
int a[11111];
LL ans=0;
int main(){
	read(n);
	for(R int i=1;i<=n;++i)read(a[i]);
	for(R int i=1;i<=n;++i){
		while(!(a[i]&1)){
			a[i]>>=1;
			ans++;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 892
N,M=gets.split.map &:to_i
S=M.times.map{|i|gets.split.map(&:to_i)[1..-1]}
P=gets.split.map(&:to_i)

p (2**N).times.map.inject(0){|res, b|
  p=Array.new(M){0}
  M.times do |i|
    S[i].each do |s|
      p[i] ^= 1 unless b[s-1].zero?
    end
  end
  res + (p==P ? 1 : 0)
}

Measured memory_bytes: 1916
#include<cstdio>
#include<algorithm>
using namespace std;

int n,q;
int c[300100],x;

int main(){
  scanf("%d%d",&n,&q);
  int lim = 0;
  for(int i=0;i<n;i++){ scanf("%d",&c[i]); lim = max(lim,c[i]); }
  sort(c,c+n);
  int m[600] = {0};
  for(int i=1;i<=600;i++){
    for(int j=0;j<n;j++)m[i] = max(m[i],c[j]%i);
  }

  for(int i=0;i<q;i++){
    scanf("%d",&x);
    if(x<=600)printf("%d\n",m[x]);
    else{
      int res = 0;
      for(int j=1;j*x<=lim;j++){
	int tmp = lower_bound(c,c+n,j*x) - c;
	if(tmp)res = max(res,c[tmp-1]%x);
      }
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 2212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
操作の逆順を考える
Codeforcesではscanfを使う
 */
struct edge{int to,cost;};
int V;
vector<edge> G[300030];
int d[300030];
void dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+V,mod);
    d[s]=0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p=que.top();
        que.pop();
        int v=p.S;
        if(d[v]<p.F)continue;
        rep(i,sz(G[v])){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
}
int main() {
    int n,m;
    cin >> n >> m;
    V=3*n;
    rep(i,m){
        int u,v;
        cin >> u >> v;
        G[u-1].pb({v+n-1,1});
        G[u+n-1].pb({v+2*n-1,1});
        G[u+2*n-1].pb({v-1,1});
    }
    int s,t;
    cin >> s >> t;
    dijkstra(s-1);
    if(d[t-1]!=mod)cout << d[t-1]/3;
    else cout << -1;
    


}

/*



 */



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

int main() {
  string s;
  cin >> s;
  if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S') cout << 0 << endl;
  if (s[0] == 'S' && s[1] == 'S' && s[2] == 'R') cout << 1 << endl;
  if (s[0] == 'S' && s[1] == 'R' && s[2] == 'S') cout << 1 << endl;
  if (s[0] == 'S' && s[1] == 'R' && s[2] == 'R') cout << 2 << endl;
  if (s[0] == 'R' && s[1] == 'S' && s[2] == 'S') cout << 1 << endl;
  if (s[0] == 'R' && s[1] == 'S' && s[2] == 'R') cout << 1 << endl;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'S') cout << 2 << endl;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
  
  return 0;
}

Measured memory_bytes: 3620
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in map(int,input().split()):
  for idx,j in enumerate(reversed('{:b}'.format(i))):
    if j == "1":
      d[idx]+=1

m = max( set(d.keys())|set([0]))
print(int(sum([((2**i)* (N-d[i])*d[i])%(1e9+7) for i in range(m+1)])%(1e9+7)))

Measured memory_bytes: 122808
#include <cstdio>  
#include <algorithm>  
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define maxn (int)1e5+500
int main()
{
	int n, x;
	while (~scanf("%d%d", &n, &x))
	{
		n %= 500;
		if (n <= x)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from copy import deepcopy

# 入力
N, M, Q = map(int, input().split())
a, b, c, d = [], [], [], []
for _ in range(Q):
    a_, b_, c_, d_ = map(int, input().split())
    a.append(a_ - 1)
    b.append(b_ - 1)
    c.append(c_)
    d.append(d_)

# 変数定義
max_sum_d = 0

def judgeA(A):
    global max_sum_d
    sum_d = 0
    for a_, b_, c_, d_ in zip(a, b, c, d):
        if A[b_] - A[a_] == c_:
            sum_d += d_
    max_sum_d = max(sum_d, max_sum_d)

# 関数定義
def dfsA(A, left):
    for i in range(left, M + 1):
        A_ = deepcopy(A)
        A_.append(i)
        if len(A_) == N:
            judgeA(A_)
        else:
            dfsA(A_, i)

# 実行
dfsA([], 1)
print(max_sum_d)


Measured memory_bytes: 9208
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111



int main(void) {
  cin >> s;
  FOR(i, 0, s.length()) {
	if (s[i] == 'S') {
	  cnt++;
	}
	else {
	  if (cnt) {
		cnt--;
		ans++;
	  }
	}
  }
  cout << s.length() - 2 * ans << endl;

  return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

const ll INF = (1ll << 60);
vector<ll> a(200010);
vector<vector<ll>> graph(200010);
vector<ll> dp(200010, INF);
vector<ll> ans(200010);

void dfs(ll now, ll pre)
{
    ll num = a.at(now);
    ll ind = lower_bound(all(dp), num) - dp.begin();
    ll mae = dp.at(ind);
    dp.at(ind) = num;
    ll tmp = lower_bound(all(dp), INF) - dp.begin();
    ans.at(now) = tmp;
    ll i;
    for(i = 0;i < graph.at(now).size();++i){
        ll next = graph.at(now).at(i);
        if(next != pre){
            dfs(next, now);
        }
    }
    dp.at(ind) = mae;
    return;
}

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    rep(i,n) cin >> a.at(i);
    rep(i,n-1){
        ll u,v;
        cin >> u >> v;
        --u,    --v;
        graph.at(u).push_back(v);
        graph.at(v).push_back(u);
    }
    dfs(0, -1);
    rep(i,n) cout << ans.at(i) << endl;

    return 0;
}

Measured memory_bytes: 33244
program r20718j
 
implicit none
integer :: ac, wa, tle, re, n, i
character(len=3) :: a
 
ac = 0
wa = 0
tle = 0
re = 0
 
read *, n
 
do i = 1, n
 
 read *, a
 
 if (trim(a) == 'AC') then
  ac = ac + 1
 else if (trim(a) == 'WA') then
  wa = wa + 1
 else if (trim(a) == 'TLE') then
  tle = tle + 1
 else
  re = re + 1
 end if
end do
 
print *, 'AC x ', ac
print *, 'WA x ', wa
print *, 'TLE x ', tle
print *, 'RE x ', re
 
end program r20718j

Measured memory_bytes: 2868
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

int main(void){
   int n;
   cin >> n;
   vector<ll> h(n);
   for (int i = 0; i < n;i++)
      cin >> h.at(i);

   ll low = h.at(0);
   for (int i = 1; i < n;i++){
      low = max(low, h.at(i) - 1);
      if (low > h.at(i)){
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
   return 0;
}

Measured memory_bytes: 1024
num = int(input())
result = ""
for i in range(1, num + 1):
    if i % 3 == 0:
        result += " " + str(i)
    else:
        j = i 
        while(j):
            if j % 10 ==3:
                result += " " + str(i)
                break
            else:
                j  = j // 10
            
print(result)
        

Measured memory_bytes: 7676
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define INF 100000000

int calc(int a,int b);

int main(){
  int a;
  cin >> a;
  vint A(a);
  int sum = 0;
  int key = 0;
  rep(i,a) cin >> A[i];
  rep(i,a){
    if(i == 0){
      sum = A[i];
      key = A[i];
    }
    else{
      if(A[i] >= A[i-1]){
        sum += A[i] - key;
        key = A[i];
      }
      else key = A[i];
    }
  }
  cout << sum << endl;
}  

Measured memory_bytes: 256
o=998244353
r=2500100
f=[1]
for i in range(1,r):f.append(f[-1]*i%o)
def c(n,k):return f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)%o
n,m=map(int,input().split())
w=3*m
a=(c(n+w-1,n-1)-n*c(n+m-2,n-1))%o
if n>m+1:
 for i in range(m+1,min(w,n)+1):
  if w-i&1:continue
  a=(a-c(n,i)*c((w-i)//2+n-1,n-1))%o
print(a)

Measured memory_bytes: 107144
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

# 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える

K = max(A) # 最も大きい数が0になるまでループ
ans = 0
j = 0
while K:
  one = 0
  for i in range(len(A)):
    if (A[i] >> j) & 1:
      one += 1
  ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV)
  ans %= DIV
  j += 1
  K >>= 1
  
print(ans)

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

#define NINF -1
#define PINF 1E9

short n;
int totalW,*w,*v;
long *dp; // value

int pos(int i,int j)
{
	return i*(totalW+1)+j;
}

void chMax(long *a,long b)
{
	if (*a<b) *a = b;
	return;
}

int main(void)
{
	int i,j;
	long max;
	scanf("%hd %d",&n,&totalW);
	w = (int *)malloc(sizeof(int) * n);
	v = (int *)malloc(sizeof(int) * n);
	for (i=0;i<n;i++) {
		scanf("%d %d",&w[i],&v[i]);
	}

	dp = (long *)malloc(sizeof(long) * (n+1)*(totalW+1));
	if (dp==NULL) {
		perror("malloc");
		exit(1);
	}
	dp[0] = 0;
	for (i=1;i<(n+1)*(totalW+1);i++) {
		dp[i] = NINF;
	}

	for (i=1;i<=n;i++) {
		for (j=0;j<totalW+1;j++) {
			dp[pos(i,j)] = dp[pos(i-1,j)];
		}

		for (j=w[i-1];j<totalW+1;j++) {
			if (dp[pos(i-1,j-w[i-1])]==NINF) continue;

			chMax(&dp[pos(i,j)] , dp[pos(i-1,j-w[i-1])] + v[i-1]);
		}

	}

	max = NINF;
	for (i=0;i<totalW+1;i++) {
		if (max < dp[pos(n,i)]) max = dp[pos(n,i)];
	}
	printf("%ld\n",max);

	free(w);
	free(v);
	free(dp);
	return 0;
}


Measured memory_bytes: 79104
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def main():
    import queue
    N, M, K = read_values()

    friend = [set() for _ in range(N)]
    friend_num = [0] * N
    for _ in range(M):
        a, b = read_values()
        a -= 1
        b -= 1
        friend[a].add(b)
        friend[b].add(a)
        friend_num[a] += 1
        friend_num[b] += 1

    
    block = [set() for _ in range(N)]
    for _ in range(K):
        a, b = read_values()
        a -= 1
        b -= 1
        block[a].add(b)
        block[b].add(a)

    already = [False] * N
    C = [0] * N
    for i in range(N):
        if already[i]:
            continue
        s = {i}
        q = queue.Queue()
        already[i] = True
        q.put(i)
        while not q.empty():
            k = q.get()
            out = friend[k]
            for l in out:
                if already[l]:
                    continue
                s.add(l)
                q.put(l)
                already[l] = True
        c = len(s)
        for j in s:
            if c > len(block[j]):
                C[j] = c - len([p for p in block[j] if p in s])
            else:
                C[j] = len(s.difference(block[j]))
    res = [str(C[i] - friend_num[i] - 1) for i in range(N)]
    print(" ".join(res))


if __name__ == "__main__":
    main()

Measured memory_bytes: 124316
s = input()
N = int(input())

for i in range(N):
    o = [x for x in input().split()]

    a = int(o[1])
    b = int(o[2]) + 1

    if o[0] == "print":
        print(s[a:b])
    if o[0] == "replace":
        s = s[:a] + o[3] + s[b:]
    if o[0] == "reverse":
        tmp = s[a:b]
        s = s[:a] + tmp[::-1] + s[b:]


Measured memory_bytes: 5624
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print('ABC' if n < 1200 else 'ARC')

if __name__ == '__main__':
    main()


Measured memory_bytes: 77180