akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;

long divCeil(long num1, long num2){
	return (num1+num2-1)/num2;
}

long intconvert(long& a){//a will be the letter next to ']'
	long res = s[a] - '0';
	a++;
	while(s[a] != ']'){
		res *= 10;
		res += s[a] - '0';
		a++;
	}
	a++;
	return res;
}

long dfs(long& vis){
	//printf("  %ld\n", vis);
	long ret = 0;
	std::vector<long> minvotes;
	if(vis < s.length() - 1 && '0' <= s[vis+1] && s[vis+1] <= '9'){
		vis++;
		return divCeil(intconvert(vis), 2);
	}
	vis++;
	while(s[vis] != ']'){
		minvotes.push_back(dfs(vis));
	}
	std::sort(minvotes.begin(), minvotes.end());
	for(int i = 0; i <= minvotes.size() / 2; i++){
		ret += minvotes[i];
	}
	if(vis < s.length() - 1){
		vis++;
	}
	//printf("    %ld\n", ret);
	return ret;
}
	

void solve(){
	std::cin >> s;
	long val = 0;
	printf("%ld\n", dfs(val));
	return;
}

int main(){
	long n;
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3400
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  int n,k,x,y,color,plase,kouten;
  cin>>n>>k;
  plase=n/2;
  if(n%2==1){
    plase=plase+1;
  }
  for(int i=0;i<k;i++){
    cin>>y>>x;
    if(y<=plase&&x<=plase){
      kouten=min(x,y);
    }
    else if(y>plase&&x<=plase){
      kouten=min(x,n-y+1);
    }
    else if(y<=plase&&x>plase){
      kouten=min(n-x+1,y);
    }
    else{
      kouten=min(n-x+1,n-y+1);
    }
    kouten=kouten%3;
    if(kouten==0){
      kouten=3;
    }
    cout<<kouten<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const int MAXN = 111111;
vector<pair<int, int> > G[MAXN];
int itr[MAXN];
bool done[MAXN];

bool dfs(int v, int s) {
    for (; itr[v] < G[v].size(); ++itr[v]) {
        auto e = G[v][itr[v]];
        if (done[e.second]) continue;
        done[e.second] = true;
        return dfs(e.first, s);
    }
    if (itr[v] == G[v].size()) {
        return v == s;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    for (int i = 0; i < N; i++) {
        if (G[i].size() > itr[i]) {
            if (!dfs(i, i)) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define npos std::string::npos
typedef long long ll;
using namespace std;
int isMonth(int x)
{
	if (x >= 1 && x <= 12){
    	return 1;
    } else {
    	return 0;
    }
}

int main()
{
  	int s;
  	cin >> s;
  	int upper = s / 100;
  	int lower = s % 100;
  	if (isMonth(upper)) {
    	if (isMonth(lower)) {
        	cout << "AMBIGUOUS" << endl;
        } else {
        	cout << "MMYY" << endl;
        }
    } else if (isMonth(lower)) {
        cout << "YYMM" << endl;
    } else {
       	cout << "NA" << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

int main() {
    long long n, m, a;
    cin >> n >> m;
    if (n % m == 0 || m % n == 0) {
        cout << n + m << endl;
    } else {
        cout << m - n << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long LL;
const LL MOD = 1e9 + 7;

LL b[100010];

LL pow_mod(LL x, LL p) {
	LL ans = 1;
	while (p) {
		if (p&1) ans = ans * x % MOD;
		x = x * x % MOD;
		p >>= 1;
	}
	return ans;
}

LL C(LL x, LL y) {
	LL ans = 1;
	for (int i = 1; i <= y; ++i) {
		ans = ans * (x - i + 1) % MOD * pow_mod(i, MOD-2) % MOD;
	}
	return ans;
}

int main() {
	LL n, m;
	scanf("%I64d%I64d", &n, &m);
	LL ans = 1;
	int tot = 0;
	for (int i = 2; i <= m; ++i) {
		if (m % i == 0) ++tot;
		while (m % i == 0) m /= i, b[tot]++;
	}
	for (int i = 1; i <= tot; ++i) {
//		puts("A");
		ans = ans * C(n + b[i] - 1, n - 1) % MOD;
	}
	printf("%I64d", ans);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e9;


//奇数なら違う色にすればよい
//偶数なら同じ色にすればよい
vector<pair<int,int> > G[100000];
bool used[100000];
int res[100000];

void dfs(int u, int color) {
    used[u] = true;
    res[u] = color;
    for (int i = 0; i < G[u].size(); i++) {
        if (!used[G[u][i].first]) {
            if (G[u][i].second % 2 == 0) {
                dfs(G[u][i].first, color);
            } else {
                dfs(G[u][i].first, (color+1)%2);
            }
        }
    }
}

int main() {
    
    int N;
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        int u,v,w;
        cin >> u >> v >> w;
        G[u-1].push_back(make_pair(v-1,w));
        G[v-1].push_back(make_pair(u-1,w));
    }

    dfs(0,0);

    for (int i = 0; i < N; i++) {
        cout << res[i] << endl;
    }







}



Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int b[32];
string bit;

void latte(char c,int idx){
    int d=isdigit(c)?(c-'0'):(c-'a'+10);
    rep(i,4)b[idx*4+i]=d>>(3-i)&1;
}

int main(){

    int Q;cin>>Q;
    while(Q--){
        cin>>bit;
        rep(i,8)latte(bit[i],i);
        if(b[0])printf("-");
        int u=0;
        for(int i=1;i<25;i++)u=(u<<1)+b[i];
        printf("%d.",u);

        int l=0,a=50000000;
        for(int i=25;i<32;i++){
            if(b[i])l+=a;
            a/=2;
        }
        if(l==0){
            puts("0");
            continue;
        }

        int lost=(int)log10(50000000)-(int)log10(l);
        rep(i,lost)printf("0");
        while(l%10==0)l/=10;
        printf("%d\n",l);
    }
    return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

long cost[90005];

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

  string s;
  cin >> s;

  int canP = false;
  int score = 0;

  rep(i, s.length()) {
    if (canP) {
      if (s[i] == 'g') score++;
      canP = false;
    } else {
      if (s[i] == 'p') score--;
      canP = true;
    }
  }

  cout << score << endl;

}


Measured memory_bytes: 888
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int w = sc.nextInt();
        int n = sc.nextInt();
        int[] array=new int[w];
        for(int i=0;i<w;i++)array[i]=i+1;
        int a=0,b=0;
        for(int i=0;i<n;i++){
            String s=sc.next();
            String st1="";
            String st2="";
            for(int j=0;j<s.length();j++){
                if(s.charAt(j)!=','){
                    st2+=s.charAt(j);
                }
                else {
                    st1=st2;
                    st2="";
                }
            }
            a=Integer.parseInt(st1);
            b=Integer.parseInt(st2);
            int tmp=0;
            tmp=array[a-1];
            array[a-1]=array[b-1];
            array[b-1]=tmp;
        }
        for(int i=0;i<w;i++)System.out.println(array[i]);
    }
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	set<string> all;
	fx(N) {
		string s;
		cin >> s;
		all.insert(s);
	}
	ce(all.size())

    return 0;
}



Measured memory_bytes: 19256
N,M = [int(hoge) for hoge in input().split()]
H = [int(hoge) for hoge in input().split()]
Survive = [True] * N
for t in range(M):
    A,B = [int(hoge)-1 for hoge in input().split()]
    if H[A] >= H[B] :
        Survive[B] = False
    if H[B] >= H[A]:
        Survive[A] = False
print(sum(Survive))

Measured memory_bytes: 86256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<cstdio>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define MOD 1000000007

#define ARRAY_MAX 100005

int d[ARRAY_MAX];

int main(){

    int n;
    while(cin >> n,n){
        REP(i,ARRAY_MAX){
            d[i] = 0;
        }
        int h,m,s;
        REP(i,n){
            scanf("%d:%d:%d",&h,&m,&s);
            d[3600*h+60*m+s]++;
            scanf("%d:%d:%d",&h,&m,&s);
            d[3600*h+60*m+s]--;
        }
        REP(i,ARRAY_MAX-1){
            d[i+1] += d[i];
        }
        int ans = 0;
        REP(i,ARRAY_MAX){
            ans = max(ans,d[i]);
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 3536
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=
vector<int>v;

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n;
	
	while(cin>>n)
	{
		v.resize(n);
		
		for(int i=0;i<n;i++)
			cin>>v[i];
		
		int ans=0;	
		
		for(int i=0,x;i<n;i++)
		{
			x=v[i];
			for(int j=i+1,y;j<n;j++)
			{
				y=v[j];
					
				for(int k=j+1,z;k<n;k++)
				{
					z=v[k];
					
					if( x!=y && x!=z && y!=z && x+y>z && x+z>y && y+z>x )
					{
						ans++;
					}
				
				}
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll ;
long long int power(long long int a,long long int n,long long int m) ;
 long long int power(long long int a,long long int n,long long int m)
{  if(n==0)
   return 1 ;
   long long int x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}



int main()
{ long long int n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o;
   map<string,ll> p ;
    string s  ;
    cin>>n ;
    for(i=0;i<n;i++)
    {
        cin>>s ;
        p[s]++ ;
    }
    cout<<p.size() ;
    return 0 ; }


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  
  for (int i = 0; i < n; i++) {
    vector<int> seat(2);
    for (int j = 0; j < 2; j++) {
      cin >> seat.at(j);
    }
    ans += seat.at(1) - seat.at(0) + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#coding: utf-8
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
ans = ""
ans += "U" * y + "R" * x
ans += "D" * y + "L" * x
ans += "L" + "U" * (y+1) + "R" * (x+1) + "D"
ans += "R" + "D" * (y+1) + "L" * (x+1) + "U"
print(ans)

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

int main() {
    string s[3];
    for (int i = 0; i < 3; i++) cin >> s[i];
    int t = 0;
    while (true) {
        if (s[t].empty()) {
            cout << char('A' + t) << endl;
            return 0;
        }
        char c = s[t][0];
        s[t].erase(s[t].begin());
        t = c - 'a';
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<long long> b(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        b[i] = a - (i + 1);
    }
    sort(b.begin(), b.end());

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(b[i] - b[n / 2]);
    }

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

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    ll n;
    cin >> n;
    int ans = 100;
    for(int i = 1;i <= sqrt(n);i++){
        ll j = n/i;
        if(n%i == 0){
            int f = max(to_string(i).size(),to_string(j).size());
            ans = min(ans,f);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3760
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int M = sc.nextInt();
	int[] x = new int[M];
	for(int i = 0; i<M; i++) {
	    x[i] = sc.nextInt();
	}
	if(N>=M) {
	    System.out.println(0);
	    return;
	}
	Arrays.sort(x);
	int[] offset = new int[M-1];
	for(int i = 0; i<M-1; i++) {
	    offset[i] = x[i+1] - x[i];
	}
	Arrays.sort(offset);
	long ans = 0;
	for(int i = 0; i<(M-1)-(N-1); i++) {
	    ans += offset[i];
	}
	System.out.println(ans);
    }
}

Measured memory_bytes: 50244
#include <iostream>
#include <cstdio>
#include <algorithm>

const int MAX_NM = 100;

int N, M;
double table[MAX_NM][MAX_NM];
double dp[MAX_NM][MAX_NM];

int main(){

    while(true){
        std::cin >> N >> M;
    
        if(N == 0 && M == 0)
            break;

        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j)
                std::cin >> table[i][j];
        }

        for(int i = 0; i < M; ++i){
            for(int j = 0; j < N; ++j){
                if(i == 0){
                    dp[i][j] = 1;
                }
                else{
                    double max = 0;
                    for(int k = 0; k < N; ++k){
                        max = std::max((double)max, table[k][j] * dp[i - 1][k]);
                    }

                    dp[i][j] = max;
                }
            }
        }
        
        double ans = 0;

        for(int i = 0; i < N; ++i)
            ans = std::max(dp[M - 1][i], (double)ans);
        
        printf("%.2f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1400
// 16D8103008D 西村悠輝　stack

#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;


int n;

int main(void) {
	stack<int> s;
	char c;
	while (scanf("%c", &c) != EOF) {
		if (c == '+') {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a + b);
		}
		if (c == '-') {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(b - a);
		}
		if (c == '*') {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a*b);
		}
		if (c >= '0' && c <= '9') {
			int d = c - '0';
			while (1) {
				scanf("%c", &c);
				if (c >= '0' && c <= '9')d = d * 10 + (c - '0');
				else break;
			}
			s.push(d);
		}
		else scanf("%*c");
	}
	printf("%d\n", s.top());
	return 0;
}



Measured memory_bytes: 2744
ab=[1]*100000
bc=[1]*100000
ac=[1]*100000
a=input()
b=input()
c=input()
A,B,C=len(a),len(b),len(c)
match=lambda x,y:x=="?" or y=="?" or x==y
for i in range(A):
  for j in range(B):
    if not match(a[i],b[j]):ab[i-j+50000]=0
for i in range(A):
  for j in range(C):
    if not match(a[i],c[j]):ac[i-j+50000]=0
for i in range(B):
  for j in range(C):
    if not match(b[i],c[j]):bc[i-j+50000]=0
ans=10**20
for i in range(-4000,4001):
  for j in range(-4000,4001):
    if ab[i+50000]+ac[j+50000]+bc[j-i+50000]==3:
      ans=min(ans,max(A,B+i,C+j)-min(0,i,j))
print(ans)

Measured memory_bytes: 54220
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 2e5 + 5;
const int maxm = 18;
const ll Mod = 1e9 + 7;
const ll INF = 1e9 + 7;

ll a[maxn];
map<int, int>p;

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

	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		cin >> a[i];
		p[a[i]]++;
	}
	for (int i = 1; i <= n; ++i) {
		cout << p[i] << endl;
	}


	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int s, w ; cin >> s >> w;
	if(w>=s) cout << "unsafe"<< endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <cstdio>
typedef long long lld;
const int MAXN = 405;
const lld INFN = 1e9 * MAXN * MAXN + 5;
int  A[MAXN];
lld dp[MAXN][MAXN];
lld pre[MAXN];
int N;

void init() {
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      dp[i][j] = -1;
    }
  }
}

// dp[l][r] = minimal moves to unify slime segment [l, r]
// Transitions are all possible positions of the final split.

lld dfs(int l, int r) {
  if (dp[l][r] >= 0) {
    return dp[l][r];
  }
  if (l == r) {
    return dp[l][r] = 0;
  }
  lld res = INFN;
  for (int m = l; m < r; ++m) {
    res = std::min(
      dfs(l, m) + dfs(m+1, r) + pre[r] - pre[l-1],
      res
    );
  }
  return dp[l][r] = res;
}

int main() {
  scanf("%d", &N);
  init();
  pre[0] = 0;
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
    pre[i] = pre[i-1] + A[i];
  }
  printf("%lld\n", dfs(1, N));
  return 0;
}

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

int main() {
  int n,ans;
  ans = 1000000;
  cin >> n;
  for(int i = 0; i < n; i++){
    int j,u;
    u = 0;
    cin >> j;
    while(j % 2 == 0){
      u += 1;
      j /= 2;
    }
    ans = ans > u ? u : ans;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;
int n , k;

int mul (long long a , long long b) {
    a = (a % MOD + MOD) % MOD;
    b = (b % MOD + MOD) % MOD;
    return a * b % MOD;
}

pair<bool , int> max_pos (vector<int> pos , vector<int> neg) {
    sort(pos.begin() , pos.end());
    sort(neg.rbegin() , neg.rend());

    int ans = 1 , rem = k;
    while (rem) {
        if ((rem == 1 || neg.size() < 2) && pos.empty())
            return {0 , 0};

        if (rem >= 2 && neg.size() >= 2) {
            long long f = -1e18 , s = -1e18;

            if (neg.size() >= 2)
                f = neg[neg.size() - 1] * 1ll * neg[neg.size() - 2];

            if (pos.size() >= 2)
                s = pos[pos.size() - 1] * 1ll * pos[pos.size() - 2];

            if (f > s) {
                neg.pop_back();
                neg.pop_back();
                ans = mul(ans , f);
                rem -= 2;
                continue;
            }
        }

        ans = mul(ans , pos.back());
        pos.pop_back();
        rem--;
    }

    return {1 , ans};
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    cin >> n >> k;

    vector<int> pos , neg;

    int sec = 1;
    for (int i = 0 ;i < n ;i++) {
        int x;
        cin >> x;
        sec = mul(sec , x);
        if (x >= 0)
            pos.push_back(x);
        else
            neg.push_back(x);
    }


    auto ans = max_pos(pos , neg);
    if (ans.first)
        cout << ans.second;
    else {
        if (pos.empty()) {
            sort(neg.rbegin() , neg.rend());
            sec = 1;
            for (int i = 0 ;i < k ;i++)
                sec = mul(sec , neg[i]);

        }
        cout << sec;
    }
}

Measured memory_bytes: 4884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni(), m = ni();
        int[][] d = new int[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(d[i], INF);
        }
        for (int i = 0; i < n; i++) {
            d[i][i] = 0;
        }

        int[] a = new int[m];
        int[] b = new int[m];
        int[] c = new int[m];

        for (int i = 0; i < m; i++) {
            a[i] = ni() - 1;
            b[i] = ni() - 1;
            c[i] = ni();
        }

        for (int i = 0; i < m; i++) {
            d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
        }

        warshallFloyd(d);

        int ans = 0;
        for (int i = 0; i < m; i++) {
            if (d[a[i]][b[i]] < c[i]) {
                ans++;
            }
        }

        out.println(ans);
    }

    int INF = Integer.MAX_VALUE / 3;

    void warshallFloyd(int[][] d) {
        int n = d.length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    d[j][k] = Math.min(d[j][k], d[j][i] + d[i][k]);
                }
            }
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    class INA {
        int[][] a;

        INA(int n, int m) throws IOException {
            this(n, m, -1);
        }

        INA(int n, int m, int t) throws IOException {
            a = new int[m][n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[j][i] = ni() + t;
                }
            }
        }

        int[] get(int i) {
            return a[i - 1];
        }
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 9172
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K, std::vector<long long> A){
  vector<vector<ll>> dp(64,vector<ll>(2));
  REP(64){
    dp[i][0]=dp[i][1]=-1;
  }
  ll ans=0;
  auto sum = [&](ll x){
    ll ret=0;
    for (auto &&i : A)
    {
      ret+=(x^i);
    }
    return ret;
  };
  dp[0][0]=0;
  REP(63){
    ll cnt=0,mask=(1LL<<(62-i));
    For(j,N){
      if(A[j]&(mask))++cnt;
    }
    dp[i+1][0]=dp[i][0]+((K&mask)?(N-cnt):cnt)*mask;
    if(K&mask){
      dp[i+1][1]=dp[i][0]+cnt*mask;
    }
    if(dp[i][1]!=-1)dp[i+1][1]=max(dp[i+1][1],dp[i][1]+max(N-cnt,cnt)*mask);
  }
  dump(dp);
  cout<<max(dp[63][0],dp[63][1])<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool ck = true;
    for(int i = 0; i < n; i++){
        if(i % 2 == 0){
            if(s.at(i) != 'h'){
                ck = false;
                break;
            }
        }
        else if(s.at(i) != 'i'){
            ck = false;
            break;
        }
    }
    if(n % 2 != 0) ck = false;
    if(ck) cout << "Yes" << endl;
    else cout << "No" << endl;
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MN 2005 
int dpL[MN][MN],dpR[MN][MN],dpU[MN][MN],dpD[MN][MN];
string a[MN];
int main(){
	int w,h;
	cin >> h >> w;
	for (int i=0;i<h;i++){
		cin >> a[i];
	}
	
	for (int i=0;i<=h+1;i++)
		for (int j=0;j<=w+1;j++)
			dpL[i][j] = dpU[i][j] =  dpR[i][j] = dpD[i][j] =  -1;
	
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++){
			if (a[i-1][j-1]=='#'){
				dpL[i][j] = dpU[i][j] =  -1;
			} else {
				dpL[i][j] = dpL[i][j-1] + 1;
				dpU[i][j] = dpU[i-1][j] + 1;
			}	
		}
		
	for (int i=h;i>=1;i--)
		for (int j=w;j>=1;j--){
			if (a[i-1][j-1]=='#'){
				dpR[i][j] = dpD[i][j] = -1;
			} else {
				dpR[i][j] = dpR[i][j+1] + 1;
				dpD[i][j] = dpD[i+1][j] + 1;
			}	
		}
	
	int maxL = 0;
	for (int i=0;i<=h+1;i++)
		for (int j=0;j<=w+1;j++){
			int ans = dpL[i][j] + dpR[i][j] + dpU[i][j] + dpD[i][j] + 1;
			if (maxL<ans) maxL = ans;
		}
	cout << maxL;
	return 0;
}

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

const int N = 1e5;
const int maxn = 3e5 + 5;
long long mod = 1e9 + 7;

int n, m;
int edg[800][800];
int col[800], f[800][800];
vector<int> g[800];
pair <int, int> sz[800];
int cnt;

int color(int u, int c) {
    col[u] = c;
    for(int j = 0; j < g[u].size(); ++j) {
        int &v = g[u][j];
        if (col[v] == col[u])
            return 0;
        else if (!col[v] && !color(v, c ^ 1))
            return 0;
    }
    return 1;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        edg[u][v] = edg[v][u] = 1;
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            if (!edg[i][j]) {
                g[i].push_back(j);
                g[j].push_back(i);
            }
    
    for (int i = 1; i <= n; i++)
        if (!col[i]) {
            ++cnt;
            if (color(i, cnt << 1)) {
                for (int j = 1; j <= n; j++) {
                    if (col[j] == col[i])
                        ++sz[cnt].first;
                    else if (col[j] == (col[i] ^ 1))
                        ++sz[cnt].second;
                }
            }
            else {
                printf("-1");
                return 0;
            }
        }
    
    f[0][0] = 1;
    for (int i = 1; i <= cnt; i++)
        for (int j = 1; j <= n; j++) {
            if (j >= sz[i].first)
                f[i][j] |= f[i - 1][j - sz[i].first];
            if (j >= sz[i].second)
                f[i][j] |= f[i - 1][j - sz[i].second];
        }
    int ans = 700 * 700;
    for (int j = 1; j <= n; j++)
        if(f[cnt][j])
            ans = min(ans, j*(j - 1) / 2 + (n - j)*(n - j - 1) / 2);
    printf("%d", ans);
}


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

int main() {
	int N;

	cin >> N;
	vector<int> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	vector<int> L( N + 1 );
	vector<int> R( N + 1 );
	L[0] = 0;
	for( int i = 0; i < N; i++ ) {
		L[i + 1] = __gcd( L[i], A[i] );
	}
	R[N] = 0;
	for( int i = N - 1; i >= 0; i-- ) {
		R[i] = __gcd( R[i + 1], A[i] );
	}
	int ans = 0;
	for( int i = 0; i < N; i++ ) {
		ans = max( ans, __gcd( L[i], R[i + 1] ) );
	}

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

Measured memory_bytes: 1408
def main():
    N, A, B, C, D = map(int, input().split())
    S = input()

    # for i in range(B-1, D-1):
    #     if S[i] + S[i+1] == "##":
    #         return 'No'
    # for i in range(A-1, C-1):
    #     if S[i] + S[i+1] == "##":
    #         return 'No'

    for i in range(B, D-2):
        if S[i] + S[i+1] == "##":
            return 'No'
    for i in range(A, C-2):
        if S[i] + S[i+1] == "##":
            return 'No'

    if C < D:
        return "Yes"
    else:
        for i in range(B-1, D):
            if S[i-1] + S[i] + S[i+1] == '...':
                return "Yes"
        return "No"

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3572
#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,k,s;
    cin >> n >> k >> s;
    rp(i,k){
        cout << s << " ";
    }
    if(s<=2){
        rp(i,n-k)
        cout << s+1 << " ";
        cout << endl;
    }
    else{
        rp(i,n-k)
        cout << s-1 << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) std::sort(v, v+n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<ll, ll> LP;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll digit_sum(ll n) {
	if (n < 10)  return n;
	return digit_sum(n / 10) + n % 10;
}


string N;
int main() {

	cin >> N;
	ll sum=0;
	REP(i, N.length()) {
		sum += int(N[i]-'0');
	}
	if (sum % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;

}


Measured memory_bytes: 3740
import itertools
N, M, Q = map(int, input().split())
P = []
LR = [[0] * (N+1) for _ in range(N+1)] 
for m in range(M):
    l, r = map(int, input().split())
    LR[l][r] += 1

for q in range(Q):
    p = list(map(int, input().split()))
    P.append(p)

csum = []
for L in LR:
    a = list(itertools.accumulate(L))
    csum.append(a)

for p in P:
    ans = 0
    l, r = p
    for c in csum[l:r+1]:
        ans += (c[r] - c[l-1])
    print (ans)

Measured memory_bytes: 97304
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn mincoughskey(x: &Vec<f64>, y: &Vec<f64>, p: i32) -> f64 {
    let iter = x.iter().zip(y.iter());
    iter.map(|(x, y)| (x - y).abs().powi(p))
        .fold(0.0, |sum, d| sum + d).powf((p as f64).recip())
}

fn chevishef(x: &Vec<f64>, y: &Vec<f64>) -> f64 {
    x.iter().zip(y.iter())
        .map(|(x, y)| (x - y).abs())
        .fold(0.0, |max, x| x.max(max))
}

fn main() {
    let _ = get_line();

    let x = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<f64>>();
    let y = get_line().split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect::<Vec<f64>>();

    let manhattan = mincoughskey(&x, &y, 1);
    let euclid = mincoughskey(&x, &y, 2);
    let three = mincoughskey(&x, &y, 3);
    let chevi = chevishef(&x, &y);

    println!("{:.09}\n{:.09}\n{:.09}\n{:.09}",
        manhattan, euclid, three, chevi);
}



Measured memory_bytes: 5172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

ll n;
vector<ll> e[202020];

void dfs(ll i,vector<ll> &used){
    for(ll j=0;j<e[i].size();j++){
        if(used[e[i][j]]==0) {
            used[e[i][j]]=used[i]+1;
            dfs(e[i][j],used);
        } 
    }
}


int main(){
    ll i,j;

    cin>>n;

    ll a,b;
    for(i=0;i<n-1;i++){
        cin>>a>>b;
        e[a-1].pb(b-1);
        e[b-1].pb(a-1);
    }

    vector<ll> used(202020,0);
    used[0]=1;
    dfs(0,used);

    ll m=-1;
    ll f=0;
    for(i=0;i<202020;i++) {
        if(m<used[i]) {
            m=used[i];
            f=i;
        }
    }
    
    vector<ll> used2(202020,0);
    used2[f]=1;
    dfs(f,used2);

    ll m2=-1;
    ll f2=0;
    for(i=0;i<202020;i++) {
        if(m2<used2[i]) {
            m2=used2[i];
            f2=i;
        }
    }


    if(m2==1) cout<<"First"<<endl;
    else if(m2==2) cout<<"Sedond"<<endl;
    else {
        if(m2%3==2) cout<<"Second"<<endl;
        else cout<<"First"<<endl;
    }


  return 0;
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
 
using namespace std;
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct Trie{
  int num;
  Trie* chd[27];

  Trie(){
	REP(i,27) chd[i] = nullptr;
	num = 0;
  }

  void insert(int l, int b, int e, VS& vs, VS& idx){
	num = e - b;
	if(e - b == 1)
	  return;
	int s = min(SZ(vs[b]),SZ(vs[e-1]));
	int i;
	for(i=l;i<s;++i){
	  if(vs[b][i] != vs[e-1][i]){
		break;
	  }
	}

	int prv = b;
	char c = vs[b][i];
	for(int j=b;j<e;++j){
	  idx[j].PB(vs[j][i]);
	  if(vs[j][i] != c){
		chd[c-'`'] = new Trie();
		chd[c-'`']->insert(i+1, prv, j, vs, idx);
		prv = j;
		c = vs[j][i];
	  }
	}
	chd[c-'`'] = new Trie();
	chd[c-'`']->insert(i+1, prv, e, vs, idx);
  }

  int index(string& s, string& ord, int l = 0){
	if(l == SZ(s)) return 0;
	int res = 0;
	int i = 0;
	while(ord[i] != s[l]){
	  if(chd[ord[i]-'`'] != nullptr)
		res += chd[ord[i]-'`']->num;
	  ++i;
	}
	res += chd[ord[i]-'`']->index(s, ord, l+1);

	return res;
  }
};

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

  int N; cin >> N;
  VS data(N);
  vector<pair<string,int>> vs(N);
  REP(i,N){
	cin >> vs[i].FF;
	vs[i].FF += "`";
	vs[i].SS = i;
  }
  SORT(vs);
  VI inv(N);
  REP(i,N) inv[vs[i].SS] = i;
  REP(i,N) data[i] = vs[i].FF;

  VS idx(N);
  Trie trie;
  trie.insert(0, 0, N, data, idx);

  int Q; cin >> Q;
  while(Q--){
	int k;
	string ord;
	cin >> k >> ord;
	--k;
	ord = "`" + ord;
	cout << trie.index(idx[inv[k]], ord)+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 47616
#include<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int,int>
#define lpi pair<long long ,long long>
#define mp make_pair
#define pb push_back
#define ll long long 
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>multiordered_set;
ll int pw(ll int a, ll int b,ll md) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2,md);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
vector<int> pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.push_back(p);
}
bool cmp(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first>b.first;
}
ll int gcd(ll int a,ll int b)
{
    if(!a)return b;
    return gcd(b%a,a);
}
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
    return true; 
} 
map<int,int>pa;
int find(int i){
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}     
void join(int i,int j){
    int a=find(i);
    int b=find(j);
    if(b>=a)pa[b]=a;
    else pa[a]=b;
}               
int ddx[]={-1,-1,-1,0,1,1,1,0};
int ddy[]={-1,0,1,1,1,0,-1,-1};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int main()
{
    faltu;
    int t=1;
   // cin>>t;
    while(t--)
    {
        int a, b;
        cin>>a>>b;
        if(a<=8&&b<=8) cout<<"Yay!\n";
        else cout<<":(\n";
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef pair<int,pair<int,int> > P;
int n,r;
string t[10];
P p[10];

int main(){
	while(cin>>n){
		if(!n)return 0;
		for(int i=0;i<n;i++){
			cin>>t[i];
			p[i].first=0;
			p[i].second.first=0;
			p[i].second.second=i;
			for(int j=0;j<n-1;j++){
				cin>>r;
				if(!r)p[i].first--;
				if(r==1)p[i].second.first++;
			}
		}
		sort(p,p+n);
		for(int i=0;i<n;i++)cout<<t[p[i].second.second]<<endl;
	}
}

Measured memory_bytes: 0
X = int(input())

lis = set([])
lis.add(0)
for i in range(1, 250):
    lis.add(i**5)

for x in lis:
    if abs(X-x) in lis:
        if x-X<0:
            print(int(x**0.2), -int(abs(x-X)**0.2))
        else:
            print(int(x**0.2), int(abs(x-X)**0.2))
        break

Measured memory_bytes: 62376
n = int(input())
a = list(map(int, input().split())) 

stack = 0
ans = 1000

Flag = False
i,j  = 0, 0

while i < n-1:
    if a[i] < a[i+1]:
        stack = ans // a[i]
        ans -= stack*a[i]
        j = i
        while j < n-1:
            if a[j] >= a[j+1]:
                ans += stack*a[j]
                stack = 0
                i = j
                Flag = True
                break
            j += 1

    if Flag:
        Flag = False
        continue

    i += 1

if a[-2] < a[-1]:
    ans += stack*a[-1]

print(ans)

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

int main() {
    string a,b,c;
    cin>>a>>b>>c;

    int at=0,bt=0,ct=0;
    char turn='a';
    bool jdg=true;

    while(jdg){
        if(turn=='a'){
            if(at==a.size()){
                jdg=false;
            }
            if(jdg){
                turn=a[at];
                at++;
            }
        }
        if(turn=='b'){
            if(bt==b.size()){
                jdg=false;
            }
            if(jdg){
                turn=b[bt];
                bt++;
            }
        }
        if(turn=='c'){
            if(ct==c.size()){
                jdg=false;
            }
            if(jdg){
                turn=c[ct];
                ct++;
            }
        }
    }
    if(turn=='a'){
        cout<<'A'<<endl;
    }
    else if(turn=='b'){
        cout<<'B'<<endl;
    }
    else{
        cout<<'C'<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s, a;
    cin>>s>>a;
    int c=0,j=0;
   for(int i=0;s[i];i++,j++)
   {
       if(s[i]!=a[j])
       {
           c++;
       }
   }
    cout<<c<<endl;
}


Measured memory_bytes: 3916
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N;
    cin >> N;

    long long ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (N % i == 0) {
            ans += N / i - 1;
        }
        else {
            ans += N / i;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
  int N;
  int t1;
  int t2;
  int t3;
  int t4;
  
  cin >> N;
  
  t1 = N / 1000;
  t2 = (N % 1000) / 100;
  t3 = (N % 100) / 10;
  t4 = (N % 10) / 1;
  
  if((t1 == t2 && t1 == t3) || (t2 == t3 && t2 == t4)){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

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

int main(){
    vector<int> a(2);
    for(auto&& v:a)cin >> v;
    sort(a.begin(), a.end());
    if(a[0] == 2)cout << 1 << endl;
    else if(a[1] == 2)cout << 3 << endl;
    else cout << 2 << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n  = sc.nextInt
  val k  = sc.nextInt

  val al = List.fill(n)(sc.nextInt)

  val res = al.foldLeft(new Array[Int](200000)){(arr, a)=>
    val v = arr(a - 1)
    arr.update(a - 1, v + 1)
    arr
  }.zipWithIndex.filter(_._1 != 0).sortWith((a1,a2) => a1._1 > a2._1).drop(k).map(_._1).sum  //.sortWith((a1,a2) => a1._2 > a2._2)  //.dropRight(k).map(_._1).sum

  println(res)
}

Measured memory_bytes: 88452
package main

import (
	"fmt"
)

type height struct {
	human int
	step  int
}

func (h height) Sum() int {
	return h.human + h.step
}

func main() {
	var N int
	fmt.Scan(&N)

	A := make([]height, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&A[i].human)
	}

	sum, tmp := 0, 0
	for i := 0; i < N-1; i++ {
		if A[i+1].human >= A[i].Sum() {
			continue
		}
		tmp = A[i].Sum() - A[i+1].human
		A[i+1].step = tmp
		sum += tmp
	}

	fmt.Println(sum)

	// A[i+1].Sum() >= A[i].Sum()
}


Measured memory_bytes: 8568
N = int(input())

L = list(map(int,input().split()))

origin = []
for i in range(1,N+1):
    origin.append(i)

count = 0
for i in range(N):
    if L[i] != origin[i]:
        count += 1

if count == 2:
    print('YES')
elif count == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064