akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define LL long long
int n,q;
LL X,r[N];
struct Node{LL a,t;}p[N];
LL l_line[N],r_line[N];
LL cnt[N];
int main(){
    scanf("%lld%d",&X,&n);
    r[0]=0;for(int i=1;i<=n;i++)scanf("%lld",&r[i]);
    scanf("%d",&q);
    for(int i=1;i<=q;i++)scanf("%lld%lld",&p[i].t,&p[i].a);
    LL na=0,nb=X;
    l_line[0]=0;r_line[0]=X;
    for(int tmp=1;tmp<=n;tmp++){
        if(tmp&1){
            LL tip=min(na,r[tmp]-r[tmp-1]);
            na-=tip;
            nb+=tip;
        }else{
            LL tip=min(nb,r[tmp]-r[tmp-1]);
            na+=tip;
            nb-=tip;
        }
        l_line[tmp]=na;
    }
    na=X,nb=0;
    for(int tmp=1;tmp<=n;tmp++){
        if(tmp&1){
            LL tip=min(na,r[tmp]-r[tmp-1]);
            na-=tip;
            nb+=tip;
        }else{
            LL tip=min(nb,r[tmp]-r[tmp-1]);
            na+=tip;
            nb-=tip;
        }
        r_line[tmp]=na;
    }
    for(int i=1;i<=n;i++)
        if(i&1)cnt[i]=cnt[i-1]-(r[i]-r[i-1]);
        else cnt[i]=cnt[i-1]+(r[i]-r[i-1]);
    for(int i=1;i<=q;i++){
        int ll=1,rr=n,res=0;
        while(ll<=rr){
            int mid=(ll+rr)>>1;
            if(r[mid]<=p[i].t)res=mid,ll=mid+1;
            else rr=mid-1;
        }
        LL pic=p[i].a+cnt[res];
        if(l_line[res]>pic)pic=l_line[res];
        if(r_line[res]<pic)pic=r_line[res];
        if(res&1)pic+=min(X-pic,p[i].t-r[res]);
        else pic-=min(pic,p[i].t-r[res]);
        printf("%lld\n",pic);
    }
    return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int n,m;
int x,y,cnt=0;
int fir[100005],nxt[100005],to[100005];
int du[100005];
queue<int> q;
int dp[100005],ans;

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt;
		du[y]++;
	}
	for(int i=1;i<=n;i++){
		if(du[i]==0) q.push(i);
	}
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(int i=fir[v];i;i=nxt[i]){
			dp[to[i]]=max(dp[to[i]],dp[v]+1);
			du[to[i]]--;
			if(du[to[i]]==0) q.push(to[i]);
		}
	}
	for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
	printf("%d\n",ans);
	
	return 0;
}

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

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

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

    for(int k=0; k<N-1; k++)
    {
        cout << A[k] << ' ';
    }
    cout << A[N-1] << endl;

    int v;

    for(int i=1; i<N; i++)
    {
        v = A[i];
        int j = i-1;
        while(j>=0 && A[j]>v)
        {
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }

        for(int k=0; k<N-1; k++)
        {
            cout << A[k] << ' ';
        }
        cout << A[N-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define f(i,a,n)        for(ll i=a;i<n;i++)
#define ve              vector
#define ss              second 
#define ff              first
#define pf              pop_front
#define pob             pop_back
#define psf             push_front
#define res(x)          cout<<x<<'\n'
#define read(t)         ll t;cin>>t

#define pii             pair<ll,ll>
#define vii             vector<ll,ll>
#define INFI            1000000000000000000;


int main(){
   string s;
   cin>>s;
   int cnt=0;
   f(i,0,3){
       if(s[i]=='R'){
           cnt++;
       }
   }
   if(cnt==2&&s[1]!='R'){
       cnt=1;
   }
   cout<<cnt<<endl;
}

Measured memory_bytes: 3620
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    num_monster = 0
    res = 0  # 余力
    for i in range(N):
        a = A[i] - res  # 前の人が倒しといてくれた分を引く
        b = B[i]
        if b <= a:  # 目の前の敵を倒し切れるかあやしい
            num_monster += b
            res = 0
        elif b <= a+A[i+1]:  # 次の敵の一部まで倒せる
            num_monster += b
            res = b - a
        else:  # 次の敵まで全部倒せる
            num_monster += a+A[i+1]
            res = A[i+1]
    print(num_monster)
main()

Measured memory_bytes: 19116
#include <stdio.h>
int main(void){
    int a,b,c,i,min,sum;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    sum = c-b;
    if(c<b)
        min=c;
    else
        min=b;
    for(i=2;i<a;i++){
        scanf("%d",&b);
        if(sum < b - min)
            sum = b - min;
        if(min > b)
            min = b;
    } 
    printf("%d\n",sum);
    return 0;
}
         


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

int main() {
	int n = 0, x = 0;
	string s = "";
	string s2 = "";
	string s3 = "";
	cin >> n >> s;
	x = n / 2;
	for (int i = 0; i < x; i++) {
		s2 += s[i];
	}
	for (int i = x; i < n; i++) {
		s3 += s[i];
	}
	
	if (s2 == s3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,X,M = map(int, input().split())

check = [0]*(M+1)
SUM1 = 0
cnt1 = 0
temp = X
check3=0
for i in range(N):

    if check[temp]==0:
        check[temp]+=1
    else:
        check3 = 1
        break
        
    SUM1 += temp
    cnt1 += 1
    temp = temp ** 2
    temp %= M


check2 = [0]*(M+1)
SUM2 = 0
cnt2 = 0
if check3==1:
    
    for i in range(N):


        if check2[temp]==0:
            check2[temp]+=1
        else:
            break
        SUM2 += temp        
        cnt2 += 1
        temp = temp ** 2
        temp %= M



SUM3 = 0

Y = (N-cnt1)%max(cnt2,1)

for i in range(Y):
    
    SUM3 += temp

    temp = temp ** 2
    temp %= M
    
if check[0]==1:
    SUM3=0
    N = cnt1+cnt2

print(SUM1+SUM2*(((N-cnt1)//max(cnt2,1)))+SUM3)

Measured memory_bytes: 69364
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll D, G;
  cin >> D >> G;
  ll p[D], c[D];
  REP(i, D) { cin >> p[i] >> c[i]; }

  ll ans = INF;
  REP(bit, (1 << D)) {
    ll sum = 0;
    ll cnt = 0;
    REP(i, D) {
      if (bit & (1 << i)) {
        sum += c[i] + p[i] * 100 * (i + 1);
        cnt += p[i];
      }
    }

    if (sum >= G) {
      ans = min(ans, cnt);
    } else {
      REPR(i, D - 1) {
        if (bit & (1 << i)) continue;

        REP(j, p[i]) {
          if (sum >= G) {
            break;
          }
          sum += 100 * (i + 1);
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Fri Apr 03 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        int oneDigit = 9;
        int threeDigit = 909;
        int fiveDigit = 90909;
        int len = String.valueOf(N).length();
        if(len == 1){
            println(N);
        }
        else if(len == 2){
            println(oneDigit);            
        }
        else if(len == 3){
            println(oneDigit + (N - 100 + 1));
        }
        else if(len == 4){
            println(threeDigit);
        }
        else if(len == 5){
            println(threeDigit + (N - 10000 + 1));
        }
        else{
            println(fiveDigit);
        }

        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

using namespace std;

int main()
{
  double num, x0, x1 ;//?????°??£?¨?
  while(cin >> num)//??????????§?
  {
    if(num == -1) break;
    else{
      x0 = num/2.0 ;//?????????
      while(1){
        x1 = x0 - (pow(x0,3.0)-num)/(3*pow(x0,2.0)) ;//?????\????????????
        if(abs(pow(x1,3.0)-num)< 0.00001*num)//???????????¶?¢????
        {
          break ;
        }
        x0 = x1 ;//???????????????????????´????¬?????¨?????????????
      }
      cout<<fixed<<setprecision(8)<< x1 <<endl;
    }
  }
  return 0 ;
}

Measured memory_bytes: 3440
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N, A, B;
    scan(N, A, B);
    auto S = sread();
    long cnt;
    long b;
    foreach (i, c; S)
    {
        switch (c)
        {
        case 'a':
            if (cnt < A + B)
            {
                cnt++;
                writeln("Yes");
            }
            else
                writeln("No");
            break;
        case 'b':
            if (cnt < A + B && b < B)
            {
                b++;
                cnt++;
                writeln("Yes");
            }
            else
                writeln("No");
            break;
        case 'c':
            writeln("No");
            break;
        default:
            break;
        }
    }
}


Measured memory_bytes: 2940
/*
 * 0309.cc: New Drug Development
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_C = 10;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

typedef vector<int> vi;

/* global variables */

string tps[MAX_N];
vi nbrs[MAX_N];

/* subroutines */

ll rec(int u) {
  ll rcs[MAX_C];
  vi &nbru = nbrs[u];
  int cn = nbru.size();

  for (int i = 0; i < cn; i++) rcs[i] = rec(nbru[i]);

  ll ret;
  
  switch (tps[u][0]) {
  case 'E': // Element
    ret = 1;
    for (int i = 0; i < cn; i++) ret = (ret * rcs[i]) % MOD;
    break;
  case 'A': // Alternate
    ret = 0;
    for (int i = 0; i < cn; i++) ret = (ret + rcs[i]) % MOD;
    break;
  case 'R': // 'or'
    ret = 1;
    for (int i = 0; i < cn; i++) ret = (ret * (rcs[i] + 1)) % MOD;
    ret = (ret - 1 + MOD) % MOD;
    break;
  }

  if (tps[u].size() > 1) ret = (ret + 1) % MOD;
  return ret;
}

/* main */

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

  for (int i = 0; i < n - 1; i++) {
    int si, ti;
    cin >> si >> ti;
    si--, ti--;
    nbrs[si].push_back(ti);
  }

  ll ans = rec(0);
  printf("%lld\n", ans);
  return 0;
}

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

void solve1()
{
    int n;cin>>n;
    int c=0,ans=0;
    for(int i=0;i<10000000;i++)
    {
        c+=7;
        c%=n;c*=10;
        ans++;
        if(c==0)
        {
            break;
        }
    }
    if(c==0)cout<<ans<<endl;
    else cout<<-1<<endl;
}


int main() {

  

   int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    solve1();

  }

  return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define INF 1001001001

long long int cnt;

void merge(std::vector<int>&A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    std::vector<int> L(n1+1);
    std::vector<int> R(n2+1);
    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
            cnt += n1 - i;
        }
        
    }
    
}

void mergeSort(std::vector<int>&A, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void){
    int n;
    cnt = 0;
    std::cin >> n;
    std::vector<int> A(n);

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

    mergeSort(A, 0, n);

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


Measured memory_bytes: 4312
import bisect

N = int(raw_input())

LIS = []

for i in range(N):
    a = int(raw_input())
    z = bisect.bisect_left(LIS, a)
    if z >= len(LIS):
        LIS.append(a)
    else:
        LIS[z] = a

print len(LIS)



Measured memory_bytes: 10896
//C - Cat Snuke and a Voyage: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

bool ans;
int n, m, x, y;

bool bfs(int no, vector<int> adj[])  {
    vector<bool> vis(n+1, false);
    vector<int> dist(n+1);
    queue<int> q;
    vis[no] = true;
    dist[no] = 0;
    q.push(no);
    while(!q.empty()) {
        int top = q.front(); q.pop();
        for(auto x : adj[top]) {
            if(!vis[x]) {
                vis[x] = true;
                dist[x] = dist[top] + 1;
                if(x == n and dist[x] == 2) return true;
                q.push(x);
            }
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> m;
    vector<int> adj[n+1];
    while(m--) {
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ans = bfs(1, adj);
    if(ans) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 13168
/*
      author  : nishi5451
      created : 14.08.2020 23:41:09
*/

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


int main(){
    long double sum=0;
    int n;
    cin >> n;
    rep(i,n){
        long double x;
        string s;
        cin >> x >> s;
        if(s=="JPY"){
            sum += x;
        } 
        else{
            sum += x*380000.0;
        }
    }
    printf("%.12llf\n",sum);
    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n;cin >> n;
  vector<ll> a(n);
  ll sum= 0;
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    sum+= a[i];
  }
  sort(a.begin(), a.end());
  ll omit = 0;
  if(sum%10==0){
    for(int i = 0; i < n; ++i){
      if(a[i]%10 != 0){
        omit = a[i];
        break;
      }
    }
    if(omit!=0){
      sum-=omit;
    }
    else{
      sum=0;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long h;
  scanf("%ld", &h);

  long attack = 0;
  long monsters = 1;

  while (h >= 1) {
    attack += monsters;
    monsters *= 2;
    h /= 2;
  }

  printf("%ld\n", attack);

  return 0;
}

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

int main() {
    double d, t, s;
    cin >> d >> t >> s;

    if (d / s <= t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

int N;
ll A[3100];
ll dp[3100][3100];
bool used[3100][3100];

ll solve(int L,int R){
    if(L > R) return 0;
    if(used[L][R]) return dp[L][R];
    used[L][R] = 1;
    int diff = (N - R - L + 1) % 2;
    ll ans = 0;
    if(diff){
        ans = INFF;
        ans = min(ans,solve(L+1,R) - A[L]);
        ans = min(ans,solve(L,R-1) - A[R]);
    }
    else{
        ans = -INFF;
        ans = max(ans,solve(L+1,R) + A[L]);
        ans = max(ans,solve(L,R-1) + A[R]);
    }
    return dp[L][R] = ans;
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N) cin >> A[i];
    cout << solve(0,N-1) << endl;
}

Measured memory_bytes: 84480
#include <iostream>
#define MAX_N 100

using namespace std;
int main(void){
	int a[MAX_N],n;
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i];
	for (int i=n-1;i!=0;i--) cout << a[i] << ' ';
	cout << a[0] << endl;
}

Measured memory_bytes: 3088
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define  pi               acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
    End
}
/* pray for me
Do before die
*/






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	if (n==1&&m==1){
		puts("1");
	}else{
		if (n==1) printf("%d\n",m-2); else
		if (m==1) printf("%d\n",n-2); else
		printf("%lld\n",1ll*(n-2)*(m-2));
	}
	return 0;
}

Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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

bool isPalindrome(const string& S, int l, int r)
{
	while (l < r)
	{
		if (S[l] != S[r])
		{
			return false;
		}
		l++;
		r--;
	}
	return true;
}

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

	if (isPalindrome(S, 0, S.size() - 1) && isPalindrome(S, 0, (S.size() - 1) / 2 - 1) && isPalindrome(S, (S.size() + 3) / 2 - 1, S.size() - 1))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int N, K;
        cin >>N >>K;
        vector<int> A(N, 0);
        Rep0(i, N)
                cin >>A.at(i);
        Sort(A);
        int S=0;
        Rep0(i, K)
                S+=A.at(i);
        cout <<S <<endl;
        return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <queue>
#define INF 1100000000
using namespace std;

char mp[60][60];
long long dist[60][60];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int main()
{
  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < 60; j++) {
      mp[i][j] = '#';
      dist[i][j] = INF;
    }
  }

  long long H, W;
  cin >> H >> W;
  long long B = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      char c;
      cin >> c;
      if (c == '#') B++;
      mp[i][j] = c;
    }
  }

  queue<pair<int, int>> q;
  q.push(make_pair(1, 1));
  dist[1][1] = 0;
  while (! q.empty()) {
    pair<int, int> tmp = q.front(); q.pop();
    int y = tmp.first;
    int x = tmp.second;
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (mp[ny][nx] == '.' && dist[ny][nx] > dist[y][x] + 1) {
        dist[ny][nx] = dist[y][x] + 1;
        q.push(make_pair(ny, nx));
      }
    }
  }

  if (dist[H][W] < INF) cout << (H*W - dist[H][W] - B - 1) << endl;
  else cout << -1 << endl;

  return 0;
}

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

int main() {
  int n, a, b, p, i, x = 0, y = 0, z = 0;
  cin >> n >> a >> b;
  for (i = 0; i < n; ++i) {
    cin >> p;
    if (p <= a) {
      ++x;
    } else if (p > b) {
      ++y;
    } else {
      ++z;
    }
  }
  cout << min(x, min(y, z)) << "\n";
  return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

bool can_make(int x, int y, int z) {
    if (x == y || y == z || z == x) return false;
    return (x < y + z) && (y < z + x) && (z < x + y);
}

int main()
{
    int n;
    cin >> n;
    auto len = vector<int>(n);
    for (auto& li : len) {
        cin >> li;
    }
    auto cnt = 0;
    for (int i = 0; i + 2 < n; ++i) {
        for (int j = i + 1; j + 1 < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (can_make(len[i], len[j], len[k])) ++cnt;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    rep(i, k){
        ans += v[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
#define re(n) cin >> n
#define all(a) a.begin(),a.end()
#define ff(i,x,n) for(ll i=(int)x;i<(int)n;i++)
#define f(i,n) ff(i,0,n)
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define te(t) ll t; re(t); while(t--)

int main(){
	ll n;
	re(n);
	ll a[n];
	f(i,n){
		re(a[i]);
	}
	ll dp[n]={0};
	if(n>=2){
		dp[1] = abs(a[0]-a[1]);
	}
	ff(i,2,n){
		if(abs(a[i-1]-a[i])+dp[i-1]<abs(a[i-2]-a[i])+dp[i-2]){
			dp[i] = dp[i-1]+abs(a[i-1]-a[i]);
		}else{
			dp[i] = dp[i-2]+abs(a[i-2]-a[i]);
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    sort(A,A+n);
    int count=0;
    for(int i=0;i<n-1;i++){
        if(A[i]==A[i+1]){
            count++;
        }
    }
    if(!count){
        cout<<"YES";
    }
    else
    cout<<"NO";
}    

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int hasNext;
		while ((hasNext = in.nextInt()) != 0) {
			while (hasNext-- > 0) {
				char rank;
				int pm = in.nextInt();
				int pe = in.nextInt();
				int pj = in.nextInt();
				int all = pm + pe + pj;
				if (pm == 100 || pe == 100 || pj == 100 || all >= 240
						|| (all - pj) >= 180) {
					System.out.println('A');
					continue;
				} else if (all >= 210 || (all >= 150 && (pm >= 80 || pe >= 80))) {
					System.out.println('B');
					continue;
				} else {
					System.out.println('C');
				}
			}
		}
	}
}

Measured memory_bytes: 28360
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        x: usize,
        m: usize,
    }

    let mut ans = x;
    let mut sum = 0;
    let mut cnt = 0;
    let mut init = 0;
    let mut ok: bool = true;
    let mut dp: Vec<usize> = Vec::new();
    for i in 0..m {
        dp.push(ans);
        ans = (ans*ans)%m;
        for j in 0..dp.len() {
            if ans==dp[j] {
                cnt = dp.len() - j;
                init = j;
                ok = false;
                break;
            }
        }
        if ok==false {
            break;
        }
    }
    let mut init_sum = 0;
    for i in 0..init {
        init_sum += dp[i];
    }

    for i in init..dp.len() {
        sum += dp[i];
    }

    let d = (n-init) / cnt;
    let r = (n-init) % cnt;
    sum *= d;
    sum += init_sum;
    for i in 0..r {
        sum += ans;
        ans = (ans*ans)%m;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2444
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }
vector<ll> getDivs(ll n) {
	vector<ll> rez;
	for(ll i = 1; i * i <= n; ++i) {
		if(n % i == 0) {
			rez.emplace_back(i);
			if(n / i != i) rez.emplace_back(n / i);
		}
	}
	return rez;
}
ll go(ll n, ll k) {
	//DBG(n); DBG(k);
	if(n < k) return n;
	if(n % k == 0) return go(n / k, k);
	return go(n % k, k);
}
void solve() {
	ll n = fetch<ll>();
	ll answ = 0;
	auto d1 = getDivs(n - 1);
	for(auto& d: d1) if(d > 1 && n % d != 0) ++answ;
	auto d2 = getDivs(n);
	for(auto& d: d2) if(d > 1 && go(n, d) == 1) ++answ;
	cout << answ << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
x1, y1, x2, y2 = map(int, input().split())
d = (x2 - x1, y2 - y1)
d90 = (-d[1], d[0])
d180 = (-d[0], -d[1])
x3 = x2 + d90[0]
y3 = y2 + d90[1]
x4 = x3 + d180[0]
y4 = y3 + d180[1]
print(x3, y3, x4, y4)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T> inline T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  if(n%2==1){
      cout<<0<<ENDL;//
  }else{
      ll ans=0,pro=5;
      n/=2;

      while(n/pro){
          ans+=n/pro;
          pro*=5;
      }
      cout<<ans<<ENDL;
  }

}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,a,b;
	cin>>x>>a>>b; 
	if(b<=a)
	cout<<"delicious"<<endl;
	else if(b>a&&b<=a+x)
	cout<<"safe"<<endl;
	else	
	cout<<"dangerous"<<endl;
	return 0; 
} 

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		int n,y,r,t;
		String b;
		n=scan.nextInt();
		if(n==0)break;
		y=scan.nextInt();
		String num[]=new String[n];
		double max=0;
		
		String most="";
		for(int i=0;i<n;i++)
		    {
			b=scan.next();
			r=scan.nextInt();
			t=scan.nextInt();
			double gankin=0;
			if(t==1)
			    {
				
				gankin=1+y*r/100.0;
				    
			    }
			else if(t==2)
			    {
				
				gankin=(Math.pow(1+r/100.0,y));
				    
			    }
			
			if(max<gankin)
			    {
				max=gankin;
				most=b;
			    }
			
		    }
		
		System.out.println(most);
	    }
    }
}

Measured memory_bytes: 35360
import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = sorted(ZZ())[::-1]
    ans = A[0]
    j = 1
    for i in range(N-2):
        ans += A[j]
        if i%2 == 1: j += 1
    print(ans)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 31504
#include <stdio.h>
#include <string.h>

#define N 100000000
int a(void);
int b(char);
void insert(void);
int find(void);

char c[14];
int x[N];
int n;

int main(){
    char str[7];
    int i;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s%s", str, c);
        if(str[0] == 'i'){
            insert();
        }
        else if(str[0] == 'f'){
            if(find())
                printf("yes\n");
            else
                printf("no\n");
        }
    }
    return 0;
}

int a(void){
    int x=0, i, p=1;
    for(i = 0; i < strlen(c); i++){
        x += p*(b(c[i]));
        p *= 5;
    }
    return x;
}

int b(char c){
    
    if(c == 'A'){
        return 1;
    }
    else if(c == 'C'){
        return 2;
    }
    else if(c == 'G'){
        return 3;
    }
    else return 4;
    
}

void insert(){
    x[a()]=1;
}
int find(){
    int key =a();
    
    if(x[key]){
        return 1;
    }
    else return 0;
}

Measured memory_bytes: 38628
K, X = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

win = Array.new(X+1)
win[0] = false
# binding.pry
1.upto(X) do |j|
  win[j] = false
# 各取得可能数毎に見て、一つでも条件を満たせばこちら手番の勝ち
  K.times do |i|
# arr[i] <= j 残石が取得可能数以上
# !win[j - arr[i]] 残石 - 取得数の結果が負けの時(取得後は相手手番となる為)
    win[j] |= arr[i] <= j && !win[j - arr[i]]
  end
end

puts win[X] ? "First" : "Second"

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

ll ans=0;
vector<ll> num(51,1);
vector<ll> p_num(51,1);
ll nibun(ll high,ll low,ll mid,ll cur,ll x){
  if(cur==0){
    //cout<<"aiueo"<<endl;
    return 1;
  }
  if(x==low){
    //cout<<"aaaaa"<<endl;
    return 0;
  }
  if(x==high){
    return p_num[cur];
    //cout<<"bbbbb"<<endl;
  }
  if(x==mid){
    //cout<<"ccccc"<<endl;
    return p_num[cur]/2+1;
  }
  if(mid<x){
    ans+=p_num[cur]/2+1;
    //cout<<high-1<<" "<<mid+1<<" "<<(high+mid)/2<<endl;
    return nibun(high-1,mid+1,(high+mid)/2,cur-1,x);
  }
  else{
    //cout<<mid-1<<" "<<low+1<<" "<<(mid+low)/2<<endl;
    return nibun(mid-1,low+1,(mid+low)/2,cur-1,x);
  }
}
int main(){
  ll n,x;
  cin>>n>>x;
  for(int i=1;i<=n;i++){
    num[i]=num[i-1]*2+3;
    p_num[i]=2*p_num[i-1]+1;
    //cout<<num[i]<<endl<<p_num[i]<<endl;
  }
  ans+=nibun(num[n],1,num[n]/2+1,n,x);
  cout<<ans<<endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int T;
    cin >> T;

    rep(i, T) {
        int N, M, A, B;
        cin >> N >> M >> A >> B;
        cout << floor_sum(N, M, A, B) << endl;
    }
}

Measured memory_bytes: 3604
# 解説を参考に作成

def solve():
    X = int(input())
    A, B = 0, 0
    for a in range(-200, 200):
        for b in range(-200, 200):
            if a ** 5 - b ** 5 == X:
                A, B = a, b
                break
    print(A, B)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 9100
N = int(input())
count = [0,0,0,0]
status = ['AC', 'WA', 'TLE', 'RE']
for i in range(N):
    S = input()
    for j in range(4):
        if S == status[j]: count[j]+=1

for j in range(4):
    print(status[j], 'x', count[j])

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

int main(){
  int N;
  cin>> N;
  int sum =0;
  
  for(int i=N; i!=0 ;i/=10){
    sum+= i%10 ;
  }
  if(N%sum==0)cout<< "Yes";
  else cout<< "No";
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    if (n % k == 0) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 384
list1=list(map(int,input().strip().split()))[:2]
n,m=list1[0],list1[1]
arr=list(map(int,input().strip().split()))[:n]
dict1={}
for i in range(m):
	l=list(map(int,input().strip().split()))[:2]
	key,val=l[0],l[1]
	if key in dict1:
		dict1[key].append(val)
	else:
		dict1[key]=[]
		dict1[key].append(val)
	if val in dict1:
		dict1[val].append(key)
	else:
		dict1[val]=[]
		dict1[val].append(key)
count=0
for i in range(1,n+1):
	flag=0
	if i in dict1:
		l=arr[i-1]
		for j in dict1[i]:
			if(l <= arr[j-1]):
				flag=1
				break
	if(flag==0):
		count+=1
print(count)

Measured memory_bytes: 31680
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b, c, d;

signed main() {
	cin >> a >> b >> c >> d;
	cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long int a,b,c;
  cin >> a;
  if(a%1000==0)
    cout << "0" << endl;
  else
    {
        b=(a/1000)+1;
        c=(b*1000)-a;
        cout << c << endl;
    }

}


Measured memory_bytes: 3620
#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 REP(i,n) for(int i=n-1;i>=(0);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 eall(v) unique(all(v), 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;
const ll INFF = 1e18;

int N, C;
int a[110], b[110], c[110];
// dp[i][j][k] := i???????????§??????, A????\??????????j??§
// ????????????c????????? B????\???????????????§???
int dp[10010][110]; 

int main(void) {
	cin >> N >> C;
	rep(i, N) cin >> a[i] >> b[i] >> c[i];
	rep(j, 10010)rep(k, 110) dp[j][k] = -1;
	dp[0][0] = 0;
	rep(i, N)REP(j, 10001)REP(k, C) {
		if(dp[j][k] == -1) continue;
		// ????????????
		chmax(dp[j][k], dp[j][k]);
		if(k + c[i] > C) continue;
		// A?????????
		chmax(dp[j + a[i]][k + c[i]], dp[j][k] + b[i]);
		// B?????????
		chmax(dp[j + b[i]][k + c[i]], dp[j][k] + a[i]);
		/*
		// ?????¨?????¨????????????????????????
		if(j + b[i] >= dp[i][j][k] + a[i]) chmax(dp[i + 1][j + b[i]][k + c[i]], dp[i][j][k] + a[i]);
		// ?????¨?????¨???????????????????????£???
		else chmax(dp[i + 1][dp[i][j][k] + a[i]][k + c[i]], j + b[i]);
		*/
	}

	int ans = 0;
	rep(i, 10001)rep(j, C + 1) chmax(ans, min(i, dp[i][j]));
	printf("%d\n", ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

lint f(lint a){
	if(a==0) return 0;
	if(a==1) return 1;
	if(a==2) return 3;
	if(a==3) return 0;
	int i;
	for(i=62;(a&(1LL<<i))==0;i--);
	return f(a-(1LL<<i))+(a%2==0?(1LL<<i):0);
}

int main(){
	lint a,b; cin>>a>>b;
	cout<<(f(b)^(a>0?f(a-1):0))<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x,y) memset(x,y,sizeof(x))
#define mcpy(x,y) memcpy(x,y,sizeof(x))
#define ll long long
#define pa pair<int,int>
#define maxn 200005
using namespace std;
inline int read(){
  int n=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){n=n*10+ch-48;ch=getchar();}
	return n*f;
}
struct edge{
	int p,v,r;
};
int n,par[2][maxn],typ[2][maxn],rt[2],ans[maxn],cur[maxn];
vector<int> adj[2][maxn];
vector<edge> G[maxn];
inline void addedge(int x,int y){
	G[x].pb({y,0,G[y].size()});
	G[y].pb({x,0,G[x].size()-1});
}
void dfs(int x,int t)
{
	typ[t][x]=1;
	for (auto y : adj[t][x])
		dfs(y,t),typ[t][x]^=1;
}
inline void dfs(int x)
{
	while(cur[x]<G[x].size())
		if(G[x][cur[x]].v) cur[x]++;
			else
			{
				int c=cur[x];
				G[x][c].v=1;
				G[G[x][c].p][G[x][c].r].v=1;
				if(x&&G[x][c].p==x+n)ans[x]=-1;
					else if (x-n&&G[x][c].p==x-n) ans[x-n]=1;
				dfs(G[x][c].p);
			}
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		par[0][i]=read(),rt[0]=(par[0][i]==-1)?i:rt[0],adj[0][par[0][i]].pb(i);
	for(int i=1;i<=n;i++)
		par[1][i]=read(),rt[1]=(par[1][i]==-1)?i:rt[1],adj[1][par[1][i]].pb(i);
	dfs(rt[0],0);
	dfs(rt[1],1);
	for(int i=1;i<=n;i++)
		if(typ[0][i]^typ[1][i]) {puts("IMPOSSIBLE");return 0;}
	puts("POSSIBLE");
	for(int i=1;i<=n;i++)
		if(~par[0][i]) addedge(par[0][i],i);
			else addedge(0,i);
	for(int i=1;i<=n;i++)
		if(~par[1][i])addedge(par[1][i]+n,i+n);
			else addedge(0,i+n);
	for(int i=1;i<=n;i++)
		if(typ[0][i])addedge(i,i+n);
	dfs(0);
	for(int i=1;i<=n;i++)
	  printf("%d%c",ans[i],(i==n)?'\n':' ');
	return 0;
}


Measured memory_bytes: 38656
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
#define ULL unsigned long long
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
const int MAXN = 100010;
int n, dp[MAXN][3];
int a[MAXN][3];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		rep(j, 3)cin >> a[i][j];
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++) {
		rep(j, 3) {
			rep(prev, 3){
				if (prev == j)continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][prev] + a[i][j]);
			}
		}
    }
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
	return 0;
}


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


int main() {

  while(1) {
    int h,w;

    cin >> h >> w;

    if(h == 0 && w == 0) break;
    int flag = 0;
    int minsya = 1000000; 
    int minx,miny,fsya;
    int sya = h*h + w*w;

    for(int i=1; i<150;i++) {
      for(int j =i;j<150;j++) {
	
	fsya = i*i + j*j;
	if(fsya == sya && i>h && i < j && flag == 0) {
	  minsya = fsya;
	  minx = j;
	  miny = i;
	  flag =1;
	}
	else if(sya < fsya && minsya > fsya && i < j) {
	  minsya = fsya;
	  minx = j;
	  miny = i;

	}
      }
      
    }
      cout << miny <<" " << minx << endl;
    
    
  }
  
  return 0;
  
}

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

int main(){
    int number;
    cin >> number;
    int digit = 10;
    int divider = number % digit;
    for (int i = 0; i<7; i++){
        if(number / digit)divider += (number % (digit*10))/digit;
        digit *= 10;
    }
    if(number%divider == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int md = 1e9 + 7;
 
int add(int a, int b) {
	a += b;
	if(a >= md) {
		a -= md;
	}
	return a;
}

int sub(int a, int b) {
	return (a - b + md) % md;
}

int mul(int a, int b) {
	return (1LL * (a % md) * (b % md)) % md;
}

int power(int a, int b) {
	int ret = 1;
	while(b) {
		if(b & 1) 
			ret = mul(ret, a);
		a = mul(a, a);
		b /= 2;
	}
	return ret;
}

int invmd(int x) {
	return power(x, md - 2);
}

int fct[N];
int invf[N];

int ncr(int n, int r) {
	return mul(fct[n], mul(invf[n - r], invf[r]));
}

void pre() {
	fct[0] = fct[1] = 1;
	invf[0] = invf[1] = 1;
	for(int i = 2; i < N; ++i) {
		fct[i] = mul(fct[i - 1], i);
		invf[i] = invmd(fct[i]);
	}
}

void getAC() {	
	ios_base :: sync_with_stdio(false); cin.tie(0);
	pre();	
	int n , k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < n; ++i) {
		if(a[i] < 0) {
			a[i] += md;
		}
	}
	int ans = 0;
	for(int i = k - 1; i < n; ++i) {
		ans = add(ans, mul(a[i], ncr(i, k - 1)));
	}
	for(int i = 0; i + k - 1 < n; ++i) {
		ans = sub(ans, mul(a[i], ncr(n - 1 - i, k - 1)));
	}
	cout << ans << '\n';
}
 
int main() {	
	getAC();
	return 0;
}

Measured memory_bytes: 1408