akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>

#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

#include <random>
#include <ctime>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)

const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;

#define int long long

/*vector<int> pr1, pr2, sz1, sz2;

int get1(int v) {
    if (pr1[v] == v)
        return v;
    else
        return pr1[v] = get1(pr1[v]);
}

int get2(int v) {
    if (pr2[v] == v)
        return v;
    else
        return pr2[v] = get2(pr2[v]);
}

void merge1(int v, int u) {
    v = get1(v);
    u = get1(u);
    if (v == u)
        return;
    if (sz1[v] > sz1[u]) {
        sz1[v] += sz1[u];
        pr1[u] = v;
    } else {
        sz1[u] += sz1[v];
        pr1[v] = u;
    }
}

void merge2(int v, int u) {
    v = get2(v);
    u = get2(u);
    if (v == u)
        return;
    if (sz2[v] > sz2[u]) {
        sz2[v] += sz2[u];
        pr2[u] = v;
    } else {
        sz2[u] += sz2[v];
        pr2[v] = u;
    }
}*/

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

    int w, h;
    cin >> w >> h;
    vector<int> p(w), q(h);
    FOR(i, 0, w)
        cin >> p[i];
    FOR(i, 0, h)
        cin >> q[i];
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    int p1 = 0, p2 = 0, cnt1 = w + 1, cnt2 = h + 1, ans = 0;
    while (p1 < w && p2 < h) {
        if (p[p1] < q[p2]) {
            ans += p[p1] * cnt2;
            --cnt1;
            ++p1;
        } else {
            ans += q[p2] * cnt1;
            --cnt2;
            ++p2;
        }
    }
    while (p1 < w) {
        ans += p[p1] * cnt2;
        --cnt1;
        ++p1;
    }
    while (p2 < h) {
        ans += q[p2] * cnt1;
        --cnt2;
        ++p2;
    }
    cout << ans << "\n";

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
    int a, b, c;
    cin >> a >> b >> c;
	if(a==b && a!=c) cout << "Yes" << endl;
  	else if(b==c && b!=a) cout << "Yes" << endl;
  	else if(c==a && c!=b) cout << "Yes" << endl;
  	else cout << "No" << endl;   	 
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

using namespace std;

#define int long long
#define fr(i, n) for(int i=0;i<n;i++)
#define frr(i, n) for(int i=n;i>=0;i--)
#define fra(i, a, n) for(int i=a;i<n;i++)
#define frra(i, a, n) for(int i=a;i>=n;i--)
#define f(i, a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef set<int> si;
typedef unordered_map<int, int> uii;
typedef unordered_set<int> usi;

const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int inf = LONG_LONG_MAX;
const double eps = 1e-9;
const double pi = 3.14159265358979323;

int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1)res = (res * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return res;
}

void solve() {
    //CODE BEGIN
    int n, W;
    cin >> n >> W;
    vi wt(n), v(n);
    vvi dp(n + 1, vi(W + 1));
    for (int i = 0; i < n; ++i) {
        cin >> wt[i] >> v[i];
    }
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= W; ++j) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
            } else if (j >= wt[i - 1]) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + v[i - 1]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][W] << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int test = 1;
//    cin >> test;
    for (int i = 0; i < test; ++i) {
//        cout << "Case #" << i + 1 << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>

using namespace std;
using ll = long long;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    string ans ="NO";
    for(int i=1; i<=b; i++){
        if((a*i)%b==c){
            ans = "YES";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int N;
  string S;
  cin >> N >> S;
  int dp[N][2];
  int tmp = 0;
  for(int i=1; i<N; i++){
    if(S[i] == 'E') tmp++;
  }
  dp[0][0] = tmp; // 東にいて東を向いてる                                                                       
  dp[0][1] = 0; // 西にいて西を向いてる                                                                         
  for(int i=1; i<N; i++){
    dp[i][0] = dp[i-1][0];
    dp[i][1] = dp[i-1][1];
    if(S[i] == 'E'){
      dp[i][0]--;
    }
    if(S[i-1] == 'W'){
      dp[i][1]++;
    }
  }
  int ret = N+1;
  for(int i=0; i<N; i++){
    // cout << dp[i][0] << ' ' << dp[i][1] << endl;                                                             
    if(dp[i][0] + dp[i][1] < ret)
      ret = dp[i][0] + dp[i][1];
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;

int main() {
    int n;
    cin>>n;
    int t;
    cin>>t;
    long long int ans = 0, max = t;
    for(int i = 1; i < n; i++) {
        cin>>t;
        if(t < max) {
            ans += max-t;
        }
        else if(t > max) {
            max = t;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  char s[101];
  scanf("%s", s);

  int n = strlen(s);
  printf("%c%d%c\n", s[0], n-2, s[n-1]);
  return 0;
}


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

int a[110];
int main(void)
{
    int n;
    cin>>n;
    double sum=0.0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    double ave=sum*1.0/n;
    int x=int(ave);
    int y=x+1;
    int ans;
    if(ave-x<=y-ave)
    {
        ans=x;
    }
    else
    {
        ans=y;
    }
    int s=0;
    for(int i=0;i<n;i++)
    {
        s+=(a[i]-ans)*(a[i]-ans);
    }
    cout << s<<endl;
    return 0;
}


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

int main(){
	int n, i, t, x, y = 0, ans;
	cin >> n;
	int a[n];
	
	for (i = 0; i < n; i++){
		cin >> a[i];
	}
	x = a[0];
	for (i = 1; i < n; i++){
		y += a[i];
	}

	ans = abs(x - y);
	for (i = 1; i < n - 1; i++){
		x += a[i];
		y -= a[i];
		t = abs(x - y);
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007

using namespace std;
#define ll long long
#define dbg if(0)

int main(){
    ll n;
    do{
        cin >>n;
        if (n==0)break;
        int mtown=0;
        ll g[10][10];
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                g[i][j]=INT_MAX;
            }
                g[i][i]=0;
        }
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            mtown=max(a,max(mtown,b));
            g[a][b]=c;
            g[b][a]=c;
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
                }
            }
        }
        dbg{
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    cout <<g[i][j]<<" ";
                }
                cout <<endl;
            }
        }
        ll ans=INT_MAX;
        ll ansid=11;
        for(int i=0;i<=mtown;i++){
            ll cand=0;
            for(int j=0;j<=mtown;j++){
                if (g[i][j]==INT_MAX)break;
                cand+=g[i][j];
            }
            if(ans>=cand){
                if (cand==ans){
                    ansid=min((ll)i,ansid);
                }else{
                    ans=cand;
                    ansid=i;
                }
            }
        }
        cout <<ansid<<" "<<ans<<endl;
    }while(1);

    return 0;
}




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

int main(){
    int N;  cin >> N;
    string S, T;  cin >> S >> T;
    string ans = "";
    for(int i=0; i<N; i++){
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int w = 0;
        int l = 0;
        int g = 1;
        int p = 0;
        if (s.charAt(0) == 'p') {
            l++;
        }
        for (int i = 1; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'g') {
                if (g > p) {
                    w++;
                    p++;
                } else {
                    g++;
                }
            } else {
                if (g > p) {
                    p++;
                } else {
                    l++;
                    g++;
                }
            }
        }
        System.out.println(w - l);
    }
}

Measured memory_bytes: 24608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
vector<int> f;
int solve(int i){
  if(f.size()>i){
    return f[i];
  }
  int flag=__builtin_popcount(i);
  int res=solve(i%flag)+1;
  return res;
}
int Smod(string const& s,int m){
    if(m==0)return 0;
  //stringからmodをとってintで返す
  int res=s[0]-'0';
  int n=s.length();
  for(int i=1;i<n;++i){
    res=res*2+s[i]-'0';
    res%=m;
  }
  return res;
}
long long myPow(int x,int n,int rest){
    int res=1;
    int cur=x;
    while(n>0){
        if(n&1){
            res*=cur;
            res%=rest;
        }
        n/=2;cur*=cur;
        cur%=rest;
    }
    return res;
}
signed main(){
  int n;cin>>n;
  string x;cin>>x;
  f.push_back(0);
  rep1(i,n){
    int buf=solve(i);
    f.push_back(buf);
  }
  /*
  vector<int> hoge(n);
  rep(i,n){
    cin>>hoge[i];
  }*/
  int flag=0;
  rep(i,n){
    if(x[i]=='1')++flag;
  }
  int z0=Smod(x,flag);
  int p1=Smod(x,flag+1);
  int m1=0;
  if(flag>0)m1=Smod(x,flag-1);
  rep(i,n){
    int ans;
    if(x[i]=='0'){
      int buf=p1;
      buf+=myPow(2,n-i-1,flag+1);
      buf%=flag+1;
      ans=f[buf];
    }
    else if(flag>1){
      int buf=m1;
      buf+=flag-1-myPow(2,n-i-1,flag-1);
      buf%=flag-1;
      ans=f[buf];
    }
    else{
        ans=-1;
    }
    cout<<ans+1<<"\n";
  }
  return 0;
}


Measured memory_bytes: 5564
#include <iostream>

using namespace std;

int N;
int A[3][110];
int main(void) {

	cin >> N;
	for (int i = 1; i <= 2; i++) {
		for (int j = 1; j <= N; j++) {
			cin >> A[i][j];
		}
	}

	int sum = 0;
	int ans = 0;

	for (int j = 1; j <= N; j++) {
		sum = 0;
		for (int k = 1; k <= j - 1; k++) {
			sum += A[1][k];
		}
		sum += A[1][j];
		sum += A[2][j];
		for (int k = j + 1; k <= N; k++) {
			sum += A[2][k];
		}

		if (sum > ans) { ans = sum; }
	}

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define One_for(i,n) for(int i=1;i<=n;++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=1;i<=b;++i)
#define int long long
static const int INF = 1<<25;
using namespace std;

int N,W;
int v[10010],w[10100];
int mem[10100][10100];
int ans;
int dfs(int n,int h){
    if(mem[n][h]!=0)ans=mem[n][h];
    else if(n==0||h==0)ans=0;
    else if(h<w[n])ans=dfs(n-1,h);
    else ans=max(max(dfs(n-1,h),dfs(n-1,h-w[n])+v[n]),
                 max(dfs(n-1,h),dfs(n,h-w[n])+v[n]));
    return mem[n][h]=ans;
}

signed main(){
    cin>>N>>W;
    One_for(i,N){
        cin>>v[i]>>w[i];
    }
    cout<<dfs(N,W)<<endl;
}

Measured memory_bytes: 9980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数
uintmax_t combination(unsigned int n, unsigned int r){    //組み合わせ
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

int main()
{
  ll n,a,b,c,d,e,ti;
  vector<ll> t;
  cin >> n >> a >> b >> c >> d >> e;
  t.push_back(a);
  t.push_back(b);
  t.push_back(c);
  t.push_back(d);
  t.push_back(e);

  sort(t.begin(), t.end());
  if(n%t[0]==0)
    ti = n / t[0]+4;
  else
  {
    ti = n / t[0] + 1+4;
  }
  cout << ti << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    // 入力
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);                           //コストの配列
    vector<vector<int>> vec(n, vector<int>(m)); //教科書で学べるアルゴリズムとその理解度
    rep(i, n)                                   //n冊分
    {
        cin >> c[i]; //教科書の価格
        rep(j, m)    //アルゴリズム分
        {
            cin >> vec[i][j]; //学べるアルゴリズムと理解度の表
        }
    }

    int ans = inf;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        int cost = 0;
        vector<int> d(m);
        rep(i, n)
        {
            if (bit & 1 << i)
            {
                cost += c[i];
                rep(j, m)
                {
                    d[j] += vec[i][j];
                }
            }
        }

        bool ok = true;
        rep(i, m)
        {
            if (d[i] < x)
                ok = false;
        }
        if (ok)
            ans = min(ans, cost);
    }
    if (ans == inf)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

int main() {
    int a,b;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b)<<endl;





    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long INF = 1e18;
int x[N];
long long f[N];
long long calc(int j) {
	return f[j] - x[j];
}
int main() {
	int n, E, T;
	scanf("%d%d%d", &n, &E, &T);
	for (int i = 1; i <= n; ++ i) scanf("%d", &x[i]);
	deque<int> q;
	x[0] = 0;
	q.push_back(0);
	long long MIN = INF;
	int r = 0;
	for (int i = 1; i <= n; ++ i) {
		while (2 * (x[i] - x[r + 1]) >= T) {
			MIN = min(MIN, - 2LL * x[r + 1] - x[r] + f[r]);
			++ r;
		}
		while (q.front() < r) q.pop_front();
		int t = q.front();
		f[i] = min(3LL * x[i] + MIN, x[i] + T + calc(t));
		while (!q.empty() && calc(q.back()) > calc(i)) q.pop_back();
		q.push_back(i);
	}
	long long ans = E - x[n] + f[n];
	printf("%lld\n", ans);
}



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

int main(){
    string S;
    int max=0,ans=0;
    cin>>S;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='A'||S.at(i)=='T'||S.at(i)=='G'||S.at(i)=='C'){
            ++ans;
            if(ans>max){
                max = ans;
            }
        }else{
            ans = 0;
        }
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		String N = sc.next();
		int sum = 0;
		
		for (int i = N.length() - 1; i >= 0; i--) {
			sum += Integer.valueOf(N.substring(i, i + 1));
		}
		// System.out.println(sum);
		if (Integer.valueOf(N) % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 23764
let [| N; Q |] = stdin.ReadLine().Split() |> Array.map int
let S = stdin.ReadLine()

let lr = Array.zeroCreate<int []> Q

for i in [ 0..Q - 1 ] do
    lr.[i] <- stdin.ReadLine().Split() |> Array.map int

let t = Array.zeroCreate<int> (N + 1)

for i in [ 1..N - 1 ] do
    if S.[i - 1] = 'A' && S.[i] = 'C' then t.[i + 1] <- t.[i] + 1
    else t.[i + 1] <- t.[i]

for i in [ 0..Q - 1 ] do
    t.[lr.[i].[1]] - t.[lr.[i].[0]] |> stdout.WriteLine


Measured memory_bytes: 35244
N, K = map(int, input().split())
MOD = 10**9 + 7

ans = 0
for k in range(K, N + 2):
    base = k * (k - 1) // 2
    mx = base + k + (N - k) * k
    ans += mx - base + 1
    ans %= MOD

print(ans)


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;


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

	int N;
	cin>>N;
	long long res = 0;
	vector<long long> A(N),B(N);
	for(int i = 0;i < N;i++) {
		cin>>A[i]>>B[i];
	}
	for(int i = N-1;i >= 0;i--) {
		A[i] += res;
		res += (A[i] + B[i] - 1ll) / B[i] * B[i] - A[i];
	}
	cout<<res<<'\n';
	return 0;
}
/**/


Measured memory_bytes: 1792
fun main(args: Array<String>){
    val N :Int = readLine()!!.toInt()
    val x = readLine()!!.split(" ").map(String::toInt)
    val y = x.toIntArray()
    y.sort()
    val ml = y[N/2-1]
    val mr = y[N/2]
    val sb = StringBuilder()
    for(i in x.indices){
      if(x[i]<=ml){
        sb.append(mr.toString())
        sb.append('\n')
      }
      else{
        sb.append(ml.toString())
        sb.append('\n')
      }
    }
    print(sb.toString())
}


Measured memory_bytes: 99528
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#define rep(i,n) for (int i=0; i<n;++i)
int N,H,W;


int main() {
  cin >> N >> H >> W;
  cout << (N-H+1)*(N-W+1) << endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

int h, w, dp[500][500];
string str[500];

int main() {
	while (cin >> h >> w, h || w) {
		REP(i, h) cin >> str[i];
		
		fill(dp[0], dp[500], 0);
		
		REP(i, h) REP(j, w) {
			int cnt = 0;
			FOR(k, i, h) {
				if (str[k][j] == '*') break;
				cnt++;
			}
			dp[i][j] = cnt;
		}
		
		int ans = 0;
		REP(i, h) REP(j, w) {
			int tmp = INF;
			FOR(k, j, w) {
				tmp = min(tmp, dp[i][k]);
				if (dp[i][k] == 0) break;
				ans = max(ans, (k - j + 1) * tmp);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2452
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
string s, t;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s >> t;
    int sl = s.size();
    int tl = t.size();
    reverse(ALL(s));
    reverse(ALL(t));
    bool c = false;
    for (int i = 0; i < sl - tl + 1; i++)
    {
        if (c == true)
            break;
        int count = 0;
        for (int j = 0; j < tl; j++)
        {
            if (s[i + j] == t[j] || s[i + j] == '?')
            {
                count++;
            }
            else
                break;
            if (count == tl)
            {
                for (int j = 0; j < tl; j++)
                {
                    s[i + j] = t[j];
                }
                c = true;
            }
        }
    }
    if (c == false)
    {
        cout << "UNRESTORABLE"
             << "\n";
        return 0;
    }
    for (int i = 0; i < sl; i++)
    {
        if (s[i] == '?')
            s[i] = 'a';
    }
    reverse(ALL(s));
    cout << s << "\n";
}

Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_STONE_MAX		200005									// 最大石数

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Stone[D_STONE_MAX];								// 石
static int siSCnt;												// 石数
static int si1SumLW[D_STONE_MAX];								// 白石合計[左位置]
static int si1SumRR[D_STONE_MAX];								// 赤石合計[右位置]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最小値 - 取得
int
fGetMinI(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	if (piVal1 < piVal2) {
		return piVal1;
	}
	else {
		return piVal2;
	}
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 石数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siSCnt);

	// 石 - 取得
	fgets(&sc1Stone[1], sizeof(sc1Stone) - 1, szpFpI);

	// 石合計 - セット
	si1SumLW[0] = 0;
	for (i = 1; i <= siSCnt; i++) {
		si1SumLW[i] = si1SumLW[i - 1];
		if (sc1Stone[i] == 'W') {
			si1SumLW[i]++;
		}
	}
	si1SumRR[siSCnt + 1] = 0;
	for (i = siSCnt; i >= 1; i--) {
		si1SumRR[i] = si1SumRR[i + 1];
		if (sc1Stone[i] == 'R') {
			si1SumRR[i]++;
		}
	}

	// 最小の操作回数 - 取得
	int liMin = INT_MAX;
	for (i = 0; i <= siSCnt; i++) {

		// 石交換回数
		int liCCnt = fGetMinI(si1SumLW[i], si1SumRR[i + 1]);

		// 変色回数 - 加算
		int liSum = liCCnt;
		liSum += si1SumLW[i] - liCCnt;
		liSum += si1SumRR[i + 1] - liCCnt;

		// 最小の操作回数 - 更新
		liMin = fGetMinI(liMin, liSum);
	}

	return liMin;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		sprintf(lc1Buf, "Yes\n");
	}
	else {
		sprintf(lc1Buf, "No\n");
	}
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 3532
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define INF INT_MAX/3
#define pi 2*acos(0.0)
#define eps 1e-14

const int MAX_N = (int)1e+5;
const int MAX_M = (int)1e+2;
int n, k;
ll a[MAX_N], b[MAX_N];
void input()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		scanf("%lld", &b[i]);
	}
}


void solve() //後ろから順に行う.
{
	ll ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		a[i] += ans;
		ll push_c = b[i] - a[i] % b[i];
		if (a[i]%b[i]==0) push_c = 0;
		ans += push_c;
	}
	cout << ans << endl;
}

int main() {
	input();
	solve();
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int n;
    string s;
    int ans = 0;
    cin >> n >> s;
    rep(i, n-2) {
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  float meanF = (a + b) /2.0F;
  int meanI = (a + b) /2;
  if((meanF - meanI) >= 0.5F){
    cout << meanI + 1;
  }else{
    cout << meanI;
  }
}


Measured memory_bytes: 256
k,s = gets.split.map!(&:to_i)

if 3*k < s then
    puts 0
elsif 3*k == s 
    puts 1
else
    ans = 0
    0.upto(k) do |x|
        0.upto(k) do |y|
            break if x + y > s
            ans += 1 if s - x - y <= k
        end
    end
    puts ans
end

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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
priority_queue<ll> q2;
priority_queue<ll, vector<ll>, greater<ll> > q1;
ll n,g1,g2,dp1[200001],dp2[300001],maxf=-1e18+7;
ll a[300001];
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n*3){
		cin>>a[i];
	}
	rep(i,n*2){
		if(i<=n){
			q1.push(a[i]);
			g1+=a[i];
			dp1[i]=g1;
		}
		else{
			q1.push(a[i]);
			g1+=a[i];
			g1-=q1.top();
			dp1[i]=g1;
			q1.pop();
		}
//		cout<<dp1[i]<<' ';
	}
//	cout<<endl;
	for(ll i=n*3;i>=n+1;i--){
		if(i>=n*2+1){
			q2.push(a[i]);
			g2+=a[i];
			dp2[i]=g2;
		}
		else{
			q2.push(a[i]);
			g2+=a[i];
			g2-=q2.top();
			dp2[i]=g2;
			q2.pop();
		}
//		cout<<dp2[i]<<' ';
	}
//	cout<<endl;
	for(ll i=n;i<=n*2;i++){
		maxf=max(maxf,dp1[i]-dp2[i+1]);
	}
	cout<<maxf;
	return 0;
}

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

int main(){
int N,temp=0;
long int absolute=-10;
    cin >> N;
int A[N];
for(int i=0; i < N;i++){
    cin >> A[i];
}
    for(int i=0; i<N;i++){
        for(int j=0; j<N;j++){
        if(i!=j){
          temp= std::abs(A[i]-A[j]);
          if(absolute<temp)  absolute=temp;
        }
        }
    }
    cout << absolute << endl;
}

Measured memory_bytes: 256
n, m, l = gets.split.map(&:to_i)

vec_a = n.times.map { gets.split.map(&:to_i) }
vec_b = m.times.map { gets.split.map(&:to_i) }
vec_c = Array.new(n) { Array.new(l, 0) }

n.times do |i|
  l.times do |j|
    m.times do |k|
      vec_c[i][j] += vec_a[i][k] * vec_b[k][j]
    end
  end
end

vec_c.each do |v|
  puts v.join(' ')
end



Measured memory_bytes: 7396
#include <bits/stdc++.h>
using namespace std;
struct dat{int a,b,c,d;};

vector<dat> block[2];
dat move(dat t,int dy,int dx){
  int mp[4][4] = {};
  mp[1+dy][1+dx] = t.a;
  mp[1+dy][2+dx] = t.b;
  mp[2+dy][1+dx] = t.c;
  mp[2+dy][2+dx] = t.d;
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++){
      if((i==1&&j==1)||(i==1&&j==2)||(i==2&&j==1)||(i==2&&j==2))continue;
      if(mp[i][j] == 0)continue;
      return (dat){-1,-1,-1,-1};
    }
  return (dat){mp[1][1],mp[1][2],mp[2][1],mp[2][2]};
}

bool isEmpty(dat a){return (!a.a && !a.b && !a.c && !a.d);}
bool isFull(dat a){return (a.a && a.b && a.c && a.d);}
bool isTouch(dat a,dat t){return ((a.a && t.a)||(a.b && t.b)||(a.c && t.c)||(a.d  && t.d));}

dat merge(dat t,dat a){
  t.a|=a.a, t.b|=a.b, t.c|=a.c, t.d|=a.d;
  return t;
}

int drop(dat a,dat b,vector<dat> &mp){
  if(!isEmpty(mp.back()))mp.push_back((dat){0,0,0,0});
  
  int res = 0;
  int idx = mp.size() - 2;
  while(!isTouch(a,mp[idx]) && !isTouch(b,mp[idx+1]))idx--;
  idx++;

  if(!isEmpty(a))mp[idx] = merge(mp[idx],a);

  if(idx+1<(int)mp.size()) mp[idx+1] = merge(mp[idx+1],b);
  else if(!isEmpty(b)) mp.push_back(b);

  for(int i=mp.size()-1;i>=1;i--) if(isFull(mp[i])) mp.erase(mp.begin()+i),res++;
  return res;
}

int sim(int idx,vector<dat>mp){
  if(idx == (int)block[0].size()) return 0; 

   int res = 0; 
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      dat nx1 = move(block[0][idx],i,j);
      dat nx2 = move(block[1][idx],i,j);
      if(nx1.a == -1 || nx2.a == -1)continue;
      vector<dat> nmp = mp;
      int r = drop(nx1,nx2,nmp);
      res = max(res,r+sim(idx+1,nmp));
    }
  return res;
}

int main(){
  while(1){
    int h,n;
    cin>>h>>n;
    if(h==0&&n==0)break;
    vector<dat> mp(h+1);
    mp[0] = (dat){1,1,1,1};
    for(int i=1;i<=h;i++){
      char  a,b,c,d;
      cin>>a>>b>>c>>d;
      mp[i].a = (a == '#');
      mp[i].b = (b == '#');
      mp[i].c = (c == '#');
      mp[i].d = (d == '#');
    }

    
    block[0].resize(n); block[1].resize(n);
    for(int j=0;j<n;j++)
      for(int i=0;i<2;i++){
        char  a,b,c,d;
        cin>>a>>b>>c>>d;
        block[i][j].a = (a == '#');
        block[i][j].b = (b == '#');
        block[i][j].c = (c == '#');
        block[i][j].d = (d == '#');
      }
    cout<<sim(0,mp)<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(){
  pair<string,int> S;
  pair<string,int> T;
  cin >> S.first >> T.first;
  cin >> S.second >> T.second;
  string str;
  cin >> str;
  if(str == S.first)S.second--;
  if(str == T.first)T.second--;
  cout << S.second << " " << T.second <<endl;
}


Measured memory_bytes: 256
#include <iostream>

using lint = long long;
constexpr lint INF = 1LL << 60;

lint dfs(lint a, lint b, lint r) {
    if (a == 0 && b == 0 && r == 0) return 0;

    if ((a + b - r) % 2 != 0) return -1;

    lint ret = INF;
    for (int d = 0; d <= 1; ++d) {
        lint res = dfs((a - d) / 2, (b + d) / 2, r / 2);
        if (res == -1) continue;
        ret = std::min(ret, res * 2 + d);
    }

    return ret == INF ? -1 : ret;
}

void solve() {
    int n;
    std::cin >> n;

    lint a, b;
    std::cin >> a >> b;

    lint r = 0;
    for (int i = 0; i < n - 2; ++i) {
        lint x;
        std::cin >> x;
        r ^= x;
    }

    lint ans = dfs(a, b, r);
    std::cout << (ans >= a ? -1 : ans) << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3648
import sys
from itertools import accumulate

n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()

MOD = 10**9+7

def nCr(n, r, mod=MOD):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

res = 0
for i, a in enumerate(a_ls):
    if i >= k - 1:
        res += a * nCr(i, k - 1)
    if i <= n - k + 1:
        res -= a * nCr(n - i - 1, k - 1)
res %= MOD
print(res)

Measured memory_bytes: 74792
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		var A = new long[N];
		Arrays.setAll(A, $ -> Long.parseLong(sc.get()));

		long prevHeight = 0;
		long result = 0;
		for (long l : A) {
			if (l >= prevHeight) {
				prevHeight = l;
			} else {
				result += prevHeight - l;
			}
		}
		System.out.println(result);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 56368
def grid_compression(H: int, W: int, A: list)->list:
    # 黒を含む行・列の番号を取得する。
    cols = []
    rows = []
    # まずは行番号
    for h in range(H):
        all_white = True
        for w in range(W):
            if A[h][w] == '#':
                all_white = False
                break
        if not all_white:
            rows.append(h)

    # 次に列番号
    for w in range(W):
        all_white = True
        for h in range(H):
            if A[h][w] == '#':
                all_white = False
                break
        if not all_white:
            cols.append(w)

    # rows/cols で示される行列の値を順番に突っ込んでく
    compressed = []
    for r in rows:
        compressed.append([])
        for c in cols:
            compressed[-1].append(A[r][c])

    return compressed


if __name__ == "__main__":
    H = 0
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    ans = grid_compression(H, W, A)
    for row in ans:
        print(''.join(row))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




vector<vector<int> > v(300);

bool bipartite_graph() {
    vector<int> col(300, -1);
    col[0] = 0;
    
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : v[now]) {
            if (col[nxt] != -1) {
                if (col[nxt] == col[now]) return 0;
                continue;
            }
            col[nxt] = col[now] ^ 1;
            q.push(nxt);
        }
    }
    
    return 1;
}

int main() {
    int n;
    cin >> n;
    
    vector<vector<int> > d(n, vector<int>(n, inf));
    rep(i, n) d[i][i] = 0;
    
    rep(i, n) rep(j, n) {
        char a;
        cin >> a;
        a -= '0';
        if (a == 1) {
            v[i].eb(j);
            d[i][j] = 1;
        }
    }
    if (bipartite_graph() == 0) { cout << -1 << endl; return 0; }
    
    
    rep(k, n) rep(i, n) rep(j, n) {
        if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
    }
    
    int ma = 0;
    rep(i, n) rep(j, n) chmax(ma, d[i][j]);
    cout << ma + 1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
	int n;
	cin >> n;
	while (n % 7 and n % 4) {
		if (n < 7) {
			cout << "No" << endl;
			break;
		}
		n -= 7;
	}
	if (n >= 7 or n == 4) {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
import Data.Ord

main = do
    n <- read <$> getLine
    v <- map read <$> words <$> getLine
    putStrLn $ show $ n - solve v

solve :: [Int] -> Int
solve v | ho /= eo  = length (head vo) + length (head ve)
        | otherwise = max (length (vo !! 0) + length (ve !! 1)) (length (vo !! 1) + length (ve !! 0))
  where
    [vo, ve] = map (reverse . sortBy (comparing length) . ([] :) . group . sort) $ uninterleave v
    [ho, eo] = map (head . head) [vo, ve]
    uninterleave []      = [[], []]
    uninterleave (h : t) = [b, h : a]
      where
        [a, b] = uninterleave t


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

int main(){
	int n;
	cin >> n;
	vector< vector<int> > a(n, vector<int>(2));
	for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
	sort(a.begin(), a.end(), [](vector<int> a, vector<int> b) {
		return a[0] == b[0] ? a[1] < b[1] : a[0] < b[0];
	});
	for (int i = 0; i < n; i++) cout << a[i][0] << " " << a[i][1] << endl;
	return 0;
}


Measured memory_bytes: 8428
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	ma := make([]map[byte]int, n)
	for i := range ma {
		fmt.Scan(&s)
		ma[i] = make(map[byte]int, 0)
		for j := 0; j < len(s); j++ {
			ma[i][s[j]]++
		}
		// fmt.Println("i", i, "ma[i]", ma[i])
	}
	ans := make([]byte, 0)
	for i := 'a'; i <= 'z'; i++ {
		k := 100
		for j := 0; j < n; j++ {
			k = min(ma[j][byte(i)], k)
		}
		// fmt.Println("i", i, "k", k)
		if k > 0 {
			for j := 0; j < k; j++ {
				ans = append(ans, byte(i))
			}
		}
	}
	fmt.Println(string(ans))
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>

int main() {
	int n,some;
	std::cin >> n;
	std::vector<int> type;
	std::map<int, int> m;
	for (int i = 0; i < n; i++) {
		std::cin >> some;
		if (m[some] == 0) {
			type.push_back(some);
		}
		m[some]++;
	}
	if (type.size() % 2 == 0) {
		std::cout << type.size() - 1 << std::endl;
	}
	else {
		std::cout << type.size() << std::endl;
	}

}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>data(3*N);
  for(int i=0;i<3*N;i++){
  	cin>>data.at(i);
  }
  long long ans=0;
  sort(data.begin(),data.end());  
  reverse(data.begin(),data.end());
	for(int i=1;i<2*N;i=i+2){
  	ans=ans+data.at(i);
  }
 cout<<ans<<endl;                     
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void makeStr(const int N, const int maxIndex, string str, vector<string> & answer) {
    if (str.size() == N) {
        answer.emplace_back(str);
        return;
    }
    rep(i,0,maxIndex+1) {
        makeStr(N,max<int>(i+1,maxIndex), str + (char)('a' + i), answer);
    }
}

void solve(long long N){
    vector<string> answer;
    makeStr(N, 1, "a", answer);
    sort(all(answer));
    rep(i,0,answer.size()) {
        cout << answer[i] << "\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

int main () {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];  
  }  
  int dp[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      dp[i][j] = 0;  
    } 
  }
  int i = 0;
  int j = 0;
  for (int l = 0; l < n; l++) {
    while (a[l] > 0) {
      a[l]--;
      if (i % 2 == 0 ) {
        dp[i][j] = l + 1;  
      }  
      else {
        dp[i][w - 1 - j] = l + 1;  
      }
      j++;
      if (j == w) {
        i++;
        j = 0;  
      }
    }  
  }
  for (int p = 0; p < h; p++) {
    for (int q = 0; q < w; q++) {
      cout << dp[p][q] << " ";  
    }  
    cout << endl;
  }
}

Measured memory_bytes: 632
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b;

	cin >> a >> b;

	if (a == b){
		cout << "Draw" << endl;
	}
	else if(a == 1)
	{
		cout << "Alice" << endl;
	}
	else if (b == 1) {
		cout << "Bob" << endl;
	}
	else if (a > b) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;

	}

	
}



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

int main()
{
    int n;
    cin >> n;
    map<string, int> s;
    string t;
    for( int i = 0; i < n; i++ )
    {
        cin >> t;
        s[t] = s[t] + 1;
    }

    int max = -10000;
    for(map<string, int>::iterator itr = s.begin(); itr != s.end(); ++itr)
    {
        if( max < itr->second )
        {
            max = itr->second;
        }
    }

    for(map<string, int>::iterator itr = s.begin(); itr != s.end(); ++itr)
    {
        if( itr->second == max)
        {
            cout << itr->first << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 25216
# coding: utf-8
n=int(input())
A=list(map(int,input().split()))

S1=0
cost1=0
for i in range(n):
    if i%2==0:
        if S1+A[i]>0:
            S1+=A[i]
        else:
            cost1+=abs(S1+A[i])+1
            S1=1
    else:
        if S1+A[i]<0:
            S1+=A[i]
        else:
            cost1+=abs(S1+A[i])+1
            S1=-1

S2=0
cost2=0
for i in range(n):
    if i%2==0:
        if S2+A[i]<0:
            S2+=A[i]
        else:
            cost2+=abs(S2+A[i])+1
            S2=-1
    else:
        if S2+A[i]>0:
            S2+=A[i]
        else:
            cost2+=abs(S2+A[i])+1
            S2=1
    
print(min(cost1,cost2))

Measured memory_bytes: 14468
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{

    static int n;
    static int m;
    static int ans;
    static int[] w;
    static int[] ww;
    static boolean[] visit;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        m = sc.nextInt();
        w = new int[m];
        ww = new int[m];
        
        for (int i = 0; i < m; i++) {
            int tmp = sc.nextInt();
            int tmpp = sc.nextInt();
            w[i] = tmp-1;
            ww[i] = tmpp-1;
        }

        visit  = new boolean[n];
        Arrays.fill(visit, false);
        dfs(0);
        System.out.println(ans);
        sc.close();
    }

    public static void dfs(int placenow) {
        visit[placenow] = true;
        boolean success = true;
        for (int i = 0; i < n; i++) {
            if (visit[i] == false) { // not go all place
                success = false;
                break;
            }
        }
        if (success) {
            ans++;
            visit[placenow] = false;
            return;
        }

        for (int i = 0; i < m; i++) {
            if (w[i] == placenow && visit[ww[i]] == false ) {
                dfs(ww[i]);
            }else if(ww[i] == placenow && visit[w[i]] == false){
                dfs(w[i]);
            }else{
                continue;
            }
        }
        visit[placenow] = false;
        return;
    }

}



Measured memory_bytes: 23252
//Volume0-0054
import java.util.Scanner;
 
public class Main {

    public static void main(String[] args) {
    	
    	//declare    	
    	int      a,b,n,mod,s;
    	String[] str;
    	
    	//input
    	Scanner sc = new Scanner(System.in);
    	while(sc.hasNext()){
    		str = sc.nextLine().split("\\s");
    		a   = Integer.parseInt(str[0]);
    		b   = Integer.parseInt(str[1]);
    		n   = Integer.parseInt(str[2]);
    		
    		//calculate
    		s = 0;
    		mod = a % b;
    		while(n-- > 0){
    			mod *= 10;
    			s   += mod / b;
    			mod %= b;
    		}
    		//output
    		System.out.println(s);
    	}
    }
}

Measured memory_bytes: 17256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read() {
	LL x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
int n, x, flag, i;
int main() {
	n = read();
	for (i = 1; i <= n; i++) {
		x = read();
		if (x % 2 == 0) if (x % 3 != 0 && x % 5 != 0) flag = 1;
	}
	cout << (!flag ? "APPROVED\n" : "DENIED\n");
	return 0;
}

Measured memory_bytes: 3624