akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

int main(void){
	int q=nextint();
	while(q-->0){
		long a=nextint();
		long b=nextint();
		if(a>b){ int t=a; a=b; b=t; }
		long ans;
		if(a==b){
			ans=a*2-2;
		}else if(a+1==b){
			ans=a*2-2;
		}else{
			long c=floorl(sqrtl(a*b-1));
			if(c*(c+1)>=a*b){
				ans=c*2-2;
			}else{
				ans=c*2-1;
			}
		}
		printf("%ld\n", ans);
	}
}


Measured memory_bytes: 2072
n, l = map(int, input().split())


sum = 0
for i in range(n):
    sum += i + l

min = 10000
ans = 0
for i in range(n):
    msum = 0
    for j in range(n):
        if (i != j):
            msum += j + l
    if (abs(sum - msum) < min):
        min = abs(sum-msum)
        ans = msum

print(ans)


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

int main(){
    string S;
    cin >> S;
    bool a = true;
    if(S.at(0)==S.at(1)) a = false;
    if(S.at(1)==S.at(2)) a = false;
    if(S.at(2)==S.at(3)) a = false;
    if(a){
        cout << "Good";
    }else{
        cout << "Bad";
    }
}

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

using namespace std;
using ll = long long;
const ll INF = 1e17;    


int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<pair<int,ll>>> hen(n);
    for(int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        if(c > l)continue;
        a--, b--;
        hen[a].push_back({b, c});
        hen[b].push_back({a, c});
    }

    vector<vector<pair<ll,ll>>> Dist;
    
    //頂点v出発
    for(int v = 0; v < n; v++) {
        vector<pair<ll,ll>> dist(n, {INF, INF}); //回数, あまり
        dist[v] = {0, 0};
        using T = pair<pair<ll,ll>,int>;
        priority_queue<T, vector<T>, greater<T>> que;
        que.push({{0, 0}, v});

        vector<bool> seen(n);

        for(int i = 0; i < n; i++) {
            pair<ll,ll> cur = {INF, INF};
            int vert;
            for(int j = 0; j < n; j++) {
                if(seen[j])continue;
                if(cur > dist[j]) {
                    cur = dist[j];
                    vert = j;
                }
            }
            seen[vert] = true;
            for(auto i : hen[vert]) {
                pair<ll,ll> nxt = (cur.second + i.second > l ? make_pair(cur.first + 1, i.second) : make_pair(cur.first, cur.second + i.second));
                if(dist[i.first] > nxt) {
                    dist[i.first] = nxt;
                }
            }
        }
        Dist.push_back(dist);
    }


    int que; cin >> que;
    vector<int> s(que), t(que);
    for(int i = 0; i < que; i++) {
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
    }

    for(int i = 0; i < que; i++) {
        cout << ( Dist[s[i]][t[i]].first >= INF ? -1 : Dist[s[i]][t[i]].first ) << endl;
    }
}


Measured memory_bytes: 4992
from collections import deque
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
adjL = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    adjL[a].append(b)
    adjL[b].append(a)
querys = [tuple(map(int, input().split())) for _ in range(Q)]

anss = [0] * N
for p, x in querys:
    anss[p-1] += x

def bfs(vSt):
    useds = [False] * (N)
    useds[vSt] = True
    Q = deque([vSt])
    while Q:
        vNow = Q.popleft()
        ans = anss[vNow]
        for v2 in adjL[vNow]:
            if not useds[v2]:
                anss[v2] += ans
                Q.append(v2)
                useds[v2] = True

bfs(0)

print(' '.join(map(str, anss)))


Measured memory_bytes: 92312
#include <iostream>
#include <string>

using namespace std;

const int N_MAX = 100;

// グラフ
// 隣接リスト表現の有効グラフGの隣接行列を出力

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int G[100][100] = { 0 };

    for (int i = 0; i< n; i++)
    {
        int u, k;
        cin >> u; // 頂点番号
        cin >> k; // 出次数
        for (int i = 0; i < k; i++)
        {
            int v;
            cin >> v;
            G[u-1][v-1] = 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << G[i][j];
            if (j != n - 1)
                cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include <iostream>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if (c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }else if (c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }else if (c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }else if (c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }else if (c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }
  }
  int top(){
    return s[0];
  }
  int front(){
    return s[1];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
};

int main(){
  Dice d;
  int i,n,a,b;
  for (i=0;i<6;i++)cin>>d.s[i];
  cin>>n;
  for (i=0;i<n;i++){
    cin>>a>>b;
    if (d.right()==a)d.roll('W');
    else if (d.left()==a)d.roll('E');
    else {
      while (d.top()!=a)d.roll('N');
    }
    while (d.front()!=b)d.roll('R');
    cout<<d.right()<<endl;
  }
  return 0;
}



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

int64_t lucas(int n){
  if(n == 0){
    return 2;
  }
  if(n == 1){
    return 1;
  }
  int64_t sum = 0;
  int64_t tmp1 = 2;
  int64_t tmp2 = 1;
  for(int i = 2;i <=n;i++){
    sum = tmp1 + tmp2;
    tmp1 =tmp2;
    tmp2 = sum;
  }
  return sum;
}

int main(){
  int n;
  cin >> n;
  cout << lucas(n) << endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if( abs( a - c ) <= d  || ( abs(a - b) <= d && abs(b - c) <= d ) ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] S = sc.next().toCharArray();
        List<List<Integer>> Mojis = new ArrayList<>();
        for(int i=0;i<3;i++){Mojis.add(new ArrayList<>());}
        for(int i=0;i<N;i++){
            int tgt = -1;
            switch(S[i]){
                case 'R':
                    tgt = 0;
                    break;
                case 'G':
                    tgt = 1;
                    break;
                case 'B':
                    tgt = 2;
                    break;
            }
            Mojis.get(tgt).add(i);
        }
        if(Mojis.get(0).size() == 0 || Mojis.get(1).size() == 0 || Mojis.get(2).size() == 0){
            System.out.println("0");
            return;
        }
        List<List<Integer>> l = Arrays.asList(Arrays.asList(0,1,2),
                Arrays.asList(0,2,1),
                Arrays.asList(1,2,0),
                Arrays.asList(1,0,2),
                Arrays.asList(2,1,0),
                Arrays.asList(2,0,1));
        long cnt=0;
        for(List<Integer> perm:l){
            List<Integer> R = Mojis.get(perm.get(0));
            List<Integer> G = Mojis.get(perm.get(1));
            List<Integer> B = Mojis.get(perm.get(2));
            cnt += calc(R, G, B);
        }
        System.out.println(cnt);

    }
    private static long calc(List<Integer> R, List<Integer> G, List<Integer> B){
        long sum = 0;
        for(Integer r: R){
            int find = findIndexMoreThan(G, r);
            for(int gind = find; gind < G.size();gind++){
                Integer g = G.get(gind);
                int ind = findIndexMoreThan(B, g);
                sum += (B.size()-ind);
                if(hasTarget(B,2*g-r)){
                    sum--;
                }
            }
        }
        return sum;
    }

    private static int findIndexMoreThan(List<Integer> lst, int tgt){
        int l=0;
        int r=lst.size()-1;
        while(l < r){
            int m=(l+r)/2;
            if(lst.get(m) <= tgt){
                l=m+1;
            }else{
                r=m;
            }
        }
        if(lst.get(l) <= tgt){
            return lst.size();
        }
        return l;
    }

    private static boolean hasTarget(List<Integer> lst, int tgt){
        int l=0;
        int r=lst.size()-1;
        while(l<r){
            int m=(l+r)/2;
            if(lst.get(m) < tgt){
                l=m+1;
            }else{
                r=m;
            }
        }
        if(lst.get(l) == tgt){
            return true;
        }else{
            return false;
        }
    }
}


Measured memory_bytes: 38820
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,a;
  map<int,int>m;
  cin>>n;
  rep(i,n){
    cin>>a;
    m[a]++;
    m[a-1]++;
    m[a+1]++;
  }
  int ans=0;
  rep(i,100005)ans=max(ans,m[i]);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){

    vector<long long> now;
    vector<long long> needs;
    vector<long long> remainder;

    long long N, moveCnt = 0, lowValue = 0;

    cin >> N;

    for(long long i = 0; i < N; i++){
        long long tmp;
        cin >> tmp;
        now.push_back(tmp);
    }

    //long long sum = 0;

    for(long long i = 0; i < N; i++){
        long long tmp;
        cin >> tmp;
        needs.push_back(tmp);

        long long sub = now[i] - needs[i];
        if(sub < 0){
            moveCnt++;
            lowValue += sub;
        }else if (sub > 0){
            //sum += sub;
            remainder.push_back(sub);
        }
    }

    // cout << "low " << lowValue << endl;
    //cout << "sum " << sum << endl;
    //cout << "res " << lowValue + sum << endl;
    //cout << "moveCnt " << moveCnt << endl;
    //cout << "remaCnt " << remainder.size() << endl;

    if(moveCnt != 0){
        sort(remainder.begin(), remainder.end(), greater<long long>());

        for(long long i = 0; i < remainder.size(); i++){
            lowValue += remainder[i];
            //cout << lowValue << endl;
            moveCnt++;
            if(lowValue >= 0){
                break;
            }
        }
    }

    if(lowValue >= 0){
        cout << moveCnt << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        BigDecimal A;
        BigDecimal B;
        // int[] A;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            A = new BigDecimal(in.next());
            B = new BigDecimal(in.next());
            // A = new int[N];
            // for (int i = 0; i < N; i++) {
            // A[i] = in.nextInt();
            // }
            long ans = A.multiply(B).longValue();
            // ans.setScale(0,BigDecimal.ROUND_DOWN)
            out.println(ans);
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 33072
def function(X, K, D):
    kai = int(abs(X)/D)
    if kai >= K:
        if X > 0:
            ans = X-K*D
        else:
            ans = X+K*D
    else:
        K = K-kai
        if X > 0:
            X = X-kai*D
        else:
            X = X+kai*D
        if K % 2 == 1:
            if X > 0:
                ans = X-D
            else:
                ans = X+D
        else:
            ans = X
    return abs(ans)


if __name__ == '__main__':
    X, K, D = input().split()
    X = int(X)
    K = int(K)
    D = int(D)
    print(function(X, K, D))


Measured memory_bytes: 9136
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 100000 + 10;
int n;
LL f[N],g[N],v[N],x[N],y[N],C;
struct node {
    int x; LL v;
};
bool operator < (const node &x, const node &y) {
    return x.v < y.v;
}
priority_queue<node> q;
int main () {
    n = gi(); C = gi();
    for(int i=1;i<=n;i+=1) x[i] = gi(), v[i] = gi(), y[i] = C-x[i];
    LL ans = 0;
    for(int i=1;i<=n;i+=1) f[i] = f[i-1] - (x[i] - x[i-1]) + v[i], ans = max(ans, f[i]);
    for(int i=n;i>=1;i-=1) g[i] = g[i+1] - (y[i] - y[i+1]) + v[i], ans = max(ans, g[i]), q.push((node){i,g[i]});
    for(int i=1;i<=n;i+=1) {
        while(!q.empty() && q.top().x <= i) q.pop();
        if(q.empty()) break;
        int t = q.top().x;
        ans = max(ans, f[i] + g[t] - x[i]);
    }
    while(!q.empty()) q.pop();
    for(int i=1;i<=n;i+=1) q.push((node){i,f[i]});
    for(int i=n;i>=1;i-=1) {
        while(!q.empty() && q.top().x >= i) q.pop();
        if(q.empty()) break;
        int t = q.top().x;
        ans = max(ans, f[t] + g[i] - y[i]);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 6004
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf
import Numeric

main :: IO ()
main = do
  [a,b]<-map (read::String->Int).words<$>getLine
  let dbl = fromIntegral a / fromIntegral b :: Double
  putStrLn . unwords $ [show (a`div`b), show (a`mod`b), printf "%.8f" dbl]

Measured memory_bytes: 3964
#

import sys
input=sys.stdin.readline
from random import shuffle, randint

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    maxT=[1 for i in range(D+1)]
    maxsat=0
    Tmoto=[i for i in range(1,27)]
    CS=[(C[i],i) for i in range(26)]
    CS.sort()
    for ignn in range(26):
        ign=set()
        for i in range(ignn):
            ign.add(CS[i][1]+1)
        Tmoto=set([i for i in range(1,27)])-ign
        Tmoto=list(Tmoto)
        ign=list(ign)
        shuffle(Tmoto)
        T=[]
        for i in range(D+1):
            if (i % 26 ==0 or i % 26== 17) and ignn>0:
                T.append(ign[randint(0,ignn-1)])
            else:
                T.append(Tmoto[i%(26-ignn)])
        last=[[0]*27 for i in range(D+1)]
        for i in range(1,D+1):
            for j in range(i,D+1):
                last[j][T[i]]=i
        sat=0
        for i in range(1,D+1):
            sat+=S[i-1][T[i]-1]
            for j in range(1,27):
                sat-=C[j-1]*(i-last[i][j])
        if ignn==0:
            maxsat=sat
            maxT=T[:]
        elif sat>maxsat:
            maxsat=sat
            maxT=T[:]
    for i in range(1,D+1):
        print(maxT[i])
    
if __name__=="__main__":
    main()


Measured memory_bytes: 78624
import java.util.Scanner;
import java.text.*;
class Main{
 public static void main(String args[]){
  int a,b,s,r;
  double f;
  Scanner sc = new Scanner(System.in);
  DecimalFormat form = new DecimalFormat("##.0000000000000");
  a=sc.nextInt();
  b=sc.nextInt();
  s=a/b;
  r=a%b;
  f=(double)a/b;
  System.out.println(s+" "+r+" "+form.format(f));
 }
}


Measured memory_bytes: 26404
#include <stdio.h>

void swap(int *num1, int *num2)
{
	int swp = *num1;
	*num1 = *num2;
	*num2 = swp;
}

void sort(int ary[50], int n)
{
	int i, p;
	
	for(i=0; i<n; i++){	//すべての配列を
		for(p=n-1; 0<p; p--){	//先頭から大きい順に並べ替え
			if(ary[p-1] < ary[p]){
				swap(&ary[p-1], &ary[p]);
			}
			if(p == i)
				break;
		}
	}
}

int main(void)
{
	int n, k;
	int l[50];
	int i, sum;
	
	scanf("%d %d", &n, &k);
	for(i=0; i<n; i++)
		scanf("%d", &l[i]);
	
	sort(l, n);
	
	sum = 0;
	for(i=0; i<k; i++)
		sum += l[i];
	
	printf("%d\n", sum);
	
	return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N = int(input())
xs, ys = [], []
for _ in range(N):
    x, y = map(int, input().split())
    x2 = x+y
    y2 = x-y
    xs.append(x2)
    ys.append(y2)

#for i in range(N):
#    print(pts[i])

minX, maxX = min(xs), max(xs)
minY, maxY = min(ys), max(ys)
#print('# minX:', minX, '/ maxX:', maxX, file=sys.stderr)
#print('# minY:', minY, '/ maxY:', maxY, file=sys.stderr)

ans = 0
for x, y in zip(xs, ys):
    cs = [abs(x-minX), abs(x-maxX), abs(y-minY), abs(y-maxY)]
    m = max(cs)
    if m > ans:
        ans = m

print(ans)


Measured memory_bytes: 91708
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
  a,b,c = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

from collections import deque

ans = 0
visited = [False]*N
d = deque()
for i in range(N):
  if visited[i]==False:
    visited[i]=True
    d.append(i)
    while len(d)>0:
      v = d.popleft()
      for w in edge[v]:
        if visited[w]==False:
          visited[w]=True
          d.append(w)
    ans += 1
print(ans)

Measured memory_bytes: 93604
#include <bits/stdc++.h>
#define MOD 1000000007
#define N 2005
using namespace std;
long long dp[N][N];
int main(){
	long long n,k,r,i,j,ans,nm,nd;
	cin>>n>>k;
	r=n-k;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			if(i==j||i==0||j==0)
			{
				dp[i][j]=1;
			}
			else
			{
				dp[i][j]=-1;
			}
		}
	}
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			if(dp[i][j]==1||j>i)
			{
				continue;
			}
			else
			{
				dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD;
			}
		}
	}
	for(i=0;i<k;i++)
	{
		if(r<i)
		{
			cout<<0<<endl;
			continue;
		}
		ans=dp[k-1][i];
		nm=i+2;
		nd=r-i;
		ans=(ans*dp[nm+nd-1][nm-1])%MOD;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
const int N =10;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--){
		bool ans=true;
		int a,b=-1,c=-1;
		for(int i=0;i<N;i++)
		{
			scanf("%d",&a);
			if(ans){
				if(a>b)	b=a;
				else if(a>c)	c=a;
				else	ans=false;
			}
		}
		cout<<(ans ? "YES":"NO")<<endl;
	}




	
	return 0;
}

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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    if(n == 1) {
        cout << p << endl;
        return 0;
    }

    ll ans = 1;
    for(ll x = 2; x <= (int)1e6; x++) {
        ll p_copy = p;
        REP(i, n) {
            if(p_copy % x == 0) p_copy /= x;
            else break;
            if(i == n - 1) ans = max(ans, x);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[][] store = new String[N][3];

		for(int i = 0; i < N; i++) {
			store[i][0] = String.valueOf(i + 1);
			store[i][1] = sc.next();
			store[i][2] = sc.next();
		}

		Arrays.sort(store, new Comparator<String[]>(){
			@Override
			public int compare(String[] s1, String[] s2) {
				if(!s1[1].equals(s2[1])) {
					return (s1[1].compareTo(s2[1]));
				}
				else {
					return (Integer.compare(Integer.parseInt(s2[2]), Integer.parseInt(s1[2])));
				}
			}
		});
		for(int i = 0; i < N; i++) {
			System.out.println(store[i][0]);
		}
	}
}

Measured memory_bytes: 21588
#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<math.h>

#define MAX 1001
#define MAX_C 100001
#define max(a,b) ((a>b)?a:b)

int C, N, c[MAX], v[MAX], i, j, dp[MAX_C];

int main() {
  scanf("%d %d",&N,&C);
  assert( N < MAX );
  assert( C < MAX_C );
  for(i=0;i<N;i++) scanf("%d %d",v+i,c+i);
  
  memset(dp,-1,sizeof dp);
  dp[0] = 0;
  /*
    // 01 Knapsack
  for(i=0;i<N;++i) {
    for(j=C;j>=0;--j) if( dp[j] != -1 ) {
      if( j + c[i] <= C ) {
	dp[j+c[i]] = max(dp[j+c[i]],dp[j]+v[i]);
      }
    }
  }
  */
  // Knapsack
  for(i=0;i<N;++i) {
    for(j=0;j<C;++j) if( dp[j] != -1 ) {
	if( j+c[i] <= C ) {
	  dp[j+c[i]] = max(dp[j+c[i]],dp[j]+v[i]);
	}
      }
  }

  int maxi = 0;
  for(i=0;i<=C;i++) maxi = max(maxi,dp[i]);
  printf("%d\n",maxi);
  
  return 0;
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  vector<P> C(N);
  for(int i=0;i<N;i++){
    C.push_back({A[i]+B[i],i});
  }
  sort(C.begin(),C.end(),greater<P>());
  ll ans = 0;
  for(int i=0;i<N;i++){
    if(i%2 == 0){
      ans += A[C[i].second];
    }
    else{
      ans -= B[C[i].second];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5376
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,T=map(int,input().split())
    A=list(map(int,input().split()))
    m=INF
    diff=0
    for i in range(N):
        m=min(m,A[i])
        diff=max(diff,A[i]-m)
    d=defaultdict(int)
    dd=defaultdict(lambda:[0,0])
    for i in range(N):
        res=d[A[i]-diff]
        if res>0:
            dd[A[i]][0]+=1
            dd[A[i]][1]+=res
        d[A[i]]+=1
    ans=0
    for l in dd.values():
        ans+=min(l)
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 81240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n;
int t[110];
int main(void){
	cin >> n;
	int sum = 0;
	rep(i, n){
		cin >> t[i];
		sum += t[i];
	}

	int m; cin >> m;
	rep(i, m){
		int p, x; cin >> p >> x;
		p--;
		printf("%d\n", sum + x - t[p]);
	}

	return 0;
}

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

const ll MOD = 1000000007;

int main()
{
  int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  
  vector<int> b(n, 0);
  if(n%2 == 1)
  {
    b[0] = 0;
    for(int i = 1; i < n; i++)
    {
      b[i] = ((i+1)/2)* 2;
    }
  }
  else
  {
    for(int i = 0; i < n; i++)
    {
      b[i] = (i/2)*2+1;
    }
  }
  //rep(i,n) cout << b[i] << " ";
  
  rep(i,n)
  {
    if(a[i] != b[i])
    {
      cout << 0 << endl;
      return 0;
    }
  }
  
  ll res = 1;
  rep(i, n/2) res = (res * 2)%MOD;
  cout << res << endl;
  
  
  return 0;
}

Measured memory_bytes: 1024
import sys
import math
 
def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S
 
def float_to_str(num):
    return str("{:.10f}".format(num))
 
def list_input(tp):
    return map(tp, str_input().split())
 
# # # # # # # # # # # # # # # # # # # # # # # # #
 
class Dice:
    pip = [0 for i in xrange(6)]
 
    def __init__(self, arg):
        self.pip = arg
 
    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip
 
    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")
 
    def check(self, a, b):
        while self.pip[0] != a:
            if self.pip[2] != a and self.pip[3] != a:
                self.roll("N")
            else:
                self.roll("N")
                self.roll("W")
                self.roll("S")
 
        while self.pip[1] != b:
            self.roll("N")
            self.roll("W")
            self.roll("S")
        return self.pip[2]
 
def sameCheck(dice1, dice2):
    for i in xrange(4):
        for j in xrange(4):
            if dice1.pip == dice2.pip:
                return True
            dice2.roll("E")
        dice2.roll("N")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    dice2.roll("N")
    dice2.roll("E")
    dice2.roll("E")
    dice2.roll("S")
    for i in xrange(4):
        if dice1.pip == dice2.pip:
            return True
        dice2.roll("E")
    return False
 
n = input()
dice = []
 
for i in xrange(n):
    tmp_dice = Dice(list_input(int))
    dice.append(tmp_dice)
 
for i in xrange(n):
    for j in xrange(i+1, n):
        if sameCheck(dice[i], dice[j]):
            print "No"
            sys.exit()
 
print "Yes"


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

using namespace std;

using ll = long long;
ll culcxor(ll a){
    ll ans = 0;
    for(int i=0;i<41;++i){
        ll block = 1ll << (i+1);
        ll num = (a+1)/block * (block/2);
        num += max(0LL, (a+1)%block - block/2);
        ans += (num%2)?1LL<<i:0;
    }
    return ans;
}
constexpr ll inf = 1<<20;
int main(){
    ll a,b;
    cin>>a>>b;
    ll ans = culcxor(a-1) ^ culcxor(b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  int a[N][3];
  rep(i,N) cin >> a[i][0] >> a[i][1] >> a[i][2];

  vector<vector<int>> dp(N+1,vector<int>(3,0));
  rep(i,N){ // 配るdp
    rep(j,3) rep(k,3) if (j!=k) {
      chmax(dp[i+1][k], dp[i][j] + a[i][k]);
    }
  }
  ll ans = *max_element(all(dp[N]));
  cout << ans << endl;

 

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 9864
#include<stdio.h>

int main(void)
{
  int a[10000];
  int i=0, j;

  while(1){
    scanf("%d", &a[i]);
    if (a[i]==0)
      break;
    i++;
  }

  for(j=0;j<i;j++)
    printf("Case %d: %d\n", j+1, a[j]);

  return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> c(n+2);
    rep(i,m){
        int l, r;
        cin >> l >> r;
        c[l]++;
        c[r+1]--;
    }
    rep(i,n+1) c[i+1] += c[i];
    int ans = 0;
    rep(i,n+1) if(c[i] == m) ans++;
    cout << ans << endl;
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define Toktama ""

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2000 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int get_int() {
  char x = getchar();
  bool mns = 0;
  while (!isdigit(x)) mns |= x == '-', x = getchar();
  int res = 0;
  while (isdigit(x)) res = res * 10 + x - '0', x = getchar();
  if (mns) res = -res;
  return res;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
int mult(int x, int y) {
  return x * 1ll * y % mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}

int n, m, q;
int f[3][N][N];
char a[N][N];

int sum(int t, int x1, int y1, int x2, int y2) {
  if (y1 > y2) return 0;
  if (x1 > x2) return 0;
  return f[t][x2][y2] - f[t][x1 - 1][y2] - f[t][x2][y1 - 1] + f[t][x1 - 1][y1 - 1];
}
void solve() {
  cin >> n >> m >> q;
  rep(i, 1, n) {
    rep(j, 1, m) {
      cin >> a[i][j];
      if (a[i][j] == '1') {
        f[0][i][j] = 1;
        if (a[i][j - 1] == '1') f[1][i][j - 1] = 1;
        if (a[i - 1][j] == '1') f[2][i - 1][j] = 1;
      }
    }
  }
  rep(t, 0, 2) {
    rep(i, 1, n)
      rep(j, 1, m)
        f[t][i][j] += f[t][i - 1][j] + f[t][i][j - 1] - f[t][i - 1][j - 1];
  }
  rep(i, 1, q) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int cnt = sum(0, x1, y1, x2, y2) - sum(1, x1, y1, x2, y2 - 1) - sum(2, x1, y1, x2 - 1, y2);
    cout << cnt << nl;
  }
}
int main() {
  #ifndef Toktama
    freopen (Toktama".in", "r", stdin);
    freopen (Toktama".out", "w", stdout);
  #endif
  Kazakhstan
  int t = 1;
  while (t--)
    solve();
  ioi
}


Measured memory_bytes: 52864
#include <bits/stdc++.h>
#define MAXN 3030
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

ll n, dp[MAXN][MAXN], pre[MAXN][MAXN], mod = 1e9 + 7;
string s;


ll go(int x, int y){
	//y good options, filling in the rhs of the xth symbol
	if(dp[x][y] != -1) return dp[x][y];
	if(y == 0){
		dp[x][y] = 0;
		pre[x][y] = 0;
		return 0;
	}
	if(x == n - 1){
		dp[x][y] = y == 1;
		pre[x][y] = dp[x][y] + pre[x][y - 1];
		pre[x][y] %= mod;
		return y == 1;
	}
	ll a = mod;
	int t = n - x;
	if(s[x] == '<'){
		if(s[x + 1] == '<')
			a += pre[x + 1][y - 1];
		else
			a += pre[x + 1][t - 1] - pre[x + 1][t - y] + dp[x + 1][t - y];
	} else{
		if(s[x + 1] == '<')
			a += pre[x + 1][t - 1] - pre[x + 1][t - y] + dp[x + 1][t - y];
		else
			a += pre[x + 1][y - 1];
	}
	dp[x][y] = a % mod;
	pre[x][y] = dp[x][y] + pre[x][y - 1];
	pre[x][y] %= mod;
	return dp[x][y];
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(dp, -1, sizeof(dp));
    cin >> n >> s;
    s = "<" + s;
    for(int i = n - 1; i >= 0; i--){
    	for(int j = 0; j <= n; j++){
    		go(i, j);
    	}
    }
    cout << go(0, n);
}

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

a_b_lis = [0] * N

for i in range(N):
    a_b_lis[i] = list(map(int, input().split()))

count = 0
#print(a_b_lis)
a_b_lis = sorted(a_b_lis, key=lambda x: x[1])

on_time = True
for item in a_b_lis:
    count += item[0]
    if count > item[1]:
        on_time = False
if on_time:
    print('Yes')
else:
    print('No')

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


void solve(long long a, long long b){
    auto n = b-a-1;
    long long total=0;
    for(int i=1; i<=n; i++)
        total+=i;
    cout << total - a << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
<?php
  $s = trim(fgets(STDIN));
  $len = strlen($s);
  $count = 0;
  $small = 0;
  $flag = true;
  for($i=0; $i<$len; $i++){
    if(!ctype_upper($s[$i])){
      $small++;
    }
    if($i>1 && $i<$len-1){
      if($s[$i] == "C"){
        $count++;
      }
    }else if($i == 0){
      if($s[$i] != "A"){
        echo "WA\n";
        exit;
      }
    }
  }
  if($small == $len-2 && $count == 1){
    if($flag){
      echo "AC\n";
      exit;
    }
  }

  echo "WA\n";

Measured memory_bytes: 4604
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;

    vector<vector<int>> edges(N, vector<int>(N, 1));
    REP(n, N) edges[n][n] = 0;
    if (N % 2 == 1) {
        for(int n = N - 2; n >= 0; --n) {
            edges[N - 2 - n][n] = 0;
        }
    } else {
        for(int n = N - 1; n >= 0; --n) {
            edges[N - 1 - n][n] = 0;
        }
    }
    // REP(v1, N) {
    //     REP(v2, N) {
    //         cout << edges[v1][v2] << " ";
    //     }
    //     cout << endl;
    // }
    
    int edge_num = 0;
    REP(v1, N) {
        REP(v2, N) {
            edge_num += edges[v1][v2];
        }
    }
    edge_num /= 2;
    cout << edge_num << endl;
    REP(v1, N-1) {
        FOR(v2, v1+1, N) {
            if (edges[v1][v2]) {
                cout << (v1 + 1) << " " << (v2 + 1) << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;int a[100005];
int main() {int tp,rb,n;scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i);
	sort(a+1,a+n+1,[](int x,int y)->bool{return x>y;});
	for (tp=1;tp<=n;++tp) if (a[tp+1]<tp+1) break;
	int sg1=(a[tp]-tp)&1,sg2=0;for (rb=tp+1;a[rb]==tp;++rb) sg2^=1;
	puts(sg1|sg2?"First":"Second");return 0;
}


Measured memory_bytes: 3552
#include<iostream>
using namespace std;
int main ()
{
  int N;
  int A[100];
  int B[100];
  int C[100];
  cin >> N;
  for (int i = 1; i < N + 1; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < N + 1; i++) {
    cin >> B[i];
  }
  for (int i = 1; i < N; i++) {
    cin >> C[i];
  }
  int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans += B[A[i]];
    if (i < N && A[i] + 1 == A[i + 1]) ans += C[A[i]];
  }
  cout << ans;
}


Measured memory_bytes: 256
object Main {
  import scala.io.StdIn._
  def main(args: Array[String]): Unit = {
    def readInts() = readLine().split(' ').map(_.toInt)
    val Array(n, m, _*) = readInts()
    val votesOfItems = readInts()
    val total = votesOfItems.sum
    def isOk(votes: Int): Boolean = votes * 4 * m >= total
    println(if(votesOfItems.count(isOk) >= m) "Yes" else "No")
  }
}


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

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (i < s.size() - 1 && s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		if (i < s.size() - 2 && s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits//stdc++.h>
using namespace std;
int main() {
	double n=0.5,m=6,n2=30;
	int a,b,n4,e=0;
	cin>>n4;
	for(int i=0;i<n4;i++){
		string d;
		cin>>d;
		d+=":";
		string h;
		e=0;
		for(int j=0;j<d.length();j++){
			if(d[j]==':'){
				if(e==0)
					a=atoi(h.c_str());
				else
					b=atoi(h.c_str());
				h="";
				e++;
			}
			else
				h+=d[j];
		}
		double n3,m3;
		n3=0;
		n3+=(a*n2+b*n);
		m3=0;
		m3+=b*m;
		double c=n3-m3;
		if(c<0)
			c=0-c;
		if(360-c<c){
			c=360-c;
		}
		if(c>=90&&c<=180)
			printf("safe\n");
		else if(c>=0&&c<30)
			printf("alert\n");
		else
			printf("warning\n");
	}
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll N,A,B,C;
	cin >> N >> A >> B >> C;
	vector<ll> L(N);
	FOR(i,0,N)cin>>L[i];
	ll ans = INF;
	ll K = 1;
	FOR(i,0,N)K*=3;
	FOR(i,0,K){
		ll p = i;
		vector<ll> a,b,c;
		FOR(j,0,N){
			if(p%3==0)a.push_back(L[j]);
			if(p%3==1)b.push_back(L[j]);
			if(p%3==2)c.push_back(L[j]);
			p /= 3;
		}
		vector<P> dpa,dpb,dpc;
		for(auto x:a){
			vector<P> d;
			d.push_back({x,0});
			for(auto y:dpa){
				d.push_back(y);
				d.push_back({y.first+x,y.second+10});
			}
			dpa = d;
		}
		for(auto x:b){
			vector<P> d;
			d.push_back({x,0});
			for(auto y:dpb){
				d.push_back(y);
				d.push_back({y.first+x,y.second+10});
			}
			dpb = d;
		}
		for(auto x:c){
			vector<P> d;
			d.push_back({x,0});
			for(auto y:dpc){
				d.push_back(y);
				d.push_back({y.first+x,y.second+10});
			}
			dpc = d;
		}
		ll mina=INF,minb=INF,minc=INF;
		for(auto x:dpa)mina = min(mina,x.second+abs(x.first-A));
		for(auto x:dpb)minb = min(minb,x.second+abs(x.first-B));
		for(auto x:dpc)minc = min(minc,x.second+abs(x.first-C));
		ans = min(ans,minc+minb+mina);
	}
	cout << ans << endl;
}

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

long long f(long long a, long long n, long long mod){
  long long res = 1;
  while(n>0){
   if(n & 1)res = res * a % mod;
    a = a * a % mod;
    n>>=1;
  }
  return res;
}
long long fm(long long x, long long mod){
  long long res = x%mod;
  if(x<0) res += mod;
  return res;
}
int main(void){
  long long N;
  cin>>N;
  long long a,b,c,ans;
  a = f(10,N,1000000007);
  b = f( 8,N,1000000007);
  c = f( 9,N,1000000007);
  ans = fm((a+b-2*c),1000000007);
  cout<<ans<<endl;

  return 0; 
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define reg register

int N, L;
int ans, m = INT_MAX;

inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void ChkMax(int &aa, int bb) {
	if(aa < bb) aa = bb;
	return;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}

int main() {
//	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	N = Rd(), L = Rd();
	int R = L + N;
	for(int i = L; i < R; ++i) {
		if(abs(i) < abs(m))
			m = i;
		ans += i;
	}
	cout << ans - m << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;
map<string, int> weight;
int Atom(int &pos, string &S);
int Number(int &pos, string &S);
int Molecure(int &pos, string &S) {
	int sum = 0;
	while (pos < S.size() && S[pos] != ')') {
		if (S[pos] == '(') {
			pos++;
			int w = Molecure(pos, S);
			if (w == -1) return -1;
			pos++;
			int n = Number(pos, S);
			sum += w*n;
		}
		else {
			int w = Atom(pos, S);
			if (w == -1) return -1;
			if (pos < S.size() && isdigit(S[pos])) {
				int n = Number(pos, S);
				w *= n;
			}
			sum += w;
		}
	}
	return sum;
}
int Atom(int &pos, string &S) {
	string name = string(1, S[pos]);
	pos++;
	while ('a' <= S[pos] && S[pos] <= 'z') {
		name += string(1, S[pos]);
		pos++;
	}
	if (weight.find(name) == weight.end()) return -1;
	return weight[name];
}
int Number(int &pos, string &S) {
	int ret = 0;
	while (pos < S.size() && isdigit(S[pos])) {
		ret *= 10;
		ret += S[pos] - '0';
		pos++;
	}
	return ret;
}
int main() {
	string s;
	while (cin >> s, s != "END_OF_FIRST_PART") {
		int w;
		cin >> w;
		weight[s] = w;
	}
	while (cin >> s, s != "0") {
		int pos = 0;
		int w = Molecure(pos, s);
		if (w == -1) cout << "UNKNOWN" << endl;
		else cout << w << endl;
	}
}


Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

struct A {
	int x, y, z, ID;
};
bool operator <(A a, A b) {
	if (a.x - a.y != b.x - b.y) {
		return a.x - a.y > b.x - b.y;
	}
	return a.ID > b.ID;
}
A a[100000];
int b[100001], c[100001];
signed main() {
	int X, Y, Z; cin >> X >> Y >> Z;
	int n = X + Y + Z;
	c[n] = LLONG_MIN / 3;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y >> a[i].z;
		a[i].ID = i;
		sum += a[i].z;
	}
	sort(a, a + n);
	priority_queue<int, vector<int>, greater<int>>Q;
	int m = 0;
	for (int i = 0; i < n; i++) {
		m += a[i].x - a[i].z;
		Q.push(a[i].x - a[i].z);
		if (Q.size() > X) {
			m -= Q.top(); Q.pop();
		}
		if(Q.size()==X)b[i] = m;
		else b[i] = LLONG_MIN / 3;
	}
	priority_queue<int, vector<int>, greater<int>>tmp;
	swap(Q, tmp);
	m = 0;
	for (int i = n-1; i >=0; i--) {
		m += a[i].y - a[i].z;
		Q.push(a[i].y - a[i].z);
		if (Q.size() > Y) {
			m -= Q.top(); Q.pop();
		}
		if (Q.size() == Y)c[i] = m;
		else c[i] = LLONG_MIN / 3;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, sum + b[i] + c[i+1]);
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	string S;
	cin >> S;
	ll dp[100005][13] = {};
	dp[0][0] = 1;
	// cout << 0;
	// rep(j,0,13) {
	// 	cout <<" "<< dp[0][j];
	// }
	// cout << endl;
	rep(i,0,S.size()) {
		int c;
		if (S[i] == '?')
			c = -1;
		else
			c = S[i] - '0';
		rep(j,0,10) {
			if (c != -1 && c != j) continue;
			rep(k,0,13) {
				dp[i+1][(k*10+j)%13] += dp[i][k];
				// cout << k*10+j <<" "<< k << endl;
			}
		}
		// cout << i+1;
		rep(j,0,13) {
			dp[i+1][j] %= mod;
			// cout <<" "<< dp[i+1][j];
		}
		// cout << endl;
	}
	ll ans = dp[S.size()][5];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10624
#include<iostream>

using namespace std;
int main()
{
    int n,i,cnt=0;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        int tmp=i,sum= 0;
        while(tmp!=0)
        {
            sum++;

            tmp=(tmp/10);
        }
        if(sum%2 !=0)

            cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(b)
mx = a[0] + s
cur = mx
for i in range(1, n):
	cur += a[i] - b[i - 1]
	mx = max(mx, cur)
print(mx) 

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int r,b,w,g;
		
		Scanner sc = new Scanner(System.in);
		
		r=sc.nextInt();
		b=sc.nextInt();
		w=sc.nextInt();
		g=sc.nextInt();
		
		System.out.println(r+b+w+g);
		

	}

}


Measured memory_bytes: 26352