akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let cs = read_vec2::<i32>(3);

    for i in 1..3 {
        let a1 = cs[i][2] - cs[i - 1][2];
        let a2 = cs[i][1] - cs[i - 1][1];
        let a3 = cs[i][0] - cs[i - 1][0];
        if a1 != a2 || a2 != a3 {
            yn(false);
            return;
        }

        let b1 = cs[2][i] - cs[2][i - 1];
        let b2 = cs[1][i] - cs[1][i - 1];
        let b3 = cs[0][i] - cs[0][i - 1];
        if b1 != b2 || b2 != b3 {
            yn(false);
            return;
        }
    }
    yn(true);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
while(1){
	int r,c,a[12][10002],ret=0,par[10];
	scanf("%d%d",&r,&c);
	if(r==0&&c==0)break;
	for(int i=0;i<r;i++)for(int j=0;j<c;j++)scanf("%d",&a[i][j]);
	for(int i=0;i<1024;i++){
		int x=i,ans=0;
		for(int j=0;j<10;j++){par[j]=x%2; x/=2;}
		for(int j=0;j<c;j++){
			int sum=0;
			for(int k=0;k<r;k++){
				if((a[k][j]+par[k])%2==0)sum++;
			}
			ans+=max(sum,r-sum);
		}
		if(ret<ans)ret=ans;
	}
	printf("%d\n",ret);
}
}

Measured memory_bytes: 1568
from collections import Counter

n = int(input())
v = list(map(int,input().split()))

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

if len(set(v)) == 1:
    ans = n // 2
elif len(set(v_even)) == 1:
    if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
        ans = (n // 2) - c_odd.most_common()[1][1]
    else:
        ans = (n // 2) - c_odd.most_common()[0][1]
elif len(set(v_odd)) == 1:
    if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
        ans = (n // 2) - c_even.most_common()[1][1]
    else:
        ans = (n // 2) - c_even.most_common()[0][1]
else:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = n - c_even.most_common()[0][1] - c_odd.most_common()[0][1]
    else:
        ans = n - c_even.most_common()[0][1] \
              - max(c_even.most_common()[1][1],c_odd.most_common()[1][1])

print(ans)


Measured memory_bytes: 23264
/*input
9999 10
540 7550
691 9680
700 9790
510 7150
415 5818
551 7712
587 8227
619 8671
588 8228
176 2461

*/
#include<bits/stdc++.h>
#define ull         unsigned long long
#define ll             long long
#define M             1000000007
#define pb             push_back
#define p_q         priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()    
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp             make_pair
#define lb             lower_bound
#define ub            upper_bound
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)    for(ll int i=0;i<n;i++) a[i]=0;
#define F            first
#define S            second
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

bool DEBUG = 0;

void solve()
{
    //initialize();
    ll h,n;cin>>h>>n;
    vi a(n),b(n);rep(i,0,n)cin>>a[i]>>b[i];
    ll maxi = 0;
    rep(i,0,n)maxi = max(maxi , a[i]);
    vi dp(h+maxi+1 , INT_MAX);
    dp[0] = 0;
    rep(i,1,h+maxi+1)
    {
        rep(j,0,n)
        {
            if (a[j] >= i)
                dp[i] = min(dp[i] , b[j]);
            else
                dp[i] = min(dp[i] , dp[i-a[j]] + b[j]);
        }
    }
    ll ans = INT_MAX;
    rep(i,h,h+maxi+1)
        ans= min(ans , dp[i]);
    cout<<ans<<"\n";
}


int main(void)
{
    ios
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

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

typedef long long ll;

ll A,B,C;
ll ans = 0;
ll fi = 0,se = 0;

int main()
{
   scanf("%lld%lld",&A,&B);
   if(A == B)
   {
       printf("1\n");
       return 0;
    }
   //ans = B - A - 1;
   C = A ^ B;
   for(int i = 60; i >= 0; i--)
   {
       //if(se != 0)break;
       if(C >> i & 1)
       {
            fi = i;
            A &= (1LL << fi + 1) - 1LL;
            B &= (1LL << fi + 1) - 1LL;
            break;
        }
    }

    C = B - (1LL << fi);

    while((1LL << se) <= C)se++;

    ans = ((1LL << fi) - A);
    ans += (1LL << fi);
    if(A > (1LL << se)) {ans -= (A - (1LL << se));}
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
string s;
vector<int>ans;
int D[10][10]={
	{0,0,0,0,0,0,0,0,0,0},
	{0,0,1,2,1,2,3,2,3,4},
	{0,1,0,1,2,1,2,3,2,3},
	{0,2,1,0,3,2,1,4,3,2},
	{0,1,2,3,0,1,2,1,2,3},
	{0,2,1,2,1,0,1,2,1,2},
	{0,3,2,1,2,1,0,3,2,1},
	{0,2,3,4,1,2,3,0,1,2},
	{0,3,2,3,2,1,2,1,0,1},
	{0,4,3,2,3,2,1,2,1,0}
};
main()
{
	cin>>n>>s;
	int c[10][10]={};
	for(int i=1;i<n;i++)c[s[i-1]-'0'][s[i]-'0']++;
	vector<int>now;
	for(int i=1;i<=9;i++)
	{
		now.push_back(i);
	}
	int ansm=1e9;
	int cnt=0;
	do{
		int nowm=0;
		for(int i=1;i<=9;i++)for(int j=1;j<=9;j++)
		{
			nowm+=c[now[i-1]][now[j-1]]*D[i][j];
		}
		if(ansm>nowm)
		{
			ansm=nowm;
			ans=now;
		}
		else if(ansm==nowm&&ans>now)
		{
			ans=now;
		}
		cnt++;
	}while(next_permutation(now.begin(),now.end()));
	for(int i=0;i<9;i++)
	{
		cout<<ans[i];
		if(i%3==2)cout<<endl;
	}
}



Measured memory_bytes: 3316
#include<bits/stdc++.h>
const static int INF = 1001001003;

std::vector<int> a;

int getTrackNum(int mid){
    int track_num, cnt, cur;
    cnt = 1;
    cur = 0;
    for(int i = 0; i < a.size(); i++){
	if(mid < a[i]){
	    return INF;
	}
	else if(cur + a[i] <= mid){
	    cur += a[i];
	}else{
	    cnt++;
	    cur = a[i];
	}
    }
    return cnt;
}

int main(void){
    int left, right, mid, track_num, n, k, ans;
    std::cin >> n >> k;
    a.resize(n);
    for(int i = 0; i < n; i++){
	std::cin >> a[i];
    }

    left = 0;
    right = 1001001002;
    while(left < right){
	mid = (left + right) / 2;
	track_num = getTrackNum(mid);
	if(track_num <= k){
	    right = mid;
	}else{
	    left = mid + 1;
	}
	
    }

    std::cout << right << std::endl;

    return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(void) {
	int n;
	double sum;

	sum = 100000;

	cin >> n;

	for (int i; i < n; i++){
		sum = ceil((sum * 1.05)/1000) * 1000;
	}

	cout << (int)sum << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int left = a[n-1];
    a.pop_back();

    int half= left/2;
    if(left%2==1){half=(1+left)/2;}
    int right = 0;
    int dist=INF32;
    for(int i = 0; i < n; ++i){
          int tmp = abs(half-a[i]);
          if(dist>tmp){
               dist=tmp;
               right=a[i];
          } 
    }

    cout << left << " " << right << endl;

    return ;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  double R;
  cin>>R;
  cout<<fixed<<setprecision(10)<<R*2*3.141592<<endl;
  return 0;
}


Measured memory_bytes: 3792
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")


MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))


s = []
for i in range(1,7):
	s.append(9**i)
	s.append(6**i)
n , = I()
a = [0]*100009
for i in range(1,100007):
	a[i] = a[i-1] + 1
	for j in s:
		if i - j >= 0:
			# print('hi',end='')
			# print(a[i-j]+1,i,a[i])
			a[i] = min(a[i - j] + 1,a[i])
print(a[n])

Measured memory_bytes: 3828
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
        int i=0;
        while(true){
          int x=sc.nextInt();
          if(x==0)
          break;
          i++;
            System.out.println("Case "+i+": "+x);
        }
    }
}


Measured memory_bytes: 42548
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;

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

int h, w;
vector<vector<bool>> used(400, vector<bool>(400));
ll black = 0, white = 0;

void dfs(int x, int y, vector<string> &s) {
  if (used[x][y]) return;
  used[x][y] = true;
  if (s[x][y] == '.') white++;
  else black++;

  char cur = s[x][y];
  rep(i, 4) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (0 <= nx && nx < h && 0 <= ny && ny < w) {
      char next = s[nx][ny];
      if (next != cur) {
        dfs(nx, ny, s);
      }
    }
  }
}

int main() {
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  ll ans = 0;
  rep(i, h) rep(j, w) {
    black = white = 0;
    dfs(i, j, s);
    ans += black * white;
  }

  cout << ans << endl;
}

Measured memory_bytes: 18048
N, M = map(int, input().split())
a = [N]*M

for i in range(N):
    A = list(map(int, input().split()))[1:]

    for j in A:
        a[j-1] -= 1


count = 0
for i in a:
    if i == 0:
        count += 1

print(count)

Measured memory_bytes: 3060
a,b = [int(i) for i in input().split()]

l =sorted([[int(i) for i in input().split()] for _ in range(a)],key = lambda x : x[0])

flg = True
for i in l:
    if i[1] <= b:
        print(i[0])
        flg = False
        break
    else:
        pass
    
if flg == True:
    print('TLE')

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 200005;
int n, ans;
int a[N], b[N];
int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}
	sort(b+1,b+1+n);
	for(int i = 1;i <= n;i++){
		a[i] = lower_bound(b+1, b+1+n,a[i])-b;
	}
	for(int i = 1;i <= n;i++){
		if((a[i]%2) != (i%2)) ans++;
	}
	printf("%d\n",ans >> 1);
	return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        long totalTime=scan.nextLong();
        long n=scan.nextLong();
        for (long i = 0; i <n ; i++) {
            totalTime-=scan.nextLong();
        }
        System.out.println(Math.max(totalTime,-1));
    }
}


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

struct edge {int from,to,cost;};

edge es[5100];
int d[2600];
int n,m,inf = 1000000007;
bool negative = false;
bool used[2600];

void bellmanford(int s){
  for(int i = 0;i < n;i++){
    d[i] = inf;
  }
  d[s] = 0;
  for(int j = 0;j < n;j++){
    bool update = false;
    for(int i = 0;i < m;i++){
      edge e = es[i];
      if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        update = true;
        if(j == n-1){
          negative = true;
        }
      }
    }
    if(!update) break;
  }
  return;
}

void dfs(int c){
  used[c] = true;
  for(int i = 0;i < m;i++){
    if(es[i].from == c && used[es[i].to] != true){
      dfs(es[i].to);
    }
  }
  return;
}

void dfs2(int c){
  used[c] = true;
  //cout << c << endl;
  for(int i = 0;i < m;i++){
    if(es[i].to == c && used[es[i].from] != true){
      dfs2(es[i].from);
    }
  }
  return;
}


int main(){
  int p;
  cin >> n >> m >> p;
  for(int i = 0;i < m;i++){
    cin >> es[i].from >> es[i].to >> es[i].cost;
    es[i].from--;es[i].to--;
    es[i].cost -= p;
    es[i].cost *= -1;
  }
  for(int i = 0;i < n;i++){
    used[i] = false;
  }
  dfs(0);
  for(int i = 0;i < m;i++){
    for(int j = 0;j < n;j++){
      if(used[es[i].from] == false || used[es[i].to] == false){
        es[i].cost = 2*inf;
      }
    }
  }
  for(int i = 0;i < n;i++){
    used[i] = false;
  }
  dfs2(n-1);
  for(int i = 0;i < n;i++){
    //cout << used[i] << ' ' << i << endl;
  }
  for(int i = 0;i < m;i++){
    for(int j = 0;j < n;j++){
      if(used[es[i].from] == false || used[es[i].to] == false){
        es[i].cost = 2*inf;
        //cout << i << endl;
      }
    }
  }
  bellmanford(0);
  if(negative == true){
    cout << -1 << endl;
  }
  else{
    cout << max(-d[n-1],0) << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr ll MOD = (ll)1e9 + 7;
constexpr ll MOD2 = 998244353;
constexpr ll HIGHINF = (ll)1e18;
constexpr ll LOWINF = (ll)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	string S; cin >> S;
	V<int> cnt(26,0);
	cnt[S[0]-'A']++;
	cnt[S[1]-'A']++;
	cnt[S[2]-'A']++;
	cnt[S[3]-'A']++;

	for(int i = 0; i < 26; ++i){
		if(cnt[i]==0) continue;
		if(cnt[i]==2) continue;
		corner(1,"No");
	}
	cout << "Yes" << endl; 

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (ll i = 0, i ## _end = n; i < i ## _end; i++)

int main() {

    ll n, t, e; cin >> n >> t >> e;
    vector<ll> x(n);
    REP(i, n) cin >> x[i];

    REP(i, n) {
        for (ll xl = 0; xl <= t+e; xl += x[i]) {
            if (t-e <= xl && xl <= t+e) {
                cout << -~i << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;

    rep(i, N) {
        int a;
        cin >> a;
        if (a % 2) {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

ll a[200010];

int main() {
    int n;cin>>n;
    rep(i,n) cin>>a[i];
    ll cnt=0,sum=0;
    int r=0;
    rep(l,n){
        while(r<n&&(sum+a[r]==(sum^a[r]))) {
            sum+=a[r];
            r++;
        }
        cnt+=r-l;
        if(l==r) r++;
        else sum-=a[l];
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 5152
#include<iostream>
#include<cmath>

using namespace std;

#define int long long

signed main(){
    int n; cin >> n; int ans = 0;
    for (int a = 1; a < n; a++){
        if (n % a == 0){
            ans += (n/a); ans--;
        }
        else {
            ans += ((double)(n)/(double)(a));
        }
    }
    cout << ans;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<limits.h>

int A[500000];
int L[10000000];
int R[10000000];
int count;

void merge(int left,int  mid, int  right)
{
	int i,j,k,n1,n2;
 	n1 = mid - left;
  	n2 = right - mid;
  	count += right - left;
	
	for (i = 0; i<n1; i++) 
	{
		L[i]=A[left+i];
	}
	for(i = 0; i<n2; i++)
	{
		R[i]=A[mid+i];
 
	}

  	L[n1] = INT_MAX;
  	R[n2] = INT_MAX;
  	i = 0;
  	j = 0;
  	
	for (k = left; k<right; k++)
	{
		if (L[i] <= R[j]) 
		{
			A[k] = L[i];
      		i++;
		}
    else 
		{
      		A[k] = R[j];
      		j++;
		}
	}
}

void mergeSort(int left, int right)
{
	int mid;
	if (left+1 >= right) return;
	
    mid = (left + right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
}

int main(void)
{
	int i,n;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	scanf("%d",&A[i]);
	count = 0;
	mergeSort(0,n);
	
	for(i=0;i<n;i++)
	{
		if(i==n-1)
		{
			printf("%d\n",A[i]);
		}
		else
		printf("%d ",A[i]);
		
	}
	printf("%d\n",count);
	
	return 0;
}


Measured memory_bytes: 5604
solve s = f s 0
  where f [] n = n
        f s n =
          let
            n' = length $ takeWhile (flip elem "ACGT") s;
            s2 = dropWhile (flip elem "ACGT") s;
            s3 = dropWhile (not . flip elem "ACGT") s2
          in f s3 (max n n')

main = getLine >>= putStrLn . show. solve


Measured memory_bytes: 380
let ()  =
  let rec make_string_w n = if n = 0 then "\n"
                            else "#" ^ make_string_w (n-1)  in
  let rec make_string_h n s = if n = 0 then ""
                              else s ^ make_string_h (n-1) s in
  let pair = ref (0, 0) in
  while pair := Scanf.scanf "%d %d\n" (fun h w -> (h, w)) ; !pair <> (0, 0)
  do
    make_string_w (snd !pair)
    |> make_string_h (fst !pair)
    |> Printf.printf "%s" ; print_newline()
  done ;;


Measured memory_bytes: 6696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String S = scan.nextLine();

		char alpha = 'a';

		for (int i = 0; i < 26; i++) {
			if (S.indexOf(String.valueOf(alpha)) != -1) {
				alpha++;
			} else {
				System.out.println(alpha);
				return;
			}

		}
		System.out.print("None");
	}
}


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

const int N = 100000;

int p[N];

int DIV(int a, int b)
{
    return (a + b - 1) / b;
}

int main()
{
    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        int where = 0;
        for (int i = 0; i < n; ++ i) {
            scanf("%d", p + i);
            if (p[i] == 1) {
                where = i;
            }
        }
        int ans = n;
        for (int l = 0; l < n && l + m <= n; ++ l) {
            if (l <= where && where < l + m) {
                ans = std::min(ans, 1 + DIV(l, m - 1) + DIV(n - (l + m), m - 1));
            }
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;

int main(){
  int n,sum;
  string s;
  cin >> n;
  rep(i,n){
	s = to_string(i);
    if(s.size()%2 == 1) sum++;
  }
  cout << sum;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	long a, b;
	long c, d;

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

	long x = c;
	long y = d;
	long base;

	if (x > y) {
		base = x;
		x = y;
		y = base;
	}

	long r = y % x;
	while (r != 0) {
		y = x;
		x = r;
		r = y % x;
	}

	long LCM = c * d / x;

	a--;

	long a_num, b_num;

	a_num = a / c + a / d - a / LCM;
	b_num = b / c + b / d - b / LCM;

	long ans = b - a - b_num + a_num;

	printf("%ld", ans);

	return 0;
}

Measured memory_bytes: 128
import sys
from itertools import product
input = sys.stdin.readline
N, M, X = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(N)]
res = -1
for p in product([0, 1], repeat=N):
    sum = [0] * M
    for i in range(N):
        if p[i]:
            for j in range(M):
                sum[j] += grid[i][j + 1]
    if all([sum[j] >= X for j in range(M)]):
        cost = 0
        for i in range(N):
            cost += p[i] * grid[i][0]
        if res == -1:
            res = cost
        else:
            res = min(res, cost)
    else:
        continue
print(res)

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

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

    string name;
    while(n > 0) {
//        cout << n << " " << name << endl;
        n--;
        name.push_back(n % 26 + 'a');
        n /= 26;
    }

    reverse(name.begin(), name.end());
    cout << name << endl;
    return 0;
}

Measured memory_bytes: 3636
H, W, M = map(int, input().split())
row=[0]*H
col=[0]*W

mat=[]

for i in range(M):
  h, w = map(int, input().split())
  row[h-1]+=1
  col[w-1]+=1
  mat.append((h-1,w-1))
  
r=max(row)
c=max(col)

rr=[1 if row[i]==r else 0 for i in range(H)]
cc=[1 if col[i]==c else 0 for i in range(W)]

x=0
for k in mat:
  if rr[k[0]]==1 and cc[k[1]]==1:
    x+=1

if sum(rr)*sum(cc)==x:
  print(r+c-1)
else:
  print(r+c)

Measured memory_bytes: 153812
import sys
def f(P):
 i=0
 for _ in[0]*k:
  s=0
  while s+w[i]<=P:
   s+=w[i];i+=1
   if i==n: return n
 return i
n,k=map(int,input().split())
w=list(map(int,sys.stdin.readlines()))
l=0;r=sum(w)
while r-l>1:
 m=(l+r)//2
 if f(m)>=n:r=m
 else:l=m
print(r)


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

int main(){
  int n, y, m, d;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> y >> m >> d;
    int cnt = 0;
    while(!(y == 1000 && m == 1 && d == 1)){
      cnt++;
      d++;
      if(y%3 == 0){
	if(d == 21)d = 1, m++;
	if(m == 11)m = 1, y++;
      }else{
	if(m%2 == 0){
	  if(d == 20)d = 1, m++;
	}else{
	  if(d == 21)d = 1, m++;
	}
	if(m == 11)m = 1, y++;
      }
    }
    cout << cnt << endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    map<char, int> mp;
    for(auto &c : s) mp[c]++;
    if(s.size() < 26){
        for(char c = 'a'; c <= 'z'; c++){
            if(mp[c] == 0){
                cout << s << c << endl;
                return 0;
            }
        }
    }else{
        string ans = "";
        for(int i = s.size() - 2; i >= 0; i--){
            if(s[i] < s[i + 1]){
                char tmp = s[i + 1];
                for(int j = i + 1; j < s.size(); j++){
                    if(s[j] > s[i]) tmp = min(tmp, s[j]);
                }
                s[i] = tmp;
                s = s.substr(0, i + 1);
                cout << s << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()

f1 = 0
if S == S[::-1]:
    l = len(S) //2
    sl = S[:l]
    if sl == sl[::-1]:
        ll = (len(S)+3)//2-1
        sll = S[ll:]
#         print(ll,sll)
        if sll == sll[::-1]:
            f1 = 1
            
if f1 == 0:
    print('No')
else:
    print('Yes')
        
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class BIT {
    int n;
    vi data0, data1;

    void add(vi& data, int i, i64 x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }

    i64 sum(vi& data, int i) {
        i64 s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

public:
    BIT(int n) : n(n) {
        data0 = vi(n + 1);
        data1 = vi(n + 1);
    }

    // [l, r)
    void add(int l, int r, i64 x) {
        l++;
        r++;
        add(data0, l, -x * (l - 1));
        add(data1, l, x);
        add(data0, r, x * (r - 1));
        add(data1, r, -x);
    }

    // [l, r)
    i64 sum(int l, int r) {
        i64 s = 0;
        s += sum(data0, r) + sum(data1, r) * r;
        s -= sum(data0, l) + sum(data1, l) * l;
        return s;
    }
};

int main() {
    int n;
    cin >> n;
    BIT bit(n);
    int q;
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t) {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            cout << bit.sum(x, y + 1) << endl;
        } else {
            int s, t, x;
            cin >> s >> t >> x;
            s--;
            t--;
            bit.add(s, t + 1, x);
        }
    }
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i = 1; i <= n; i++)
#define gi(k) scanf("%d",&k)
#define gl(k) scanf("%lld",&k)
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl
#define pf printf
#define sc scanf
#define SZ(x) ((vlong)(x).size())
#define MP make_pair
#define pb push_back
#define CLR(x,y) memset(x,y,sizeof(x))
#define mem CLR
#define ff first
#define ss second
#define phl printf ( "hello\n" )
#define nl puts ("")
#define LL long long
#define endl "\n"
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define NMAX ((1LL << 31) - 1)
 
using namespace std;


#ifdef forthright48
    #define debug(args...) { dbg,args; cerr<<endl; }
#else
    #define debug(args...)
#endif // forthright48
 
 
struct debugger { template<typename T> debugger& operator, (const T& v) {
    cerr << v << " ";
    return *this;
    }
}dbg;
 
 
typedef long long vlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
 
 
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
 
 
int main () {
 
    #ifdef forthright48
    freopen ( "00_input.txt", "r", stdin ); //freopen ( "00_output.txt", "w", stdout );
    #endif

    int x,ans;
    vector<int> v;

    rep(i,3) {
        cin >> x;
        v.pb(x);
    }

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

    ans = v[2]*10;
    ans += v[1] + v[0];

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

Measured memory_bytes: 256
int main()
{
    int a,b,c,d,t,m;
    while(~scanf("%d%d%d%d",&a,&b,&c,&d))
    {
        if(a>b)
            t=b;
        if(b>a)
            t=a;
        if(a==b)
            t=a;
        if(c>d)
            m=d;
        if(d>c)
            m=c;
        if(c==d)
            m=c;

        printf("%d\n",t+m);
    }
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define ll long long

int main(void){
  int T; cin >> T;
  while (T--){
    ll N, M, A, B;
    cin >> N >> M >> A >> B;
    cout << floor_sum(N, M, A, B) << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int stoi(char c){ return (c-48); }


int main(){
  string str; cin >> str;
  vector<int> num(4,0);
  vector<char> op;
  rep(i,4) num[i] = stoi(str[i]);
  rep(bit,8){ //bit全探索
    int ans = num[0];
    for(int j = 0; j < 3; ++j){
      if(bit >> j & 1){
        op.push_back('+');
        ans += num[j+1];
      }else{
        op.push_back('-');
        ans -= num[j+1];
      }
    }
    if(ans == 7){
      cout << num[0];
      rep(j,3) cout << op[j] << num[j+1];
      cout << "=7" << endl;
      return 0;
    }
    op.clear();
  }
  return 0;
}


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

int c[100020];

bool isp(int n){
  if(n==1) return false;
  for(int i=2;i<=int(sqrt(n));i++){
    if(n%i==0)return false;
  }
  return true;
}


int main(){
  int q,l,r;
  cin>>q;

  for(int i=1;i<100007;i++){
    if( isp(i) && isp((i+1)/2) )c[i]=1+c[i-1];
    else c[i]=c[i-1];
  }

  rep(i,q){
    cin>>l>>r;
    cout<<c[r+1]-c[l-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
const int N = 1e6;
ll ar[N];
ll dp[N];
int main(){
	Fast;
    ll n ,x;
    cin >> n >> x;
    cout << 3*(n-(__gcd(n,x)));
	return 0;
}

Measured memory_bytes: 256
n=int(input())
travel=[]
dif=[]
current=0
for i in range(n):
    travel.append(list(map(int,input().split())))
    dif.append(travel[-1][0]-current)
    current=travel[-1][0]
    
   
current=[0,0]
tamam=True
for i in range(n):
    need=abs(travel[i][1]-current[0])+abs(travel[i][2]-current[1])
    current=[travel[i][1],travel[i][2]]
    
    if dif[i] < need :
        tamam = False
        break
    elif (dif[i] - need) % 2 != 0 :
        tamam = False 
        break
if tamam :
    print("Yes")
else:
    print("No")
    
   

Measured memory_bytes: 28092
import numpy as np

n, m, c = map(int, input().split())
b = np.array(list(map(int, input().split())))
ans = 0
for _ in range(n):
  a = np.array(list(map(int, input().split())))
  if sum(a*b) + c > 0:
    ans += 1
print(ans)

Measured memory_bytes: 12504
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String O = sc.next();
    String E = sc.next();
    for (int i = 0; i < E.length(); i++) {
      System.out.print(O.charAt(i));
      System.out.print(E.charAt(i));
    }
    if (O.length() > E.length()) {
      System.out.print(O.charAt(O.length() - 1));
    }
    System.out.println();
  }
}

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

int N;
string s;

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

    int ans = 1;
    for(int i = 1; i < N; i++) {
        if(s[i] != s[i - 1]) ans++;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
# ABC069D - Grid Coloring (ARC080D)
def main():
    """
    move left to right in odd rows and vice versa in even rows
    1 s--->
    2 <----
    3 --->d
    """
    H, W = tuple(map(int, input().split()))
    N = int(input())
    A = tuple(map(int, input().split()))
    F = []  # flatten grid
    for color, cnt in enumerate(A, 1):
        F += [color] * cnt
    for p, i in enumerate(range(1, H + 1), 1):
        if p & 1:  # odd rows (1-idx)
            print(*F[(i - 1) * W : i * W])
        else:
            print(*F[(i - 1) * W : i * W][::-1])


if __name__ == "__main__":
    main()

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin >> a[i];
    long long ans = 0;
    map<int, int> nums;
    for (int i=0; i<n; ++i) nums[i+a[i]]++;
    for (int i=0; i<n; ++i) ans += nums[i-a[i]];
    cout << ans << endl;
}

Measured memory_bytes: 21192
n,a,b=map(int,input().split())
ans=0
# end=True
# while end:
#     if n>=a:
#         n-=a
#         ans+=a
#         if n>b:n-=b
#         else:end=False
#     else:
#         ans+=n
#         end=False

cnt=n//(a+b)
ans+=cnt*a
ama=n%(a+b)
if ama-a>=0:ans+=a
else:ans+=ama
print(ans)

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

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    int M2 = M;
    while(M2--){
        cin >> B[M2];
    }

    int IN, con, cal;
    con = 0;
    while(N--){
        M2 = M;
        cal = 0;
        while(M2--){
            cin >> IN;
            cal += (IN*B[M2]);
        }
        if(cal + C > 0) con++;
    }
    cout << con;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int a, b;
  cin >> a >> b;
  int ans = a + b;

  if(a < b) swap(a, b);
  int r = a % b;

  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }

  ans -= (b - 1);
  cout << ans << endl;
}



Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int t, s=0;
    cin >> t;
    s+=t;
    cin >> t;
    s+=t;
    cin >> t;
    s+=t;
    cin >> t;
    s+=t;
    cout << s/60 << endl << s%60 << endl;
}

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

int main(void){

    string n;
    cin >> n;

    // for (int i=0; i<3; i++) {
    //     cout << i+1 << "文字目" << n[i] << endl;
    // }

    for(int i=0; i<3; i++) {
        if(n[i] == '1') {
            cout << 9;
        } else {
            cout << 1;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <cctype>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<long long>
#define vvl vector<vector<long long>>

using namespace std;

typedef long long ll;

int main()
{
  int a, b, c;
  cin >> a >> b;
  for (int i = 1; i <= 3; i++)
  {
    if ((a * b * i) % 2 == 1)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
class Dice < Array
	def roll(drct)
		drct.split("").each{|s|
		case s
		when "E" then
			self.replace([at(3),at(1),at(0),at(5),at(4),at(2)])
		when "N" then
			self.replace([at(1),at(5),at(2),at(3),at(0),at(4)])
		when "S" then
			self.replace([at(4),at(0),at(2),at(3),at(5),at(1)])
		when "W" then
			self.replace([at(2),at(1),at(5),at(0),at(4),at(3)])
		end
		}
	end
	def top
		at(0)
	end
end

a = Dice.new(gets.split.map(&:to_i))
a.roll(gets.chomp)
puts a.top

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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
    int coun = 0;
    
    string ch;
    
    stack<char>s;
    
    cin >> ch;
    
    int len = ch.size();
    
    if(len == 1) {cout << 0 << endl;return 0;}
    else
    {
		s.push(ch[0]);
		
		for(int i = 1; i < len; i++)
		{
			if(s.size() == 0)
			{
				s.push(ch[i]);
				continue;
			}
			
			if((s.top() == '0' && ch[i] == '1') || (s.top() == '1' && ch[i] == '0'))
			{
				s.pop();
				coun++;
			}
			else s.push(ch[i]);
		}
	}
    
    
    cout << coun*2 << endl;
    
    return 0;	
}


Measured memory_bytes: 512
#include<iostream>
using namespace std; 
int main(){
    int x,y;
    while(1){
        cin>>x>>y;
        if(x==0&y==0) break;
        if(x>=y) cout<<y<<" "<<x<<endl;
        else cout<<x<<" "<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	vector
# CreatedDate:  2020-07-08 17:17:40 +0900
# LastModified: 2020-07-08 17:25:11 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, q = map(int, input().split())
    big_list = [[] for _ in range(n)]
    for _ in range(q):
        query = list(map(int, input().split()))
        if len(query) == 3:
            big_list[query[1]].append(query[2])
        else:
            if query[0] == 1:
                if big_list[query[1]]:
                    print(big_list[query[1]][0], end="")
                    for i in range(1, len(big_list[query[1]])):
                        print(" {}".format(big_list[query[1]][i]), end="")
                print()
            else:
                big_list[query[1]].clear()


if __name__ == "__main__":
    main()



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

public class Main {

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		String result = " ";

		int [] list = new int [] {a, b, c};
		Arrays.sort(list) ;

		if (list[2] == list[1] + list[0]) {
			result = "Yes" ;
		} else {
			result = "No" ;
		}

        System.out.println(result);
	}
}

Measured memory_bytes: 23380
def calc(S):
    N = len(S)
    result = [0 for _ in range(N)]
    rc = 1
    i = 0
    while (i < N - 1):
        if (S[i: i + 2] == 'RL'):
            lc = 0
            j = i + 1
            while (j < N):
                if (S[j] == 'L'):
                    lc += 1
                    j += 1
                else:
                    break
            result[i] = (rc + 1) // 2 + lc // 2
            result[i + 1] = rc // 2 + (lc + 1) // 2
            i = j
            rc = 1
        else:
            rc += 1
            i += 1
    return ' '.join([str(x) for x in result])


print(calc(input()))

Measured memory_bytes: 10484
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

void dfs(int c, int p, vvi &edges, vl &ret) {
    for (auto &e : edges[c]) {
        if (e == p)
            continue;
        ret[e] += ret[c];
        dfs(e, c, edges, ret);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    vvi edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    vl ret(n, 0);
    for (int i = 0; i < q; ++i) {
        int p, x;
        cin >> p >> x;
        p--;
        ret[p] += x;
    }
    dfs(0, -1, edges, ret);
    print(ret);
    return 0;
}

Measured memory_bytes: 30464
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++)
			a[i] = sc.nextInt();
        int[][] s = new int[H][W];
		int h = 0, w = 0;
		for(int i = 0; i < N; i++){
			while(a[i]-- > 0){
				s[h][w] = i+1;
				if(h%2 == 0){
					if(w == W-1)
						h++;
					else 
						w++;
				} else {
					if(w == 0)
						h++;
					else
						w--;
				}
			}
		}
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				System.out.print(s[i][j] + " ");
			}
			System.out.println();
		}
    }
}


Measured memory_bytes: 32728
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


bool is_prime_number(int N)
{
    for (int i = 2; i <= N / 2; i++)
    {
        if (N % i == 0)
            return false;
    }
    return true;
}


int main(){
    int Q;
    cin >> Q;
    vector<int> l(Q), r(Q);
    rep(i, Q) cin >> l[i] >> r[i];

    vector<int> primes;
    for(int i = 2; i <= 100000; i++){
        if(is_prime_number(i)) primes.push_back(i);
    }
    vector<int> numbers;
    for(int i = 0; i < primes.size(); i++){
        int target = (primes[i] + 1) / 2;
        if(binary_search(primes.begin(), primes.end(), target)) numbers.push_back(primes[i]);
    }
    int n = numbers.size();
    for(int i = 0; i < Q; i++){
        int left_idx, right_idx;
        left_idx = lower_bound(numbers.begin(), numbers.end(), l[i])- numbers.begin();
        right_idx = upper_bound(numbers.begin(), numbers.end(), r[i]) - numbers.begin();
        cout << right_idx - left_idx << endl;
    }

    return 0;

}


Measured memory_bytes: 1536
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define o(x) cout << x << '\n'
#define on() cout << '\n'
#define os(x) cout << x << ' '

#define i(x) cin >> x
#define i2(x, y) cin >> x >> y

#define DBG = 1

using ll = long long;


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

    int n, k = 3;

    i(n);

    vector<vector<ll>> a(n, vector<ll>(3));

    for (int i = 0; i < n; i++) {
        for (auto &x: a[i]) {
            i(x);
        }
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < k; j++) {
            ll prevMax = 0;
            for (int l = 0; l < k; l++) {
                if (l != j) {
                    prevMax = max(prevMax, a[i - 1][l]);
                }
            }
            a[i][j] += prevMax; 
        }
    }

    o(max(a[n - 1][0], max(a[n - 1][1], a[n - 1][2])));

    return 0;
}

Measured memory_bytes: 5760
N = int(input())
A = [0] + [int(s) for s in input().split()]
ball = [0] * (N + 1)
for i in range(N, 0, -1):
    ball[i] = (sum(ball[i::i]) - A[i]) % 2
ans = [i for i, v in enumerate(ball) if v == 1]
print(len(ans))
print(*ans)


Measured memory_bytes: 14124
char*p;M(r){for(r=T();*p%5==2;)r=*p&1?r/T():r*T();return r;}A(r){for(r=M();abs(*p-=44)<2;)r-=*p*M();return++p,r;}T(){return*++p-40?strtol(p,&p,10):A(p);}main(f){for(;~scanf("%as",&p);f=0)f||printf("%d\n",A(--p));}

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

int main(){

    string S;

    cin >> S;

    if(S[0] != 'A' or S[1] < 97 or S[1] > 122 or S[S.size()-1] < 97 or S[S.size()-1] > 122){
      cout << "WA" << endl;
      return 0;
    }

    int Ccount = 0;

    for(int i = 2;i < S.size()-1;i++){

        if(S[i] == 'C' and Ccount == 0)Ccount++;
        else if(S[i] >= 97 and S[i] <= 122);
        else{
          cout << "WA" << endl;
          return 0;
        }

    }


    if(Ccount == 1)cout << "AC" << endl;
    else cout << "WA" << endl;

}

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

void disp(vector<int> h){
    for(int i = 0; i< h.size(); i++){
        cout << h[i] << " ";
    }
    cout << endl;
}

void grow(vector<int>& h, int l, int r){
    if(l > r){
        exit(0);
    }    
    for(int i = l; i <= r; i++){
        if(h[i] == 0) {
            disp(h);
            exit(0);
        }
        h[i]--;
    }
}

bool check(vector<int> h){
    for(int i = 0;i < h.size(); i++){
        if(h[i] != 0){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    std::vector<int> h;
    cin >> N;
    for(int i = 0; i< N; i++){
        int tmp;
        cin >>  tmp;
        h.push_back(tmp);
    }

    int count =0;;
    while(!check(h)){
        int l = 0;
        int r = N -1;
        bool choice = false;
        for (int i = 0 ; i < N ; i++){
            if(h[i] == 0&& !choice){
                continue;
            }
            else if(h[i] == 0 && choice){
                r = i -1;
                break;
            }
            else if(h[i] != 0 && !choice){
                l = i;
                choice = true;
            }
            else {
                r = i;
            }
        }
        grow(h,l,r);
        // disp(h);
        count++;
    }
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 256