akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

#define ll long long

const int N = 55555 + 1;

int n, pr[N];
vector<int> ps;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for (int i = 0; i < N; i++) pr[i] = i;
    for (int i = 2; i < N; i++) {
        if (pr[i] == i) ps.pb(i);
        for (auto p : ps) {
            if ((ll)p * i >= N || p > pr[i]) break;
            pr[p * i] = p;
        }
    }
    cin >> n;
    int num = 2;
    for (int i = 0; i < n; i++) {
        while (pr[num] != num || num % 5 != 1) num++;
        cout << num++ << " ";
    }
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    long int oni_A, hito_B;
    long int v_oni,v_hito;
    long int Time;
    scanf("%ld %ld",&oni_A,&v_oni);
    scanf("%ld %ld",&hito_B,&v_hito);
    scanf("%ld",&Time);
    //最大10^9 + 10^9+10^9 < long int(8bite) 
    long int Aed,Bed;
    //正の方に逃げる
    if(oni_A < hito_B){
        Aed = oni_A + Time*v_oni;
        Bed = hito_B + Time*v_hito;
        if(Aed >= Bed){
            printf("YES");
            return 0;
        }else{
            printf("NO");
            return 0;
        }
    }else{
        Aed = oni_A -(Time*v_oni);
        Bed = hito_B - Time*v_hito;
        if(Aed <= Bed){
            printf("YES");
            return 0;
        }else{
            printf("NO");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1724
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int lmax(long int a, long int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int lmin(long int a, long int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
long int power(int a,int b){
  long int count=1;
  for(int i=0;i<b;i++){
    count *= 2;
  }
  return count;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int a,b,k,count=0;
  int num[1000];
  scanf("%d %d %d",&a,&b,&k);
  for(int i=1;i<=min(a,b);i++){
    if(a%i==0 && b%i==0){
      count++;//printf("%d\n",i);
      num[count]=i;
    }
  }
  printf("%d",num[count - k+1]);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
int main() {
  int a,b,d,e;
  while(1){
    std::cin>>a>>b>>e;
    e+=a+b;
    if(e==0)break;
    int p[e];
    for(a=0;a<e;a++)p[a]=2;
    std::cin>>d;
    int s[4][d];
    for(a=0;a<d;a++)std::cin>>s[0][a]>>s[1][a]>>s[2][a]>>s[3][a];
    for(a=0;a<d;a++)
      if(s[3][a]==1)p[s[0][a]-1]=1,p[s[1][a]-1]=1,p[s[2][a]-1]=1;
    for(a=0;a<d;a++){
      if(p[s[0][a]-1]+p[s[1][a]-1]+p[s[2][a]-1]>3) {
	if(p[s[0][a]-1]==1)
	  if(p[s[1][a]-1]==1) {
	    p[s[2][a]-1]=0;
	  }else if(p[s[2][a]-1]==1) p[s[1][a]-1]=0;
	if((p[s[2][a]-1]==1)&&(p[s[1][a]-1]==1)) p[s[0][a]-1]=0;
      }
    }
    for(a=0;a<e;a++)std::cout<<p[a]<<"\n";
  }
}

Measured memory_bytes: 0
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

const int N=100010;

map<pair<pii,pii>,int> ww;

int a[N],b[N][20],lg2[N],pow2[20];

int _min(int x,int y) {if (a[x]<a[y]) return x; else return y;}

int ask(int l,int r)
{
	int k=lg2[r-l+1];
	return _min(b[l][k],b[r-pow2[k]+1][k]);
}

int query(int l,int r,int p,int q,int x,int y)
{
	int k=ask(l,r);
	int t=a[k],s=0;bool ok=1;
	while (t>1) {if (t&1) ok=0;t>>=1;s++;}
	if (s>x) p=0;if (s>y) q=0;
	if (ww[mp(mp(l,r),mp(p,q))]) return ww[mp(mp(l,r),mp(p,q))]-1;
	ok^=1;
	int w1=(k>l ? query(l,k-1,p,ok,x,s)-s : ok|p)+(k<r ? query(k+1,r,0,q,s,y)-s : q);
	int w2=(k>l ? query(l,k-1,p,0,x,s)-s : p)+(k<r ? query(k+1,r,ok,q,s,y)-s : ok|q);
	ww[mp(mp(l,r),mp(p,q))]=min(w1,w2)+s+1;
	return min(w1,w2)+s;
}

int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	lg2[1]=0;for (int i=2;i<=n;i++) lg2[i]=lg2[i>>1]+1;
	pow2[0]=1;for (int i=1;i<=lg2[n];i++) pow2[i]=pow2[i-1]<<1;
	for (int i=1;i<=n;i++) b[i][0]=i;
	for (int j=1;j<=lg2[n];j++)
		for (int i=1;i<=n-pow2[j]+1;i++)
			b[i][j]=_min(b[i][j-1],b[i+pow2[j-1]][j-1]);
	printf("%d\n",query(1,n,0,0,-1,-1));
	return 0;
}


Measured memory_bytes: 35328
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N,M = map(int,readline().split())
A = [int(x) for x in readline().split()]

OD = [x for x in A if x&1]
EV = [x for x in A if not x&1]

if len(OD) >= 3:
    print('Impossible')
    exit()

if len(A) == 1:
    if N == 1:
        B = [1]
    else:
        B = [1,N-1]
elif len(OD) == 0:
    B = A.copy()
    B[0] -= 1
    B[-1] += 1
elif len(OD) == 1:
    A = OD + EV
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
else:
    A = [OD[0]] + EV + [OD[-1]]
    B = A.copy()
    B[0] += 1
    B[-1] -= 1
B = [x for x in B if x > 0]

print(*A)
print(len(B))
print(*B)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

vector<ll> prime;

void setPrime() {
    for (int i=2; i<=10000; i++) {
        bool ok = true;
        for (int e: prime) {
            if (i%e==0) {
                ok = false;
                break;
            }
            if (e*e>i) {
                break;
            }
        }
        if (ok) prime.push_back(i);
    }
}


int main(){
    ll n, m;
    cin >> n >> m;
    setPrime();
    map<ll, ll> mp;
    
    for (ll e: prime) {
        while (m%e==0) {
            m /= e;
            mp[e]++;
        }
        if (m==1) break;
        if (e*e>m) break;
    }
    if (m>1) mp[m]++;
    
    mint ans = 1;
    combination comb(n*30);
    for (auto m: mp) {
        mint now = comb(m.second+n-1, m.second);
        ans *= now;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 47104
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int idx = 0;
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int type = sc.nextInt();
		    int k = sc.nextInt();
		    if (type == 0) {
		        int out = (idx + k) % n;
		        if (out == 0) {
		            out = n;
		        }
		        sb.append(out).append("\n");
		    } else {
		        idx = (idx + k) % n;
		    }
		}
		System.out.print(sb);
	}
}



Measured memory_bytes: 100788
H, W, K = map(int, input().split())
ans = 0
# H列W行の入力
# K個だけ#を残す
C = [list(input()) for _ in range(H)]
# bit全探索
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if 2**h & i > 0 and 2**w & j > 0:
                    if C[h][w] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1
print(ans)

Measured memory_bytes: 9116
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

#include<map>

map<pair<int,int>,int> mp;
int x[55],y[55],q,w;

int main()
{
	int n;
	read(n);
	for (int i=1;i<=n;i++) read(x[i]),read(y[i]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
		{
			if (i==j) continue;
			q=x[i]-x[j];
			w=y[i]-y[j];
			ans=max(ans,++mp[make_pair(q,w)]);
		}
	cout<<n-ans;
	return 0;
}









Measured memory_bytes: 2432
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=STR()
    print('ABC'+n)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 2e5 + 25;

int N, M;

vector<pair<int, long long>> end_points[MAXN];

struct SegmentTree {

    int size;
    
    vector<long long> seg;
    vector<long long> lazy;

    SegmentTree(int size) : size(size) {

        seg.resize(size * 10, 0);
        lazy.resize(size * 10, 0);
    }

    void _push_down( int id, int b, int e ) {

        if (lazy[id]) {

            seg[id] += lazy[id];

            lazy[id * 2] += lazy[id];
            lazy[id * 2 + 1] += lazy[id];
            
            lazy[id] = 0LL; 
        }
    }

    void _add( int id, int b, int e, int ib, int ie, long long v) {

        _push_down(id, b, e);

        if (b > ie || e < ib ) {
            return;
        } else if (b >= ib && e <= ie) {
            
            lazy[id] += v;

            _push_down(id, b, e);
            
            return;
        } else {

            _push_down(id, b, e);

            _add(id * 2, b, (b + e) / 2, ib, ie, v);
            _add(id * 2 + 1, (b + e) / 2 + 1, e, ib, ie, v);

            seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
        }
    }

    long long _query( int id, int b, int e, int ib, int ie ) {

        _push_down(id, b, e);

        if ( b > ie || e < ib ) {
            return 0LL;
        } else if (b >= ib && e <= ie ) {
            return seg[id];
        } else {

            long long l = _query(id * 2, b, (b + e) / 2, ib, ie);
            long long r = _query(id * 2 + 1,(b + e) / 2 + 1, e, ib, ie);
            
            return max(l, r);
        }
    }

    long long query( int l, int r) {
        return max(0LL, _query(1, 1, size, l, r));
    }

    long long add(int l, int r, long long v) {
        _add(1, 1, size, l, r, v);   
    }

};

int main() {

    scanf("%d%d", &N, &M);

    SegmentTree segment_tree(N);

    for( int l, r, v, i=1 ; i <= M  ; i++ ) {
        
        scanf("%d%d%d", &l, &r, &v);

        end_points[r].emplace_back(l, v);
    }

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

        long long cur = segment_tree.query(1, max(1, i - 1));

        segment_tree.add(i, i, cur);

        for( auto interval : end_points[i] ) {
            segment_tree.add(interval.first, i, interval.second);
        }
    }

    printf("%lld\n", segment_tree.query(1, N));
    return 0;
}

Measured memory_bytes: 42496
#include <iostream>
#include <sstream>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <list>
#include <cmath>
#include <deque>
#include <bitset>
#include <map>
#include <set>
#include <iomanip>
#include <climits>
#include <cctype>
#include <functional>
#include <utility>
#include <cassert>
#include <iterator>
#include <fstream>
#include <cstring>
#include <memory>

#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)
#define il inline

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;
const double PI = acos(-1);
const double EPS = 1e-7;
const ll INF = 0x3F3F3F3F;

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

il int read()
{
	int x = 0, f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar())
	{
		if (c == '-')
		{
			f = -1;
		}
	}

	for (; isdigit(c); c = getchar())
	{
		x = (x << 1) + (x << 3) + (c^'0');
	}

	return x * f;
}

il void cinfast()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int main()
{
	ll n, a, b;
	n = read(), a = read(), b = read();

	if (n > 1 && a <= b || n == 1 && a == b)
	{
		cout << (n - 2)*(b - a) + 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}

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

int main(int, char**) {
  int N;
  cin >> N;

  unordered_set<string> lookup;

  string last;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;

    if (last.size() == 0) {
      lookup.insert(last);
      last = s;
    } else {
      if (lookup.count(s) || s.front() != last.back()) {
        cout << "No" << endl;
        return 0;
      }
      lookup.insert(last);
      last = s;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 764
import Data.List.Split
main = do
  s <- getLine
  t <- getLine
  putStrLn $ aux s t

aux :: String -> String -> String
aux s t = (show xmin) ++ " " ++ (show xmax) ++ " " ++ (show xsum)
  where
     xminLimit = -1000001 :: Int
     xmaxLimit =  1000001 :: Int
     n = read s :: Int
     f = map (\x->read x :: Int) $ splitOn " " t
     xmax = foldr (\x acc -> max x acc) xminLimit f
     xmin = foldr (\x acc -> min x acc) xmaxLimit f
     xsum = sum f :: Int

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

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

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


int main() {

	ll n;
	cin >> n;
	vector<ll> a(n);
	map<ll, ll> mp;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		mp[a[i]]++;
	}

	ll cnt = 0;
	for (auto itr : mp)
	{
		cnt += itr.second - 1;
	}

	
	if (cnt % 2)
	{
		cout << n - cnt - 1 << endl;
	}
	else
	{
		cout << n - cnt << endl;
	}
	
}





Measured memory_bytes: 7296
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    cnt = min(A[i], B[i])
    ans += cnt
    A[i] -= cnt
    B[i] -= cnt

    cnt = min(A[i + 1], B[i])
    ans += cnt
    A[i + 1] -= cnt
    B[i] -= cnt
    
print(ans)



Measured memory_bytes: 82148
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define vii vector<ll>
#define all(x) x.begin(),x.end()
#define mod 998244353
#define pb push_back
#define ii pair<int,int>
#define iii pair<ll,ll>
#define MAX 10000000000000
typedef long long ll;
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
  int n; cin>>n;
  vi a(n),b(n),c(n);
  vector<vii> dp(n,vii (3,0));
  f(i,0,n) cin>>a[i]>>b[i]>>c[i];
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  f(i,1,n)
  {
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
  }
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
  return 0;
}


Measured memory_bytes: 6912
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		if(A>=B){
			System.out.println("delicious");
		}else if(B-A<=X){
			System.out.println("safe");
		}else{
			System.out.println("dangerous");
		}
	}
	
}

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

using namespace std;

#define REP(i,b) for(int i=0;i<b;i++)

struct Data{
	int l,r,a,m;
};

Data Comb(Data a,Data b){
	return Data{
		max(a.l,a.a+b.l),
		max(a.r+b.a,b.r),
		a.a+b.a,
		max({a.m,b.m,a.r+b.l})
	};
}

const int unSet=114514;

struct Node{
	typedef Node* NP;
	NP l,r,p;
	Data d;
	bool rev;
	int v,g,s;
	Node():l(NULL),r(NULL),p(NULL),rev(false){}
	void Propagate(){
		if(rev){
			swap(l,r);
			swap(d.l,d.r);
			if(l) l->rev^=true;
			if(r) r->rev^=true;
			rev=false;
		}
		if(g!=unSet){
			v=g;
			int c=(g<0?1:s)*g;
			d={c,c,g*s,c};
			if(l) l->g=g;
			if(r) r->g=g;
			g=unSet;
		}
	}
	void Update(){
		d={v,v,v,v};
		s=1;
		if(l){
			l->Propagate();
			d=Comb(l->d,d);
			s+=l->s;
		}
		if(r){
			r->Propagate();
			d=Comb(d,r->d);
			s+=r->s;
		}
	}
	int Pos(){
		if(p&&p->l==this) return -1;
		if(p&&p->r==this) return 1;
		return 0;
	}
	void Prepare(){
		if(Pos())
			p->Prepare();
		Propagate();
	}
	void Rotate(){
		NP q=p,c;
		if(Pos()==1){
			c=l;
			l=p;
			p->r=c;
		}else{
			c=r;
			r=p;
			p->l=c;
		}
		if(c) c->p=p;
		p=p->p;
		q->p=this;
		if(p&&p->l==q) p->l=this;
		if(p&&p->r==q) p->r=this;
		q->Update();
	}
	void Splay(){
		Prepare();
		while(Pos()){
			int a=Pos(),b=p->Pos();
			if(b&&a==b) p->Rotate();
			if(b&&a!=b) Rotate();
			Rotate();
		}
		Update();
	}
	void Expose(){
		for(NP x=this;x;x=x->p) x->Splay();
		for(NP x=this;x->p;x=x->p){
			x->p->r=x;
			x->p->Update();
		}
		Splay();
	}
	void Evert(){
		Expose();
		if(l){
			l->rev^=true;
			l=NULL;
			Update();
		}
	}
	void Link(NP x){
		Evert();
		p=x;
	}
	void Set(int q){
		Expose();
		r=NULL;
		g=q;
	}
	int Get(){
		Expose();
		r=NULL;
		Update();
		return d.m;
	}
} ns[200000];

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	REP(i,n)
		scanf("%d",&ns[i].g);
	REP(i,n-1){
		int s,e;
		scanf("%d%d",&s,&e);
		ns[s-1].Link(ns+e-1);
	}
	REP(i,q){
		int t,a,b,c;
		scanf("%d%d%d%d",&t,&a,&b,&c);
		if(t==1){
			ns[a-1].Evert();
			ns[b-1].Set(c);
		}else if(t==2){
			ns[a-1].Evert();
			printf("%d\n",ns[b-1].Get());
		}
	}
}

Measured memory_bytes: 14168
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  a, b, c = map(int, input().strip().split())
  if a==b and a!=c:
    print('Yes')
    return
  if a==c and a!=b:
    print('Yes')
    return
  if c==b and a!=b:
    print('Yes')
    return
  print('No')

if __name__=='__main__':
  main()


Measured memory_bytes: 2940
#include <iostream>                                                  
#include <cstdio>                                                    
#include <cstring>                                                   
using namespace std;                                                 
                                                                     
int main() {                                                         
  int n, m, l;                                                       
  cin >> n >> m >> l;                                                
  int a[n][m], b[m][l];                                              
  long long c[n][l];                                                 
  memset(c,0,sizeof(c));                                             
  for (int i=0; i<n; i++) {                                          
    for (int j=0; j<m; j++) {                                        
      cin >> a[i][j];                                                
    }                                                                
  }                                                                  
  for (int i=0; i<m; i++) {                                          
    for (int j=0; j<l; j++) {                                        
      cin >> b[i][j];                                                
    }                                                                
  }                                                                  
  for (int i=0; i<n; i++) {                                          
    for (int j=0; j<l; j++) {                                        
      for (int k=0; k<m; k++) {                                      
        c[i][j] += a[i][k]*b[k][j];                                  
      }                                                              
    }                                                                
  }                                                                  
  for (int i=0; i<n; i++) {                                          
    for (int j=0; j<l; j++) {                                        
      cout << (i>=0 && j==0?"":" ") << c[i][j] << flush;             
    }                                                                
    printf("\n");                                                    
  }                                                                  
  return 0;                                                          
}               

Measured memory_bytes: 3224
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	char a[N + 1];
	char b[N + 1];
	f(i, N + 1) {
		a[i] = 0;
		b[i] = 0;
	}
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	scanf("%s", a);
	a[n] = a[0];
	b[0] = 'S';
	b[1] = 'S';
	f(i, n) {
		if (a[i + 1] == 'o') {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
		}
		else {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
		}
	}
	if ((b[0] == b[n]) && (b[1] == b[n + 1])) {
		b[n] = 0;
		b[n + 1] = 0;
		printf("%s", b);
		return 0;
	}
	b[0] = 'W';
	b[1] = 'S';
	f(i, n) {
		if (a[i + 1] == 'o') {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
		}
		else {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
		}
	}
	if ((b[0] == b[n]) && (b[1] == b[n + 1])) {
		b[n] = 0;
		b[n + 1] = 0;
		printf("%s", b);
		return 0;
	}
	b[0] = 'S';
	b[1] = 'W';
	f(i, n) {
		if (a[i + 1] == 'o') {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
		}
		else {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
		}
	}
	if ((b[0] == b[n]) && (b[1] == b[n + 1])) {
		b[n] = 0;
		b[n + 1] = 0;
		printf("%s", b);
		return 0;
	}
	b[0] = 'W';
	b[1] = 'W';
	f(i, n) {
		if (a[i + 1] == 'o') {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
		}
		else {
			if (b[i + 1] == 'S') {
				if (b[i] == 'S') {
					b[i + 2] = 'W';
				}
				else {
					b[i + 2] = 'S';
				}
			}
			else {
				if (b[i] == 'S') {
					b[i + 2] = 'S';
				}
				else {
					b[i + 2] = 'W';
				}
			}
		}
	}
	if ((b[0] == b[n]) && (b[1] == b[n + 1])) {
		b[n] = 0;
		b[n + 1] = 0;
		printf("%s", b);
		return 0;
	}


	printf("-1\n");


	return 0;
}

Measured memory_bytes: 640
package main

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

var nrs = bufio.NewReaderSize(os.Stdin, 1000000)

func readLineToInt() []int {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := nrs.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    line := strings.Split(string(buf), " ")
    var intLine []int
    for _, str := range line {
        n, _ := strconv.Atoi(str)
        intLine = append(intLine, n)
    }
    return intLine
}

func main() {
    nk := readLineToInt()
    n, k := nk[0], nk[1]
    aList := readLineToInt()
    counter := make(map[int]int)
    left, right := 0, 0
    ans := n + 1
    used := 0
    if aList[0] <= k {
        counter[aList[0]]++
        used++
    }
    for left < n {
        for used < k && right < n - 1{
            right++
            a := aList[right]
            if a <= k {
                v, _ := counter[a]
                if v > 0 {
                    counter[a]++
                } else {
                    counter[a]++
                    used++
                }
            }
        }
        if used < k {
            break
        }
        if ans > right - left + 1 {
            ans = right - left + 1
        }
        v, _ := counter[aList[left]]
        if v == 1 {
            used--
            counter[aList[left]]--
        } else {
            counter[aList[left]]--
        }
        left++
    }
    if ans == n + 1 {
        fmt.Println(0)
    } else {
        fmt.Println(ans)
    }
}


Measured memory_bytes: 10860
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define pb push_back
#define all(v) (v).begin(),v.end()
struct query{
    int ind,type,a,b;
};
int main(){
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<max(min(b,d)-max(a,c),0)<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n;
	cin>>n;
	vector<tuple<string,ll,ll>>q;
	for(ll i=0;i<n;i++){
		string s;ll x;
		cin>>s>>x;
		q.push_back(make_tuple(s,-x,i+1));
	}
	sort(q.begin(),q.end());
	for(ll i=0;i<n;i++){
		cout << get<2>(q[i])<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#define MAXN 200010
#define LL long long
using namespace std;

int n;
LL v1[MAXN],v2[MAXN];
int s1,s2;

LL gao1(){
	if(s1==s2) return 1LL<<62;
	LL res1=v1[s1]-v2[s2];
	LL lim1=min(v1[s2],v2[s1]),lim2=max(v1[s2],v2[s1]);
	if(n==2) return res1*(lim2-lim1);
	static multiset< pair<LL,int> > S1;
	static multiset<LL> S2;
	static int c[MAXN];
	for(int i=1;i<=n;i++)
		if(i!=s1 && i!=s2){
			c[i]=2;
			S2.insert(v2[i]);
			S1.insert(make_pair(v1[i],i));
			S1.insert(make_pair(v2[i],i));
		}
	LL ans=1LL<<62;
	for(multiset< pair<LL,int> >::iterator it=S1.begin();it!=S1.end();it++){
		LL l1=min(it->first,lim1);
		LL l2=max(*(--S2.end()),lim2);
		if(res1*(l2-l1)<ans) ans=res1*(l2-l1);
		if(c[it->second]==1) break;
		c[it->second]--;
		S2.erase(S2.find(v2[it->second]));
		S2.insert(v1[it->second]);
	}
	return ans;
}

LL gao2(){
	LL l1=v1[s1],l2=v2[s2];
	for(int i=1;i<=n;i++){
		if(v1[i]<l1) l1=v1[i];
		if(v2[i]>l2) l2=v2[i];
	}
	return (v1[s1]-l1)*(l2-v2[s2]);
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",v1+i,v2+i);
		if(v1[i]<v2[i]) swap(v1[i],v2[i]);
	}
	s1=s2=1;
	for(int i=1;i<=n;i++){
		if(v1[i]>v1[s1]) s1=i;
		if(v2[i]<v2[s2]) s2=i;
	}
	LL res=min(gao1(),gao2());
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 40576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        String output = "No";

        while (input >= 10){
            if (input%10 == 7) output = "Yes";
            input/= 10;

        }
        if (input==7) output = "Yes";
        System.out.println(output);
    }
}


Measured memory_bytes: 35652
import string

S = input()
abc = string.ascii_lowercase

if len(S) == 26:
    for i in range(24, -1, -1):
        cand = list(S[i+1:])
        cand.sort()
        for c in cand:
            if ord(c) > ord(S[i]):
                print(S[:i]+c)
                exit(0)
    print(-1)
else:
    for l in abc:
        if l not in S:
            print(S+l)
            exit()


Measured memory_bytes: 3772
#include <stdio.h>

int main(void) {
	int n;
	double a, ans = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%lf", &a);
		ans += 1 / a;
	}

	printf("%lf", 1 / ans);

	return 0;
}

Measured memory_bytes: 128
n=int(input())
testimony_list=[[[-1,0] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	flag=True
	for k in range(n):
		if kind_l[k]:
			for m in range(n-1):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if subject==-1:continue
				if kind_l[subject]!=judge:
					flag=False
	if flag:
		ans=max(ans,sum(kind_l))
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] sorted = new int[n];
		for(int i = 0; i < n; i++) {
			sorted[i] = in.nextInt();
		}
		for(int i = 0; i < n; i++) {
			int temp = sorted[i];
			int j = i-1;
			while(j >= 0 && temp < sorted[j]) {
				sorted[j+1] = sorted[j];
				j--;
			}
			sorted[j+1] = temp;
			for(int a = 0; a < sorted.length; a++) {
				if(a == sorted.length - 1) System.out.print(sorted[a]);
				else System.out.print(sorted[a] + " ");
			}
			System.out.println();
		}
	}

}



Measured memory_bytes: 31344
#include<iostream>
#include<algorithm>
#define LL long long 
LL Q, H, S, D, N;
LL one, two;
int main() {
	std::cin >> Q >> H >> S >> D >> N;
	one = std::min({ Q * 4,H * 2,S });
	two = std::min(D, one * 2);
	LL ans = (N / 2)*two + (N % 2)*one;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int func(long x){
  if(x % 2 != 0)
    return 0;
  return (func(x / 2) + 1);
}

int main(){
  
  int i,N;
  scanf("%d",&N);
  long A[N];
  for(i = 0; i < N; i++){
    scanf("%ld",&A[i]);
  }
  
  int answer = 0;
  for(i = 0; i < N; i++){
    answer += func(A[i]);
  }
    
  printf("%d",answer);
  
  return 0;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i = 0;i<n;i++){
    cin >> v.at(i);
  }
  for(int i = 0;i<n;i++){
    cin >> c.at(i);
  }
  int ans = 0;
  for(int i = 0;i<n;i++){
    if( v.at(i) - c.at(i) > 0){
      ans += v.at(i) - c.at(i);
    }
  }
  cout << ans ;
    
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;
long long a[N];
int n, m, v, p;

bool check(int x) {
  if (a[x]+m < a[p-1]) return false;
  int vv = v-(n-x)-(p-1);
  if (vv <= 0) return true;
  long long c = 1LL*m*vv;
  long long s = 0;
  for (int i = p-1; i < x; ++i) {
    s += a[x]+m-a[i];
  }
  return s >= c;
}

void solve() {
  scanf("%d %d %d %d", &n, &m, &v, &p);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", a+i);
  }
  sort(a, a+n, greater<long long>());
  int lo = p-1, hi = n;
  while (lo+1<hi) {
    int mid = (lo+hi)/2;
    if (check(mid)) lo = mid;
    else hi = mid;
  }
  printf("%d", lo+1);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4612
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
#define ld long double
 
using namespace std;
 
const int N = 5e5 + 123;
const ll mod = 1e9 + 7;

ll dp[4][N];
int n;

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

	cin >> n;

	for(int i = 1;i <= n;i++){
		int x, y, z;
		cin >> x >> y >> z;
		dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + x;
		dp[2][i] = max(dp[1][i - 1], dp[3][i - 1]) + y;
		dp[3][i] = max(dp[2][i - 1], dp[1][i - 1]) + z;
	}
	
	cout << max(dp[1][n], max(dp[2][n], dp[3][n]));
}

Measured memory_bytes: 12544
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <map>
using namespace std;
int main()
{
    int n,t,q;
    while(~scanf("%d%d",&n,&t))
    {
        long long sum=0;
       int  m=-1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&q);
             m=max(m,q);
            sum+=q;
            if(t>=sum)
                printf("%lld\n",(t-sum)/m+2);
            else
                printf("1\n");
}
}
return 0;
}


Measured memory_bytes: 3208
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner stdin = new Scanner(System.in);
		String blood = null;
		String[] str = new String[2];
		Arrays.fill(str, null);

		int a = 0;
		int b = 0;
		int ab = 0;
		int o = 0;

		while(stdin.hasNext()) {

			blood = stdin.next();
			str = blood.split(",");
			if(str[1].equals("A")) {
				a++;
			} else if(str[1].equals("B")) {
				b++;
			}  else if(str[1].equals("AB")) {
				ab++;
			} else if(str[1].equals("O")) {
				o++;
			}

		}

		System.out.println(a);
		System.out.println(b);
		System.out.println(ab);
		System.out.println(o);


	}

}

Measured memory_bytes: 26048
s=input()
n=len(s)
nn=n-1
ans=0
for i in range(1<<nn):
  t=0
  t_str=s[0]
  for j in range(nn):
    if i&(1<<j):
      t+=int(t_str)
      t_str=s[j+1]
    else:
      t_str+=s[j+1]
  if t_str!="":
    t+=int(t_str)
  ans+=t
print(ans)




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

#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
// c(n + k, k)
vector<int> g[N];
vector<pair<pair<ll, int>, int> > v[N];
vector<pair<ll, int> > prefix[N], suffix[N];
ll n, fact[N];
pair<ll, int> ans[N];

ll power(ll x, ll y) {
    if (y == 0) return 1;
    ll temp = power(x, y / 2);
    if (y & 1) return temp * temp % mod * x % mod;
    return temp * temp % mod;
}

ll c(ll n, ll k) {
    return fact[n] * power(fact[k] * fact[n - k] % mod, mod - 2) % mod;
}

pair<ll, int> mer(pair<ll, int> a, pair<ll, int> b) {
    pair<ll, int> ret = {a.first * b.first % mod * c(a.second + b.second, b.second) % mod, b.second + a.second};
    return ret;
}

void dfs(int node, int parent) {
    ans[node] = {1, 0};
    for (auto child : g[node]) {
        if (parent == child) continue;
        dfs(child, node);
        v[node].push_back({ans[child], child});
        ans[node] = mer(ans[node], ans[child]);
    }
    ans[node].second++;
}

ll Ans[N];

void solve(int node, int parent) {
    Ans[node] = ans[node].first;
    int p = 0, s = (int)suffix[node].size() - 2;
    for (auto child : g[node]) {
        if (child == parent) continue;
        pair<ll, int> cur = {1, 0}, on = ans[node], oc = ans[child];
        if (p) cur = mer(cur, prefix[node][p - 1]);
        if (s >= 0) cur = mer(cur, suffix[node][s]);
        if (node != parent)
        cur = mer(cur, ans[parent]);
        cur.second++;
//        cout << node <<' '<< child <<' ' << p <<' ' << s <<' ' << cur.first <<' ' << cur.second<<' ' << ans[child].second<< endl;
        ans[node] = cur;
        ans[child].second--;
        ans[child] = mer(ans[child], ans[node]);
        ans[child].second++;
        solve(child, node);
        ans[node] = on, ans[child] = oc;
        s--;
        p++;
    }
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    fact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = fact[i - 1] * i % mod;
    }
    cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1, 1);
    for (int i = 1; i <= n; i++) {
        pair<ll, int> cur = {1, 0};
        for (auto it : v[i]) {
            cur = mer(cur, it.first);
            prefix[i].push_back(cur);
        }
        reverse(v[i].begin(), v[i].end());
        cur = {1, 0};
        for (auto it : v[i]) {
            cur = mer(cur, it.first);
            suffix[i].push_back(cur);
        }
        reverse(v[i].begin(), v[i].end());
    }
    solve(1, 1);
    for (int i = 1; i <= n; i++) cout << Ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 50816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> p(n);
  rep(i,n) cin>>p[i].first>>p[i].second;
  vector<pair<int,int>> t(m);
  rep(i,m){
    cin>>t[i].first>>t[i].second;
  }
  rep(i,n){
    int cnt=0;
    int cnt2=INF;
    int ans=0;
    rep(j,m){
      cnt=abs(p[i].first-t[j].first)+abs(p[i].second-t[j].second);
      if(cnt2>cnt){
        cnt2=cnt;
        ans=j+1;
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3608
N,T = map(int,input().split())
l = []
for i in range(N):
    c,t = map(int,input().split())
    l.append([c,t])
l = [x[0] for x in l if x[1]<=T]
if len(l)==0:
    print('TLE')
else:
    print(min(l))

Measured memory_bytes: 3060
#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 rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, k;
  cin >> n >> k;
  vvi ds(n);
  rep(i,n) {
    int t, d;
    cin >> t >> d;
    --t;
    ds[t].pb(d);
  }
  vi y0, y1;
  rep(i,n) {
    if (ds[i].size() == 0) continue;
    // 昇順ソート(たぶんvectorのアクセスが一番後ろからできるようにするため)
    sort(ds[i].begin(), ds[i].end());
    // 1つ目(種類が増える)として、一番大きいものを選ぶ->y1
    y1.pb(ds[i].back());
    ds[i].pop_back();
    // 2つ目以降は加えても種類が増えない->y0
    y0.insert(y0.end(), ds[i].begin(), ds[i].end());
  }
  // 降順ソート
  sort(y0.rbegin(), y0.rend());
  sort(y1.rbegin(), y1.rend());

  ll ans = 0;

  // Y: 種類数
  // 初期値として、y0から取れるだけ取ったときの残りを設定
  int Y = max(0, k-int(y0.size()));
  // X: 「おいしさ」の総和
  ll X = 0;
  rep(i,Y) X += y1[i];
  rep(i,k-Y) X += y0[i];
  while (1) {
    ans = max(ans, X+(ll)Y*Y);
    if (Y >= k || Y >= y1.size()) break;
    // 種類が増えるものの中から「おいしさ」が最大のものを加える
    X += y1[Y];
    // 種類が増えないものの中から、「おいしさ」が最小のものを除く
    X -= y0[k-Y-1];
    ++Y;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args){
		BufferedReader reader =
				new BufferedReader(new InputStreamReader(System.in));

		String str;
		
		try{
		while((str = reader.readLine()) != null){
			
			char[] ch = str.toCharArray();

			for(int i = 0; i < ch.length; i++){
				if(ch[i] == '@'){
					for(int j = 0; j < ch[i + 1] - '0'; j++)
						System.out.print(ch[i + 2]);
					i += 2;
				}else{
					System.out.print(ch[i]);
				}
			}
			System.out.println();
		}
		reader.close();
		}catch(IOException e){
		}
		}
}

Measured memory_bytes: 16876
n = int(input())
l = list(map(int, input().split(" ")))
res = 0
current = l[0]
currentans = 0
for i in range(1, n):
    if(l[i] <= current):
        currentans = currentans + 1
        if(currentans > res):
            res = currentans
    else:
        currentans = 0
    current = l[i]
print(res)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A.at(i);
    ll MOD = 1000000007;
    ll cnt = 0;
    rep(i,N) {
        rep(j,N) {
            if (i == j) continue;
            if (A[i] > A[j]) {
                if (i > j) {
                    cnt += (K - 1) * K / 2;
                    cnt %= MOD;
                } else { 
                    cnt += K * (K + 1) / 2;
                    cnt %= MOD;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

typedef long long ll;
const double EPS = 1e-10;
const double PI  = acos(-1);

int main(int argc, char* argv[])
{
  int n;
  std::vector< std::vector< int > > a;

  std::cin >> n;

  for (int i = 0; i < 2; i++){
    std::vector< int > vi;
    for (int j = 0; j < n; j++){
      int tmp = 0;
      std::cin >> tmp;
      vi.push_back(tmp);
    }
    a.push_back(vi);
  }

  int max_val = 0;
  for (int i = 0; i < n; i++){
    int sum = 0;
    for (int j = 0; j <= i; j++){
      sum += a[0][j];
    }
    for (int j = i; j < n; j++){
      sum += a[1][j];
    }
    max_val = std::max(max_val, sum);
  }

  std::cout << max_val << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (max, left, right) = readLine()!!.split(" ").map(String::toInt)
    val total = (1..max)
        // a in left...right is left <= a && a <= right
        .filter { it.toString().sumBy(Character::getNumericValue) in left..right }
        .sum()
    print(total)
}

Measured memory_bytes: 38520
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
//const int m=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}



int32_t main(){
	
	FIO();
	
		int n;cin>>n;
		vi a(n);
		int sum=0;
		for(int i=0; i<n; i++){
			cin>>a[i];
			//sum+=a[i];
		}
		descSort(a);
		int ans=a[0];
		int cnt=n-2,i;
		for(i=1; cnt>=2; i++){
			ans+=2*a[i];
			cnt-=2;
		}
		if(cnt)
			ans+=a[i];
		//sum-=a[n-1];
		cout<<ans<<"\n";
	
	return 0;
		
}
		
		



Measured memory_bytes: 4776