akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var B = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var C = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = 0;
        var prevMenu = int.MinValue;

        for (int i = 0; i < N; i++)
        {
            var menu = A[i] - 1;

            ans += B[menu];

            if (prevMenu == menu - 1)
                ans += C[prevMenu];

            prevMenu = menu;
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 28148
#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>;
#define PI 3.14159265359
const int INF = 1001001001;
const int MOD = 1000000007;

int counter(ll x)
{
    int count=0;
    while(x>=1)
    {
        x=x/10;
        count++;
    }
    return count;
}
int main()
{
    /*A
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    */
   
    int n;
    cin>>n;
    vector <ll> a(n);
    ll sum=1;
    bool flag = 1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            flag = 0;
        }
    }
    if(!flag)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        ll temp = 1;;
        temp *= sum*a[i];
        if(temp<sum || temp>1000000000000000000)
        {
            cout<<-1<<endl;
            return 0;
        }
        else
        {
            sum=temp;
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

int gcd(int x, int y) {
  while (x) {
    y %= x;
    swap(x, y);
  }
  return y;
}

int N;
vector<int> a;

bool solve() {
  bool lost = true;
  for (int i = 0; i < N; ++i) {
    if (a[i] != 1) {
      lost = false;
    }
  }

  if (lost) {
    return false;
  }

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] % 2 == 0) {
      ++cnt;
    }
  }

  if (cnt & 1) {
    return true;
  }

  if (N - cnt > 1) {
    return false;
  }

  for (int i = 0; i < N; ++i) {
    if (a[i] % 2 == 1) {
      if (a[i] == 1) {
        return false;
      }
      --a[i];
      break;
    }
  }

  int g = a[0];
  for (int i = 0; i < N; ++i) {
    g = gcd(g, a[i]);
  }

  for (int i = 0; i < N; ++i) {
    a[i] /= g;
  }

  return !solve();
}

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

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

  if (solve()) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}


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

int main(){
	int x,n;	cin>>x>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr,arr+n);
	
	int traverse=-1;
	
	for(int i=0;i<n;i++){
		if(arr[i]>=x){
			traverse=i;
			break;
		}
	}
	
	if(traverse==-1){
		cout<<x<<endl;
	}
	else if(arr[traverse]>x){
		cout<<x<<endl;
	}
	else{
		int k=x+1;
		int ans=-1;
		for(int i=traverse+1;i<n;i++){
			if(arr[i]!=k){
				ans=k;
				break;
			}
			k++;
		}
		
		if(ans==-1){
			ans=arr[n-1]+1;
		}
		
		ans-=x;
		
		k=x-1;
		int p=-1;
		for(int i=traverse-1;i>=0;i--){
			if(arr[i]!=k){
				p=k;
				break;
			}
			k--;
		}
		
		if(p==-1){
			p=arr[0]-1;
		}
		
		p=x-p;
		
		if(p<=ans){
			cout<<x-p<<endl;
		}
		else{
			cout<<ans+x<<endl;
		}
	}
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;


int main(){
	int n,x;
	long long int res=0;
	int a[114514];

	cin >> n >> x;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]>x){
			res += a[i]-x;
			a[i]=x;
		}
	}

	int wa;
	for(int i=1; i<n; i++){
		wa=a[i-1]+a[i];
		if(wa>x){
			int sa = wa-x;
			res += sa;
			a[i] -= sa;
		}
	}

	cout << res << endl;
	return 0;
}

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

#define MAX 210

vector<int> g[MAX];
int cor[MAX];
int dis[MAX][MAX];

bool pode=true;

void dfs(int node, int k){
	cor[node]=k;
	
	for (int i=0; i<g[node].size(); i++){
		int v=g[node][i];
		if (cor[v]==-1) dfs(v,!k);
		else if (cor[v]==cor[node]) pode=false;
	}
}

int main(){
	memset(cor, -1, sizeof(cor));
	for (int i=0; i<MAX; i++){
		for (int j=0; j<MAX; j++){
			if (i!=j) dis[i][j]=1000;
		}
	}

	int n;
	cin>>n;
	
	for (int i=0; i<n; i++){
		string s;
		cin>>s;
		
		for (int j=0; j<n; j++){
			if (s[j]=='1'){
				g[i].push_back(j);
				dis[i][j]=1;
			}
		}
	}
	
	dfs(0,0);
	
	
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); 
			}
		}
	}	
	
	
	if (!pode){
		cout<<-1<<endl;
		return 0;
	}
	
	
	else {
		int maior=0;
		for (int i=0; i<n; i++){
			for (int j=0; j<n; j++){
				maior=max(maior, dis[i][j]);
			}
		}
		
		cout<<maior+1<<endl;
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    stack stk1, stk2;
    char str[11];
    int i = 0;

    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk1);
    initialize_stack(&stk2);
    //文字列を受け取る
    scanf("%s", str);
    //スタックにデータを追加
    for(i = 0; i < 10; i++){
        if(str[i] == 'B'){
            if(stk1.count > 0){
                pop(&stk1);
            }
        }else if(str[i] == '0' || str[i] == '1'){ 
            push(&stk1, str[i]);
        }else{
            break;
        }
    }

    //スタック内部のデータの前後反転
    while(stk1.count > 0){
        push(&stk2, pop(&stk1));
    }

    //答えを出力
    while(stk2.count > 0){
        printf("%c", pop(&stk2));
    }
    printf("\n");

    return 0;
}
//0B00B1BB01

Measured memory_bytes: 1592
import itertools
n = int(input())

ps = list(map(int,input().split()))

qs = list(map(int,input().split()))


a = 0
b = 0
r = 0
for i in range(n):
    if ps[i] == qs[i]:
        continue
    else:
        r = i
        break

ts = ps[r:]
ts.sort()

ns = list(itertools.permutations(ts))
m = len(ns)

for j in range(m):
    if list(ns[j]) == ps[r:]:
        a = j
        break

for l in range(m):
    if list(ns[l]) == qs[r:]:
        b = l
        break
    

print(abs(a-b))

Measured memory_bytes: 8052
n,m = map(int,input().split())
dic = {}
for i in range(n):
    a,b = map(int,input().split())
    dic.setdefault(a,0)
    dic[a] += b
#print(dic)
nedan = sorted(dic)
#print(nedan)
ans = 0
for yen in nedan:
    if dic[yen] < m:
        #print(yen,dic[yen],m)
        ans += yen * dic[yen]
        m -= dic[yen]
    else:
        #print(yen,dic[yen],m)
        ans += yen * m
        break
print(ans)

Measured memory_bytes: 21996
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = -1000001;
        int min = 1000001;
        int maxi = 0;
        int mini = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            max = Math.max(max, A[i]);
            min = Math.min(min, A[i]);
            if(max==A[i]){
                maxi = i + 1;
            }
            if(min==A[i]){
                mini = i + 1;
            }
        }
        
        if(min>=0){
            System.out.println(N - 1);
            for(int i=1; i<=N-1; i++){
                System.out.println(i + " " + (int)(i + 1));
            }
        }
        else{
            System.out.println(2 * N - 1);
            if(Math.abs(max)>=Math.abs(min)){
                for(int i=1; i<=N; i++){
                    System.out.println(maxi + " " + i);
                }
                for(int i=1; i<=N-1; i++){
                    System.out.println(i + " " + (int)(i + 1));
                }
            }
            else{
                for(int i=1; i<=N; i++){
                    System.out.println(mini + " " + i);
                }
                for(int i=N - 1; i>=1; i--){
                    System.out.println(i + 1 + " " + i);
                }
            }
        }
    }
}

Measured memory_bytes: 23892
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e5 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
ll tree[Max+5];

ll query(ll idx)
{
    ll sum=0;

    while(idx>0)
    {
        sum=max(tree[idx],sum);

        idx-= idx & (-idx);

    }

    return sum;
}

void update(ll idx,ll x,ll n)
{
    while(idx<=n)
    {
        tree[idx]=max(tree[idx],x);

        idx+= idx & (-idx);
    }
}

int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;

      cin>>n;

      ll ara[n+2],dp[n+2];



      ll mx=0;

       input(ara,n);

       for(i=0; i<n; i++)
       {
         cin>>a;

        a+=query(ara[i]-1);

          update(ara[i],a,Max);

          mx=max(mx,a);


       }

       cout<<mx<<endl;

}


Measured memory_bytes: 6760
#include <iostream> //cout
#include <vector> //vector
#include <cmath> //floor
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    long long X;
    cin >> X;
    // cout << "in:" << X << endl;

    long long ans = 100;
    for(int year = 0; ; year++){
        // cout << year << ":" << ans << endl;
        if(ans >= X){
            cout << year << endl;
            break;
        }

        ans = (double)ans * 1.01;
    }
}


Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
  if(b == 0LL) return a;
  return gcd(b, a % b);
}

//============================
int main(){
  int N;
  cin >> N;
  ll a[N];
  for(int i=0;i<N;i++) cin >> a[i];

  ll gcl[N];
  ll gcr[N];
  gcl[0] = a[0];
  for(int i=1;i<N;i++) gcl[i] = gcd(gcl[i-1], a[i]);
  gcr[N-1] = a[N-1];
  for(int i=N-2;i>=0;i--) gcr[i] = gcd(gcr[i+1], a[i]);

  ll ans = max(gcl[N-2], gcr[1]);
  for(int i=1;i<N-1;i++){
    ans = max(ans, gcd(gcl[i-1], gcr[i+1]));
  }

  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
from collections import defaultdict

def solve():
    N = int(raw_input())
    D = map(int, raw_input().split())
    cnt = defaultdict(int)
    for di in D:
        cnt[di] += 1
    M = int(raw_input())
    T = map(int, raw_input().split())
    for ti in T:
        if cnt[ti] == 0:
            return False
        cnt[ti] -= 1
    return True

print "YES" if solve() else "NO"


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

using namespace std;
int main(){
	long long n;
	cin>>n;
	long long a[5];
	long long mini=1e15+5;
	for(int i=0;i<5;i++){
		cin>>a[i];
		mini=min(mini,a[i]);
	}
	n-=mini;
	long long ns=5;
	if(n<=0){
		cout<<ns;
		return 0;
	}
	if(n%mini==0)ns+=n/mini;
	else ns+=(n/mini+1);
	cout<<ns;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, t, x, y;
  cin>> n;
  
  int nt = 0, nx = 0, ny = 0;
  bool no = false;
  
  for(int i = 0; i < n; i++) {
    cin>> t >> x >> y;
    int d = abs(x - nx) + abs(y -ny);
    if(t - nt < d || t - nt >= d && (t - nt - d) % 2 == 1) no = true;
    nt = t;
    nx = x;
    ny = y;
  }
  
  if(no) cout<< "No" <<endl;
  else   cout<< "Yes" <<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

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

        if(scan.hasNext())
            c=scan.next().charAt(0);
        System.out.println((char)(c+1));
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair

using namespace std;
typedef long long ll;

int main()
{
  int n; cin >> n;
  int alf[26] = {};
  REP(i, 26) alf[i] = INF;
  REP(i, n) {
    string S;
    cin >> S;
    int tmp[26] = { };
    REP(i, S.size()) tmp[S[i] - 'a']++;
    REP(i, 26) alf[i] = min(alf[i], tmp[i]);
  }
  REP(i, 26) {
    REP(j, alf[i]) cout << (char)(i + 'a');
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main()
{
   int n;
   double xa,ya,ra,xb,yb,rb;
   cin >> n;
   for (int i=0;i<n;i++){
       cin >> xa >> ya >> ra >> xb >> yb >> rb;
       double d;
       d = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
       if (d > ra + rb){
           cout << 0 << endl;  //交わらない
       } else if (d < ra - rb){
           cout << 2 << endl;  //B in A
       } else if (d < rb - ra){
           cout << -2 << endl;  //A in B
       } else {
           cout << 1 << endl;  //交わる
       }
   }
 
    return 0;
}

Measured memory_bytes: 1232
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	map<string, int> mp;
	string sta[4] = { "AC", "WA", "TLE", "RE" };
	for (int i = 0; i < 4; ++i)mp[sta[i]] = 0;

	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for (int i = 0; i < 4; ++i) {
		cout << sta[i] << " " << "x" << " " << mp[sta[i]] << endl;
	}

	return 0;
}




Measured memory_bytes: 3640
import sys
import numpy as np


def main():
    input = sys.stdin.buffer.readline
    k, n = map(int, input().split())
    a = np.array(list(map(int, input().split())))
    a_dash = a[list(range(1, n)) + [0]]
    a[-1] -= k
    dist = np.abs(a - a_dash)
    max_dist = np.max(dist)
    print(k - max_dist)


if __name__ == "__main__":
    main()


Measured memory_bytes: 46120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <climits>
#include <cstring>
#include <string>
#include <ctype.h>
#include <sstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

#define FOR(i,a,b) for (int i=a;i<b;i++)
#define fi first
#define se second

int N, M, Q;
// vpi trains, queries;
pii memo[505][505];
int main(){
    FOR(i,0,503){
        FOR(j,0,503){
            memo[i][j] = {0,0};
        }
    }
    scanf("%d %d %d",&N,&M,&Q);
    // trains.resize(M);
    // queries.resize(Q);
    // FOR(i,0,M) scanf("%d %d",&trains[i].fi, &trains[i].se);
    // // FOR(i,0,Q) scanf("%d %d",&queries[i].fi, &queries[i].se);
    FOR(i,0,M){
        int x, y;
        scanf("%d %d",&x,&y);
        // for (int r = x; r >= 1; r--){
        //     for (int c = y; c <= N; c++){
        //         memo[r][c]++;
        //     }
        // }
        memo[x][y].first++;
    }
    for (int r = N; r > 0; r--){
        for (int c = r+1; c <= N; c++){
            memo[r][c].first += memo[r][c-1].first;
            memo[r][c].second += memo[r+1][c].second + memo[r+1][c].first;
        }
    }
    FOR(i,0,Q){
        int l, r;
        scanf("%d %d",&l,&r);
        printf("%d\n",memo[l][r].first + memo[l][r].second);
    }
    return 0;
}

Measured memory_bytes: 2944
s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)
alp = [chr(i) for i in range(97, 97+26)]

n = min(len(s), len(t))
flag = True
for i in range(n):
    if alp.index(s[i]) < alp.index(t[i]):
        print('Yes')
        flag = False
        break
    elif alp.index(s[i]) > alp.index(t[i]):
        print('No')
        flag = False
        break
    else:
        continue

if flag:
    if len(s) < len(t):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

void solve()
{
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	ll c1=0,c2=0,c3=0;
	c1 = min(a, k);
	k -= c1;
	c2 = min(b, k);
	k -= c2;
	c3 = min(c, k);
	k -= c3;
	cout << c1-c3 << "\n";
}

int main()
{
	fastIO;
	int t=1;
	// cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}

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

using namespace std;

string a;
int num[4];


int main() {
	cin >> a;
	for (int i = 0; i < 4; i++) num[i] = a[i] - '0';
	
	for (int i = 0; i < 2; i++)for (int j = 0; j < 2; j++)for (int k = 0; k < 2; k++) {
		int temp = num[0];
		if (i) {
			temp += num[1];
		}
		else {
			temp -= num[1];
		}
		if (j) {
			temp += num[2];
		}
		else {
			temp -= num[2];
		}
		if (k) {
			temp += num[3];
		}
		else {
			temp -= num[3];
		}

		if (temp == 7) {
			cout << num[0];
			if (i) {
				cout << "+";
			}
			else {
				cout << "-";
			}
			cout << num[1];
			if (j) {
				cout << "+";
			}
			else {
				cout << "-";
			}
			cout << num[2];
			if (k) {
				cout << "+";
			}
			else {
				cout << "-";
			}
			cout << num[3];
			cout << "=7" << endl;
			goto a;
		}
	}

	a:
	return 0;
}

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

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

  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];

  sort(d.begin(), d.end());
  
  int total = 1;
  for (int i = 1; i < n; i++) 
    if (d[i] != d[i - 1]) total++;

  cout << total << endl;
}


Measured memory_bytes: 256
n = gets.to_i
s = []
n.times { s << gets.chomp }
m = gets.to_i
t = []
m.times { t << gets.chomp }
u = s.uniq
ans = 0
u.each do |_u|
  x = s.count{_1 == _u}
  y = t.count{_1 == _u}
  ans = [ans, x - y].max
end
puts ans


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

int main()
{
  int x[5];
  int i = 0;
  for(i = 0; i < 5; i++){
    cin >> x[i];
  }
  
  for(i = 0; i < 5; i++){
    if(x[i] == 0){
      break;
    }
  }
  
  cout << i + 1 << endl;
}

Measured memory_bytes: 3584
def compare(a, b):
    a_str = ''
    b_str = ''
    for _ in range(a):
        a_str += str(b)
    for _ in range(b):
        b_str += str(a)

    if int(a_str) > int(b_str):
        return a_str
    else:
        return b_str

if __name__ == "__main__":
    a, b = map(int, input().split(' '))
    print(compare(a, b))

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int N;
    int num;

    int max=0;
    int min=1000000000;

    scanf("%d", &N);

    for (int i = 0; i < N; i++)
    {
        scanf("%d",&num);
        if(num>=max)max=num;
        if(num<=min)min=num;
    }

    printf("%d\n",max-min);
    return 0;
}

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

public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int N = scan.nextInt();
      int K = scan.nextInt();
      int p[] = new int[N];

      for(int i = 0;i < N;i++){
          p[i] = scan.nextInt();
      }
      Arrays.sort(p);

      int ans = 0;
      for(int i = 0;i < K;i++){
          ans += p[i];
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 38664
# coding: utf-8

def md(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

MI = lambda: map(int, input().split())

def main():
    N = int(input())
    t, x, y = 0, 0, 0
    for i in range(N):
        tn, xn, yn = MI()
        tr = tn - t - md(x, y, xn, yn)
        if tr < 0 or tr % 2:
            return "No"
    return "Yes"


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3188
N, Y = map(int, input().split())

count = 0
x, y, z = -1, -1, -1

for i in range(N + 1):
  for j in range(N + 1 - i):
    if Y - (i*10000 + j*5000) == (N - i - j)*1000:
      x, y, z = i, j, N - i - j
      break
  else:
    continue
  break

print(x, y, z)


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

#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define DEBUG(x) cerr << __PRETTY_FUNCTION__ << ">> " << #x << " : " << x << endl

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vi a(n);
  REP(i, n) cin >> a[i];
  ll tot = accumulate(ALL(a), 0LL);
  if (tot % (1LL * n * (n + 1) / 2) != 0) {
    puts("NO");
    return 0;
  }
  ll cnt = tot / (1LL * n * (n + 1) / 2);
  REP(i, n) {
    ll diff = a[i] - a[(i - 1 + n) % n];
    if (cnt - diff < 0 || (cnt - diff) % n != 0) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,i,j,k;
    cin>>n>>k;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
    }
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for(i=2;i<n;i++)
    {
    	ll ind = max((ll)0,i-k);
    	ll minval = 10000000009;
    	for(j=ind;j<i;j++)
    	{
    		minval = min(minval,dp[j]+abs(arr[i]-arr[j]));
    	}
    	dp[i] = minval;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

Pm = [0] * M
Ym = [0] * M
ym = [0] * M

Am = [''] * M
Cn = [0] * N

D = {}

for i in range(M):
    P, Y = map(int, input().split())

    Pm[i], Ym[i] = P, Y

    ym[i] = Y

    D[Y] = i

ym.sort()

for i in range(M):
    k = D[ym[i]]

    # 0-indexed
    Cn[Pm[k] - 1] += 1
    Am[k] = str(Pm[k]).rjust(6, '0') + str(Cn[Pm[k] - 1]).rjust(6, '0')

for i in range(M):
    print(Am[i])


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

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else if(s[k-1]=='C') s[k-1]='c';
cout << s <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
//using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto next(int now, int len)
{
    return (now + 1) % len;
}

auto solve1(int k, int n, std::vector<ll> &&v)
{
    auto dist_max = 0, dist = 0;

    for (int i = 0; i < n; i++)
    {
        auto x = next(i, n);
        if (i < x)
        {
            dist = v[x] - v[i];
        }
        else
        {
            dist = k - v[i] + v[x];
        }
        dist_max = std::max(dist_max, dist);
        //cout << i << " " << x << " : " << dist << endl;
        //cout << "dist max : " << dist_max << endl;
    }

    return k - dist_max;
}

int main(void)
{
    int k, n;
    cin >> k >> n;
    std::vector<ll> a(n);
    REP(i, n) { cin >> a[i]; }
    cout << solve1(k, n, std::move(a)) << endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> l(m), r(m);
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i];

  sort(l.begin(), l.end());
  sort(r.begin(), r.end());

  if (l[m - 1] > r[0])
    cout << 0 << endl;
  else if (l[m - 1] <= r[0])
    cout << r[0] - l[m - 1] + 1 << endl;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
     sc.Split(bufio.ScanWords)
     n := nextLine()

     b := strings.Contains(n,"7")
     if b {
     	fmt.Println("Yes")
     } else {
        fmt.Println("No")
     }
}  

Measured memory_bytes: 1756
#!/usr/bin/env python
# coding: utf-8

# In[5]:


import math
from functools import reduce


# In[15]:


N,X = map(int, input().split())
x = list(map(int, input().split()))


# In[16]:


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


# In[17]:


def myfunc(x,X):
    mylist = [abs(i-X) for i in x]
    print(gcd_list(list(set(mylist))))


# In[18]:


myfunc(x,X)


# In[ ]:






Measured memory_bytes: 24048
#include <stdio.h>
int main(void){
    int a,b,tot=0,sum=0,cnt=0;
    double ave;
    
    while(scanf("%d,%d",&a,&b)!=EOF){
        cnt++;
        sum+=b;
        tot+=a*b;
    }
    ave=(double)sum/cnt+0.5;
    
    printf("%d\n%.0f\n",tot,ave);
    return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int main(){
  cin >> n;
  vector<ll> h(n);
  for(int i=0 ; i<n ; i++){
    cin >> h[i];
  }
  h[0]--;
  for(int i=0 ; i+1<n ; i++){
    if(h[i] > h[i+1]){
      cout << "No" << endl; return 0;
    }else if(h[i]<h[i+1]){
      h[i+1]--;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1024
H, W = map(int,input().split())

odd = W // 2 + 1
even = W // 2

answer = 0
if W % 2 != 0 and W != 1 and H != 1:
    if H % 2 == 0:
        answer = (odd + even) * (H // 2)
    else:
        answer = (odd + even) * (H // 2) + odd
else:
    answer = even * H

if W == 1 or H == 1:
    answer = 1

print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18
 
int main() {
    int n,m;
    cin>>n>>m;
    for (int i=1;i<=m/2;i++){
        cout<<i<<" "<<m-(i - 1)<< endl;
    }
    for (int i=1;i<=(m+1)/2;i++) {
        cout<<m+i<<" "<<(2*m+1)-(i-1)<< endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef long long ll;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll T;
    cin>>T;
    rep(i, T){
        cpp_int N, A, B, C, D;
        map<cpp_int, cpp_int> dp;
        cin>>N>>A>>B>>C>>D;
        cpp_int th2=1, th3=1, th5=1;
        //取りうるfloor()とceiling()を全列挙してmapを構成しておく
        rep(i, 60){
            th3=1;
            rep(j, 40){
                th5=1;
                rep(k, 28){
                    //cout<<th2*th3*th5<<sp;
                    dp[N/(th2*th3*th5)]=(N-N/(th2*th3*th5))*D;
                    if(N%(th2*th3*th5)!=0) dp[N/(th2*th3*th5)+1]=(N-N/(th2*th3*th5))*D;
                    if(N/(th2*th3*th5)==0) break;
                    th5*=5;
                }
                
                th3*=3;
            }
            th2*=2;
        }
        dp[N]=0;
        //mapを逆順でdpする。itrはイテレータ
        auto itr=dp.end();
        do{
            itr--;
            //cout<<itr->first<<sp<<itr->second<<endl;
            
            if(itr->first==1){
                dp[0]=dp[1]+D;
                break;
            }
            dp[itr->first/2]=min(min((itr->first-(itr->first/2)*2)*D+A, (itr->first-itr->first/2)*D)+dp[itr->first], dp[itr->first/2]);
            dp[itr->first/3]=min(min((itr->first-(itr->first/3)*3)*D+B, (itr->first-itr->first/3)*D)+dp[itr->first], dp[itr->first/3]);
            dp[itr->first/5]=min(min((itr->first-(itr->first/5)*5)*D+C, (itr->first-itr->first/5)*D)+dp[itr->first], dp[itr->first/5]);
           if(itr->first%2!=0) dp[itr->first/2+1]=min(min(((itr->first/2+1)*2-itr->first)*D+A, (itr->first-itr->first/2-1)*D)+dp[itr->first], dp[itr->first/2+1]);
           if(itr->first%3!=0) dp[itr->first/3+1]=min(min(((itr->first/3+1)*3-itr->first)*D+B, (itr->first-itr->first/3-1)*D)+dp[itr->first], dp[itr->first/3+1]);
           if(itr->first%5!=0) dp[itr->first/5+1]=min(min(((itr->first/5+1)*5-itr->first)*D+C, (itr->first-itr->first/5-1)*D)+dp[itr->first], dp[itr->first/5+1]);
        } while(itr!=dp.begin());
        cout<<dp[0]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  char a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  string ans;
  int time = b - '0';
  rep(i, time) ans += a;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
import scala.collection.mutable
import scala.io.StdIn._

object Main extends App {

  val count = readInt
  val numList = readLine.split(" ").map(_.toInt)


  val set = mutable.Set.empty[Int]
  var result = "YES"

  numList.foreach { num =>
    if (set.contains(num)) {
      result = "NO"
    }
    set.add(num)
  }

  println(result)
}


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

int main(){
  int N;
  bool y = false;
  int sum = 0;
  cin >> N;
  
  for(int i=0;i<N;i++){
    int d1,d2;
    cin >> d1 >> d2;
    if(d1 != d2)
      sum = 0;
    else
      sum++;
    
    if(sum >= 3){
      y = true;
      break;
    }
  }
    
    if(y)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int s = sc.nextInt();
        int w = sc.nextInt();

        if (s > w) {
            System.out.println("safe");
        } else {
            System.out.println("unsafe");
        }
    }
}

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

int main()
{
    while(true)
    {
        string S; cin >> S;
        if(S == ".") return 0;

        stack<int> left;
        string ans = "";
        int point = 0;

        for(auto c : S)
        {
            if (c == '[')
            {
                left.push(ans.size());
            }
            else if (c == ']')
            {
                int l = left.top();
                left.pop();
                reverse(ans.begin() + l, ans.begin() + ans.size());
            }
            else if (c == '+')
            {
                point++;
            }
            else if(c == '-')
            {
                point--;
            }
            else if(c == '?')
            {
                ans += 'A';
                point = 0;
            }
            else
            {
                int num = c - 'A';
                num = num + point;
                num = (num % 26 + 26) % 26;
                ans += (char)('A' + num);
                point = 0;
            }                             
        }
        cout << ans << "\n";
    }
}



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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int A,B,C;
  cin>>A>>B>>C;
  int K;cin>>K;
  int res = 0;
  while(A >= B)
  {
    B  *= 2;
    res++;
  }
  while(B >= C)
  {
    C *= 2;
    res++;
  }
  if(K < res)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  }
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

int main(){
  int n;
  cin>>n;
  if(n==25) cout<<"Christmas";
  else if(n==24) cout<<"Christmas Eve";
  else if(n==23) cout<<"Christmas Eve Eve";
  else if(n==22) cout<<"Christmas Eve Eve Eve";
  cout<<endl;
  return (0);
  }



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

int main() {
  vector<int> x(5);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
    if (x.at(i) == 0) {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3592
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var X int64
	scanner.Scan()
	X, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var Y int64
	scanner.Scan()
	Y, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var Z int64
	scanner.Scan()
	Z, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	solve(X, Y, Z)
}
func solve(X int64, Y int64, Z int64) {
	fmt.Println(Z, X, Y)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, s;
  in(n);
  b = s = 0;
  a = 9999999999999;
  vector<ll> c(n);
  rep(i, n){
    in(c[i]);
    a = min(a, abs(c[i]));
    if(c[i] < 0)
      b++;
    s = s + abs(c[i]);
  }
  if(b % 2 == 0)
    out(s);
  else
    out(s - 2 * a);
  memi;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>  //for bool
#include <stdlib.h> // abs,labs,llabs
#include <limits.h>
#include <ctype.h>

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld; //%Lf

int main(void) {
  int a;
  scanf("%d", &a);
  char s[110];
  scanf("%s", s);
  if (a < 3200) {
    printf("red\n");
  } else {
    printf("%s\n", s);
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define calc(x,y) ((((x)*((x)+1))/2)+(y))
#define safe_calc(x, y) ((((x)+2)*((x)+3)/2)+(y)+1)

int n;
int sum;
int nails[13000000];

void process() {
    int i;

    for (i=1;i<n+3;i++) {
        int j;
        for (j=1;j<=i;j++) {
            nails[calc(i,j)] += nails[calc(i,j)-1];
        }
    }

    for (i=0;i<n+3;i++) {
        int j;
        for (j=1;j<(n+3-i);j++) {
            nails[calc(i+j,i)] += nails[calc(i+j-1,i)];
        }
    }

    for (i=0;i<n+3;i++) {
        int j;
        for (j=1;j<(n+3-i);j++) {
            nails[calc(i+j,j)] += nails[calc(i+j-1,j-1)];
        }
    }

    for (i=0;i<n+3;i++) {
        int j;
        for (j=0;j<=i;j++) {
            if (nails[calc(i,j)] > 0) sum++;
        }
    }
}

int main() {
    int i;
    int m;

    scanf("%d %d", &n, &m);
    for (i=0;i<m;i++) {
        int a, b, x;
        scanf("%d %d %d", &a, &b, &x);
        a--;
        b--;
        x++;
        nails[safe_calc(a,b)]++;
        nails[safe_calc(a,b)+1]--;
        nails[safe_calc(a+x,b)]--;
        nails[safe_calc(a+x,b+x)+1]++;
        nails[safe_calc(a+x+1,b+1)]++;
        nails[safe_calc(a+x+1,b+x+1)]--;
    }

    process();

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

Measured memory_bytes: 50172
#include<iostream>
using namespace std;
 
int main()
{
 long long int n;
  cin>>n;
  long long int a[n+1];
  long long int mod=1000000007;
long long int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
   sum+=a[i];
}
  long long int r=0;
  for(int i=0;i<n-1;i++)
  {
    sum-=a[i];
   r+=((a[i]%mod)*(sum%mod))%mod;
    r%=mod;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 5160
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll n; cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  sort(all(a));
  ll ans=0;
  set<ll> s;
  for(ll i=0;i<n;i++){
    ll p=s.size();
    s.insert(a[i]);
    ll q=s.size();
    if(p!=q){
      if(i<n-1&&a[i]!=a[i+1]){
        ans++;
      }else if(i==n-1){
        ans++;
      }
    }
  
    for(ll j=a[i];j<=a[n-1];j+=a[i]){
      s.insert(j);
    }
  }
  /*map<ll,ll> mp;
  rep(i,n){
    mp[a[i]]++;
  }
  for(auto x: mp){
    if(x.second>=2)ans--;
  }*/
  cout <<ans<<endl;
}

Measured memory_bytes: 51404
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a,b,c;cin>>a>>b>>c;
  cout<<max(0,c-(a-b))<<endl;

 

  return 0;
}

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

using namespace std;

struct Graph {
    int n, m;
    vector<vector<int>> g;
    bool is_digraph;
    Graph(int _n) : n(_n), m(0) {
        assert(n >= 1);
        g.resize(n);
        set_di(false);
    }
    Graph(int _n, int _m, bool _di=false) : n(_n), m(0) {
        assert(n >= 1);
        assert(1ll*n*(n-1)/2 >= m);
        g.resize(n);
        set_di(_di);
        input(_m);
    }
    inline void add(int u, int v) {
        assert(0 <= u && u < n);
        assert(0 <= v && v < n);
        assert(u != v);
        g[u].emplace_back(v);
        if (!is_digraph)
            g[v].emplace_back(u);
        m++;
    }
    void input(int _m) {
        int u, v;
        for (int i = 0; i < _m; i++) {
            cin >> u >> v;
            u--;v--; // to 0-based
            add(u, v);
        }
    }
    void set_di(bool _di) {
        is_digraph = _di;
    }
    vector<bool> trk;
    vector<int> pa;
    vector<int> end;
    int tim;
    void dfs(int u) {
        trk[u] = true;
        for (int v: g[u]) {
            if (trk[v]) continue;
            dfs(v);
        }
        end[u] = tim++;
    }
    void run() {
        trk = vector<bool>(n, false);
        pa = vector<int>(n, -1);
        end = vector<int>(n, 0);
        tim = 1;
        for (int i = 0; i < n; i++) {
            if (!trk[i]) dfs(i);
        }
        vector<int> mi(n, n<<2);
        for (int u = 0; u < n; u++) {
            //cout << end[u] << "\n";
            for (int v: g[u]) {
                if (end[u] < mi[v]) {
                    mi[v] = end[u];
                    pa[v] = u;
                }
            }
        }
        for (auto& x: pa) {
            cout << (x+1) << "\n";
        }
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    Graph g(n, n-1+m, true);
    g.run();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long LL;
const int maxn=1e5+100;
const double pi=4.0*atan(1.0);
typedef pair<int,int> pil;
int n,m,k;
int T;
int vis[maxn],res[maxn];
vector<int> G[maxn];
queue<pil> q;
int main()
{
    cin>>n>>m;
    int x,y;
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    q.push({1,-1});
    vis[1]=1;
    while(!q.empty())
    {
        pil st=q.front();
        q.pop();
        x=st.first;
        y=st.second;
        for(int i=0;i<G[x].size();i++)
        {
            int u=G[x][i];
            if(u==y||vis[u]) continue;
            res[u]=x;
            vis[u]=1;
            q.push({u,x});
        }
    }
    int cnt=0;
    for(int i=2;i<=n;i++)
        if(res[i]) cnt++;
    if(cnt!=n-1) cout<<"No"<<endl;
    else
    {
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++)
            cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 11148
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
    int a;
    int b;
    cin>>a>>b;
    if(max(a,b)>8)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long f[55][55];
int a[105],n;
long long dfs(int cn,int s)
{
	if(s<0) return 0;
	if(f[cn][s]!=-1) {return f[cn][s];}
	if(cn==0)
	{
		f[cn][s]=0;
		return 0;
	}
	f[cn][s]=dfs(cn-1,s-a[cn])+dfs(cn-1,s);
	return f[cn][s];
}
int main()
{
	int k;
	cin>>n>>k;
	memset(f,-1,sizeof(f));
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]%=2;
		sum+=a[i];
	}
	f[0][0]=1;
	if(f[0][a[0]]==1)f[0][a[0]]++; else f[0][a[0]]=1;
	long long res=0;
	for(int i=0;i<=sum;i++)
	{
		long long r=dfs(n-1,i);
		if(i%2==k&&r!=-1) res+=r;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256