akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main (void){
  int n;
  int i;


  scanf("%d",&n);
  int a[n];



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


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

  return 0;
}

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

using namespace std;

const int INF = 1145141919;

vector<int> g[100010];
int N, K;
int ans = 0;

int dfs(int cur, vector<int>& used) {
	int res = 0;
	for (int nex : g[cur]) {
		res = max(res, dfs(nex, used) + 1);
	}
	if (cur != 0 && res == K - 1) {
		if (!used[cur]) {
			ans++;
			used[cur] = true;
		}
		res = -1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		a[i]--;
	}

	vector<int> used(N, false);
	used[0] = true;
	for (int i = 1; i < N; i++) {
		g[a[i]].push_back(i);
		if (a[i] == 0) used[i] = true;
	}
	dfs(0, used);

	ans += (a[0] != 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12800
while True:
    s = input()
    if s == '-':
        break
    else:
        n = int(input())
        hl = list(int(input()) for _ in range(n))
        ss = list(s)
        tmp = []
        for h in hl:
            tmp = ss[h:] + ss[:h]
            ss = tmp
        print(*ss, sep='')



Measured memory_bytes: 5628
#include <stdio.h>

int main(void)
{
    int a, b, p;

    if(scanf("%d %d", &a, &b) == 1);

    if(13 <= a) p = b;
    else if(6 <= a && a <= 12) p = b / 2;
    else p = 0;
    printf("%d\n", p);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string>s(n);
  int i,j;
  for(i=0;i<n;i++){
    cin >> s[i];
  }
  vector<int>alp(26);
  vector<int>alptmp(26);

  for(i=0;i<s[0].length();i++){
    int ss = (int)(s[0][i]-'a');
    alp[ss]++;
  }
  for(i=1;i<n;i++){
    for(j=0;j<26;j++){
      alptmp[j] = 0;
    }
    for(j=0;j<s[i].length();j++){
      int ss = (int)(s[i][j]-'a');
      alptmp[ss]++;
    }
    for(j=0;j<26;j++){
      alp[j] = min(alp[j],alptmp[j]);
    }
  }
  string tmp = "";
  for(i=0;i<26;i++){
    char moji = (char)(i+'a');

    while(alp[i]>0){
      tmp += moji;
      alp[i]--;
    }
  }
  cout << tmp << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < (int) s.size(); i++) {
    if (s[i - 1] == s[i]) {
      ans++;
      s[i] = '1' + '0' - s[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n; 
    vector<double> p(n);
    rep(i,n) cin >> p[i];
    vector<vector<double>> dp(3030,vector<double>(3030,0));
    dp[0][0] = 1.0;
    for(int i=1;i<=n;i++){
        rep(j,i+1){
            if(j>0) dp[i][j] = dp[i-1][j] * (1-p[i-1]) + dp[i-1][j-1] * p[i-1];
            else  dp[i][j] = dp[i-1][j] * (1-p[i-1]);
        }
    }
    double ans = 0;
    for(int i=(n+1)/2;i<=n;i++){
        //cout << dp[n][i] << endl;
        ans += dp[n][i];
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 72192
import sys
sys.setrecursionlimit(10**6+1) #再帰関数の上限,10**5以上の場合python


def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None


#N, Q = map(int, input().split())
N, Q = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
#S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

edge = [[] for i in range(N)]
for i in range(N-1):#木の場合M=N-1
    a,b,c,w = map(int,input().split())
    edge[a-1].append((b-1,c-1,w))
    edge[b-1].append((a-1,c-1,w)) #有向のばあいコメントアウト



#ダブリングによるLCA, 前処理NlogN, 呼び出しlogN, 安定  
def dfs(start):
    q=[(start,-1,0,0)]
    pars=[-1]*N
    depth=[-1]*N
    dist=[-1]*N
    while len(q):
        e,p,d,dis=q.pop()#ここをpopleftにすると幅優先探索BFSになる
        if depth[e]!=-1:continue
        pars[e]=p
        depth[e]=d
        dist[e]=dis
        for ne,c,w in edge[e]:
            q.append((ne,e,d+1,dis+w))
    return pars,depth,dist
pars,d,dist=dfs(0)
ln=N.bit_length()
dp=[[-1]*N for _ in range(ln+1)]
dp[0]=pars
for i in range(1,ln+1):
    for j in range(N):
        dp[i][j]=dp[i-1][dp[i-1][j]]


# LCAの計算
def lca(u, v):
    du = d[u]; dv = d[v]
    if du > dv:
        du, dv = dv, du
        u,v=v,u
    dif=dv-du
    for i in range(ln+1):
        if (dif>>i)&1:
            v=dp[i][v]
    if u==v:return u
    for i in range(ln,-1,-1):
        pu=dp[i][u];pv=dp[i][v]
        if pu!=pv:
            u,v=pu,pv
    return pars[u]

q=Q
#qs = tuple(tuple(map(int, input().split())) for i in range(Q)) #改行行列
# ans=[0]*Q
# qn=[[] for _ in range(N)]
# for i,(x,y,u,v) in enumerate(qs):
#     ans[i]=dist[u-1]+dist[v-1]-dist[lca(u-1,v-1)]
#     qn[u-1].append((i,x-1,y))
#     qn[v-1].append((i,x-1,y))
# cnt=[0]*Q
# #printe(qn)

# qc=[[0,0] for _ in range(Q)]
# cc=[[0,0] for _ in range(N-1)]

# dfq=[(0,None,0,-1)]
# def dfs2(e,c,d,p):
#     if c!=None:
#         cc[c][0]+=1
#         cc[c][1]+=d
#     for qi,x,y in qn[e]:
#         if cnt[qi]==0:
#             qc[qi][0]-=cc[x][0]
#             qc[qi][1]-=cc[x][1]
#         elif cnt[qi]==1:
#             qc[qi][0]+=cc[x][0]
#             qc[qi][1]+=cc[x][1]
#             ans[qi]+=y*qc[qi][0]-qc[qi][1]
#         cnt[qi]+=1
#     for ne,nc,nd in edge[e]:
#         if ne==par[e]:continue
#         dfs2(ne,nc,nd,e)
#     if c!=None:
#         cc[c][0]+=1
#         cc[c][1]+=d
# dfs2(0)
# printl(ans)
n=N
A = [0]*q
C = [[] for _ in range(n)]
num = [0]*n
cum = [0]*n
for i in range(q):
  x, y, u, v = map(int, input().split())
  u -= 1
  v -= 1
  a = lca(u, v)
  C[u].append((i, x, y, 1))
  C[v].append((i, x, y, 1))
  C[a].append((i, x, y, -2))
dist = 0
stack = [0]
def dfs2(v):
  global dist
  for i, x, y, b in C[v]:
    A[i] += (dist + num[x]*y - cum[x]) * b
  for nv, c, d in edge[v]:
    c+=1
    if nv ==pars[v]:continue
    dist += d
    num[c] += 1
    cum[c] += d
    dfs2(nv)
    dist -= d
    num[c] -= 1
    cum[c] -= d
dfs2(0)
print(*A, sep="\n")

Measured memory_bytes: 184440
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<vector<int>> a;
    for(int h=1;h<200;++h)
        for(int w=h+1;w<200;++w)
            a.push_back({h*h+w*w, h, w});

    sort(a.begin(), a.end());
    int h, w;
    while (true) {
        cin>>h>>w;
        if (h==0 and w==0) break;
        vector<int> t={h*h+w*w, h, w};
        auto res=*upper_bound(a.begin(), a.end(), t);
        cout<<res[1]<<" "<<res[2]<<endl;
    }
}

Measured memory_bytes: 2308
from collections import defaultdict
import itertools

N, K = map(int, input().split())
A = [int(c)-1 for c in input().split()]
A = [0] + A
Acum = list(itertools.accumulate(A))
Acum = [x%K for x in Acum]

counter = defaultdict(int)

ans = 0
for i,x in enumerate(Acum):
  ans += counter[x]
  counter[x] += 1
  if i>=K-1:
    counter[Acum[i-K+1]] -= 1
print(ans)

Measured memory_bytes: 115960
h,w,d=map(int,input().split())
num=[0]*(h*w)
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        num[a[j]-1]=(i,j)

cost=[0]*(h*w)
for i in range(d,h*w):
    cost[i]=cost[i-d]+abs(num[i][0]-num[i-d][0])+abs(num[i][1]-num[i-d][1])

q=int(input())
ans=[0]*q
for i in range(q):
    l,r=map(int,input().split())
    ans[i]=cost[r-1]-cost[l-1]

print(*ans,sep='\n')

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    ll min_num = 1e10;
    rep(i, n - k + 1 ) {
        min_num = min(min_num, h[i+k-1] - h[i]);
    }
    cout << min_num << endl;
    return 0;
}

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

using namespace std;

int main(void) {
	
	int x;
	cin >>x;
	
	if (x==3 || x==5 || x==7) {
		cout <<"YES" <<endl;
	} else {
		cout <<"NO" <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

 
int main(void)
{
	int  a,b, c;
	
	scanf("%d" , &a);
	scanf("%d" , &b);
	scanf("%d" , &c);
		
	if(a<b) {
		if(b<c){
			printf("%d %d %d\r\n", a,b,c);		
		}
		else{
			if(a<c){
				printf("%d %d %d\r\n", a,c,b);
			}
			else{
				printf("%d %d %d\r\n", c,a,b);								
			}
		}
	}
	else{
		if(a<c){
			printf("%d %d %d\r\n", b,a,c);		
		}
		else{
			if(b<c){
				printf("%d %d %d\r\n", b,c,a);					
			}
			else{
				printf("%d %d %d\r\n", c,b,a);								
			}
		}
	}

	 return 0;	 
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;

vector<bool> b_sta(1e5+10,false);

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> dp(n+5,0);
  rep(i,m) {
    int a;
    cin >> a;
    b_sta[a] = true;
  }
  dp[0] = dp[1] = 1;
  for(int i=2;i<=n;i++){
    //一段前からくる
    if(b_sta[i-1] == false) dp[i] += (dp[i-1]%mod);
    //二段前からくる
    if(b_sta[i-2] == false) dp[i] += (dp[i-2]%mod); 
    dp[i]%=mod;
  } 
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
a=int(input())
b=[0]*a
import sys
for i in range(a):
    b[i]=int(input())
b.sort()
c=sum(b)
if c%10==0:
    for i in range(a):
        if b[i]%10!=0:
            c=c-b[i]
            print(c)
            sys.exit()
    print(0)
else:
    print(c)


Measured memory_bytes: 62556
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;

int n,dp[101010],a,b,vis[101010],leaf,deg[101010];
vi adj[101010];
bool flag;

void init(){
       for(int i=1;i<=n;i++){
              dp[i]=0;
              vis[i]=0;
       }
       flag = true;
}
/*bool can2(int pos, int b){
       if(pos<0)return true;
       int k = v.size();
       int itr = k/2,mx=0;
       for(int i=0;i<k;i++){
              if(i!=pos)q.pb(v[i]);
       }
       int i=0;
       sort(all(q));
       while(itr--){
              int cur = q[i++]+q.back();
              mx = max(cur,mx);
              q.pop_back();
       }
       q.clear();
       return mx<=b;
}*/
int dfs(int s, int p){
       vi v;
       for(auto t:adj[s]){
              if(t!=p){
                    int m = dfs(t,s);
                    if(m!=inf)v.pb(m);
                    else return inf;
                     //v.pb(dp[t]);
              }
       }
       if(p==-1)return 0;
       if(v.size()==0)return 1;
       sort(all(v));
       int k = (int)v.size();
       flag = true;
       if(k%2==0){
              for(int i=0;i<k/2;i++){
                     if(v[i]+v[k-i-1]>b)flag = false;
              }
              if(flag)return 1;
              v.pop_back();
       }
       //if(!can2(k-1,b))flag=false;
       k = v.size();
       int l=-1,r=k;
       while(r-l>1){
              int mid = (l+r)/2;
              int ll=0,rr=k-1;
              flag = true;

              for(int i=0;i<k/2;i++){
                     if(ll==mid)ll++;
                     if(rr==mid)rr--;
                     if(v[ll]+v[rr]>b)flag = false;
                     ll++;rr--;
              }
              if(flag)r=mid;
              else l=mid;
       }
       if(r==k)return inf;
       if(v[r]+1>b)return inf;
       return v[r]+1;
}
bool can(int x){
       init();
       b = x;
       return dfs(leaf,-1)!=inf;
}

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

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

cin >> n;
for(int i=1;i<n;i++){
       int x,y;
       cin >> x >> y;
       adj[x].pb(y);
       adj[y].pb(x);
       deg[x]++;
       deg[y]++;
}
for(int i=1;i<=n;i++){
       if(deg[i]%2)a++;
       if(deg[i]==1)leaf=i;
}
int l=0,r=n,ans;
while(r-l>1){
       int mid = (l+r)/2;
       if(can(mid)){
              r=mid;
       }
       else {
              l=mid;
       }
}

cout << a/2 << " " << r << endl;





return 0;}
///....


Measured memory_bytes: 20608
def LI(): 
    return list(map(int,input().split()))

n, m = LI()
ks = [LI() for _ in range(m)]
p = LI()

count_total = 0

for i in range(2**n):
    bit = [(i>>j)&1 for j in range(n)]
    failed = False
    for k in range(m):
        kx = ks[k][0]
        count_on = 0
        for l in range(1, kx + 1):
            skl = ks[k][l]
            count_on += bit[skl - 1]
        if count_on % 2 != p[k]:
            failed = True
    if not failed:
        count_total += 1

print(count_total)
    

Measured memory_bytes: 43228
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long 
int main(){
    ll n,lower,cnt=0,max_cnt=0;
    vector<ll> h;
    cin>>n;
    h.resize(n);
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    lower=h[0];
    for(int i=1; i<n; i++){
        if(lower>=h[i]){
            lower=h[i];
            //cout<<"lower : "<<h[i]<<endl;
            cnt++;
        }else{
            lower=h[i];
            if(cnt>max_cnt){
                max_cnt=cnt;
                //cout<<"max_cnt : "<<max_cnt<<endl;
            }
            cnt=0;
        }
    }
    if(cnt>max_cnt){
        max_cnt=cnt;
        //cout<<"max_cnt : "<<max_cnt<<endl;
    }
    cout<<max_cnt<<endl;
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        String str2 = sc.next();
        char[][] c = new char[2][n];
        for (int i = 0; i < n; i++) {
            c[0][i] = str.charAt(i);
        }
        for (int i = 0; i < n; i++) {
            c[1][i] = str2.charAt(i);
        }
        
        long ans = 1;
        int offset = 0;
        int type = 0;
        if (c[0][0] == c[1][0]) {
            ans *= 3;
            offset++;
            type = 1;
        } else {
            ans *= 6;
            offset += 2;
            type = 2;
        }
        
        for (int i = 0 + offset; i < n; i++) {
            if (c[0][i] == c[1][i]) {
                if (type == 1) {
                    ans *= 2;
                    ans %= MOD;
                } else {
                    ans *= 1;
                    ans %= MOD;
                }
                type = 1;
            } else {
                if (type == 1) {
                    ans *= 2;
                    ans %= MOD;
                } else {
                    ans *= 3;
                    ans %= MOD;
                }
                type = 2;
                i++;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

const long long INF = 1e18 + 19;
const long long maxSize = 1e5 + 17;

int cost(int a, int b)
{
    if(b == 0 || b == 4)
        return a;
    else if(b == 2)
    {
        if(a== 0 || a % 2 == 0)
            return 1;
        return 0;

    }
    else
    {
        if(a == 0)
            return 2;
        if(a % 2 == 1)
            return 1;
        return 0;
    }
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //dp[i][j] - len i, last in group j
    //dp[0][j] = 0 dp[1][j] - can easily fill
    //answer min(dp[n][j])
    //dp[i][j] = min(dp[i][k]) (k <= j) + check
    long long n;
    cin >> n;
    vector<long long> v(n + 1, 0);
    vector<vector<long long> > dp(n + 1, vector<long long>(5, 0));
    for(long long i = 1; i <= n; ++i)
        cin >> v[i];

    for(long long i = 0; i < 5; ++i)
        dp[0][i] = 0;

    dp[1][0] = dp[1][4] = v[1], dp[1][1] = dp[1][3] = (v[1] & 1), dp[1][2] = !(v[1] & 1);

    for(int i = 2; i <= n; ++i)
    {
        for(int j = 0; j < 5; ++j)
        {
            dp[i][j] = dp[i - 1][0] + cost(v[i], 0);
            for(int k = 1; k <= j; ++k)
                dp[i][j] = min(dp[i - 1][k] + cost(v[i], k), dp[i][j] );
        }
    }

    long long answer = INF;
    for(long long i = 0; i < 5; ++i)
        answer = min(answer, dp[n][i]);

    cout << answer << '\n';

}






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

using namespace std;

 

char h[1000][1000];//第一个方括号记录第i个字符串，第二个方括号记录第i个字符串的第j个字符。

int s[1000],ans1[1000],ans2[1000];

 

int main(){

	int n,flag = 0;

	scanf("%d",&n);

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

		scanf("%s",h[i]);//这里字符串的输入要注意一下

		s[i] = strlen(h[i]);

	}

	for(int i = 49;i <=74;i++){

		ans2[i] = 10000000;//初始化

	}

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

		for(int j = 0;j < s[i];j++){

	    	ans1[h[i][j] - '0']++;

		}

		for(int k = 49;k <= 74;k++){

			ans2[k] = min(ans1[k],ans2[k]);

		}

		memset(ans1,0,sizeof(ans1));

	}

	char p;

	for(int i = 49;i <= 74;i++){

		if(ans2[i] != 0){

			for(int j = 1;j <= ans2[i];j++){

				flag = 1;

				printf("%c",i + '0');

			}

		}

	}

	if(flag == 0) printf("\n");

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define vi vector<long long>
#define pi pair<ll ,ll>
#define mkp make_pair
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e8;
const ll INF = (ll)1e18+1;

struct E
{
    ll a, b, c;
};

ll n, m, p, af, aa, aaa, x;
vector<E> e;
vi adj[2501];
vi v(2501);
vi d(2501, INF);

void dfs(int x)
{
    v[x]=1;
    for(auto i : adj[x])
    {
        if(!v[i]) dfs(i);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m >> p;
    for(int i=0; i<m; i++)
    {
        cin >> af >> aa >> aaa;
        adj[aa].pb(af);
        e.pb({af, aa, -(aaa-p)});
    }
    dfs(n);
    d[1]=0;
    for(int i=0; i<n-1; i++)
    {
        for(auto cur : e)
        {
            if(d[cur.a]<INF)
            {
                ll y = d[cur.a]+cur.c;
                if(y<d[cur.b])
                {
                    d[cur.b] = y;
                    x=cur.a;
                }
            }
        }
    }
    for(auto cur : e)
    {
        if(d[cur.a]<INF)
        {
            ll y = d[cur.a]+cur.c;
            if(y<d[cur.b])
            {
                if(v[cur.a])
                {
                    cout << -1;
                    return 0;
                }
            }
        }
    }
    cout << max(0LL, -d[n]);
}


Measured memory_bytes: 768
from collections import Counter
n, m, *d = map(int, open(0).read().split())
a = Counter(d[:n])
for b, c in zip(d[n::2], d[n+1::2]):
    a[c] += b
ans = 0
for k, v in sorted(a.items())[::-1]:
    if n < v:
        exit(print(ans + k * n))
    n -= v
    ans += k * v

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

int main()
{
  string s;
  cin>>s;
  
  
  
    if(s=="SUN")
    {
         int ans=7;
        cout<<ans<<endl;
    }
    
    else if(s=="MON")
    {
         int ans=6;
        cout<<ans<<endl;
    }
    
    else if(s=="TUE")
    {
         int ans=5;
        cout<<ans<<endl;
    }
    
    else if(s=="WED")
    {
         int ans=4;
        cout<<ans<<endl;
    }
    
    else if(s=="THU")
    {
         int ans=3;
        cout<<ans<<endl;
    }
    
    else if(s=="FRI")
    {
         int ans=2;
        cout<<ans<<endl;
    }
    
    else if(s=="SAT")
    {
         int ans=1;
        cout<<ans<<endl;
    }
    
      
    return 0;
  }
      
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007


int main() {
    FIN;
    int n, m;
    cin >> n >> m;
    int arreglo[n];
    forn(i,n) cin >> arreglo[i];
    sort(arreglo, arreglo+n);
    int suma=0;
    forn(i,n) suma+=arreglo[i];
    forn(i,m)
    {
        if((arreglo[n-1-i]*4)*m < suma)
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int N;

void generate(string S, int n, int m) {
    if (n == N) {
        cout << S << endl;
        return;
    }

    REP(i, 0, n + 1) {
        if (i > m + 1) break;
        generate(S + (char)('a' + i), n + 1, max(m, i));
    }
}

int main() {
    cin >> N;
    generate("", 0, 0);
    return 0;
}

Measured memory_bytes: 1536
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    k = int(input())

    lens = len(s)
    if len(s) == 1:
        print(k // 2)
        sys.exit()

    if k == 1:
        r2 = 0
        rt = 1
        c = ""
        flag = False
        for se in s:
            if c == se:
                flag = True
                rt += 1
            else:
                c = se
                if flag:
                    r2 += rt // 2
                    rt = 1
                    flag = False
        r2 += rt // 2
        print(r2)
        sys.exit()

    s_daburi = 0
    s_last = s[-1]
    while s_daburi < lens:
        if s[s_daburi] == s_last:
            s_daburi += 1
        else:
            break
    s1 = s + s_last * s_daburi

    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s1:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    if s_daburi == lens:
        if k % 2 == 0:
            r = r2 * (k // 2)
            print(r)
            sys.exit()
        else:
            r = r2 * (k // 2) + lens//2
            print(r)
            sys.exit()

    r = r2
    s2 = s[s_daburi:] + s_last * s_daburi
    r2 = 0
    rt = 1
    c = ""
    flag = False
    for se in s2:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r2 += rt // 2
                rt = 1
                flag = False
    r2 += rt // 2

    s3 = s[s_daburi:]
    r3 = 0
    rt = 1
    c = ""
    flag = False
    for se in s3:
        if c == se:
            flag = True
            rt += 1
        else:
            c = se
            if flag:
                r3 += rt // 2
                rt = 1
                flag = False
    r3 += rt // 2
    if k == 2:
        print(r + r3)
    else:
        print(r + r3 + r2 * (k-2))



if __name__ == '__main__':
    main()


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

using namespace std;

/*
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;*/

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

void printV(vi v) {
    for (int i = 0; i<v.size(); ++i) cout << v.at(i) << " ";
    cout << "\n";
}

//g++ -std=c++11 -O2 -Wall c.cpp

void solve() {
    ll n; cin >> n;
    ll a=1,b=1;
    ll count = 0;
    while (a*b < n) {
        while (a*b < n) {
            count++;
            b++;
            //cout << a*b << endl;
        }
        a++;
        b = 1;
    }
    cout << count << "\n";

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    solve();


    /**
     * ALGORITHME DE TRI ET EN LEVER LES DUPLICATES
     * set<int> s( v.begin(), v.end() );
     * v.assign( s.begin(), s.end() );
     * */
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
int ara_D[100][200];
int ara[100000];
char ara1[100000];
int main()
{
    int i,j,k,l,a,b,h,area;
    gets(ara1);
    printf("A%cC\n",ara1[8]);
    return 0;
}




Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        double monies[] = new double[N];
        String currencies[] = new String[N];

        for (int i = 0; i < N; i++){
            
            monies[i] = sc.nextDouble();
            currencies[i] = sc.next();
        }

        double total = 0;
        int coefficient = 0;

        for (int i = 0; i < N; i++){
            
            if (currencies[i].equals("JPY")) {
                coefficient = 1;
            } else if ( currencies[i].equals("BTC")) {
                coefficient = 380000;
            } else {

            }

            total += (monies[i] * coefficient);
        }



        System.out.println(total);
     }
}

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

int N, K;

int main(){
    cin >> N >> K;
    long long ans = 0;
    for(int b = K+1; b <= N; b++){
        ans += (N/b) * (b-K) + max(0, (N%b) - K + 1);
    }
    if(K == 0){
        ans -= N;
    }
    cout << ans << endl;
}


            

Measured memory_bytes: 256
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  map<int,int> a;
  int tot=0;
  rep(i,n){
      int tmp;cin>>tmp;
      auto itr=a.find(tmp);
      if(itr!=a.end())a[tmp]++;
      else a[tmp]=1;
  }
  for( auto itr=a.begin();itr!=a.end();++itr){
      if((itr->first)<(itr->second))tot+=itr->second-itr->first;
      else if((itr->first)>(itr->second)) tot+=itr->second;
  }
  cout<<tot<<endl;
  return 0;
  }


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rp(i,n) cin >> h.at(i);
    int ans=0;
    for(int i=1; i<=100; i++){
        rp(j,n-1){
            if(h[j]>=i&&h[j+1]<i) {
                ans++;
            }
        }
        if(h[n-1]>=i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int calc(int n){
  if(n == 1 || n == 0) return 0;
  return calc(n-2);
}

int main(int argc, char const *argv[]) {
  unsigned long long int res = 0;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    for(int j = 1; j+i <= s.size(); j++){
      int p1 = (int)pow(2.0, i==0?0:i-1);
      int p2 = (int)pow(2.0, i+j-1==s.size()-1?0:s.size()-i-j-1);
      unsigned long long int stmp = stoll(s.substr(i, j));
      for(int k = 0; k < p1*p2; k++){
        res += stmp;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int a,b,c,sum;
  
  scanf("%d%d%d", &a, &b, &c);
  
  sum = a + b;
  
  if (sum >= c){
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

int main()
{
    const int a_size = 3;
    vector <int> a(a_size);
    REP(i,a_size)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
void insertionSort(vector<int>& A,int N){
    for(int i=0;i<N;i++){
        int v = A[i];
        int j= i-1;
        while(j>=0&&A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1] =v;
        for(int k=0;k<N;k++){
            cout<<A[k];
            if(k<N-1)cout<<" ";
        }
        cout<<endl;
    }
}
int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++){
      cin>>A[i];
  }
  insertionSort(A,N);
  return 0;
}


Measured memory_bytes: 3088
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func modpow(a, n, mod int64) int64 {
	r := int64(1)

	for {
		if (n & 1) == 1 {
			r = (r * a) % mod
		}
		n = n >> 1
		a = (a * a) % mod
		if n <= 0 {
			break
		}
	}

	return r
}

func calcsmall(k int) int {
	return (k - 1) * k / 2
}

func calclarge(k, n int) int {
	return (2*n - k + 1) * k / 2
}

func sumscount(N, K int) int {
	sums := 0
	for i := K; i <= (N + 1); i++ {
		small := calcsmall(i)
		large := calclarge(i, N)

		cnt := large - small + 1
		sums += cnt
	}
	return sums
}

func main() {
	lines := inputs(1)

	tmp := strings.Split(lines[0], " ")
	N, _ := strconv.Atoi(tmp[0])
	K, _ := strconv.Atoi(tmp[1])
	MOD := int64(math.Pow10(9) + 7)

	ans := int64(sumscount(N, K)) % MOD
	fmt.Println(ans)

}

Measured memory_bytes: 1828
n, *a = map(int, open(0).read().split())           
a.sort()                                           
s = set()                                          
checked = set()                                    
dup = set()                                        
count = 0                                          
for x in a:                                        
    if x in s:                                     
        if x in checked:                           
            dup.add(x)                             
        continue                                   
    count += 1                                     
    checked.add(x)                                 
    for i in range(1, 10**6 // x + 1):             
        s.add(x * i)                               
                                                   
print(count - len(dup))                            

Measured memory_bytes: 177120
import sys
 
while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break
    members = []
    sales  = {}
    for i in range(n):
        e,p,q = sys.stdin.readline().rstrip().split(' ')
        if not e in members:
            members.append(e)
            sales[e] = 0
        sales[e] += int(p) * int(q)
    ret = [member for member in members if sales[member] >= 1000000]
    if len(ret) != 0:
        for d in ret:
            print(d)
    else:
        print("NA")

Measured memory_bytes: 6448
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    vector < ll > vec;

    while(cin >> n >> m)
    {
		vec.clear();

		for(i = 0; i < n; i++)
		{
			cin>> input;
			vec.push_back(input);
		}

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

		ans = 0;

		for(i = 0; i < m; i++)
		{
			ans += vec[i];
		}

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


}





Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int K, A, B;
  	double S;
  	cin >>K >> A >>B;
	for (int i = A; i <= B; i++) {
    	S=i%K;
    	if (S==0){
        	cout <<"OK" <<endl;
          	break;
        }
      	else if(i==B && S!=0) {
        	cout <<"NG" <<endl;
          	break;
        }
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<int> t(n+1);
    t.at(0)=0;
    vector<P> point(n+1);
    point.at(0).first=0;
    point.at(0).second=0;
    for(int i=1;i<n+1;++i){
        cin>>t.at(i)>>point.at(i).first>>point.at(i).second;
    }
    bool flag=true;
    rep(i,n){
        int dt,dist;
        dt=t.at(i+1)-t.at(i);
        dist=abs(point.at(i+1).first-point.at(i).first)
            +abs(point.at(i+1).second-point.at(i).second);
        if(dt<dist) flag=false;
        if(dt%2!=dist%2) flag=false;
    }
    if(flag) cout<<"Yes"<<endl;
    else     cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std; 
const int maxn = 200500;
int cnt[maxn];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long n;
    cin >> n;
    if(n & 1) return cout << 0 << '\n', 0;
    long long pw = 2;
    long long tw = 0, fv = 0;
    long long idx = 1;
    while(pw <= n / 5){
        pw *= 5LL;
        fv += idx * (n / pw - n / (pw * 5LL));
        idx++;
    }
    idx = 1;
    pw = 1LL;
    while(pw <= n / 2){
        pw *= 2LL;
        tw += idx * (n / pw - n / (pw * 2LL));
        idx++;
    }
    cout << min(fv, tw);
    return 0;
}


Measured memory_bytes: 256
import { readFileSync } from 'fs'

const notFind = '-1'

const search = (list: number[], log: string): string => {
  if (list.length === 0) return log

  for (let i = list.length; i--;) {
    if (i + 1 !== list[i]) continue

    const nextList = list.filter((_, index) => index !== i)
    const result = search(nextList, `${i + 1}\n${log}`)

    if (result === notFind) continue

    return result
  }

  return notFind
}

function main(input: string) {
  const [len, bList] = input.split('\n').map(v => v.split(' ').map(Number))

  if (bList.some((v, i) => v > i + 1)) {
    console.log(notFind)
    return
  }

  const result = search(bList, '')

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 7500
#include<stdio.h>

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

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define int ll


int32_t main(){
    FAST
    int n; cin >> n;
    vector<int> vec1;
    map<int, vector<int> > mp;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        vec1.pb(arr[i] + i);
        mp[i - arr[i]].pb(i);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += mp[vec1[i]].size() - (upper_bound(mp[vec1[i]].begin(), mp[vec1[i]].end(), i) - mp[vec1[i]].begin());
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 40548
#include<iostream>
using namespace std;
int main(){
    int m,d;
    double n;
    double ans=0;
    cin >> n >> m >> d;
    if(d ==0){
        ans= n * (m - 1) /(n*n);
    }else{
        ans= (n-d)*2 * (m - 1) /(n*n);
    }
    printf("%10.10lf", ans);
    return 0;
}

Measured memory_bytes: 256
D = ((-1,0),(0,1),(1,0),(0,-1))
while 1:
    N = int(input())
    if not N:break

    min_x = min_y = max_x = max_y = 0

    a = [(0,0)]
    for i in range(N-1):
        n1, d1 = list(map(int, input().split()))
        spam = (lambda x: (x[0] + D[d1][0],  x[1] + D[d1][1]))(a[n1])
        min_x = min(spam[0],min_x)
        min_y = min(spam[1],min_y)
        max_x = max(spam[0],max_x)
        max_y = max(spam[1],max_y)
        a.append(spam)

    print('%d %d' % (max_x - min_x + 1, max_y - min_y + 1))

Measured memory_bytes: 6736
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

flag = 0
if a.size % 2 == 0
    (a.size/2).downto(1) do |i|
        if flag == 0 then
            flag = 1
        else
            print " "
        end
        print "#{a[i*2-1]}"
    end
    0.step(a.size-2, 2) do |i|
        print " #{a[i]}" 
    end
else
    (a.size/2).downto(0) do |i|
        if flag == 0 then
            flag = 1
        else
            print " "
        end
        print "#{a[i*2]}"
    end
    1.step(a.size-2, 2) do |i|
        print " #{a[i]}" 
    end
end

print "\n"

Measured memory_bytes: 23820
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	LL n, min_t, num, ans;
	vector<LL> time(5);
	cin >> n;
	rep(i, 0, 5) cin >> time[i];
	SORT(time);
	min_t = time[0];
	num = n / min_t;
	if (n % min_t != 0) {
		num += 1;
	}
	ans = num + 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
t = input()
before_is_zero = True
n0 = 0
n1 = 0
seq1 = 0
ans = 0
for i, x in enumerate(t):
    if x == '0':
        n0 += 1
        before_is_zero = True
    elif before_is_zero:
        tmp_add = -(n0 - (i+1)%2)//2
        ans += tmp_add
        n1 += 1
        before_is_zero = False
    else:
        ans -= tmp_add
        n1 += 1
        seq1 += 1
        before_is_zero = True
ans += (n1 - seq1) * n0 + ((n1+1)//2) * (n1//2 + 1)
print(ans)

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

void chmin (int &a, int b) {
    if (a > b) a = b;
}

int main() {
    int n;
    cin >> n;
    vector<int> t(110), s(110), v(110);
    for (int i = 1; i <= n; i++) {
        cin >> t[i]; t[i] *= 2;
        s[i + 1] = s[i] + t[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> v[i]; v[i] *= 2;
    }
    s[n + 2] = s[n + 1];
    
    const int time = s[n + 1];
    vector<int> p(time + 1);
    for (int x = 0; x <= time; x++) {
        int res = numeric_limits<int>::max();
        for (int j = 0; j < n + 2; j++) {
            const int l = s[j], r = l + t[j];
            if (x < l) chmin(res, v[j] + (l - x));
            else if (x < r) chmin(res, v[j]);
            else chmin(res, v[j] + (x - r));
        }
        p[x] = res;
    }
    
    double ans = 0;
    for (int i = 0; i < time; i++) {
        double res = (double)(p[i] + p[i + 1]) / 2.0;
        ans += res;
    }
    
    cout << fixed << setprecision(5) << ans / 4.0 << '\n';
    return 0;
}

Measured memory_bytes: 384
from sys import stdin 

ABCD = stdin.readline().rstrip()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

def func1(ABCD,k):
    if k==len(ABCD)-1:
        return [[ABCD[k]],["-"+ABCD[k]]]
    prev_output = func1(ABCD,k+1)
    output = []
    if k==0:
        for ele in prev_output:
            temp = [ABCD[k]]
            temp.extend(ele)
            output.append(temp)
        return output

    for ele in prev_output:
        temp = [ABCD[k]]
        temp.extend(ele)
        output.append(temp)

        temp = ["-"+ABCD[k]]
        temp.extend(ele)
        output.append(temp)
    return output

def search_combi(combinations):
    for combi in combinations:
        tot_sum = 0
        for ele in combi:
            tot_sum+=int(ele)
        if tot_sum==7:
            return combi

combinations = func1(ABCD,0)
#print("search_copmbi:",search_combi(combinations))
def make_answer(numbers):
    output_string=""
    for i,num in enumerate(numbers):
        num_int = int(num)
        if i==0:
            output_string += num
        else:
            if num_int<0:
                output_string += "-"+num[1]
            else:
                output_string += "+"+num
    return output_string+"=7"


print(make_answer(search_combi(combinations)))

        

Measured memory_bytes: 3064
import java.util.Scanner;
import java.math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(gcd(a,b));
	}
	public static int gcd(int a, int b) {
		if(b == 0) {
			return a;
		}else if(a ==0 ) {
			return b;
		}
		else if(a>=b) {
			return gcd(b,a%b);
		}else {
			return gcd(a,b%a);
		}
	}

}


Measured memory_bytes: 26348
# test
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd
class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I] * (self.sz * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


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

int main(void)
{
    int N;
    cin >> N;
    vector<vector<int>> part(3, vector<int>(N));

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> part[i][j];
        }

        sort(part[i].begin(),part[i].end());
    }
    
    ll cases = 0;
    for (int mid = 0; mid < N; mid++)
    {
        ll as = lower_bound(part[0].begin(), part[0].end(), part[1][mid]) - part[0].begin();
        ll cs = N - (upper_bound(part[2].begin(), part[2].end(), part[1][mid]) - part[2].begin());

        cases += (as * cs);
    }
    
    cout << cases << endl;
    return 0;
}


Measured memory_bytes: 4744