akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	int n, m;
	vector<int> a;
	cin >> n >> m;
	long int all = 0;
	for (size_t i = 0; i < n; i++)
	{
		int v;
		cin >> v;
		a.push_back(v);
		all += v;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(), a.end());
	bool flg = 1;
	for (size_t i = 0; i < m; i++)
	{
		if (a[i] < all / (4.0 * (double)m)) {
			flg = 0;
			break;
		}
	}
	if (flg) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fr(i,n) for(int i=0;i<n;i++)
#define M 1000000007
signed main()
{ 
          int n,k;
          cin>>n>>k;
          int arr[n+1];
          for(int i=1;i<=n;i++) cin>>arr[i];
          
          vector<int>dp(k+1);
          dp[0]=1;
          vector<int>presum(k+1,1);
          
          for(int i=1;i<=n;i++)
          {    
                for(int j=0;j<=k;j++)
                  {
                    int pos=max(0ll,j-arr[i]);
                    if(pos>0)
                    {
                    dp[j]=(presum[j]-presum[pos-1]+M)%M;
                    }
                    if(pos==0)
                    {
                     dp[j]=(presum[j])%M;         
                    }
                    //cout<<dp[j]<<" ";
                  }//cout<<"\n";
                  presum[0]=dp[0];
                  for(int j=1;j<=k;j++)
                  {
                            presum[j]=(presum[j-1]+dp[j])%M;
                  }
          }
          cout<<dp[k]<<"\n";
          
          
}




Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
static const int MAX_N = 1000;

int N, M;
vector<int> G[MAX_N];
int match[MAX_N];
bool used[MAX_N];

void add_edge(int u, int v){
  G[u].push_back(v);
}
 
bool dfs(int v){
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i], w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res = 0;
  fill(match, match + N + M, -1);
  for(int v = 0; v < N + M; v++){
    if(match[v] < 0){
      fill(used, used + N + M, 0);
      if(dfs(v)){
        res++;
      }
    }
  }
  return res;
}

int gcd(int a, int b){
  if(b == 0) return a;
  else return gcd(b, a % b);
}
 
int main(){
  for(;;){
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    int b[500], r[500];
    for(int i = 0; i < N; i++) cin >> b[i];
    for(int i = 0; i < M; i++) cin >> r[i];
    for(int i = 0; i < N; i++){
      for(int j = 0; j < M; j++){
        if(gcd(b[i], r[j]) > 1){
          add_edge(i, j + N);
          add_edge(j + N, i);
        }
      }
    }
    cout << bipartite_matching() << endl;
    for(int i = 0; i < N + M; i++) G[i].clear();
  }
  return 0;
}



Measured memory_bytes: 4932
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <bitset>

using ll = long long;
using ull = unsigned long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N;
    cin >> N;
    unsigned long long A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    ll count[60];
    for(int i = 0; i < 60; i++){
        count[i] = 0;
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 60; j++){
            //cout << A[i] << " ";
            if(A[i] & (1ull << j)){
                //cout << j << endl;
                count[j]++;
            }
        }
    }
    ll MOD = 1000000000 + 7;
    ll result = 0;
    for(int i = 0; i < 60; i++){
        //cout << count[i] * (N - count[i]) * (1 << i) << endl;
        ull tmp = (count[i] * (N - count[i])) % MOD;
        ull tmp2 = (1ull << i) % MOD;
        ull tmp3 = (tmp * tmp2) % MOD;
        result = (result + tmp3) % MOD;
    }
    cout  << result << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;


class UnionFindTree {
private:
	static const int MAX_N = 100002;
	int par[MAX_N], ran[MAX_N];
	int con_size[MAX_N];

public:
	UnionFindTree(int n) {
		if (n > MAX_N) cerr << "INVALID INPUT" << endl;
		for (int i = 0; i < n; i++) {
			par[i] = i;
			ran[i] = 0;
			con_size[i] = 1;
		}
	}

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

public:
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (ran[x] < ran[y]) {
			con_size[y] += con_size[x];
			par[x] = y;
		}
		else {
			con_size[x] += con_size[y];
			par[y] = x;
			if (ran[x] == ran[y]) ran[x]++;
		}
	}

	int size(int x) {
		return con_size[find(x)];
	}

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


UnionFindTree uft(100001);

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		cin >> q[i].first >> q[i].second;
		q[i].first--; q[i].second--;
	}
	vector<ll> ans(m);
	ll sum = (ll)n*(n - 1)/2;
	for (int i = m - 1; i >= 0; i--) {
		ans[i] = sum;
		int a = q[i].first, b = q[i].second;
		if (!uft.same(a, b)) {
			ll aa = uft.size(a), bb = uft.size(b);
			sum += aa * (aa - 1) / 2 + bb * (bb - 1) / 2;
			uft.unite(a, b);
			ll t = uft.size(a);
 			sum -= t * (t - 1) / 2;
		}
	}
	for (int i = 0; i < m; i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4096
import sys
blood = {"A": 0, "B": 0, "AB": 0, "O": 0}
for line in sys.stdin:
    if line == "\n":
        break
    no, b = line.rstrip().split(",")
    blood[b] += 1
print(blood["A"])
print(blood["B"])
print(blood["AB"])
print(blood["O"])

Measured memory_bytes: 7300
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    
    for (int i = 1; i < N; i++) {
      if (A[i] > A[i-1]) {
        A[i] = gcd(A[i], A[i-1]);
      } else {
        A[i] = gcd(A[i-1], A[i]);
      }
    }
    
    System.out.println(A[N-1]);
  }
  
  private static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 50464
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

from math import ceil,log
n,k = myinput()
ans = 0
for i in range(n):
    m = i+1
    if m<k:
        x = ceil( log(k/m,2) )
        ans += 1/n * ( (1/2)**x )
    else:
        ans += 1/n
print(ans)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define stop exit(0)
#define dd double
#define po pop_back
#define pb push_back
#define ub upper_bound
#define lb lower_bound
int main(){
    vector <long long> v;
    ll a,b,c,d=0,e=0,f=0,g=0,i,j,k=1,l=1,r=1,n,m[300001],z[400001],h[600001],p[600001];
    string s,t,x,y[1001];
    dd q,u,w;
    cin>>a;
    for(i=1;i<=a;i++){
        p[i]=0;
    }
    for(i=1;i<a;i++){
        cin>>b;
        p[b]++;
    }
    for(i=1;i<=a;i++){
        cout<<p[i]<<endl;
    }
}

Measured memory_bytes: 5228
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		char [] s = stdIn.next().toCharArray();
		char [] t = stdIn.next().toCharArray();
		
		for(int i = 0; i < n; i++) {
			System.out.print(s[i]);
			System.out.print(t[i]);
		}
		
		
		
	}

}


Measured memory_bytes: 23252
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,sum1,sum2,ans=1e9;

int main(){
    cin>>N;
    int A[N];
    rep(i,N)cin>>A[i];
    sum1=A[0];
    rep(i,N-1){
        sum2+=A[i+1];
    }
    ans=min(ans,abs(sum1-sum2));
    repi(i,1,N-1){
        sum1+=A[i];
        sum2-=A[i];
    ans=min(ans,abs(sum1-sum2));

    }
    out(ans);
    
    
    
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        sc.close();

        int ans = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    if (X == 500 * i + 100 * j + 50 * k)
                        ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include <stdio.h>
 
int main(void){
    int saikoro[6];
    int q,i;
    int top,front;
    int result;
 
 
    for(i=0; i<6; i++){
        scanf("%d",&saikoro[i]);
    }
    scanf("%d",&q);
    for(i=0; i<q; i++){
        scanf("%d %d",&top,&front);
        result = dice(saikoro,top,front);
        printf("%d\n",result);
    }
 
     
    return 0;
}
int dice(int saikoro[6], int top, int front){
 
        if(top == saikoro[0]){
            if( front == saikoro[1]) return saikoro[2];
            if( front == saikoro[2]) return saikoro[4];
            if( front == saikoro[3]) return saikoro[1];
            if( front == saikoro[4]) return saikoro[3];
        }
        if(top == saikoro[1]){
            if( front == saikoro[0]) return saikoro[3];
            if( front == saikoro[2]) return saikoro[0];
            if( front == saikoro[3]) return saikoro[5];
            if( front == saikoro[5]) return saikoro[2];
        }
        if(top == saikoro[2]){
            if( front == saikoro[0]) return saikoro[1];
            if( front == saikoro[1]) return saikoro[5];
            if( front == saikoro[4]) return saikoro[0];
            if( front == saikoro[5]) return saikoro[4];
        }
        if(top == saikoro[3]){
            if( front == saikoro[0]) return saikoro[4];
            if( front == saikoro[1]) return saikoro[0];
            if( front == saikoro[4]) return saikoro[5];
            if( front == saikoro[5]) return saikoro[1];
        }
        if(top == saikoro[4]){
            if( front == saikoro[0]) return saikoro[2];
            if( front == saikoro[2]) return saikoro[5];
            if( front == saikoro[3]) return saikoro[0];
            if( front == saikoro[5]) return saikoro[3];
        }
        if(top == saikoro[5]){
            if( front == saikoro[1]) return saikoro[3];
            if( front == saikoro[2]) return saikoro[1];
            if( front == saikoro[3]) return saikoro[4];
            if( front == saikoro[4]) return saikoro[2];
        }
        return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
 
vector <int> p(0);
 
void Prime(int n){
 
  bool flg[(int)sqrt( pow(10,9) ) +1];
  int indx=2;
 
  flg[0]=flg[1]=0;
  for(int i=0; i<sqrt(n)+1; i++)flg[i]=0;
   
 
  while(indx<=sqrt(n)){
    flg[indx]=1;
    p.push_back(indx);
    for(int i=2; i*indx<sqrt(n); i++){
      flg[indx]=1;
    }
 
    while(flg[indx]==1 && indx<=sqrt(n))indx++;
 
  }
   
 
}
 
 
int main(){
 
  int n;
 
  cin >> n;
 
  Prime(n);
 
  cout << n << ':';
 
  int i=0;
  while(n!=1 && i<(int)p.size()){
     
    while(n%p[i]==0){
      cout << ' ' << p[i];
      n /= p[i];
    }
 
    i++;
     
  }
 
  if(i==(int)p.size() && n!=1)cout << ' '<<n;
  cout << endl;
 
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int dm = 1 << 19;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = ' ';
		return;
	}
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	char S[100001];
	int N = fread_unlocked(S, 1, 100001, stdin);
	if (S[N - 1] == '\n') N--;
	int kotae[100000] = {};
	
	int k = 0;
	rep(i, N) {
		if (S[i] == 'R') {
			k++;
		}
		else {
			kotae[i - 1] += (k + 1) / 2;
			kotae[i] += k / 2;
			k = 0;
		}
	}
	k = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == 'L') {
			k++;
		}
		else {
			kotae[i + 1] += (k + 1) / 2;
			kotae[i] += k / 2;
			k = 0;
		}
	}

	rep(i, N) putint(kotae[i]);
	fwrite_unlocked(dn, di - dn - 1, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pi = pair<P, int>;
#define FF first.first
#define FS first.second

int main(void){
    int h, w;
    cin >> h >> w;
    bool map[1001][1001];
    fill(map[0], map[1001], true);
    int ch, cw, dh, dw;
    cin >> ch >>  cw >> dh >> dw;
    --ch; --cw; --dh; --dw;
    string s[h];
    rep(i, h) cin >> s[i];
    deque<Pi> bfs;
    bfs.push_front(Pi(P(ch, cw), 0));
    int dx[25] = {0, 1, 0, -1, 1, 1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1};
    int dy[25] = {-1, 0, 1, 0, -1, 1, 1, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2};
    while(!bfs.empty()){
        auto v = bfs.front(); bfs.pop_front();
        int y = v.FF, x = v.FS, cost = v.second;
        if(!map[y][x]) continue;
        map[y][x] = false;
        if(y == dh && x == dw){
            cout << cost << endl;
            return 0;
        }
        for(int i = 0; i < 24; ++i){
            int to_x = x + dx[i], to_y = y + dy[i];
            if(to_x < 0 || to_x >= w || to_y < 0 || to_y >= h) continue;
            if(map[to_y][to_x] && s[to_y][to_x] == '.'){
                if(i < 4)
                    bfs.push_front(Pi(P(to_y, to_x), cost));
                else
                    bfs.push_back(Pi(P(to_y, to_x), cost + 1));
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 7116
#include <iostream>
using namespace std;
int a[100];
int main()
{
  int n,max=0,min=1e9,rez;
  cin >> n;
  for(int i=0;i<n;i++)
  {
    cin >> a[i];
    if (a[i]>max)
      max=a[i];
    if (a[i]<min)
      min=a[i];
  }
  rez=max-min;
  cout << rez;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,K;
    cin>>N>>K;
    ll ans = 0;
    while(N>0){
        N/=K;
        ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
from collections import deque
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

A = sorted(A)
q = deque()
q.append(A[0])
i = 1
j = N - 1
mi = True
while i < N and j >= 0 and i <= j:
    if mi:
        p1, p2 = q[0], q[-1]
        q1, q2, q3, q4 = abs(A[j] - p1), abs(A[j] - p2), abs(A[i] - p1), abs(A[i] - p2)
        qm = max(q1, q2, q3, q4)
        if qm == q1:
            q.appendleft(A[j])
            j -= 1
        elif qm == q2:
            q.append(A[j])
            j -= 1
        elif qm == q3:
            q.appendleft(A[i])
            i += 1
        else:
            q.append(A[i])
            i += 1

num = 0
pre = q[0]
for i in range(1, N):
    num += abs(q[i] - pre)
    pre = q[i]

print(num)

Measured memory_bytes: 8760
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define in input_int()
#define ins input_string()
int input_int(){int a;cin>>a;return a;}
string input_string(){string s;cin>>s;return s;}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};



int n,m,k,a,b,c,d,x,y,arr[N];
string s;
void solve()
{
    cin>>s;
    x=0;
    int ans=0;
    for(auto i:s)
    {
        if(i=='R')
        {
            x++;
            ans=max(ans,x);
        }
        else x=0;
    }
    cout<<ans;
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}
//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll gcd(ll a, ll b) {
    if (a < b) return gcd(b, a);
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

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

    ll gcds[201][201];
    for (ll i = 0; i <= 200; i++) {
        for (ll j = 0; j <= 200; j++) {
            gcds[i][j] = gcd(i, j);
        }
    }

    ll ans = 0;
    ll k; cin >> k;
    for (ll i = 0; i < k; i++) {
        for (ll j = 0; j < k; j++) {
            for (ll l = 0; l < k; l++) {
                ans += gcds[i+1][gcds[j+1][l+1]];
            }
        }
    }
    cout << ans << endl;
    
}

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

int main(){
	string c, d;
	cin >> c >> d;
	if(c.at(1)!=d.at(1) || c.at(0)!=d.at(2) || c.at(2)!=d.at(0)){
		cout << "NO" << endl;
	}
	else cout << "YES" << endl;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll A, B, C;
  cin >> A >> B >> C;

  ll ans = 0;
  while (true) {
    if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
      cout << ans << endl;
      return 0;
    }

    if (A == B && B == C) {
      cout << "-1" << endl;
      return 0;
    }

    ll a = A / 2;
    ll b = B / 2;
    ll c = C / 2;
    A = b + c;
    B = a + c;
    C = a + b;

    ++ans;
  }

  return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w;
  cin >> h >> w;
  vector<int32> cnt(26,0);
  REP(i,h){
    string s;
    cin >> s;
    REP(j,w){
      cnt[s[j] - 'a']++;
    }
  }
  int32 need4,need2,need1;
  if(h % 2 && w % 2){
    need4 = h * w - h - w + 1;
    need2 = h + w - 2;
    need1 = 1;
  }else if(h % 2 || w % 2){
    if(h%2)swap(h,w);
    need4 = h * w - h;
    need2 = h;
    need1 = 0;
  }else{
    need4 = h * w;
    need2 = need1 = 0;
  }
  // cout << need4 << " " << need2 << " " << need1 << endl;
  REP(i,26){
    if(cnt[i] % 2){
      if(need1 > 0){
        cnt[i]--;
        need1--;
      }else{
        Yes(false);
        return 0;
      }
    }
  }
  REP(i,26){
    if(cnt[i] % 4 == 2){
      if(need2 > 0){
        cnt[i] -= 2;
        need2 -= 2;
      }else{
        Yes(false);
        return 0;
      }
    }
  }
  Yes(true);
  return 0;
}

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;

public class Program{
    public static void Main(){
        int[] i=Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        int ans=i[1]+i[2]-i[0];
        Console.WriteLine(ans>=0?ans:0);
    }
}


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

int n, m;
set<int> g[100000];
set<int> rev_g[100000];

void solve(int cur) {
  set<int> remove;
  for (int to: g[cur]) {
    if (rev_g[to].size() > 1) {
      remove.insert(to);
    }
  }
  for (int i: remove) {
    g[cur].erase(i);
    rev_g[i].erase(cur);
  }
  for (int to: g[cur]) {
    solve(to);
  }
}
int main() {
  cin>>n>>m;
  for (int i=0; i<n-1+m; i++) {
    int a, b;
    cin>>a>>b;
    --a;
    --b;
    g[a].insert(b);
    rev_g[b].insert(a);
  }
  int root;
  for (int i=0; i<n; i++) {
    if (rev_g[i].size() == 0) {
      root = i;
      break;
    }
  }
  solve(root);
  for (int i=0; i<n; i++) {
    if (i == root) {
      cout<<0<<endl;
    } else {
      cout<<*rev_g[i].begin() + 1<<endl;
    }
  }
}

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

int main(){
  int n;
  cin >> n;
  int ans=0; 
  for(int i=1; i<=n; i++){
        if (1 <= i and i <= 9) ans++;
        else if (100 <= i and i <= 999) ans++;
        else if (10000 <= i and i <= 99999) ans++;
    }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
n,x=map(int, input().split())
if x==1 or x==2*n-1:
    print('No')
    exit()
from collections import deque
ll=deque()
for i in range(n+1,2*n):
    if x!=i and len(ll)<n:
        ll.append(i)

ll.append(x)
for i in range(1,n):
    if x!=i:
        ll.append(i)
if x<n:
    ll.append(n)
elif x>n:
    ll.appendleft(n)
print("Yes")
for i in ll:
    print(i)

Measured memory_bytes: 80508
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int N;
vector<vector<int>> A;
int ans = 0;

void dfs(int a, int b,int now){
  now += A[a][b];
  if(a == 1 && b == N-1){
    ans = max(ans,now);
    return;
  }

  if(a+1 < 2) dfs(a+1,b,now);
  if(b+1 < N) dfs(a,b+1,now);
}

int main(){
  cin >> N;
  A.resize(2,vector<int>(N));
  rep(i,2)rep(j,N) cin >> A[i][j];
  dfs(0,0,0);
  cout << ans << endl;

}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
 
ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    string s;
    
    cin>>s;
    if( s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
    cout<<"Yes";
    }
    else cout<<"No"; 
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    int n = s.size();

    vector<int> ans(n, 0);
    for(int i=0; i<n-1; i++){
        int cntR = 0, cntL = 0;
        int idR;
        while(1){
            if((s[i] == 'L' && s[i+1] == 'R') || i == n - 1){
                cntL++;
                break;
            }
            if(s[i] == 'R' && s[i+1] == 'L'){
                idR = i;
            }

            cntR += (s[i] == 'R');
            cntL += (s[i] == 'L');
            i++;
        }

        int miR = cntR / 2;
        int maR = cntR - miR;
        int miL = cntL / 2;
        int maL = cntL - miL;

        ans[idR] = maR + miL;
        ans[idR+1] = miR + maL;
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << " \n"[i==n-1];
    }
}

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

int main() {
  int A,B; cin >> A >> B; int ans = -1;
  vector<int> kouho(1251,0);
  int i =1;
  while (i <=1250) {
    int kouhoA = i * 0.08; int kouhoB = i * 0.1;
    if (kouhoA == A) kouho.at(i)++; 
    if (kouhoB == B) kouho.at(i)++; 
    i++;
  }
 
  for (int i =1; i<=1250; i++) {
    if (kouho.at(i) == 2) {
      ans = i; break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        Int N, K, Q;
        cin >> N >> K >> Q;
        vector<Int> P(N, K - Q);
        for (int i = 0; i < Q; ++i) {
            Int a;
            cin >> a;
            a--;
            P[a]++;
        }
        for (int i = 0; i < N; ++i) {
            if (P[i] > 0) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1408
N = int(input())
S = [int(input()) for _ in range(N)]
S.sort()
sum_score = sum(S)
if sum_score %10 != 0:
    print(sum_score)
    exit()
else:
    for s in S:
        if s %10 != 0:
            print(sum_score - s)
            exit()
        else:
            continue

print(0)

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

int main(){
 int a,b,c;

 vector<int> vec(3);
 for(int i=0;i<3;i++){
 cin >> vec.at(i);
 }

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

 cout<<(vec.at(2)-vec.at(0))<<endl;

 return 0;
}

Measured memory_bytes: 256
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a
# Python 1st Try

import sys
# from collections import defaultdict
import collections as col
# import pprint
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(ALLNUM, KIND, ball_numbers):
    result = 0
    # prp = pprint.pprint
    counter_result = col.Counter(ball_numbers)
    ball_num_len = len(counter_result)
    counter_result_sorted = sorted(counter_result.items(), key=lambda x: x[1])
    # prp(counter_result_sorted)
    if ball_num_len <= KIND:
        return 0
    reduce_kind = ball_num_len - KIND
    # prp(reduce_kind)
    for _, ballCount in counter_result_sorted:
        result += ballCount
        reduce_kind = reduce_kind - 1
        # prp(reduce_kind)
        if reduce_kind <= 0:
            break
    return result


if __name__ == "__main__":
    N, K = MI()
    Ai = list(map(int, sys.stdin.readline().split()))
    # print(Ai)
    print("{}".format(solver(N, K, Ai)))


Measured memory_bytes: 44184
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    int a, b;
    cin >> a >> b;
    if(1 != a && 1 != b)
    {
        cout << 1 << endl;
    }else if(2 != a && 2 != b){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
}

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

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

    k--;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    int ans = 1e18;
    for(int bit = 0; bit < (1 << (n - 1)); bit++){
        int cnt = 0;
        for(int i = 0; i < n - 1; i++){
            if(1 & (bit >> i)) cnt++;
        }
        if(cnt != k) continue;

        int tmp = 0;
        int maxv = a[0];
        for(int i = 1; i < n; i++){
            if(1 & (bit >> (n - 1 - i))){
                if(a[i] <= maxv){
                    tmp += (maxv + 1 - a[i]);
                    maxv = maxv + 1;
                }
            }
            maxv = max(maxv,a[i]);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define buli(x) (__builtin_popcountll(x))
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define dec(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define EPS 1e-7
#define fcin ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef vector<int> vi;
const int mo=1e9+7;
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))

int n, t[111111],a[1111111];
pii pos[111111];

int main() {
	gn(n);
	rep(i,0,n) gn(t[i]);
	rep(i,0,n) gn(a[i]);
	int maior=0;
	rep(i,0,n) {
		if(maior < t[i]){
			pos[i].fi=pos[i].se=t[i];
			maior=t[i];
		}else{
			pos[i].fi=1;pos[i].se=maior;
		}
	}
	maior=0;
	dec(i,n-1,0){
		int a1=0,b=0;
		if(maior < a[i]){
			a1=a[i];b=a[i];
			maior=a[i];
		}else{
			a1=1;b=maior;
		}
		if(pos[i].fi>b||pos[i].se<a1){
			puts("0");
			return 0;
		}
		pos[i].fi=max(pos[i].fi,a1);
		pos[i].se=min(pos[i].se,b);
	}
	ll res=1;
	rep(i,0,n){
		mmo(res,pos[i].se-pos[i].fi+1);
	}
	printf("%lld\n", res);
}


















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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N;
    cin >> N;
    vector<int> v;
    while (N > 0)
    {
        v.push_back(N % 10);
        N /= 10;
    }

    int max = 0;
    for (int i = 0; i < v.size(); ++i)
    {
        int sum = 0;
        REP(j, v.size())
        {
            sum += v[j];
        }
        v[i] = 9;
        if (i + 1 < v.size())
            v[i + 1]--;
        max = std::max(max, sum);
    }
    cout << max << endl;
    return 0;
}

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


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

    vector<int> p(n), q(n);

    for(int i = 0; i < n; ++i)
        cin >> p[i];
    for(int i = 0; i < n; ++i)
        cin >> q[i];

    vector<int> sorted = p;
    sort(sorted.begin(), sorted.end());

    ll p_cnt, q_cnt;
    ll cnt = 0;
    do {
        cnt++;
        if(sorted == p) p_cnt = cnt;
        if(sorted == q) q_cnt = cnt;
    } while(next_permutation(sorted.begin(), sorted.end()));

    cout << abs(p_cnt - q_cnt) << "\n";
    return 0;
}

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

using namespace std;
int dp[3001][3001];
string s,t;
char nr[3001];
int main()
{
    int i,j;
    cin >> s;
    cin >> t;
    int n = s.size();
    int m = t.size();
    for(i = n - 1;i >= 0;i--){
        s[i + 1] = s[i];
    }
    for(i = m - 1;i >= 0;i--){
        t[i + 1] = t[i];
    }
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
        {
            if(s[i] == t[j])
            {
                dp[i][j] =dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }

        }
    }
    i = n;
    j = m;
    int varf = 0;
    while(i >= 1 &&  j >= 1)
    {
        if(s[i] == t[j])
        {
            nr[++varf] = s[i];
            i--;
            j--;
        }
        else if(dp[i][j] == dp[i-1][j])
        {
            i--;
        }
        else
        {
            j--;
        }
    }

    for(i = varf ; i > 0; i--)
    {
        cout << nr[i];
    }
    return 0;
}


Measured memory_bytes: 35456
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :]) - B[0])


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

int main() {
  int h,w;
  cin >>h>>w;
  vector<vector<char>>a(h+1,vector<char>(w+1));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(i==0||i==h+1||j==0||j==w+1)cout<<'#';
      else cout<<a[i][j];
    }
    cout<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    
    int k;
    int x;
    
    scanf("%d%d", &k, &x);
    
    for(int i=x-k+1; i<x+k; i++){
        
        printf("%d", i);
        
        if(i<x+k-1){
            
            printf(" ");
            
        }
        
    }
    
    return 0;
    
}

Measured memory_bytes: 128
a = input()
m1 = False
m2 = False

ab = int(a[:2])
cd = int(a[2:])
if ab > 0 and ab <= 12:
  m1 = True

if cd > 0 and cd <= 12:
  m2 = True

if m1 and m2:
  print("AMBIGUOUS")
elif m1 and not m2:
  print("MMYY")
elif not m1 and m2:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main()
{
	int N,K,X;
	1<=N<=1000;
	2<=K<=1000;
	scanf("%d%d",&N,&K);
	X=K*pow((K-1),(N-1));
	printf("%d",X);
	return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    std::string s, t;
    std::cin >> s >> t;
    long long a, b;
    std::cin >> a >> b;
    std::string u;
    std::cin >> u;

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


Measured memory_bytes: 256
import numpy as np
import copy


def dfs(adj_list, cur_node, visited_nodes):
    visited_nodes.append(cur_node)

    # next_nodes = np.argwhere(adj_mat[cur_node] != 0).flatten()
    next_nodes = adj_list[cur_node]

    if len(next_nodes) == 0:
        # N
        visited_nodes.remove(cur_node)
        return 0

    for tup in next_nodes:
        if tup[0] in visited_nodes:
            visited_nodes.remove(cur_node)
            return np.inf

    # score_max = max([dfs(adj_list, b, visited_nodes) + c
    #                  for b, c in next_nodes])
    scores = []
    for b, c in next_nodes:
        score = dfs(adj_list, b, visited_nodes) + c
        if np.isinf(score):
            visited_nodes.remove(cur_node)
            return np.inf
        scores.append(score)

    score_max = max(scores)

    visited_nodes.remove(cur_node)
    return score_max


def main():
    N = int(input())
    S = input()

    y_max = 0
    y = 0
    for c in S:
        if c == '(':
            y -= 1
        else:
            y += 1

        if y > y_max:
            y_max = y

    S_ans = ''
    if y_max > 0:
        S_ans += '(' * y_max
        y -= y_max

    S_ans += S

    if y < 0:
        S_ans += ')' * (-y)

    # if __debug__:
    #     y_max = 0
    #     y = 0
    #     for c in S_ans:
    #         if c == '(':
    #             y -= 1
    #         else:
    #             y += 1

    #         if y > y_max:
    #             y_max = y

    #         assert y <= 0

    #     assert y_max == 0

    print(S_ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12432
#include<stdio.h>
int main(){
  int n,x,count=0,i;
  scanf("%d%d",&n,&x);
  int l[n+2];
  for(i=1;i<=n;i++)
    scanf("%d",&l[i]);
  i=0;
  while(count<=x && i<n+1){
    i++;
    if(i<n+1)
      count+=l[i];
  }
  printf("%d\n",i);
  return 0;
}


Measured memory_bytes: 128
<?php
$money = trim(fgets(STDIN));
$cake = trim(fgets(STDIN));
$donut = trim(fgets(STDIN));
$budget = $money - $cake;
while ($budget > 0) {
  if ($donut <= $budget) {
    $budget -= $donut;
  } else {
    break;
  }
}
echo $budget."\n";


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
 
int main(){
    int n,m; cin >> n >> m;
    vector <int> broken(n+1);
    rep(i,m){
        int a; cin >> a;
        broken[a]=1;
    }
    
    vector <int> dp(n+2,0);
    const int mod = 1e9+7;
    dp[n]=1;
    for (int i=n-1; i>=0; i--){
        if (broken[i]){
            dp[i]=0;
            continue;
        }
        dp[i]=(dp[i+1]+dp[i+2])%mod;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

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

        for (int i = 0; i < n.length(); i++) {
            if (n.charAt(i) == '1') {
                n.setCharAt(i, '9');
            } else if(n.charAt(i) == '9') {
                n.setCharAt(i, '1');
            }
        }

        System.out.println(n);
    }
}


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

vector < int > v , c ; 

int main() {

    int n, sum =0  ; 
    cin >> n ; 
    v.resize(n) ;
    c.resize(n) ;
    
    c[0] = 0 ; 
    
    for ( int i = 0 ; i < n ; ++i ){
        cin >> v[i] ; 
        
        if ( i == 1 ){
            c[i] = abs ( v[i-1] - v[i] ) ; 
        }
        else if ( i > 1 ){
            c[i] = min ( abs ( v[i-2] - v[i] ) + c[i-2] , abs ( v[i-1] - v[i] ) + c[i-1] ) ; 
        }
    }
    
    cout << c[n-1] ; 
    

  return 0 ; 
}

Measured memory_bytes: 1024
N = int(input())
i = 0
total = 0
while True:
    total += i
    if total >= N:
        tmp = i
        break
    i += 1

for j in range(tmp, 0, -1):
    if N - tmp >= 0:
        N -= tmp
        print(tmp)
    if N == 0:
        break
    tmp -= 1


Measured memory_bytes: 3316