akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

int main(){

	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;

	a*=100,b*=100;

	vector<bool> water(5000,false);
	for(int i=0;i<=f;i+=a) water[i]=true;

	vector<bool> tmp=water;
	for(int i=0;i<=f;i++){
		if(!water[i]) continue;
		for(int j=i+b;j<=f;j+=b) tmp[j]=true;
	}
	water=tmp;

	vector<bool> sugar(5000,false);
	for(int i=0;i<=f;i+=c) sugar[i]=true;

	tmp=sugar;
	for(int i=0;i<=f;i++){
		if(!sugar[i]) continue;
		for(int j=i+d;j<=f;j+=d) tmp[j]=true;
	}
	sugar=tmp;

	int x=a,y=0;
	for(int i=0;i<=f;i++){
		if(!water[i]) continue;
		for(int j=0;i+j<=f;j++){
			if(!sugar[j]) continue;
			if(e*i < 100*j) continue;
			if( (i+j)*y < (x+y)*j ) x=i,y=j;
		}
	}

	cout<<x+y<<" "<<y<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>

#include <cstring>
using namespace std;

#ifdef LOCAL
    #define LLD_SPEC "%lld"
#else
    #define LLD_SPEC "%I64d"
#endif

const int MOD = 1e9 + 7;

inline void ModSum(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
    if (x < 0) {
        x += MOD;
    }
}

inline int GetModSum(int x, int y) {
    ModSum(x, y);
    return x;
}

inline void ModMul(int& x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int GetModMul(int x, int y) {
    ModMul(x, y);
    return x;
}

inline int GetSum(const vector<int>& sum, int l, int r) {
    return (l == 0 ? sum[r] : GetModSum(sum[r], -sum[l - 1]));
}

int main() {
    int n, c;
    scanf("%d%d", &n, &c);
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &b[i]);
    }

    const int LIM = 400;
    vector<vector<int>> pw(LIM + 1, vector<int>(LIM + 1));
    for (int i = 0; i <= LIM; ++i) {
        pw[i][0] = 1;
        for (int j = 1; j <= LIM; ++j) {
            pw[i][j] = pw[i][j - 1];
            ModMul(pw[i][j], i);
        }
    }

    vector<vector<int>> pwSum(LIM + 1, vector<int>(LIM + 1));
    for (int i = 0; i <= LIM; ++i) {
        pwSum[i][0] = pw[0][i];
        for (int j = 1; j <= LIM; ++j) {
            pwSum[i][j] = pwSum[i][j - 1];
            ModSum(pwSum[i][j], pw[j][i]);
        }
    }

    vector<vector<int>> result(n + 1, vector<int>(c + 1, 0));
    result[0][0] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int prev = 0; prev <= c; ++prev) {
            for (int cur = 0; cur + prev <= c; ++cur) {
                ModSum(result[i][cur + prev], GetModMul(result[i - 1][prev], GetSum(pwSum[cur], a[i - 1], b[i - 1])));

                /*
                for (int p = a[i - 1]; p <= b[i - 1]; ++p) {
                    ModSum(result[i][cur + prev], GetModMul(result[i - 1][prev], pw[p][cur]));
                }
                */
            }
        }
    }

    printf("%d\n", result[n][c]);

    return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K >> S;

  if (S.size() <= K)
    cout << S << endl;
  else {
    S = S.substr(0, K);
    cout << S + "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 100;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n;

int main() {
    int i, j;
    cin >> n;
    int four = 0, two = 0;
    for (i = 0; i < n; ++i) {
        int t;
        cin >> t;
        if (t % 4 == 0)
            ++four;
        else if (t % 2 == 0)
            ++two;
    }
    bool ans = false;
    int one = n - four - two;
    if (one <= four)
        ans = true;
    else if (one == four + 1 && two == 0)
        ans = true;
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.*;

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

        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        double ans = Math.abs(a - t + h[0]*0.006);
        int an = 1;
        for (int i = 1; i < n; i++) {
            if (Math.abs(a - t + h[i]*0.006) < ans) {
                ans = Math.abs(a - t + h[i]*0.006);
                an = i+1;
            }
        }

        System.out.println(an);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    set<int> moti;
    rep(i, 0, n) {
        int x; cin >> x;
        moti.insert(x);
    }
    cout << moti.size() << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for e in sys.stdin:
 a,v=map(int,e.split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>m:w,m=a,s[a]
 elif s[a]==m:w=min(w,a)
 print(w,m)


Measured memory_bytes: 13712
S = input()
N = len(S)

Ans = [-1,-1]
# 1-indexedであることに注意。。。
for i in range(N-1):
    if S[i]==S[i+1]:
        Ans = [i+1,i+2]
        break
for i in range(N-2):
    if S[i]==S[i+2] and S[i]!=S[i+1]:
        Ans = [i+1,i+3]
        break

print(Ans[0],Ans[1])

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<bool> vb;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 100000007;
const int inf = 1000000000;
const int N = 200007, M = N;
ll i,jx,cnt,par,n;

void solve() {
   ll n,m,k;
   cin>>n>>m>>k;

   string a[n];
   cnt = 0;
   for(int i=0;i<n;i++) {
    cin>>a[i];
   }

   ll temp , ans = 0;

   for(int i=0;i<(1LL<<n);i++) {
    for(int j=0;j<(1LL<<m);j++) {
        cnt = 0;
        for(int h=0;h<n;h++) {
            for(int w=0;w<m;w++) {
                if((i & (1LL<<h)) && (j & (1LL<<w)) && a[h][w] == '#') cnt++;
            }
        }
        if(cnt == k) ans++;
    }
   }
   cout<<ans<<"\n";

   }



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

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

    return 0;
}




Measured memory_bytes: 3592
# 入力
A,B,C = list(map(int, input().split()))
K = int(input())
ans = 'No'

for i in range(K+1):
    if(A>=B):
        B *= 2
    else:
        if(B>=C):
            C *= 2
        else:
            ans = 'Yes'
            break

print(ans)


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

struct point{ll x; ll y;};
int main()
{
	cout << setprecision(10);
	ll w, h, n;
	cin >> w >> h >> n;
	vector<point> xy(n);
	vector<ll> one_four(n);
	rep(i,n){
		cin >> xy[i].x >> xy[i].y >>one_four[i];
	}
	ll x1 = 0, x2 = w, y1 = 0, y2 = h;
	rep(i,n){
		if(one_four[i] ==1){
			chmax(x1,xy[i].x);
		}
		else if(one_four[i] == 2){
			chmin(x2,xy[i].x);
		}
		else if(one_four[i] == 3){
			chmax(y1,xy[i].y);
		}
		else if(one_four[i] == 4){
			chmin(y2,xy[i].y);
		}
	}
	ll xrange = (x2-x1);
	ll yrange = (y2-y1);
	ll ans =  0 ;
	//xrange, yrangeどっちかが負だったら処理しないようにする
	if(xrange>=0&&yrange>=0){
		ans = max(xrange * yrange, (ll)0);
	}
	cout << ans << endl;

	
}


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

int n, x;
int a[200005];


int main() {
    cin >> n;

    for (int i =0; i < n-1; i++) {
        cin >> x;
        a[x-1]++;
    }

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

Measured memory_bytes: 4404
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int result = (int)(a*b/2);
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22868
using System;
using System.Linq;

namespace ABC117B
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] L = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

            int sum = L.Sum();
            for (int i = 0; i < N; i++)
            {
                if (sum <= L[i] * 2)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    if(A & 1) {
        ans ^= A;
        A++;
    }
    if(!(B & 1)) {
        ans ^= B;
        B--;
    }
    ans ^= (B - A + 1) / 2 & 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int X;
    cin >> X;
    for (int i = 0; i < 8; i++)
    {
        if (400 + 200 * i <= X && X <= 599 + 200 * i)
        {
            cout << 8 - i << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3620
n,k = map(int,input().split())
mod = 10**9 + 7
count_gcd = [0]*(1+k)

ans = 0
for i in range(k,0,-1):
    tmp = pow(k//i, n, mod)
    for j in range(2, k//i + 1):
        tmp  =  (tmp - count_gcd[j*i])%mod
    count_gcd[i] = tmp
    ans = (ans +  tmp*i) % mod

print(ans)

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

int A[101];

void Show_Array(int n)
{
    for (int i = 0; i < n; ++i) 
    {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void Inserttion_Sort(int n) 
{
    Show_Array(n);
    for (int i = 1; i < n; ++i) 
    {
        int target = A[i];
        int j = i-1;
        while (j >= 0 && target < A[j]) 
        {
            A[j+1] = A[j];
            --j;
        }
        A[++j] = target;

        // print out 
        Show_Array(n);
    }
}

int main() 
{
    int n; cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];

    Inserttion_Sort(n);
    
}


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

int mdc(int a, int b){
    if(b == 0) return a;
    return mdc(b, a % b);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
    
    int x, sum = 0; cin >> x;
    for(int i = 1; i <= x; ++i){
        for(int p = 1; p <= x; ++p){
            int temp = mdc(i,p);
            for(int k = 1; k <= x; ++k){
                sum += mdc(temp, k);
            }
        }
    }
    cout << sum << "\n";
}


Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st1 = new StringTokenizer(br.readLine());
		int x=Integer.parseInt(st1.nextToken());
		int y=Integer.parseInt(st1.nextToken());

		int z=0;

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

		while(x!=0 || y!=0){
			System.out.println(x+" "+y);

			StringTokenizer st2 = new StringTokenizer(br.readLine());
			x=Integer.parseInt(st2.nextToken());
			y=Integer.parseInt(st2.nextToken());

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

}


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

#define fr(i, a, b) for(int i = (a); i <= (b); i++)
#define rf(i, a, b) for(int i = (a); i >= (b); i--)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
 
    int n, m, k;
    cin >> n >> m >> k;

    ve<ve<char>> c(n, ve<char>(m));
    fr(i, 0, n - 1) {
        fr(j, 0, m - 1) {
            cin >> c[i][j];
        }
    }

    int res = 0;
    fr(mask_row, 0, pw(n) - 1) {
        fr(mask_col, 0, pw(m) - 1) {
            int ans = 0;
            fr(i, 0, n - 1) {
                fr(j, 0, m - 1) {
                    if(!(mask_row & pw(i)) && !(mask_col & pw(j)) && c[i][j] == '#') {
                        ans++;
                    }
                }
            }
            if(ans == k) {
                res++;
            }
        }
    }

    cout << res << "\n";

    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int len=s.length();
    int ans=0;
    for(int i=0;i<len;i++)
    ans+=s[i]-'0';
    if(ans%9==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <set>
#include <vector>
#include <map>
using namespace std;

typedef long long LL;
	
const LL INF = 0x7ffffffff;
const LL NBDR = -2e7;
const LL BDR = 2e7;
const LL MAXN = 200;
LL G[MAXN][MAXN];

LL n, k, u, v, w;


void init()
{
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			G[i][j] = i == j ? 0 : INF;
}

void floyd()
{
	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i < n; i++)
		{
			if(G[i][k] == INF)
				continue; 
			for(int j = 0; j < n; j++)
			{
				if(G[k][j] == INF)
					continue;
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);	
			}
		}
			
	}		
}


int main()
{
	while(scanf("%lld %lld", &n, &k) != EOF)
	{
		init();
		int flag = 0;
		while(k--)
		{
			scanf("%lld %lld %lld", &u, &v, &w);
			G[u][v] = w;
		}
		
		floyd();
		
		for(int i = 0; i < n; i++)
			if(G[i][i] < 0)
			{
				printf("NEGATIVE CYCLE\n");
				flag = 1;
				break;
			}
				
		if(flag == 1)
			continue;		
				 
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if(G[i][j] == INF && j < n-1)
					printf("INF ");
				else if(G[i][j] == INF && j < n)
					printf("INF");
				else if(G[i][j] != INF && j < n-1)
					printf("%lld ", G[i][j]);
				else if(G[i][j] != INF && j < n)
					printf("%lld", G[i][j]);
			}
			printf("\n");
		}
	}


	return  0;
}



Measured memory_bytes: 3344
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll

using namespace std;
using Graph = vector<vector<int> >;

const int MAX = 101010;
vector<int> is_prime(MAX, 1);
int ansarray[MAX];

void make_primes() {
  // initialization
  is_prime[0] = 0; is_prime[1] = 0;

  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) continue;
    for (int j = i * 2; j < MAX; j += i) {
      is_prime[j] = 0;
    }
  }
}


int main() {
  int N; cin >> N;
  vector<pair<int, int> > Input(N);

  int maxn = -1;
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    Input[i] = make_pair(a, b);
    maxn = max(maxn, b);
  }

  memset(ansarray, 0, sizeof(ansarray));
  make_primes();
  
  for (int i = 1; i <= maxn; i++) {
    if (is_prime[i] && is_prime[(i + 1) / 2]) ansarray[i] = 1;
    ansarray[i] += ansarray[i-1];
  }

  for (auto x : Input) {
    cout << ansarray[x.second] - ansarray[x.first - 1] << endl;
  }
  // cout << "here" << endl;
  // for (int i = 0; i < 10; i++) {
  //   cout << ansarray[i] << endl;
  // }
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int mp[100001]={0};
  for(int i=0;i<n;i++){
    mp[a[i]]++;
  }
  int ans =0;
  int c=0;
  for(int i=0;i<100001;i++){
    if(mp[i]>=2){
      c+=mp[i]-1;
    }
    if(mp[i]>=1)
      ans++;
  }
  if(c%2==1)
    ans--;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    bytes: Vec<u8>,
    begin: usize,
    end: usize,
}

impl Scanner {
    pub fn new() -> Self {
        use std::io::Read;
        let mut buffer: Vec<u8> = Vec::new();
        std::io::stdin().read_to_end(&mut buffer).unwrap();
        let end = (0..buffer.len())
            .find(|i| buffer[*i].is_ascii_whitespace())
            .unwrap_or(buffer.len());
        Scanner {
            bytes: buffer,
            begin: 0,
            end: end,
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
        let ret: T = s.parse::<T>().ok().expect("Parse error.");
        self.skip();
        ret
    }
    pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
    pub fn next_word(&mut self) -> Vec<u8> {
        let r = Vec::from(&self.bytes[self.begin..self.end]);
        self.skip();
        r
    }
    fn skip(&mut self) {
        self.begin = (self.end..self.bytes.len())
            .find(|i| !self.bytes[*i].is_ascii_whitespace())
            .unwrap_or(self.bytes.len());
        self.end = (self.begin..self.bytes.len())
            .find(|i| self.bytes[*i].is_ascii_whitespace())
            .unwrap_or(self.bytes.len());
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
    pans: usize,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    ans[u] = if dp[idx] == i32::max_value() {
        pans + 1
    } else {
        pans
    };
    dp[idx] = a[u];

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge, ans[u]);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge, 0);
    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 39220
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


int main(){
  int n;
  string result;

  cin >> n;

  if(n < 1200)
    result = "ABC";
  else if(n < 2800)
    result = "ARC";
  else
    result = "AGC";


  cout << result << endl;

  return 0;
}


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

int main(){
    int n,flag=1,ans=0,num=1;
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
        if(A[i]==1){
            flag = 0;
        }
    }
    if(flag){
        cout << -1 << endl;
        return 0;
    }
    
    for(int i=0;i<n;i++){
        if(A[i]!=num){
            ans++;
        }else{
            num++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
  int n, m, c;
  scanf("%d%d%d", &n, &m, &c);
  int b[m], a[n][m], count = 0;
  for (size_t i = 0; i < m; i++) {
    scanf("%d", b+i);
  }
  for (size_t i = 0; i < n; i++) {
    int d = c;
    for (size_t j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      d += a[i][j] * b[j];
    }
    count += (d > 0) ? 1 : 0;
  }
 printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
n,m = map(int, input().split())
K = []
A = []
for _ in range(n):
  k, *a = map(int, input().split())
  K.append(k)
  A.append(a)
C = 0
for a in A[0]:
  c = 0
  for i in range(1,n):
    if A[i].count(a):
      c += 1  
  if c==n-1:
    C += 1  
print(C)

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

using namespace std;

const int N = 1e5 + 5;

int a[N], b[N];
long long ans[12];
map< pair<int, int>, int > mp;

int main() {
  int h, w, n;
  scanf("%d %d %d", &h, &w, &n);
  vector < int > vh;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", a+i, b+i);
    for (int j = -2; j <= 0;  j++)
      for (int k = -2; k <= 0; k++) {
        int x = a[i] + j, y = b[i] + k;
        if (x > 0 && x+2 <= h && y > 0 && y+2 <= w)
          mp[make_pair(x, y)]++;
      }
  }
  for (auto it = mp.begin(); it != mp.end(); it++)
    ans[it->second]++;
  ans[0] = max(0LL, (long long)1LL * (h-2) * (w-2) - (long long)mp.size());
  for (int i = 0; i < 10; i++)
    printf("%lld\n", ans[i]);
  return 0;
}

Measured memory_bytes: 57216
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	int X[10000];
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = ans + 2 * min(X[i], K - X[i]);
	}
	cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuRangeSumQuery solver = new AizuRangeSumQuery();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuRangeSumQuery {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();

            int[] a = new int[n];
            int[] b = new int[4 * n];

            build(0, 0, n - 1, a, b);

            while (q-- != 0) {
                int o = in.nextInt();
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                if (o == 0) {
                    update(0, 0, n - 1, l, r + 1, a, b);
                } else {
                    out.printf("%d\n", query(0, 0, n - 1, l, r, b));
                }
            }
        }

        private void build(int n, int s, int e, int[] a, int[] b) {
            if (s == e) {
                b[n] = a[s];
            } else {
                int m = (s + e) / 2;
                build(2 * n + 1, s, m, a, b);
                build(2 * n + 2, m + 1, e, a, b);

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private void update(int n, int s, int e, int idx, int val, int[] a, int[] b) {
            if (s == e) {
                a[idx] += val;
                b[n] += val;
            } else {
                int m = (s + e) / 2;
                if (s <= idx && idx <= m) {
                    update(2 * n + 1, s, m, idx, val, a, b);
                } else {
                    update(2 * n + 2, m + 1, e, idx, val, a, b);
                }

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private long query(int n, int s, int e, int l, int r, int[] b) {
            if (r < s || e < l) {
                return 0;
            } else if (l <= s && e <= r) {
                return b[n];
            } else {
                int m = (s + e) / 2;
                long s1 = query(2 * n + 1, s, m, l, r, b);
                long s2 = query(2 * n + 2, m + 1, e, l, r, b);

                return s1 + s2;
            }
        }

    }
}




Measured memory_bytes: 134124
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	ll N;
	cin>>N;
	vector<ll> d(N);
	rep(i,N) cin>>d[i];
	ll ans=0;
	rep(i,N){
		rep(j,N){
			if(i<j){
				ans+=d[i]*d[j];
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

void yari(vector<int> &a,int n){
    n += 1;
    REP(i,a.size()){
        if(a[i] <= 0){
            n ++;
        }
        a[i]--;
    }
}


signed main(){
    int n;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    int ans = 0;
    int bo = 0;
    while(bo == 0){
        bool renzoku = false;
        REP(i,a.size()){
            if(a[i] > 0){
                if(renzoku){

                }
                else{
                    renzoku = true;
                    ans++;
                }
            }
            else{
                renzoku = false;
            }
            a[i]--;
            if(a[i]>0){
                bo = 2;
            }
        }
        if(bo==2){
            bo = 0;
        }
        else{
            bo = 1;
        }
    }
    cout << ans << endl;
    
    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Team struct {
	Name string
	Win, Lose, Draw, Index int
}
type lessFunc func(p1, p2 *Team) bool
type multiSorter struct {
	teams []Team
	less    []lessFunc
}
func (ms *multiSorter) Sort(teams []Team) {
	ms.teams = teams
	sort.Sort(ms)
}
func OrderedBy(less ...lessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.teams)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.teams[i], ms.teams[j] = ms.teams[j], ms.teams[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.teams[i], &ms.teams[j]
	var k int
	for k = 0; k < len(ms.less)-1; k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	win := func(c1, c2 *Team) bool {
		return c1.Win > c2.Win
	}
	lose := func(c1, c2 *Team) bool {
		return c1.Lose < c2.Lose
	}
	index := func(c1, c2 *Team) bool {
		return c1.Index < c2.Index
	}

	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		teams := make([]Team, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			name := buf[0]
			tmp := make([]int, n-1)
			for i := range tmp {
				tmp[i], _ = strconv.Atoi(buf[i+1])
			}
			cntwin, cntlose, cntdraw := 0, 0, 0
			for _, v := range tmp {
				switch v {
				case 1:
					cntlose++
				case 0:
					cntwin++
				case 2:
					cntdraw++
				}
			}
			teams[i] = Team{name, cntwin, cntlose, cntdraw, i}
		}
		OrderedBy(win, lose, index).Sort(teams)
		for _, t := range teams {
			fmt.Println(t.Name)
		}
	}
}


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

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

  vector<ll> T(5, 0);

  string s;
  for(ll i = 0; i < n; i++){
    cin >> s;
    if(s[0] == 'M') T[0]++;
    if(s[0] == 'A') T[1]++;
    if(s[0] == 'R') T[2]++;
    if(s[0] == 'C') T[3]++;
    if(s[0] == 'H') T[4]++;
  }

  ll ans = 0;
  for(int i = 0; i < 3; i++){
    for(int j = i+1; j < 4; j++){
      for(int k = j+1; k < 5; k++){
        ans += T[i] * T[j] * T[k];
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n , r = map(int, input().split())
while(n != 0 or r != 0):
    deck = []
    for i in range(n):
        deck.append(i+1)
    deck.reverse()
    for i in range(r):
        p, c = map(int, input().split())
        deck[:p + c -1] = deck[p-1:p+c-1] + deck[:p-1]
    print(deck[0])
    n , r = map(int, input().split())
    


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int MAXM = 200100;

struct edge{int st, ed; edge(int ast = 0, int aed = 0){st = ast; ed = aed;}};
int n, a, b, ans;
int tot, frt[MAXN], nxt[MAXM]; edge ed[MAXM];
int forb, fa[MAXN], dis[MAXN];

inline void add_edge(int au = 0, int av = 0){
	ed[++tot] = edge(au, av);
	nxt[tot] = frt[au]; frt[au] = tot;
}
void dfs(int u){
	int v;
	for(int i = frt[u]; i; i = nxt[i]){
		v = ed[i].ed;
		if(dis[v] == -1 && v != forb){
			dis[v] = dis[u] + 1;
			fa[v] = u;
			dfs(v);
		}
	}
}

int main(){
	int av, au;
	scanf("%d %d %d", &n, &a, &b);
	for(int i = 1; i < n; i++){
		scanf("%d %d", &au, &av);
		add_edge(au, av); add_edge(av, au);
	}
	ans = 0; forb = -1;
	memset(fa, -1, sizeof(fa));
	memset(dis, -1, sizeof(dis));
	fa[a] = 0; dis[a] = 0; dfs(a);
	int D = dis[b], arr[MAXN], tmps = b; arr[0] = 0;
	while(tmps != a) arr[++arr[0]] = tmps, tmps = fa[tmps]; arr[++arr[0]] = a;
	int newrt = arr[arr[0] - (arr[0] >> 1) + 1];
	if(D % 2 == 0) ans++;
	// for(int i = 1; i <= arr[0]; i++) printf("%d ", arr[i]); printf("\n");
	// printf("%d\n", newrt);
	ans += (arr[0] >> 1) - 1;
	// printf(":%d\n", ans);
	memset(fa, -1, sizeof(fa));
	memset(dis, -1, sizeof(dis));
	fa[newrt] = 0; dis[newrt] = 0; forb = arr[arr[0] - (arr[0] >> 1)];
	// printf("%d\n", forb);
	dfs(newrt);
	int maximum = 0; for(int i = 1; i <= n; i++) maximum = max(maximum, dis[i]);
	ans += maximum;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6272
//ヘッダー
#include <bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

//REPマクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a)
{
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts)
{
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(), (x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      //size
#define MAX(x) *max_element(ALL(x))   //最大値
#define MIN(x) *min_element(ALL(x))   //最小値

int main()
{
    ll N;
    cin >> N;
    ll ans = 1;
    ll sum = 0;
    ll t, a;
    REP(i, N)
    {
        ll T, A;
        cin >> T >> A;
        if (i == 0)
        {
            t = T;
            a = A;
            sum = t + a;
        }
        else
        {
            ll k1 = (t - 1) / T + 1;
            ll k2 = (a - 1) / A + 1;
            ll k3 = (sum - 1) / (T + A) + 1;
            ll k = max(k1, k2);
            k = max(k, k3);
            sum = k * (T + A);
            t = k * T;
            a = k * A;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 2050
#define MAXM MAXN * MAXN
#define mod 1000000007
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int n, k;
ll fac[MAXM], invf[MAXM], dp[MAXN][MAXN];
ll fpow(ll x, ll y) {
	ll ret = 1;
	while(y) {
		if(y & 1) ret = ret * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ret;
}
ll C(int n, int m) {
	if(n == m) return 1;
	return fac[n] * invf[m] % mod * invf[n-m] % mod;
}
int main() {
	read(n, k);
	fac[0] = 1;
	rep(i, 1, n*k) fac[i] = fac[i-1] * i % mod;
	invf[n*k] = fpow(fac[n*k], mod-2);
	repd(i, n*k, 1) invf[i-1] = invf[i] * i % mod;
	dp[0][0] = 1;
	rep(j, 1, n) dp[0][j] = dp[0][j-1] * C(j*(k-1)-1, k-2) % mod;
	rep(i, 1, n) 
		rep(j, i, n)
			dp[i][j] = (dp[i-1][j] + dp[i][j-1] * C(j*(k-1)+i-1, k-2)) % mod;
	cout << dp[n][n] * (k > 1 ? fac[n] : 1) % mod << endl;
	return 0;
}


Measured memory_bytes: 98560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int32_t main()
{
    fastio();
    int n;
    cin>>n;
    int a[n+1];
    f(i,1,n+1)
    cin>>a[i];
    int an[n+1];
    memset(an,0,sizeof(an));
    for(int i=n;i>n/2;i--)
    {
        if(a[i]==1)
            an[i]=1;
    }
    for(int i=n/2;i>=1;i--)
    {
        int tp=0;
        for(int j=2*i;j<=n;j+=i)
        {
            if(an[j]==1)
                tp++;
        }
        if(tp%2!=a[i])
            an[i]=1;
    }
    f(i,1,n+1)
    {
        int tp=0;
        for(int j=i;j<=n;j+=i)
        {
            tp+=an[j];
        }
        if(tp%2!=a[i])
        {
            cout<<-1;
            return 0;
        }
    }
    int ct=0;
    f(i,1,n+1)
    {
        if(an[i]==1)
            ct++;
    }
    cout<<ct<<endl;
    f(i,1,n+1)
    {
        if(an[i]==1)
            cout<<i<<" ";
    }
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define inf 0x7FFFFFFF
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<string>s(n);
	for(auto&i:s)cin>>i;
	vector<vector<int>>v(n,vector<int>(26,0));
	for(int i=0;i<n;++i){
		for(int j=0;j<s.at(i).size();++j){
			++v.at(i).at(s.at(i).at(j)-'a');
		}
	}
	vector<int>ans(26,inf);
	for(int y=0;y<n;++y){
		for(int x=0;x<26;++x){
			ans.at(x)=min(ans.at(x),v.at(y).at(x));
		}
	}
	for(int i=0;i<26;++i){
		while(ans.at(i)){
			cout<<(char)('a'+i);
			--ans.at(i);
		}
	}
	cout<<"\n"s;
}

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

int main() {
	// your code goes here
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	int dp[n+1];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	dp[2]=min(abs(a[2]-a[0]),abs(a[2]-a[1])+dp[1]);
	for(i=3;i<n;i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

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

using namespace std;

int main() {
    string s , a = "" , b = "";
    cin>>s;
    for(int i = 0 ; i < 12; ++i){
        if(i < 4){
            a += s[i];
        }else b += s[i];
    }
    cout<<a<<" "<<b<<"\n";
}

Measured memory_bytes: 256
import java.util.*;


class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++){
            p[i]=sc.nextInt();
        }

        Arrays.sort(p);
        int K = p[n/2] - p[n/2-1];
        System.out.println(K);
    }
}

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

using namespace std;


int main() {

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

    int l,k;
    cin>>l;
    double ans;

    double tmp = (double)l/3.0;
    ans = tmp*tmp*tmp;

    printf("%0.12f\n",ans);


    return 0;
}


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

#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()cout
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)

signed main(){
  int A,B,N,M,O,P,count=0,count2=0,count3=0,stack=0;
  str S,T;
  cin>>A>>B>>N;
  rep(0,10){
    N=A*N-B;
    cout<<N<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        long[] A = new long[N+1];
        for (int i = 1; i <= N; i++) {
            A[i] = scanner.nextLong();
        }

        long[] DP = new long[N+1];

        DP[0] = 1000;
        DP[1] = 1000;

        for (int i = 2; i <= N; i++) {
            for (int j = 1; j < i; j++) {
                DP[i] = Math.max(DP[j], A[i] * (DP[j]/A[j]) + DP[j]%A[j]);
            }
        }

        System.out.println(DP[N]);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 36120
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 1000000007LL
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,n_;
ll a,b;
ll s[150001];
ll dp[1<<21];

void update(int k,ll a){
	k+=n_-1;
	dp[k]=a;
	while(k>0){
		k=(k-1)/2;
		dp[k]=(dp[k*2+1]+dp[k*2+2])%MOD;
	}
}

ll query(int a,int b,int k=0,int l=0,int r=n_){
	if(b<=l || r<=a)return 0;
	if(a<=l && r<=b)return dp[k];
	ll vl=query(a,b,k*2+1,l,(l+r)/2);
	ll vr=query(a,b,k*2+2,(l+r)/2,r);
	return (vl+vr)%MOD;
}

int main(void){
	scanf("%d%lld%lld",&n,&a,&b);
	if(n==1){
		printf("2\n");
		return 0;
	}
	n_=1;
	while(n_<=n)n_*=2;
	if(a>b)swap(a,b);
	for(int i=1;i<=n;i++){
		scanf("%lld",&s[i]);
	}
	s[0]=-INF*INF;
	n++;
	for(int i=0;i<n-2;i++){
		if(s[i+2]-s[i]<a){
			printf("0\n");
			return 0;
		}
	}
	int now=1,prev=0;
	int zero=0;
	update(0,1);
	for(int i=1;i<n;i++){
		int l=upper_bound(s,s+n,s[i]-b)-s;
		ll val=query(0,l);
		update(i,val);
		if(s[i]-s[i-1]<a){
			for(int j=zero;j<i-1;j++){
				update(j,0);
			}
			zero=i-1;
		}
	}

	printf("%lld\n",query(0,n));
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    n %= 26;
    rall(c, s) {
        char d = c + n;
        if(d > 'Z') d -= 26;
        cout << d;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
list1 = []
list2 = []

for i in range(len(S) - 2):
	num = int(S[i:i+3])
	list1.append(num)

for i in range(len(list1)):
	diff = abs(list1[i] - 753)
	list2.append(diff)

print(min(list2))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn=4e3+5, INF=1e9;
int n, k, q, cntc, a[maxn], b[maxn], dable[maxn], ans=INF;
int fa[maxn], len[maxn];  //len表示一个结点所代表的区间长度

struct Node{  //对能选的数排序
    int v, id;
}c[maxn];

bool cmp(const Node &a, const Node &b){ return a.v<b.v; }

int main(){
    scanf("%d%d%d", &n, &k, &q); int x, cnt, minm, t;
    for (int i=1; i<=n; ++i){ scanf("%d", &a[i]); b[i]=a[i]; }
    sort(b+1, b+n+1);
    for (int i=1; i<=n; ++i){ x=b[i];  //x表示最小的最小元素
        memset(dable, 0, sizeof(dable));
        memset(fa, 0, sizeof(fa)); cntc=0; t=1;
        for (int j=1; j<=n; ++j) if (a[j]<x) dable[j]=1;  //比x小的数不能选
        for (int j=1; j<=n; ++j){  //j-t表示区间长度 t是区间起点
            if (!dable[j]) fa[j]=t, c[++cntc].v=a[j], c[cntc].id=j;
            if (dable[j]) len[t]=j-t, t=j+1;
        }
        len[t]=n+1-t;
        sort(c+1, c+cntc+1, cmp); cnt=1;
        for (int j=1; cnt<=q&&j<=cntc; ++j){  //取q个数
            if (len[fa[c[j].id]]<k) continue;
            --len[fa[c[j].id]];  //取完以后所在的区间长度-1
            minm=c[j].v; ++cnt;  //minm表示最小的最大元素
        }
        if (cnt<=q) break;
        ans=min(ans, minm-x);
    }
    printf("%d\n", ans);
    return 0;
}


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

const double pi = 3.14159265358979;

int main() {
    double a, b, x; cin >> a >> b >> x;

    double theta;
    if (x > a * a * b / 2) {
        theta = atan(2 * (a * a * b - x) / (a * a * a));
    } else  {
        theta = atan(a * b * b / (2 * x));
    }

    theta = theta * 180 / pi;
    cout << fixed << setprecision(15);
    cout << theta << endl;

    return 0;
}

Measured memory_bytes: 256