akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int W = scan.nextInt();
		
		int arr[][] = new int[N+1][2];
		
		for(int i = 1;i<N+1;i++) {
			arr[i][0] = scan.nextInt();
			arr[i][1] = scan.nextInt();
		}		
		System.out.println(knapSack(arr, N, W));				
	}

	private static long knapSack(int[][] arr, int N, int W) {
		long dp[][] = new long[N+1][W+1];
		
		for(int w = 0;w<=W;w++) {
			dp[1][w] = 0;
		}
		
		dp[1][arr[1][0]] = arr[1][1];
		
		for(int i =2;i<=N;i++) {
				for(int w =0;w<=W;w++) {
					dp[i][w] = dp[i-1][w];
					if(arr[i][0]>w)
						continue;
					dp[i][w] = Math.max(dp[i][w],arr[i][1]+dp[i-1][w-arr[i][0]]);
				}
		}
		
		long ans = Long.MIN_VALUE;
		for(int i  =0;i<=W;i++) {
			ans = Math.max(ans,dp[N][i]);
			//System.out.print(dp[N][i] + "  ");
		}
		return ans;
	}
}

Measured memory_bytes: 127056
//bit全探索を学ぼう
//bit演算がわからん
//http://keita-matsushita.hatenablog.com/entry/2016/11/07/141236

#include<iostream>
#include<vector>
#include<set>

using namespace std;

int main(){
  int n;cin >> n;vector<int> a(n);for(int i=0;i<n;i++){cin>>a[i];}
  int q;cin >> q;vector<int> m(q);for(int i=0;i<q;i++){cin>>m[i];}
  //int型は内部では二進数として扱われる意識
  //bit演算が可能
  //1を左にn回シフトした時(2^n)よりも小さいiを考える
  //0~2^n-1でループを回している感じ
  set<int> c;
  for(int i=0;i< 1<<n;i++){
    //それぞれの桁を順に見ていく感じ
    int c_sub=0;
    for(int j=0;j<n;j++){
      if((1 & i>>j)==1){
        //iをjだけ左シフトさせてそれと1とのand
        //左シフトした時の一桁目が1かどうかの判定
        //1桁目から順に判定してる感じ
        c_sub+=a[j];
      }
    }
    c.insert(c_sub);
  }
  for(int i=0;i<q;i++){
    if(c.find(m[i])==c.end()){
      cout << "no" << endl;
    }else{
      cout << "yes" << endl;
    }
  }
}



Measured memory_bytes: 3120
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B,C=LI()

print(max(10*A+B+C, 10*B+A+C, 10*C+B+A))


Measured memory_bytes: 3064
# 2019-11-16 14:51:41(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import insort_left as in_l 
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
# import heapq

def main():
    n, m = [int(x) for x in sys.stdin.readline().split()]

    job_list = dict((i, list()) for i in range(1, m+1))
    for _ in range(n):
        a, b = [int(x) for x in sys.stdin.readline().split()]
        if a <= m:
            job_list[a].append(b)
    
    schedule = [0 for _ in range(m+1)] 
    rewards_of_appliable_jobs = []
    for i in range(1, m+1):
        for reward in job_list[i]:
            in_l(rewards_of_appliable_jobs, reward) 
        if rewards_of_appliable_jobs: 
            schedule[i] = rewards_of_appliable_jobs[-1]
            rewards_of_appliable_jobs.pop()

    print(sum(schedule))


if __name__ == "__main__":
    main()


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

int rows, column, bnykbom, m, n;
string grid [75];

int main (){
	cin>>rows>>column;
	for (int i=1; i<=rows; i++){
		cin>>grid [i];				//input grid
	}
	for (int i=1; i<=rows; i++){
		for (int j=0; j<column;j++){			//karakter dalam loop
			if (grid [i] [j]=='.'){				//cek apakah kosong
				bnykbom=0;						//yey reset
				for (int k=i-1; k<=i+1; k++){
					if (k<1){
						m=1;
                        k=1;					//biar ga out of bounds
					}else {
						m=k;
					}
					for (int l=j-1; l<=j+1; l++){
						if(l<0){
							n=0;
                            l=0;				//ga out of bounds lagi yey
						}else {
							n=l;
						}
						if (grid [m] [n]=='#'){	//cek bom apa kgk
							bnykbom++;
						}
					}
				}
				grid [i] [j]='0'+bnykbom;		//biar berubah nilainya
			}
		}
	}
	
	for (int i=1; i<=rows; i++){
		cout<<grid [i]<<endl;				//berdoa supaya outputnya bener
	}
}


Measured memory_bytes: 3636
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll n;
    cin>>n;
    if(n&1){
        ll cnt=0;
        for(int i=0;i<n;i++){
            for(int t=i+1;t<n;t++){
                if(i+t+2!=n){cnt++;}
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<n;i++){
            for(int t=i+1;t<n;t++){
                if(i+t+2!=n){cout<<i+1<<" "<<t+1<<endl;}
            }
        }
    }
    else{
        ll cnt=0;
        for(int i=0;i<n;i++){
            for(int t=i+1;t<n;t++){
                if(i+t+2!=n+1){cnt++;}
            }
        }
        cout<<cnt<<endl;
        for(int i=0;i<n;i++){
            for(int t=i+1;t<n;t++){
                if(i+t+2!=n+1){cout<<i+1<<" "<<t+1<<endl;}
            }
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N, W = MI()
inp = LI2(N)
w = [0]+[inp[i][0] for i in range(N)]
v = [0]+[inp[i][1] for i in range(N)]
dp = FILL2(INF,N+1,100001)
dp[0][0] = 0
for i in range(1,N+1):
    for j in range(100001):
        if j-v[i] >= 0:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = dp[i-1][j]
ans = 0
for j in range(100001):
    if dp[N][j] <= W:
        ans = j

print(ans)


Measured memory_bytes: 322224
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=2e5+100;
int n,t;
ll a[maxn],dp[200][340];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin>>n;
	rep(i,1,n){
		cin>>a[i];
	} 
	ll cur=1000;
	rep(i,1,n){
		int now=i;
		while(now<=n&&a[now+1]>=a[now])++now;
		if(now<i)continue;
		else{
			cur=(cur%a[i])+(cur/a[i])*a[now];
			i=now;
		}
	}
 	cout<<cur;
 
 
    return 0;
}

Measured memory_bytes: 3680
def resolve():
  a, b, c = map(int, input().split())
  ans = 1000
  if ans > abs(b - a) + abs(c - b):
    ans = abs(b - a) + abs(c - b)

  if ans > abs(c - b) + abs(a - c):
    ans = abs(c - b) + abs(a - c)

  if ans > abs(a - c) + abs(b - a):
    ans = abs(a - c) + abs(b - a)

  print(ans)


if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
int N, K, card[500][500], r[1000];
int main() {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < N / 2; j++) {
			scanf("%d", &card[i][j]);
		}
	}
	while (true) {
		for (int i = 0; i < N; i++) r[i] = rand() % 2;
		bool flag = true;
		for (int i = 0; i < K; i++) {
			int c = 0;
			for (int j = 0; j < N / 2; j++) {
				if (r[card[i][j] - 1]) c++;
			}
			if (c < N / 8 || 3 * N / 8 < c) { flag = false; break; }
		}
		if (flag) {
			for (int i = 0; i < N; i++) {
				printf("%d", r[i]);
			}
			printf("\n"); break;
		}
	}
	return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;


int main()
{
   int n,a,b;
   cin>>n>>a>>b;
   cout<<min(n*a,b)<<endl;
   return 0;

//    if(){
//        cout<<"YES"<<endl;
//        //cout<<"Yes"<<endl;
//    }
//    else{
//        cout<<"NO"<<endl;
//        //cout<<"Yes"<<endl;
//    }
   return 0;
    
}


Measured memory_bytes: 256
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int sum = 0;

        for (Integer i=A; i<=B; i++) {
            String s = i.toString();
            if (s.charAt(0) == s.charAt(4) && s.charAt(1) == s.charAt(3)) {
                sum++;
            }
        }

        System.out.println(sum);
    }
}



Measured memory_bytes: 28372
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+7;
// z[i] = len of lcp of s, s[i..]; lcp(longest common prefix)
int z[20007];
void z_fn(const string& s) {
    int n = s.size();
    for(int i=0;i<n;i++) z[i]=0;
    for (int i = 1, l = 0, r = 0; i < n; i++) 
    {
        if (i <= r)
            z[i] = min(r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) 
            z[i]++;
        if (i+z[i]-1 > r) 
        {
            l = i;
            r = i+z[i]-1;
        }
    }
}
bool cg[maxn][10007];
bool l[10007];
int n,k;
string s[maxn];
void db()
{
    l[0]=1;
    for(int i=n;i>=1;i--)
    {
        for(int j=k;j>=0;j--)
        {
            cg[i][j]=l[j];
            if(j>=s[i].length())
                l[j]|=l[j-s[i].length()];
        }
    }
}
int dp[10007];
void solve()
{
    dp[0]=1;
    string pre;
    for(int i=0;i<k;i++) pre+='z'+1;
    for(int i=1;i<=n;i++)
    {
        string cur=s[i]+'$'+pre;
        int len=s[i].length();
        z_fn(cur);
        //cout<<cur<<endl;
        //for(int i=0;i<cur.length();i++) cout<<i<<":"<<z[i]<<endl;
        int pos=-1,curans=k;
        //cout<<i<<"!"<<s[i].length()<<endl;
        for(int j=k-s[i].length();j>=0;j--)
        {
            if(!dp[j]||!cg[i][k-len-j]) continue;
            int lcp=z[len+1+j];
            //cout<<i<<","<<j<<":"<<lcp<<endl;
            if(lcp>=len) continue;
            if(s[i][lcp]<pre[j+lcp]&&j+lcp<curans)
            {
                pos=j;
                curans=j+lcp;
            }
        }
        if(pos==-1) continue;
        for(int j=0;j<len;j++)
            pre[j+pos]=s[i][j];
        for(int j=pos+len;j<k;j++)
            pre[j]='z'+1;
        for (int j=pos+z[len+1+pos]+1;j<k;j++)
            dp[j]=false;
        dp[pos+len]=true;
        //cout<<i<<":"<<pre<<endl;
    }
    cout<<pre<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>s[i];
    db();
    solve();
}

Measured memory_bytes: 21120
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,X;
    cin >> N >> X;
    vector<int> L(N);
    REP(i,N)cin >> L.at(i);
    int counter = 0;
    int l = 0;
    while(counter <= X){
        if(l >=  N){
            l++;
            break;
        }
        counter += L.at(l);
        l++;
    }
    cout << l <<  "\n";
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int a;
    int b;
    int c;
    int d;
    cin>>a>>b>>c>>d;
    int sm=min(a,b)+min(c,d);
    cout<<sm<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int A, B, C; cin >> A >> B >> C;
    
    
    cout << C/A * B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int vf[200001], a[200000];
int main(){
  int n, i;
  cin>>n;
  long long rez=0;
  for(i=0; i<n; i++){
    cin>>a[i];
    if(i>=a[i])
      rez+=(long long)vf[i-a[i]];
    if(i+a[i]<=n)
      vf[i+a[i]]++;
  }
  cout<<rez;
  return 0;
}


Measured memory_bytes: 5108
x,y,a,b,c = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
q = gets.split.map(&:to_i)
r = gets.split.map(&:to_i)

puts (p.sort[-x, x] + q.sort[-y, y] + r).sort[-(x + y), x + y].sum

Measured memory_bytes: 34820
n=int(input())
a=input().split()
b=input().split()
c=input().split()
ans=0
ans+=int(b[int(a[0])-1])

for i in range(n-1):
  ans+=int(b[int(a[i+1])-1])
for j in range(n-1):
    if int(a[j])+1==int(a[j+1]):
      ans+=int(c[int(a[j])-1])
print(ans)  

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

using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long int
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define L(x) ('a'<=x && x<='z')
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  200*1000 + 1;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
const double epsilon = 1e-9; 
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}



 int32_t main(){
    IOS;
 
   int t;
   //cin>>t;
     t=1;
   while(t--){

   int n;
   cin>>n;
   int cnt=0;
   int flag=0;
   while(n--){
      int x,y;
      cin>>x>>y;

      if(x==y){
         cnt++;
         if(cnt>=3)flag=1;
      }
      else{
         cnt=0;
      }
   }

   if(flag==1)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   }

 }

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


int s[100002];

int main(){

  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    int l, r;
    cin >> l >> r;
    s[l] += 1;
    s[r+1] += -1;
  }
  int ans = 0;
  for (int i = 1; i < 100001; i++){
    s[i] += s[i-1];
    ans += s[i];
  }

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


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int m, k;
    cin >> m >> k;
    m = (1<<m);
    if(k == 0) {
        rp(i, 0, m) {
            printf("%d %d ", i, i);
        }
        printf("\n");
        return 0;
    }
    if(k >= m || (k == 1 && m == 2)) {
        cout << -1 << endl;
        return 0;
    }
    rp(i, 0, m) {
        if(i != k) printf("%d ", i);
    }
    printf("%d ", k);
    for(int i = m-1; i >= 0; i--) {
        if(i != k) printf("%d ", i);
    }
    printf("%d\n", k);
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    cout << max(a+b, max(a-b, a*b)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    cout << (S == "ABC" ? "ARC" : "ABC") << "\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<string>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

// dp[i][j]: i番目までの子供たちにj個の飴を配る場合の数
int dp[105][110000];

int main () {
  int N, K;
  cin >> N >> K;
  vi a(N);
  rep(i,N) cin >> a[i];

  /*dp[0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= K; ++j) {
      // dp[i][j] = ∑(k=max(0,j-a[i-1]), j)dp[i-1][k]と同じ
      for (int k = 0; k <= a[i-1]; ++k) {
        if (j-k >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j-k])%mod;
      }
    }
  }*/
  
  dp[0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    // csum[j] = dp[i-1][0] + dp[i-1][1] + ... + dp[i-1][j-1]
    vector<int> csum(K+2);
    for (int j = 0; j <= K; ++j) csum[j+1] = (csum[j] + dp[i-1][j])%mod;
    for (int j = 0; j <= K; ++j) dp[i][j] += (csum[j+1] - csum[max(0,j-a[i-1])] + mod)%mod;
  }

  cout << dp[N][K] << endl;
  return 0;
}

Measured memory_bytes: 45180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int main() {
	string s;
	cin >> s;
	int a = 0, b = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'A') a++;
		else b++;
	}
	if(a == 0 || b == 0) printf("No\n");
	else printf("Yes\n");
	return 0;
}


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

MAXN = N*M+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

a = 0
for d in range(1,N):
    a += d*(N-d) * M*M
b = 0
for d in range(1,M):
    b += d*(M-d) * N*N
ans = (a+b) * comb(N*M-2, K-2)
ans %= MOD
print(ans)

Measured memory_bytes: 34084
#include<bits/stdc++.h>
#define MAXN 5005
#define LL long long
#define P int(1e9+7)
using namespace std;

int N,K;
int a[MAXN];

LL dp[MAXN];

void insert(int x){
	for(int j=K;j>=x;j--){
		dp[j] += dp[j-x];
	}
}

void remove(int x){
	for(int j=x;j<=K;j++){
		dp[j] -= dp[j-x];
	}
}

bool chk(int x){
	if(x > K) return 0;
	for(int j=K-x;j<K;j++){
		if(dp[j]) return 0;
	}
	return 1;
}

int main(){
	
	cin>>N>>K;
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	
	dp[0] = 1;
	for(int i=2;i<=N;i++){
		insert(a[i]);
	}
	
	int cnt = 0;
	for(int i=1;i<=N;i++){
		if(chk(a[i])) ++cnt;
		insert(a[i]);
		if(i+1 <= N) remove(a[i+1]);
	}
	
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,m,count=0,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
      count++;
    }
    if(count>=n)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve() {
    int ans = 0;
    
    bool V[MAX];
    for (int i = 0; i < n; i++) {
        B[i] = A[i];
        V[i] = false;
    } 
    sort(B, B+n);
    for (int i = 0; i < n; i++)  T[B[i]] = i;
    for (int i = 0; i < n; i++) {
        if (V[i] ) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while(1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
         
           S += v;
            cur = T[v];
            if ( V[cur] ) break;
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    
    return ans;
}

int main() {
    cin >> n;
    s = VMAX;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;
    
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int a,b,c;
  cin >>  a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define int long long
int digit[25];
int d[25][15][2];
int dfs(int len,int limit,int pre,int last,int ok){
    if(!len)return ok;
    if(!limit&&!pre&&d[len][last][ok]!=-1)return d[len][last][ok];
    int ans=0;
    int ma=(limit?digit[len]:9);
    for(int i=0;i<=ma;i++){
        ans+=dfs(len-1,limit&&i==ma,pre&&i==0,i,ok&&(pre||abs(i-last)<=1));
    }
    if(!limit&&!pre){
        d[len][last][ok]=ans;
    }
    return ans;
}
int solve(int x){
    int len=0;
    while(x){
        digit[++len]=x%10;
        x/=10;
    }
    return dfs(len,1,1,0,1);
}
int check(int mid){
    return solve(mid)-solve(0);
}
signed main(){
    memset(d,-1,sizeof d);
    int k;
    cin>>k;
    int l=1,r=1e15;
    int ans=-1;
    while(l<=r){
        int mid=(l+r)/2;
        if(check(mid)>=k){
            ans=mid;
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 7;

int n,x,y;
int a[N],mx,f,mn = inf;

int main () {
        cin >> n >> x >> y;

        for (int i = 1; i <= n; i ++)
                cin >> a[i];

        mx = max(mx,abs(a[n] - y));

        for (int i = 1; i < n; i ++) {
                mn = inf;
                for (int j = i + 1; j < n; j ++) {
                        mn = min(mn,abs(a[n] - a[j]));
                }
                if (mn != inf)
                        mx = max(mx,mn);
        }
        cout << mx << endl;
}


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

int main()
{
    string S, T;
    cin >> S >> T;

    int A, B;
    cin >> A >> B;

    string U;
    cin >> U;

    if (S == U) {
        cout << A - 1 << " " << B << endl;
    }
    else {
        cout << A << " " << B - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))

L = [0 for _ in range(N)]
R = [0 for _ in range(N)]
L[0] = A[0]
R[-1] = A[-1]
for i in range(N-1):
  L[i+1] = gcd(L[i],A[i+1])
  R[N-2-i] = gcd(R[N-1-i],A[N-2-i])
#print(L)
#print(R)

ans = 0
for i in range(N):
  if i == 0:
    ans = max(ans,R[1])
  elif i == N-1:
    ans = max(ans,L[N-2])
  else:
    ans = max(ans,gcd(L[i-1],R[i+1]))
print(ans)

Measured memory_bytes: 90208
#include <bits/stdc++.h>
//#define int long long int
#define MOD 1000000007
#define MAX INT_MAX
using namespace std;

int add(int a, int b) {
    int z = (a%MOD + b%MOD) % MOD;
    return z;
}

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

int myXOR(int x, int y) {
     return (x | y) & (~x | ~y);
}

void solve() {
    int a, b;
    cin >> a >> b;
    if(a < 0 && b >= 0)
        cout << "Zero" << '\n';
    else if(a > 0 && b > 0)
        cout << "Positive" << '\n';
    else if(a < 0 && b < 0) {
        if(abs(a-b)%2 != 0)
            cout << "Positive" << '\n';
        else
            cout << "Negative" << '\n';
    }
    return ;
}              

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}


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

int main(){
    int n,m;
    int sum = 0;
    cin >> n >> m;
    vector<int> A(n);
    rep(i,n){
        cin >> A.at(i);
        sum += A.at(i);
    }
    sort(A.rbegin(),A.rend());
    double check = ((double)sum / (double)(4 * m));

    if(A.at(m - 1) >= check) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  string s;cin>>s;
  bool res=true;
  if(s[0]!='A')res=false;
  if(!isLowerCase(s[1]))res=false;
  bool cFlag=false;
  FOR(i,2,s.size()-1){
    if(s[i]=='C'){
      if(!cFlag){
        cFlag=true;
        continue;
      }else{
        res=false;
        break;
      }
    }else if(!isLowerCase(s[i])){
      res=false;
      break;
    }    
  }
  if(!cFlag)res=false;
  if(!isLowerCase(s[s.size()-1]))res=false;
  cout << (res?"AC":"WA") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int main()
{
	int s[100010]={}, t[100010]={};
	string x, y;
	cin >> x >> y;
	reps(i, x.size())
	{
		s[i]=s[i-1];
		if(x[i-1]=='A') s[i]++;
	}
	reps(i, y.size())
	{
		t[i]=t[i-1];
		if(y[i-1]=='A') t[i]++;
	}
	int q;
	cin >> q;
	int a, b, c, d, e, f;
	rep(i, q)
	{
		cin >> a >> b >> c >> d;
		e=2*(b-a+1)-(s[b]-s[a-1]);
		f=2*(d-c+1)-(t[d]-t[c-1]);
		if((e+2*f)%3==0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
       
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        if(Math.abs(a - b) <= d && Math.abs(b-c) <= d){
            System.out.println("Yes");
        }else if(Math.abs(a - c) <= d){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main()
{
    string name;
    cin >> name;
    
    //0つ
    if (name == "SSS") {
        cout << 0 << endl;
    }

    //1つ
    if (name == "RSS") {
        cout << 1 << endl;
    }   
    if (name == "SRS") {
        cout << 1 << endl;
    }
    if (name == "SSR") {
        cout << 1 << endl;
    }
    if (name == "RSR") {
        cout << 1 << endl;
    }

    //2つ
    if (name == "RRS") {
        cout << 2 << endl;
    }
  
    if (name == "SRR") {
        cout << 2 << endl;
    }

    //3つ
    if (name == "RRR") {
        cout << 3 << endl;
    }

    
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  char c; cin >>c;
  if (c=='a' or c=='i' or c=='u' or c=='e' or c=='o') cout <<"vowel" <<endl;
  else cout <<"consonant" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

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

    for (int i=0;i<S.length();i++){
        cout << "x";
    }

}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll ans = 0;
    rep(i, 0, n) {
        if(a[i] % 2 == 1 && i % 2 == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <assert.h>
#include <stdio.h>

long long int absll(long long int n) {
  if (n < 0) {
    return -n;
  }
  return n;
}

int main() {
  long long int n, k, l, m;
  assert(scanf("%lld %lld", &n, &k) == 2);
  l = absll(n - k * (long long int)(n / k));
  m = absll(n - k * (long long int)(n / k + 1));
  printf("%lld\n", l > m ? m : l);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(char*)a - *(char*)b;
}
int compare_int2(const void *a, const void *b)
{
    return *(char*)b - *(char*)a;
}

int main()
{
    char s[100]={};
    char t[100]={};
    scanf("%s", s);
    scanf("%s", t);
    qsort(s,100,sizeof(char),compare_int);
    qsort(t,100,sizeof(char),compare_int2);
    int n=0,m=0;
    while(s[n]==0){n++;}
    while(t[m]==0){m++;}
    for(int i=0;i<100-n;i++){
        s[i]=s[i+n];
        if(n!=0)
        s[i+n]=0;
    }
    for(int i=0;i<100-m;i++){
        t[i]=t[i+m];
        if(m!=0)
        t[i+m]=0;
    }
    int flag=0;
    for(int i=0;i<100;i++){
        if(s[i]==t[i]){
            if(s[i]==0)
                break;
            continue;
        }
        if(s[i]<t[i]){
            flag=1;
            break;
        }
        if(t[i]<s[i]){
            flag=0;
            break;
        }
    }
    printf("%s\n",(flag==1)?"Yes":"No");
    
    return 0;
}


Measured memory_bytes: 128
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x) 			   cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set; 
const int N = 1e5+7;  
/*  
    time : 12 : 14    
    date : 19.01.2020
*/    
// int L,R,mid,target,idx ;
const int INF = 1e9 + 7 ;
int h[N],dp[N] ;   
int solve(int idx){
	if(idx <= 0  )
		return 0 ;  
	if(dp[idx] != -1) 
		return dp[idx]; 
	int result  = INF  ; 
	if(idx-1 >= 0 )	
	result =  min(result,abs(h[idx]-h[idx-1])+solve(idx-1)) ;
	if(idx-2 >= 0 )
	result =  min(result,abs(h[idx]-h[idx-2])+solve(idx-2)) ;
	return (dp[idx] = result) ;
}
int tests() 
{	
	int n ; 
	cin >> n ;
	int i ; 
	forn(i,0,n+1)
		dp[i]  = -1 ; 

	forn(i,0,n)
		cin >> h[i] ; 
 	cout << solve(n-1) << '\n'; 
	return 0 ; 
}
int32_t main(){
    I__O ;   
    int cases = 1 ; 
 	// cin >> cases;  
    while(cases--)
	    tests(); 
	return 0 ; 
}

Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>

using namespace std;

int main(){
  string s;
  cin >> s;
  cout << s.substr(0, s.length()-8) << endl;
}


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

int main(){
  int n,m;
  vector<pair<int,int>> conclusion;

  while(cin>>n>>m,n,m){
    int taro_total=0;
    int hanako_total=0;
    int min=200;
    int t;
    int h;
    vector<int> taro;
    vector<int> hanako;
    pair<int,int> result;

    for(int i=0;i<n;++i){
      cin>>t;
      taro.push_back(t);
      taro_total+=t;
    }

    for(int i=0;i<m;++i){
      cin>>h;
      hanako.push_back(h);
      hanako_total+=h;
    }

    int flag=0;

    for(auto p:taro){
      for(auto q:hanako){
	if((taro_total-p+q==hanako_total-q+p) && min>p+q){
	  flag=1;
	  min=p+q;
	  result.first=p;
	  result.second=q;
	}
      }
    }
    if(flag==0) conclusion.push_back({-1,-1});
    else conclusion.push_back(result);
  }
  for(auto p:conclusion){
    if(p.first==-1) cout<<p.first<<endl;
    else cout<<p.first<<" "<<p.second<<endl;
  }
}

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

signed main(){
    int n,m; cin>>n>>m;
    int ans=m*1900+(n-m)*100;
    rep(i,m) ans*=2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,m; cin>>n>>m;
	ll g=__gcd(n,m);
	ll lcm = (ll(n)*m)/g;
	string s,t; cin>>s>>t;
	vector<ii> L,R;
	for(ll i=0;i<n;i++)
	{
		L.pb(mp((lcm/n)*i,i));
	}
	for(ll i=0;i<m;i++)
	{
		R.pb(mp((lcm/m)*i,i));
	}
	for(ll i=0;i<m;i++)
	{
		ll pos=R[i].fi; char c=t[R[i].se];
		auto it = lower_bound(L.begin(),L.end(),mp(pos,-1LL));
		if(it!=L.end()&&(*it).fi==pos&&s[(*it).se]!=c){cout<<-1<<'\n'; return 0;}
	}
	cout<<lcm<<'\n';
}


Measured memory_bytes: 4976
#include <stdio.h>

int main(void) {
  int n, sum = 0, i, a[1001];

  scanf("%d", &n);

  for ( i = 0; i < n - 1; i++) {
    scanf("%d", &a[i]);
  }

  sum = a[0];

  for (i = 1; i < n - 1; i++) {
    if(a[i - 1] < a[i]) {
      sum = sum + a[i - 1];
    }
    else {
      sum = sum + a[i];
    }
  }

  sum = sum + a[n - 2];

  printf("%d\n", sum);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};

auto& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
	int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
	int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
	return max(sa,sb)<0;
}

int na,nb;
P a[1010],b[1010];


//Appropriately Changed
using W = R;
using edge = struct {int to; W cost;};
using G = vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph, int from, int to, W cost) {
	graph[from].push_back({to, cost});
	graph[to].push_back({from, cost});
}


auto dijkstra(const G &graph, int s) {
    const int n = graph.size();
    vector<W> dist(n, INF);
    using state = tuple<W, int>;

    priority_queue<state, vector<state>, greater<state>> q;
    dist[s] = 0, q.push(state(0, s));

    while (!q.empty()) {
        W c; int v;
        tie(c, v) = q.top(); q.pop();
        for (auto &e : graph[v]) {
            W nc = c + e.cost; int nv = e.to;
            if (chmin(dist[nv], nc)) q.push(state(nc, nv));
        }
    }
    return dist;
}

R check(int n,P p[1010],L ban){
	G graph(n);
	rep(j,n)rep(i,j){
		L line = L{p[i],p[j]};
		if(iss(line,ban)) continue;
		add_edge(graph,i,j,abs(line.s-line.t));
	}

	auto dist = dijkstra(graph,0);
	return dist[1] + abs(ban.s-ban.t);
}

int main(void){
	cin >> na >> nb;
	rep(i,na) cin >> a[i];
	rep(i,nb) cin >> b[i];

	cout.precision(20);

	R ans = min(check(na,a,L{b[0],b[1]}),check(nb,b,L{a[0],a[1]}));

	if(ans < INF)
		cout << fixed << min(check(na,a,L{b[0],b[1]}),check(nb,b,L{a[0],a[1]})) << endl;
	else
		cout << -1 << endl;
	
	return 0;
}

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

vector<int> e[100001];

struct DSU{
	vector<int> p,sz;
	void init(int n){
		p.resize(n+1);sz.resize(n+1);
		for(int i=1;i<=n;i++)
			sz[p[i]=i]=1;
	}
	int F(int x){
		return x==p[x]?x:p[x]=F(p[x]);
	}
	bool U(int x,int y){
		x=F(x),y=F(y);
		if(x==y)	return false;
		if(sz[x]<sz[y])	swap(x,y);
		sz[x]+=sz[y];
		p[y]=x;
		return true;
	}
};
int dep[100001],dp[100001],f[100001];
void dfs(int x,int p){
	f[x]=p;
	dp[x]=((dep[x]&1)?-1:1);
	for(int it:e[x])
		if(it!=p){
			dep[it]=dep[x]+1;
			dfs(it,x);
			dp[x]+=dp[it];
		}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,a,b;
	int ans=0;
	cin>>n>>m;
	DSU D;
	D.init(n);
	for(int i=1,u,v;i<=m;i++){
		cin>>u>>v;
		if(D.U(u,v)){
			e[u].emplace_back(v);
			e[v].emplace_back(u);
		}
		else
			a=u,b=v;
	}
	if(n==m+1){
		dfs(1,0);
		if(dp[1]!=0){
			cout<<-1<<endl;
			return 0;
		}
	}
	else{
		dfs(a,0);
		if(dep[b]&1){
			if(dp[a]){
				cout<<-1<<endl;
				return 0;
			}
			vector<int> v;
			for(int i=b;i!=a;i=f[i])
				v.emplace_back(dp[i]);
			sort(v.begin(),v.end());
			ans=abs(v[v.size()/2]);
			for(int i=b;i!=a;i=f[i])
				dp[i]-=v[v.size()/2];
		}
		else{
			if(dp[a]&1){
				cout<<-1<<endl;
				return 0;
			}
			int x=dp[a]/2;
			ans=abs(x);
			dp[a]=0;
			for(int i=b;i!=a;i=f[i])
				dp[i]-=x;
		}
	}
	for(int i=1;i<=n;i++)
		ans+=abs(dp[i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 14588
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        mut As: [i64; N],
    }

    As.sort();
    let n = As[N - 1];
    let mut r = 0;

    for i in 0..N {
        let mut cand = As[i];
        if 2 * cand > n {
            cand = n - cand;
        }

        let mut ans = r;
        if 2 * ans > n {
            ans = n - ans;
        }

        if cand > ans {
            r = As[i];
        }
    }

    println!("{} {}", n, r);
}


Measured memory_bytes: 4296
#include <iostream>
#include <iomanip>  
#include <cmath>
#include <algorithm> 
#include <vector> 

using namespace std; 

int n, m, q, ans, A[13];

struct item {
    int a, b, c, d;
} st[55];

inline void dfs(int i, int j) {
    A[i] = j;
    if (i == n) {
        int sum = 0;
        for (int i = 1; i <= q; ++i) {
            if (A[st[i].b] - A[st[i].a] == st[i].c)
                sum += st[i].d;
        }
        ans = max(ans, sum);
        return;
    }
    for (int k = j; k <= m; ++k)
        dfs(i + 1, k);
}

int main(){
    cin >> n >> m >> q;
    for (int i = 1; i <= q; ++i) {
        cin >> st[i].a >> st[i].b >> st[i].c >> st[i].d;
    }
    for (int i = 1; i <= m; ++i) {
        dfs(1, i);
    }
    cout << ans << "\n";
}
/* 3.57 */

Measured memory_bytes: 3612
#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>;
const int INF = 1000000001;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  cout << n * n * n << endl;
  return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string s;
    cin >> s;
    ll cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if(s[i] == '2'){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "DENIED" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    ll N=S.size();
    string T=S;
    ll buf=0;
    repr(i,N-1,0){
        ll x=S[i]-'0';
        if(buf==0){
            if(x==0) T[i]='0';
            else { T[i]='0'+(10-x); buf=1;}
        } 
        else{
            T[i]='9'-x;
        }
    }

    ll dp[N+1][2]={}; //桁数 反転 //出した枚数
    rep(i,N+1){
        dp[i][0]=INF2;
        dp[i][1]=INF2;
    }
    dp[0][0]=0;
    dp[0][1]=1;
    rep(i,N){
        mini(dp[i+1][0],dp[i][0]+(S[i]-'0'));
        mini(dp[i+1][1],dp[i][0]+(S[i]-'0'+1));
        mini(dp[i+1][1],dp[i][1]+(T[i]-'0'));
        mini(dp[i+1][0],dp[i][1]+(T[i]-'0'+1));
    }
    cout<< min(dp[N][0],dp[N][1]) <<"\n";
}

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


Measured memory_bytes: 17948