akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

S = raw_input()
if S[-1] == '1' or S[0] == '0':
    print -1
    exit()

S = S[:-1]
N = len(S)

for i in range(N):
    if S[i] != S[N - i - 1]:
        print -1
        exit()

pos = 2
print "1 2"
for i in range(1, N):
    print pos, i + 2
    if S[i] == '1':
        pos = i + 2

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

using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
int inf_int=1e8;
ll inf_ll=4e18;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define siz(a) a.size()
#define sz size()

const int MAXN = 2e5+100;
int a[MAXN];
void bad(){
    cout <<"-1"<<endl;
    exit(0);
}
void solve(){
   int n;
   cin >> n;
   ll ans = 0;
   for(int i=1;i<=n;++i){
        cin >> a[i];
   }
   if(a[1]>0){
     bad();
   }
   for(int i=2;i<=n;++i){
      if(a[i]>a[i-1]+1)
        bad();
   }
   int cur = 0;
   for(int i=2;i<=n;++i){
       if(a[i]==cur+1){
        ans++;
       } else if(a[i]<=cur){
            ans+=a[i];
       }
       cur = a[i];
   }
   cout << ans<<endl;
}

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


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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

struct UnionFind {
    vector<int> par, treesize;
    int groups;
    
    UnionFind(int n){
        rep(i, n) par.push_back(i);
        treesize = vector<int>(n,1);
        groups = n;
    }
    
    int root(int x){
        if(x == par.at(x)) return x;
        return par.at(x) = root(par.at(x));
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        if(same(x,y)) return;
        int rx = root(x), ry = root(y);
        treesize[ry] += treesize[rx];
        treesize[rx] = 0;
        groups--;
        par.at(rx) = ry;
    }
    
    int get_size(int x){
        return treesize[root(x)];
    }
};

signed main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    while(m--){
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }
    cout << uf.groups << endl;
}

Measured memory_bytes: 4932
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<set>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second
 
using namespace std;

int main(){
  int n,x,y;
  cin >> n;
  x = 800 * n;
  y = 200 * (n / 15);
  cout << x - y << endl;
}


Measured memory_bytes: 3576
num = (0..9).to_a
while true do
  l = gets.chomp
  if l == "0 0" then
    exit
  end

  n_s, s_s = l.split " "
  n = n_s.to_i
  s = s_s.to_i

  count = 0
  num.combination(n).each do |arr|
    if arr.inject(:+) == s then
      count += 1
    end
  end

  puts count
end

Measured memory_bytes: 8764
// And Then the GOD Entered..   
#include<bits/stdc++.h>
 using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define fi first
#define sec second 
#define pb push_back
#define test cout<<"debuged\n";
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Minato_Namikaze ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015

int main()
{
    Minato_Namikaze
   
    
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if((a[0] == a[1] and a[1] != a[2]) or (a[0] == a[2] and a[1] != a[2]) or (a[2] == a[1] and a[1] != a[0]))
        cout << "Yes\n";
    else
        cout << "No\n";

    
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String str =sc.nextLine();
			String[] stra = str.split(" ");
			System.out.println(Integer.parseInt(stra[0]) + Integer.parseInt(stra[1]));
		}
		sc.close();
		
	}

}

Measured memory_bytes: 17456
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){
	double r,S,C;
	cin>>r;
	S=r*r*M_PI;
	C=r*2*M_PI;
	cout<<fixed<<setprecision(6)<<S<<" "<<C<<endl;
	return 0;
}

Measured memory_bytes: 1288
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    A,B,C=map(int,input().split())
    print(min(C,B//A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
 
int main(){
  int a;
  cin >> a;
  if(a==0)cout << 1 << endl;
  else cout << 0<< endl;
}

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

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a%=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  map<pair<ll,ll>,ll> cor;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    if(a!=0 && b!=0){
      ll gc = gcd(abs(a),abs(b));
      a = a/gc;
      b = b/gc;
    }
    else if(a==0 && b!=0) b = b/abs(b);
    else if(a!=0 && b==0) a = a/abs(a);    
    cor[{a,b}]++;
  }
  set<pair<ll,ll>> used;
  ll ans =1;
  for(auto i:cor){
    auto tcor = i.first;
    ll x = tcor.first;
    ll y = tcor.second;
    if(x>0 && y<0){
      swap(x,y);
      x = abs(x);
    }
    else if(x<0 && y>0){
      swap(x,y);
      y = abs(y);
    }
    else if(x<0 && y<0) {
      x = abs(x);
      y = abs(y);
    }
    else if(x==0 && y==0){

    }
    else if(x==0) {
      x=1;y=0;
    }
    else if(y==0){
      x=1;y=0;
    }
    

    if(used.count({x,y})) continue;
    else used.insert({x,y});
    // cout << x << " " << y << endl;
    if(x==0 && y==0){      
      continue;
    }


    ll pre1 = cor[{x,y}] + cor[{-x,-y}];
    ll pre2 = cor[{y,-x}] + cor[{-y,x}];

    ans = mu(ans,ad(mod -1, ad(pw(2,pre1),pw(2,pre2))));
  }
  
  ans = (ans + mod - 1)%mod;
  if(used.count({0,0})) ans = ad(ans,cor[{0,0}]);
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 65996
#include <iostream>

using namespace std;

int main() {
    int a[4] = {0, 0, 0, 0};
    int i;
    cin >> i;
    while (i--) {
        string s;
        cin >> s;
        if (s == "AC")a[0]++;
        if (s == "WA")a[1]++;
        if (s == "RE")a[2]++;
        if (s == "TLE")a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[3] << endl;
    cout << "RE x " << a[2] << endl;
    return 0;
}

Measured memory_bytes: 3608
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
res=0
for i in range(K):
    st=T[i::K]
    le=len(st)
    dp=[[0,0,0] for i in range(le+1)]
    for j in range(1,le+1):
        dp[j][0]=max(dp[j-1][1]+R,dp[j-1][2]+R) if st[j-1]=='s' else max(dp[j-1][1],dp[j-1][2])
        dp[j][1]=max(dp[j-1][0]+S,dp[j-1][2]+S) if st[j-1]=='p' else max(dp[j-1][0],dp[j-1][2])
        dp[j][2]=max(dp[j-1][0]+P,dp[j-1][1]+P)  if st[j-1]=='r' else max(dp[j-1][0],dp[j-1][1])
    res+=max(dp[le])
print(res)

Measured memory_bytes: 16448
# https://atcoder.jp/contests/abc152/tasks/abc152_d

s = gets.chomp
N = s.to_i
l = s.size

css = Array.new(10) { Array.new(10, 0) }

1.upto(9) do |i|
  1.upto(9) do |j|
    ix = s[0].to_i
    jx = s[-1].to_i
    c = 0
    c += (i <= N ? 1 : 0) if i == j
    (l - 2).times { |k| c += 10**k }
    if l >= 2
      if i < ix
        c += 10**(l - 2)
      elsif i == ix
        c += ('0' + s[1..-2]).to_i
        c += 1 if j <= jx
      end
    end
    css[i][j] = c
  end
end

# p css

ans = 0
1.upto(9) do |i|
  1.upto(9) do |j|
    ans += css[i][j] * css[j][i]
  end
end

puts ans


Measured memory_bytes: 1788
//....
#include<cstdio>
using namespace std;
#define N 1040
int n,fg,as[N][N];
int main()
{
	scanf("%d",&n);
	if(n<=9)
	{
		printf("%d\n",n);
		for(int i=1;i<=n;i++,printf("\n"))
		for(int j=1;j<=n;j++)
		printf("%d ",(i+j-2)%n+1);
		return 0;
	}
	if(n%4)fg=4-n%4,n+=fg;
	n/=2;
	for(int i=1;i<=n/2;i++)
	for(int j=1;j<=n/2;j++)
	{
		int st=(i+j-2)%(n/2)+1;
		as[i*2-1][j*2-1]=st*4-3;
		as[i*2-1][j*2]=st*4-2;
		as[i*2][j*2-1]=st*4-1;
		as[i*2][j*2]=st*4;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>3)as[i][j]--;
			else if(as[i][j]==3)as[i][j]=2;
		}
		fg--;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>6)as[i][j]--;
			else if(as[i][j]==6)as[i][j]=5;
		}
		fg--;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>9)as[i][j]--;
			else if(as[i][j]==9)as[i][j]=8;
		}
		fg--;
	}
	printf("%d\n",n);
	for(int i=1;i<=n;i++,printf("\n"))
	for(int j=1;j<=n;j++)
	printf("%d ",as[i][j]);
}

Measured memory_bytes: 3200
n, m = map(int, input().split())
l0, r0 = 1, n
for j in range(m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(max(0, r0-l0+1))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,a,d,m;
    cin >>n >>a >>d >>m;

    map<int,int> c;
    rep(i,m){
        int x,y,z;
        cin >>x >>y >>z;
        --y;
        --z;

        if(!c.count(y)) c[y] = a+y*d;
        if(!c.count(z)) c[z] = a+z*d;

        if(x==0) swap(c[y],c[z]);
        else c[y] = c[z];
    }

    int k;
    cin >>k;
    --k;

    int ans = a+k*d;
    if(c.count(k)) ans = c[k];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3120
/* ***********************************************
Author        :caoyu01
Created Time  :2016/9/4 20:32:25
File Name     :b.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cle(x) memset(x,0,sizeof(x))
#define rep(i,x) for(int i=0;i<x;i++)
const int N=2000+10;
const double eps=1e-10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll a[N],b[N],x;
int n;
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(cin>>n>>x){
		int i,j;
		ll ans=0;
		rep(i,n)cin>>a[i],b[i]=a[i],ans+=a[i];
		rep(i,n){
			rep(j,n){
				int ip=j+1;
				if(ip>=n)ip-=n;
				a[j]=min(a[j],b[ip]);
			}
			rep(j,n)b[j]=a[j];
			ll sum=0;
			rep(j,n)sum+=a[j];
			sum+=(i+1)*x;
			ans=min(ans,sum);
		}
		cout<<ans<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

int a[200000];
int main(void){
	int n, k, i;
	scanf("%d%d", &n, &k);
	for(i=0; i<n; i++){
		int b;
		scanf("%d", &b);
		a[b-1]++;
	}
	qsort(a, 200000, sizeof(int), compr);
	int sum=0;
	for(i=0; i<k; i++){
		sum+=a[i];
	}
	printf("%d\n", n-sum);
}


Measured memory_bytes: 1404
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(){
    ll n, a, b;
    ll r = 0;
    ll t = 0;
    cin >> n >> a >> b;
    r = n/(a+b) * a;
    t =  n % (a+b);
    if (t > a)  t = a;
    r += t;
    cout << r;
    
    
    
    
    return 0;
    
}


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

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int p, q, r;
    cin >> p >> q >> r;
    int ans = 1000;
    ans = min(ans, p+q);
    ans = min(ans, q+r);
    ans = min(ans, p+r);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
	ios::sync_with_stdio(false);
	
	string a,b;
	cin >> a >> b;
	
	int ka = len(a);
	int kb = len(b);
	if (ka > kb)
	{
		cout << "GREATER" << endl;
		return 0;
	}
	if (kb > ka)
	{
		cout << "LESS" << endl;
		return 0;
	}
	REP(i,ka)
	{
		if (a[i] > b[i])
		{
			cout << "GREATER" << endl;
			return 0;
		}
		if (b[i] > a[i])
		{
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    string a;
    int r[6][2]={{1,2},{-1,3},{1,-1},{4,5},{5,2},{2,1}};
    while(cin >> a,a != "#"){
        int now = 0;
        for(int i = 0; i < a.size(); i++){
            now = r[now][a[i]-'0'];
            if(now == -1){
                break;
            }
        }
        cout << (now == 5?"Yes":"No") << endl;
    }
    return 0;
}

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

#define cnd(c, a, b) (c ? a : b);
#define fl(x,y,z) for(int x=y;x<z;x++)
#define fe(x,y,z) for(int x=y;x<=z;x++)
#define fge(x,y,z) for(int x=y;x>=z;x--)

#define debug(x) std::cerr << #x << " --> " << x << "\n";
#define fastIO std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define pb push_back
#define pob pop_back
 
#define ln '\n'
typedef long long int ll;

ll mod=1e9+7;

ll a[1000001];

ll num_div(ll n) {
	ll val, cnt, ans;
	cnt = 0;
	ans = 1;

	val = -1;
	if(n==1) {
		return 1;
	}
	while(n>1) {
		val = a[n];
		cnt = 0;
		while(n%val==0) {
			n = n/val;
			cnt++;
		}
		ans = ans*(cnt+1);
	}
	return ans;
}
void decrypt() {
	ll n;
	cin>>n;
	ll ans = 0;
	fl(i,1,n) {
		ll pr = n-i;
		ans += (num_div(pr));
		// cout<<"DE: "<<pr<<" "<<ans<<ln;
	}
	cout<<ans<<ln;
	return;
}

int main() {
    fastIO
    fl(i,0,1000001) {
    	a[i] = i;
    }
    fl(i,2, 1000001) {
    	if(a[i]==i) {
    		for(int j=2*i; j<1000001;j+=i) {
    			a[j] = i;
    		}
    	}
    }
    int t = 1;
    // cin >> t;
    fl(i,0,t) {
    	// cout << "Case #"<< i+1 <<": ";
    	decrypt();
    }
    return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vi a(n + 1);
	a[0] = 0;
	int sum = 0;
	rep2(i, 1, n) {
		cin >> a[i];
		sum += abs(a[i - 1] - a[i]);
	}
	a.push_back(0);
	sum += abs(a[n] - a[n + 1]);
	rep2(i, 1, n) {
		int ans = sum - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1656
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n, m, x]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const c: number[] = [];
    const a: number[][] = [];
    for (let i = 0; i < n; i++) {
      const t: number[] = tmp.shift().split(" ").map(int => parseInt(int));
      c.push(t[0]);
      const l = [];
      for (let j = 0; j < m; j++) {
        l.push(t[j + 1]);
      }
      a.push(l);
    }
    let minCost = Infinity;
    for (let i = 1, len = Math.pow(2, n) - 1; i <= len; i++) {
      const xlist = [];
      for (let j = 0; j < m; j++) {
        xlist.push(0);
      }
      let cost = 0;
      const d = i.toString(2).split("");
      d.reverse();
      for (let j = 0, lenj = d.length; j < lenj; j++) {
        if (d[j] == "1") {
          for (let k = 0; k < m; k++) {
            xlist[k] += a[j][k];
          }
          cost += c[j];
        }
      }
      if (cost >= minCost) {
        continue;
      }
      let boo = true;
      for (let k = 0; k < m; k++) {
        if (xlist[k] < x) {
          boo = false;
          break;
        }
      }
      if (boo) {
        minCost = cost;
      }
    }
    return `${minCost == Infinity ? -1 : minCost}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 33612
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

bool ok(lli n, lli m , lli v, lli p, vector<lli>&A, lli k){
  // idx k はなりうるか
  lli val = A[k] + m;
  vector<lli> B;
  rep(i, n)if(i!=k)B.push_back(A[i]);
  v-=1;

  // BのB[p-1] 番目の最小化をしたい
  rep(i, p-1) B[i]+=m;
  v -= p-1;

  if(v<=0){
    return B[p-1] <= val;
  }
  // cerr << "HOGE"<< B.size()<<endl;
  // rep(i, B.size())cerr << B[i] << " ";
  // cerr << endl;



  vector<lli> C;
  rep(i, B.size()){
    if(i>=p-1){
      C.push_back(B[i]);
    }
  }

  // Cの最大値の最小化
  lli rem = v * m;
  rep(i, C.size()){
    if(C[i]>val){
      return false;
    }
    lli tmp = val-C[i];
    rem -= min(tmp, m);
  }

  return rem<=0;
}
void solve(long long N, long long M, long long V, long long P,
           std::vector<long long> A) {
  sort(A.begin(), A.end());
  reverse(A.rbegin(), A.rend());
  // rep(i, N)cerr << A[i] << " ";
  // cerr << endl;

  lli up = N, low = 0;
  while(up-low>1){
    lli  mid = (up+low)/2;
    bool o = ok(N, M, V, P, A, mid);

    //cerr << up << " " << low << " " << mid << " " << o << endl;
    if(o){
      low = mid;
    }else{
      up = mid;
    }
  }
  cout << low+1 << endl;
}
int main() {
  int a;
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long V;
  scanf("%lld", &V);
  long long P;
  scanf("%lld", &P);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, M, V, P, std::move(A));
  return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll n;
    cin>>n;
    for(ll i=-200;i<201;i++){
        for(ll j=-200;j<201;j++){
            if(pow(i,5)-pow(j,5)==n){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    return 0;
}

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

using namespace std;
#define ll long long
int main()
{
	ll n;
	cin >> n;
	ll w[n], s[n], v[n], wmax=0, w1[n], s1[n], v1[n];
	vector <pair<ll, ll> > weights, temp;
	for(ll i = 0; i < n; i++)
	{
		cin >> w[i] >> s[i] >> v[i];
		if(w[i] + s[i] > wmax)
			wmax = w[i] + s[i];
		temp.push_back(make_pair(s[i]+w[i], i));
	}
	sort(temp.begin(), temp.end());
	for(ll i = 0; i < n; i++)
	{
		w1[i] = w[temp[i].second];
		s1[i] = s[temp[i].second];
		v1[i] = v[temp[i].second];
	}
	ll ans[n][wmax+1], check[n][wmax+1];
	for(ll i = 0; i < wmax+1; i++)
	{
		if(i>=w1[0])
		{
			ans[0][i] = v1[0];
		}
		else
		{
			ans[0][i] = 0;
		}
	}
	for(ll i = 1; i < n; i++)
	{
		ans[i][0] = 0;
		for(ll j = 1; j<wmax+1; j++)
		{
			if(j-w1[i]<=s1[i] && j-w1[i]>=0)
				ans[i][j] = max(ans[i-1][j], ans[i-1][j-w1[i]]+v1[i]);
			else if(j-w1[i] < 0)
				ans[i][j] = ans[i-1][j];
			else
				ans[i][j] = max(ans[i-1][j], ans[i-1][s1[i]] + v1[i]);
		}
	}
	cout << ans[n-1][wmax];
}

Measured memory_bytes: 156544
import java.util.Scanner;


public class Main {

    
    public static void main(String[] args) {
       Scanner input= new Scanner(System.in);
       int y,n,i,x,sum=0;
       y= input.nextInt();
       n=input.nextInt();
       for(i=0;i<n;i++){
           x=input.nextInt();
           sum=sum+x;
       }
    if(sum>=y){
        System.out.println("Yes");
    }
    else 
        System.out.println("No");
}
}

Measured memory_bytes: 46848
#include <stdio.h>

int main()
{
  int k,a,b;
  scanf("%d%d%d",&k,&a,&b);
  int i;
  i = 0;
  int ans;
  while (i <= 1000)
  {
    if (i >= a && i <= b && i % k == 0)
    {
      printf("OK");
      return (0);
    }
    i++;
  }
  printf("NG");
  
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string> a(h);
  for(int i=0;i<h;i++){
    cin >> a[i];
  }
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j] == '#'){
        row[i] = true;
        col[j] = true;
      }
    }
  }
  for(int i=0;i<h;i++){
    if(row[i]){
      for(int j=0;j<w;j++){
        if(col[j]){
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
int n;
  cin >> n;
  int ans;
  if (n % 2 == 0) ans = n;
  else
    ans = 2 * n;

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


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

long n;
char c[20];

void print(long l,char had) {
	if(l>n) {
		for(long i=1;i<=n;++i)
			putchar(c[i]);
		putchar('\n');
		return;
	}
	for(char i='a';i<had;i++) {
		c[l]=i;
		print(l+1,had);
	}
	c[l]=had;
	print(l+1,had+1);
}

int main() {
	cin>>n;
	print(1,'a');
	return 0;
}

Measured memory_bytes: 1536
//  Created by conan1024hao on 2019/11/19.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int t,x;
    cin>>t>>x;
    printf("%.6lf\n",(double)t/x);
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main(void) {
	long long x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	unsigned long long m = min(x % d, d - x % d), cnt = x/d;
	if ((x % d) > (d - x % d))cnt++;
	if (cnt > k)cout << x - d * k;
	else if ((k - cnt) % 2 == 0)cout << m;
	else cout << d - m;
	return 0;
}

Measured memory_bytes: 3576
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    ct = 0
    for i in range(1, n+1):
        for j in range(i + 1, n+1):
            for k in range(j + 1, n+1):
                if i + j + k == x:
                    ct += 1
    print(ct)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> hs(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> hs[i];
    }

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

    int min_diff = INT_MAX;
    for (int i = 0; i <= N - K; ++i)
    {
        auto d = hs[i + K - 1] - hs[i];
        if (d < min_diff)
        {
            min_diff = d;
        }
    }

    cout << min_diff << endl;

    return 0;
}

Measured memory_bytes: 640
/*
Problem

Category
全探索：ビット全探索
(参考: https://qiita.com/drken/items/7c6ff2aa4d8fce1c9361)

URL:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A&lang=ja

考察:
nが小さいので全探索で解ける。
最大で 2^20(10^6) 程度

Date: 2020/04/04
*/

#include <bits/stdc++.h>
// #include "../utils.cpp"
using namespace std;
// #define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int n, m;
vector<int> A;
int q;
vector<int> M;

/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>n;
    A = vector<int>(n, 0);
    for(int i=0; i<n; ++i) {
        cin>>A[i];
    }
    cin>>q;
    M = vector<int>(q, 0);
    for(int i=0; i<q; ++i) {
        cin>>M[i];
    }
}


void solve() {
    set<int> ansSet;
    for(int i=0; i< (1<<n); ++i) {
        int cnt=0;
        for(int j=0; j<n; ++j) {
            if(i & (1<<j)) {
                cnt += A[j];
            }
        }
        ansSet.insert(cnt);
    }
    
    for(int i=0; i<q; ++i) {
        if(ansSet.find(M[i]) != ansSet.end()) {
            cout<<"yes"<<endl;
        } else {
            cout<<"no"<<endl;
        }
    }
}




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

#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



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


int main()
{
	_fastio
	double a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	/*if(a>b)
	{
		double tm=a;
		a=b;
		b=tm;

		tm=v;
		v=w;
		w=tm;
	}*/

	double x=(v*abs(b-a))/(v-w);

	if(x<0)
		cout<<"NO"<<en;
	else if((x/v)<=t)
		cout<<"YES"<<en;
	else
		cout<<"NO"<<en;
}

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

int main() {
	int n, x;
	cin >> n >> x;
	int sum = 0;
	int min = 1001;
	for(int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		sum += temp;
		if(temp < min)
			min = temp;
	}
	cout << n + (x-sum)/min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdlib>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MAX = 100000;
#define fi first
#define se second
int a[26];

int main() {
    ios::sync_with_stdio(false);
    string w;
    cin >> w;
    for (char i : w) a[i - 'a']++;
    bool fg = true;
    for (int i = 0; i < 26; i++) {
        if (a[i] % 2 != 0) fg = false;
    }
    if (fg) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, ca, cb;
	int i;

	while( scanf("%d %d", &a, &b) != EOF ){
		ca = a;
		cb = b;
		while(1){
			if(ca > cb) ca = ca - cb;
			if(cb > ca) cb = cb - ca;
			if(ca == cb) break;
		}
		i = (a / ca) * b;
		printf("%d %d\n", ca, i);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
int main() {
	ll A, B;
	cin >> A >> B;
	cout << A * B;
}

Measured memory_bytes: 3600
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vi x(n);
  vi y(n);
  rep(i, n){
    cin>>x[i]>>y[i];
  }

  if (n==1){
    cout << 1 << endl;
    return 0;
  }

  int res = INF;
  rep(i, n){
    rep(j, n){
      if (i==j) continue;
      int p = x[j]-x[i];
      int q = y[j]-y[i];
      int cnt = 0;
      rep(k, n){
        rep(m, n){
          if (x[k]-x[m]==p and y[k]-y[m]==q){
            cnt++;
            break;
          }
        }
      }
      chmin(res, n-cnt);
    }
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
import math
a, b = map(int, input().split())
diff = b - a
if diff > 20:
    print(-1)
else:
    x1 = (diff - 1) * 50
    x2 = (diff + 2) * 50
    flg = 0
    for i in range(x1, x2, 1):
        if(math.floor(i * 0.08) == a):
            if(math.floor(i * 0.1) == b):
                print(i)
                flg = 1
                break
    if flg == 0:
        print(-1)

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

int main(){
    int A,B,C,X;
    int S;
    int K = 0;
    cin >> A >> B >> C >> X;

    for(int a=0;a<=A;a++){
        for(int b=0;b<=B;b++){
            for(int c=0;c<=C;c++){
                S = a * 500 + b * 100 + c * 50;
                if(S == X){
                    K += 1;
                }
            }
        }
    }

    cout << K << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

vector<vector<int> >adj;
int dp[100005];
int a[100005];
bool flag=true;

void dfs(int ver,int pr)
{
    if(!flag)
        return ;
    int mx=-1;
    int tot=0;
    for(auto i:adj[ver])
    {
        if(i!=pr)
        {
            dfs(i,ver);
            tot+=dp[i];
            mx=max(mx,dp[i]);
        }
    }

    if(mx==-1)
        dp[ver]=a[ver];
    else
    {
        int z=tot-a[ver];
        if(z<0)
        {
            flag=false;
            return ;
        }
        if(min(tot-mx,mx)<z && mx>=tot-mx)
        {
            flag=false;
            return ;
        }
        dp[ver]=tot-2*z;        
        if(dp[ver]<0)
        {
            flag=false;
            return ;
        }
    }    
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    adj.resize(n+1);
    int x,y;
    
    for(int i=0;i<n-1;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }   
    if(n==2)
    {
        if(a[1]!=a[2])
        {
            cout<<"NO";            
        }
        else
        {
            cout<<"YES";
        }
        return 0;        
    }

    for(int i=1;i<=n;i++)
    {
        if(adj[i].size()>1)
        {
            dfs(i,0);
            if(dp[i]!=0)
            {
                flag=false;
            }
            break;            
        }
    }

    if(!flag)
    {
        cout<<"NO";
    }
    else
    {
        cout<<"YES";
    }
    
} 
    
 


Measured memory_bytes: 16904
N, W = map(int, input().split())
item = [[0] * 2 for _ in range(N)]
for i in range(N):
    w, v = map(int, input().split())
    item[i][0], item[i][1] = w, v
dp = [[1000000001] * (1000*N+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    for j in range(1000*N+1):
        if item[i-1][1] <= j:
            dp[i][j] = min(dp[i-1][j-item[i-1][1]] + item[i-1][0], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
ans = 0
for i in range(1000*N+1):
    if dp[N][i] <= W:
        ans = i
print(ans)

Measured memory_bytes: 120172
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    const int area1 = a * b;
    const int area2 = c * d;
    if (area1 > area2) {
        cout << area1 << endl;
    } else {
        cout << area2 << endl;
    }
    return 0;
}


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

int main() {
    string s; cin >>s;
    int w=0;
    for (auto c: s) if(c=='W'){w++;}

    int left_white = 0, t;
    long long ret = 0;
    for (int i = 0; i < w; i++) {
        t = s.substr(left_white, s.size()).find('W');
        if (t==0) {
            // do nothing
        }
        else {
            // s[left_white] = 'W';
            if (t>0) s[left_white+t] = 'B';
            ret += t;
        }
        left_white++;
    }
    cout << ret << endl;
    return 0;
}

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

vector<int> v;

void prime(int n) {
	while (n != 1) {
		if (n == 2 || n == 3) {
			v.push_back(n);
			n /= n;
			break;
		}

		for (int i = 2; i <= sqrt(n);i++) {
			if (n%i == 0) {
				n /= i;
				v.push_back(i);
				break;
			}
			if (i == (int)sqrt(n)) {
				v.push_back(n);
				n /= n;
				break;
			}
		}
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	prime(n);
	v.erase(unique(v.begin(), v.end()), v.end());
	int Ans = n;
	for (int i = 0; i < v.size();i++) {
		Ans = Ans - Ans / v[i];
	}
	cout << Ans << endl;
}

Measured memory_bytes: 3180
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,p;
    cin>>n>>p;
    string s; cin>>s;
    if(p == 2 || p == 5){
        ll ret = 0;
        FOR(i,0,s.size()){
            if((s[i] - '0') % p == 0) ret += i+1;
        }
        cout<<ret<<endl;
        return 0;
    }
    REV(s);
    ll tmp  = 0;
    map<ll,ll> mp;
    ll ans = 0;
    mp[0]++;
    ll ten = 1;
    FOR(i,0,n){
        tmp += ten*(s[i] - '0');
        tmp%=p;
        ans += mp[tmp];
        mp[tmp]++;
        ten *= 10;
        ten%=p;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1044
import sys
input=sys.stdin.readline
n=int(input())
P=tuple(map(float,input().split()))
DP=[[0.0]*(n+1) for _ in range(n+1)]
DP[0][0]=1.0
for i in range(1,n+1):
    for j in range(i+1):
        DP[i][j]=DP[i-1][j]*(1-P[i-1])
        if j:
            DP[i][j]+=DP[i-1][j-1]*P[i-1]
ans=0.0
for i in range(n//2+1,n+1):
    ans+=DP[-1][i]
print(ans)

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

int main(){
  int N;
  cin >> N;
  long long L[86];
  L[0] = 2;
  L[1] = 1;
  for(int i = 2; i <= N; i++){
    L[i] = L[i - 1] + L[i - 2];
  }
  cout << L[N] << endl;
}


Measured memory_bytes: 3612
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        mut n: usize
    };
    let mut s = Vec::new();
    while n > 0 {
        n -= 1;
        s.push((b'a' + ((n % 26) as u8)) as char);
        n /= 26;
    }
    println!("{}", s.iter().rev().collect::<String>());
}


Measured memory_bytes: 2192
def main():
    S = input()    
    if S == 'SUN':
        print(7)
    if S == 'MON':
        print(6)
    if S == 'TUE':
        print(5)
    if S == 'WED':
        print(4)
    if S == 'THU':
        print(3)
    if S == 'FRI':
        print(2)
    if S == 'SAT':
        print(1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	count := make(map[string]int)
	for n > 0 {
		n--
		var s string
		fmt.Scan(&s)
		count[s]++
	}
	ss := []string{"AC", "WA", "TLE", "RE"}
	for _, s := range ss {
		fmt.Printf("%s x %d\n", s, count[s])
	}
}


Measured memory_bytes: 6336
#include<bits/stdc++.h>
#define taskname "test1"
#define int long long
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    int n, m;   cin >> n >> m;
    vector<vector<int>> s(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            char c; cin >> c;
            s[i][j] = c == '#';
            s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
        }
    for (int i = 1; i <= n; ++i)
    {
        bool ok = false;
        for (int j = 1; j <= m; ++j)
            if (s[i][m] - s[i - 1][m] && s[n][j] - s[n][j - 1])
            {
                ok = true;
                int x = s[i][j] - s[i - 1][j] - s[i][j - 1] + s[i - 1][j - 1];
                if (x) cout << '#';
                else cout << '.';
            }
        if (ok) cout << '\n';
    }
}


Measured memory_bytes: 384
#include <stdio.h>

using namespace std;

int main(){
	int r,c,sum,total_sum = 0;
	scanf("%d %d",&r,&c);
	int table[r+1][c+1];

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			table[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d",&table[i][j]);
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		total_sum += sum;
	}
	table[r][c] = total_sum;

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
			printf("%d ",table[i][j]);
		}
		printf("%d\n",table[i][c]);
	}
}



Measured memory_bytes: 2736
def main():
    _ = input()
    lst = list(map(int, input().split()))
    ans = 1

    if 0 in lst:
        print(0)
        exit()
    for i in lst:
        ans *= i
        if ans > 10 ** 18:
            print(-1)
            exit()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21784