akhauriyash/Code-Regression huggingface dataset:
a=int(input())
b=int(input())
c=int(input())
x=int(input())
cnt=0
for i in range(0,int(a)+1):
    # print("i=%d" % i)
    for j in range(0,int(b)+1):
        # print("j=%d" % j)
        for k in range(0,int(c)+1):
            # print("k=%d" % k)
            if i*500+j*100+k*50 == x:
                # print(i*500+j*100+k*50)
                cnt+=1
print(cnt)




Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int main() {
    int N,K;
    cin>>N>>K;
    int d[K];//iのお菓子を持っている人数
    int A[N][K];//お菓子を持っているかフラグ
    for(int i=0;i<N;i++){
      for(int t=0;t<K;t++)
      {
        A[i][t]=0;
      }
    }
    int count =0;
    for(int i =0;i<K;i++)
    {
      cin>>d[i];
      //cout<<d[i]<<endl;
      for(int t=0;t<d[i];t++)
      {
        int num=0;
        cin>>num;
        //cout<<num-1<<endl;
        A[num-1][i]=1;
      }
    }
    for(int t=0;t<N;t++)
      {
        bool flg =true;
        for(int i =0;i<K;i++)
    	{
          //cout<<i+1<<"種類目のお菓子"<<endl;
          //cout<<t+1<<"人目:"<<A[i][t]<<endl;      
          if(A[t][i]==1)flg=false;      
        }
        if(flg)count++;
      }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

vector<ll> A,Al,Ar;
void regi(vector<ll> D){
    A=D;
    Al=D;
    REP(i,D.size()-1){
        Al[i+1]=Al[i]+D[i+1];
    }
    Ar=D;
    RREP(i,D.size()-1){
        Ar[i]=Ar[i+1]+D[i];
    }
}

ll accu(ll l,ll r){
    if(l<=r){
        if(l==0){
            return Al[r];
        }else{
            return Al[r]-Al[l-1];
        }
    }else{
        ll R=0;
        R+=Al[r];
        R+=Ar[l];
        return R;
    }
}

ll sum(void){
    return Ar[0];
}


int main(void){
    
    ll N,K,a;
    vector<ll> P,C;
    cin >> N >> K;
    REP(i,N){
        cin >> a;
        a--;
        P.push_back(a);
    }
    REP(i,N){
        cin >> a;
        C.push_back(a);
    }
    
    ll Ans=-INF;
    
    vector<bool> visit(N,false);
    REP(i,N){
        if(visit[i])continue;
        ll k=i;
        vector<ll> R={};
        while(1){
            if(visit[k])break;
            visit[k]=true;
            R.push_back(C[k]);
            k = P[k];
        }
        
        /*REP(j,R.size()){
            cout << R[j] << " ";
        }cout << endl;*/
        
        if(R.size()==0)continue;
        regi(R);
        
        ll S = sum();
        if(S<=0){
            ll num=-INF;
            REP(i,R.size()){
                REP(j,R.size()){
                    ll s;
                    if(i<=j){s=j-i+1;}else{s=((ll)R.size())-(i-j-1);}
                    //cout << R.size() MM i MM j MM s << endl;
                    
                    if(s<=K){
                        num=max(num,accu(i,j));
                    }
                    
                }
            }
            Ans=max(Ans,num);
        }else{
            ll num = 0;
            ll T = K%(R.size());
            ll succ=0;
            if(T==0){
                T=R.size();
                succ-=S;
            }
            
            REP(i,R.size()){
                REP(j,R.size()){
                    ll s;
                    if(i<=j){s=j-i+1;}else{s=((ll)R.size())-(i-j-1);}
                    
                    if(s<=T){
                        num=max(num,accu(i,j));
                    }
                    
                }
            }
            num += S*(K/(R.size()));
            num += succ;
            
            
            Ans=max(Ans,num);
        }
        
    }
    
    cout << Ans << endl;
    
    return 0;
}



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

int main(){
	string S;
	cin >> S;
	if(S=="Sunny"){
		cout << "Cloudy" << endl;
	}else if(S=="Cloudy"){
		cout << "Rainy" << endl;
	}else {
		cout << "Sunny" << endl;
	}
}

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

int main() {
  int n;
  cin >> n;
  
  map<string, int> cut;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    cut[s]++;
  }
  
  for (string s : {"AC", "WA", "TLE", "RE"}) {
    cout << s << " x " << cut[s] << endl;
  }
  return 0;
}

Measured memory_bytes: 3660
import sys
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()
kakko = ["(", ")"]

cnt = 0
for i in range(N):
  if s[i] == kakko[0]:
    cnt += 1
  else:
    cnt = max(cnt-1, 0)
right = cnt

cnt = 0
for i in range(N-1,-1,-1):
  if s[i] == kakko[1]:
    cnt += 1
  else:
    cnt = max(cnt-1, 0)
left = cnt

print(kakko[0]*left + s + kakko[1]*right)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
int X, A, B;
int main(void){
    std::cin >> X >> A >> B;
    if(B-A <= 0){
        std::cout << "delicious" << std::endl;
    }else if(B-A >= X+1){
        std::cout << "dangerous" << std::endl;
    }else{
        std::cout << "safe" << std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
  int n;
  cin>>n;
  int ct;
  int t=n;
  while(n>0)
  {
    ct++;
    n/=10;
    
  }
  
  int ans=0;
  if(ct%2==0)
  {
    
    for(int i=1;i<ct;i+=2)
    {
      ans+=9*((int)pow(10,i-1));
    }
    
    
  }
  else
  {
    for(int i=1;i<ct;i+=2)
    {
      ans+=9*((int)pow(10 ,i-1));
    }
    ans+=t-1*((int)pow(10,ct-1))+1;
    
  }
  
  cout<<ans;
  
}

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

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

using namespace std;

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

    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> a(Q), b(Q), c(Q), d(Q);
    REP(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i];
        --b[i];
    }

    vector<int> A(N);
    A[0] = 0;

    int result = 0;

    function<void(int)> dfs = [&](int pos) {
        if (pos == N) {
            int score = 0;
            REP(i, Q) {
                if (A[b[i]] - A[a[i]] == c[i]) {
                    score += d[i];
                }
            }
            result = max(result, score);
            return;
        }
        FOR(i, A[pos - 1], M) {
            A[pos] = i;
            dfs(pos + 1);
        }
    };

    dfs(0);

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3584
N = list(map(int,input().split()))
q = int(input())

for _ in range(q):
    problem = [int(x) for x in input().split()]
    
    
    if problem in [[N[0],N[1]],[N[1],N[5]],[N[5],N[4]],[N[4],N[0]]]:
        print(N[2])
    elif problem in [[N[3],N[1]],[N[1],N[2]],[N[2],N[4]],[N[4],N[3]]]:
        print(N[0])
    elif problem in [[N[3],N[5]],[N[5],N[2]],[N[2],N[0]],[N[0],N[3]]]:
        print(N[1])
    elif problem in [[N[4],N[5]],[N[5],N[1]],[N[1],N[0]],[N[0],N[4]]]:
        print(N[3])
    elif problem in [[N[2],N[5]],[N[5],N[3]],[N[3],N[0]],[N[0],N[2]]]:
        print(N[4])
    elif problem in [[N[1],N[3]],[N[3],N[4]],[N[4],N[2]],[N[2],N[1]]]:
        print(N[5])



Measured memory_bytes: 5616
#include <cstdio>
const int mo=1000000007;
int sum[1000005];
int main(){
	int n,ans;
	scanf("%d",&n);
	ans=1ll*n*n%mo;
	sum[1]=n;sum[2]=(ans+n)%mo;
	for (int i=3;i<=n;i++){
		ans=(ans+sum[i-3]+1ll*n*(n-1)-i+3)%mo;
		sum[i]=(sum[i-1]+ans)%mo;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    int N;
    cin >> N;
    int P[N];
    rep(i, N) cin >> P[i];
    int min_array[N]; //そのインデックスまでで最小の値を格納する配列
    min_array[0] = P[0];
    for(int i = 1; i < N; i++){
        min_array[i] = min(min_array[i - 1], P[i]);
    }
    int count = 0;
    rep(i, N){
        if(min_array[i] == P[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
N= int(input())
A=list(map(int,input().split()))
m=0
for k in range(N):
    if A[k]%2==0:
        if A[k]%5==0 or A[k]%3==0:
            m+=1    
            continue
        else:
            print("DENIED")
            break
    else:
        m+=1
        continue
if m==N:
    print("APPROVED")

Measured memory_bytes: 3060
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def distance(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return abs(x1-x2) + abs(y1 - y2)


n, m = read_int_list()
students = [read_int_list() for i in range(n)]
checkpoints = [read_int_list() for j in range(m)]

for student in students:
    dist = 10 ** 20
    res = -1
    for index, checkpoint in enumerate(checkpoints):
        distance1 = distance(student, checkpoint)
        if distance1 < dist:
            dist = distance1
            res = index + 1
    print(res)


Measured memory_bytes: 3064
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

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

    if(s[1]=='B') cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3592
x,k,d=map(int,input().split())

x=abs(x)

if x-k*d >= 0:
  ans=x-k*d
else:
  e=int(x//d)
  x-=e*d
  k-=e
  if k%2==1:
    ans=abs(x-d)
  else:
    ans=x
print(ans)

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

const int N = 1e4 + 5;
const int CH = 1e3;

string l, t;
int l_len, t_len;
int idxs[N][CH];
int dp[N][N];
int solve(int idx1, int idx2) {
//	cout << idx1 << " " << idx2 << endl;
	if (idx1 >= l_len || idx2 >= t_len)
		return 0;
	int &ret = dp[idx1][idx2];
	if (~ret)
		return ret;
	ret = solve(idx1 + 1, idx2);
	if (idxs[idx2][(int) l[idx1]] < t_len)
		ret = max(ret, 1 + solve(idx1 + 1, idxs[idx2][(int) l[idx1]] + 1));
	return ret;
}

void build(int idx1, int idx2) {
	if (idx1 >= l_len || idx2 == t_len)
		return;
	int &ret = dp[idx1][idx2];
	if (solve(idx1 + 1, idx2) == ret) {
		build(idx1 + 1, idx2);
		return;
	} else {
		cout << l[idx1];
		build(idx1 + 1, idxs[idx2][(int) l[idx1]] + 1);
	}
}

int main() {
	memset(idxs, -1, sizeof(idxs));
	memset(dp, -1, sizeof(dp));
	cin >> l;
	cin >> t;
	l_len = l.length();
	t_len = t.length();
	for (int j = 0; j < CH; ++j)
		idxs[t_len][j] = t_len;
	for (int i = t_len - 1; i >= 0; --i) {
		for (int j = 0; j < CH; ++j)
			idxs[i][j] = idxs[i + 1][j];
		idxs[i][(int) t[i]] = i;
	}
	solve(0, 0);
	build(0,0);
	return 0;
}


Measured memory_bytes: 430592
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N){
    cout<<(N+1)/2<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
n, a, b, c = [input() for i in range(4)]
n = int(n)

ret = 0
for i in range(n):
    if (a[i] == b[i]) and (a[i] == c[i]):
        pass

    elif (a[i] == b[i]) and (a[i] != c[i]):
        c = c[:i] + a[i] + c[i + 1:]
        ret += 1

    elif a[i] == c[i] and a[i] != b[i]:
        b = b[:i] + a[i] + b[i + 1:]
        ret += 1

    elif a[i] != c[i] and b[i] == c[i]:
        a = a[:i] + b[i] + a[i + 1:]
        ret += 1

    elif a[i] != b[i] and a[i] != c[i]:
        b = b[:i] + a[i] + b[i + 1:]
        c = c[:i] + a[i] + c[i + 1:]
        ret += 2


print(ret)


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

int main() {
	int n;
	cin >> n;
	if(n == 1){
		cout << "Hello World" << endl;
	} else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] d = new int[n];
		for (int i = 0; i < d.length; i++) {
			d[i] = Integer.parseInt(sc.next());
		}
		int ans = 0;
		for (int i = 0; i < d.length - 1; i++) {
			for (int j = i + 1; j < d.length; j++) {
				ans += d[i] * d[j];
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23508
from math import pi,sin,cos,tan,sqrt
a, b, h, m = map(int, input().split())
s = [cos((h/6 + m/60/6)*pi) * a, sin((h/6 + m/60/6)*pi) * a]
l = [cos((m/30)*pi) * b, sin((m/30)*pi) * b]
val = [s[0]-l[0],s[1]-l[1]]
print(sqrt(val[0]**2 + val[1]**2))


Measured memory_bytes: 9512
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<ll>> a(N, vector<ll>(M + 1));
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < M + 1; ++j)
    {
      cin >> a[i][j];
    }
  }
  ll ans = INF;
  for (int bit = 0; bit < (1 << N); ++bit)
  {
    vector<ll> t;
    t.assign(M, 0);
    ll sum = 0;
    for (int i = 0; i < N; ++i)
    {
      if (bit & (1 << i))
      {
        for (int j = 0; j < M; ++j)
        {
          t[j] += a[i][j + 1];
        }
        sum += a[i][0];
      }
    }
    bool flag = true;
    for (int i = 0; i < M; ++i)
    {
      if (t[i] < X)
      {
        flag = false;
      }
    }
    if (flag)
    {
      ans = min(ans, sum);
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll h, w;
	cin >> h >> w;
	vector<string>s(h);
	ll a[50][50] = {0};
	for (ll i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			for (ll k = -1; k <= 1; k++) {
				if (i == 0&&k==-1||i==h-1&&k==1) {
					continue;
				}
				for (ll l = -1; l <= 1; l++) {
					if (j == 0&&l==-1||j==w-1&&l==1) {
						continue;
					}
					else if (s[i + k][j + l] == '#') {
						a[i][j]++;
					}
				}
			}
		}
	}
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				cout << '#';
			}
			else {
				cout << a[i][j];
			}
		}
		cout << endl;
	}




}


Measured memory_bytes: 256
import collections

S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()

for i, j in enumerate(input()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while True:
                if S2:
                    if S2[-1] > left_edge:
                        S2.pop()
                        new_puddle += S3.pop()
                    else:
                        break
                else:
                    break
            S2.append(left_edge)
            S3.append(new_puddle)
        else:
            pass


print(sum(S3))

print(len(S3), *list(S3))

Measured memory_bytes: 8400
#include<iostream>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li f(li k,li n){
  return (k*(n-k+1)+1)%MOD;
}

int main(){
  li n,k; cin >>n >>k;
  li s=0;
  repa(i,k,n+2){
    (s+=f(i,n))%=MOD;
  }
  print(s);
}


Measured memory_bytes: 3612
#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;

class Graph{
public:
    int N;
    vector<vector<int>> G;
    vector<bool> used;

    Graph(int n){
        N = n;
        G.resize(N);
        used.resize(N, false);
    }

    void make_edge(int s, int t){
        G[s].push_back(t);
        G[t].push_back(s);
    }

    vector<int> find_pass(int _v){
        vector<int> ret;
        int v = _v;

        while(true){
            ret.push_back(v);
            used[v] = true;
            bool found = false;

            for(int i = 0; i < (int)G[v].size(); i++){
                if(!used[G[v][i]]){
                    v = G[v][i];
                    found = true;
                    break;
                }
            }

            if(found) continue;
            else break;
        }

        return ret;
    }
};

int main(){
    int N, M;
    cin >> N >> M;

    Graph g = Graph(N);
    for(int i = 0; i < M; i++){
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        g.make_edge(s, t);
    }

    vector<int> v1 = g.find_pass(0);
    vector<int> v2 = g.find_pass(0);

    int sz1 = v1.size();
    int sz2 = v2.size();

    cout << sz1 + sz2 - 1 << endl;
    for(int i = sz1 - 1; i >= 0; i--){
        cout << v1[i] + 1 << " ";
    }
    for(int i = 1; i < sz2; i++){
        cout << v2[i] + 1 << " ";
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 6776
from heapq import heappush, heappop

def main():
    n, q = map(int, input().split())
    Qt = [list() for _ in range(n)]
    for _ in range(q):
        para = [int(a) for a in input().split()]

        if para[0] == 0:
            heappush(Qt[para[1]], -(para[2]))
        if para[0] == 1:
            if len(Qt[para[1]]) != 0:
                m = heappop(Qt[para[1]])
                print(-m)
                heappush(Qt[para[1]], m)
        if para[0] == 2:
            if len(Qt[para[1]]) != 0:
                heappop(Qt[para[1]])
main()



Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> field[i][j];
        }
    }
    vector<vector<char>> red(h, vector<char>(w, '.'));
    vector<vector<char>> blue(h, vector<char>(w, '.'));
    for(int i = 0; i < h; i++) red[i][0] = '#';
    for(int i = 0; i < h; i++) blue[i][w-1] = '#';
    for(int i = 0; i < h; i++)
    {
        for(int j = 1; j < w-1; j++)
        {
            if(i % 2) red[i][j] = '#';
            else blue[i][j] = '#';
            if(field[i][j] == '#') red[i][j] = blue[i][j] = '#';
        }
    }
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++) cout << red[i][j];
        cout << endl;
    }
    cout << endl;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++) cout << blue[i][j];
        cout << endl;
    }
}


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

using namespace std;

int main(){
  int64_t n;
  cin >> n;
  string ans = "";
  while (n > 0){
  	ans += 'a' + ((n - 1)  % 26) ;
  	n = (n - 1) / 26;
  }
  
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) max_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

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

    int N,M; cin >> N >> M;
    vei a(M), b(M);
    rep(i,M) cin >> a[i] >> b[i];
    bool connect[N][N];
    memset(connect, false, sizeof(connect));
    int v[N-1];
    rep(i,N) v[i] = i+2;//2~Nまでの番号の配列

    rep(i,M) {
        connect[a[i]-1][b[i]-1] = true;
        connect[b[i]-1][a[i]-1] = true;
    }

    int ans = 0;

    do{
        bool check = true;
        rep(i,N-1) {
            if(i == 0 and !connect[i][v[i]-1]) {
                check = false;
                break;
            }
            if(i != 0 and !connect[v[i-1]-1][v[i]-1]) {
                check = false;
                break;
            }
        }
        if(check) ans++;
    }while(next_permutation(v,v+N-1));
    
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long, long long>
#define ff first
#define ss second
const int MAXN = 1e5;

int N, M;
bool vis[MAXN];
vector<int> toposort;
vector<int> adj[MAXN];

void dfs(int v){
    vis[v] = true;
    for(auto x : adj[v]){
        if(!vis[x])
            dfs(x);
    }
    toposort.push_back(v);
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    while(M--){
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
    }
    for(int i = 0; i < N; i++){
        if(!vis[i])
            dfs(i);
    }
    reverse(toposort.begin(), toposort.end());
    vector<int> DP(N, 0);
    for(auto u : toposort){
        for(auto v : adj[u])
            DP[v] = max(DP[v], DP[u] + 1);
    }
    cout << *max_element(DP.begin(), DP.end());
}

Measured memory_bytes: 11748
from fractions import gcd
a, b, c, d = map(int, input().split())
lcm = (c*d) // gcd(c, d)

if a % c == 0:
    c_div = (b//c) - (a//c) + 1
else:
    c_div = (b//c) - (a//c)
if a % d == 0:
    d_div = (b//d) - (a//d) + 1
else:
    d_div = (b//d) - (a//d)
if a % lcm == 0:
    cd_div = (b//lcm) - (a//lcm) + 1
else:
    cd_div = (b//lcm) - (a//lcm)

print(b-a+1 - (c_div + d_div - cd_div))

Measured memory_bytes: 5344
/**
 *    author:  math2do
 *    created: 21.12.2019 00:17:24
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string a, b;
  cin >> n;
  cin >> a >> b;
  string ans;
  int i = 0, j = 0, turn = 0;
  while (i < n || j < n) {
    if (turn == 0) {
      ans.push_back(a[i]);
      i++;
    } else {
      ans.push_back(b[j]);
      j++;
    }
    turn ^= 1; 
  }
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const string YES = "YES";
const string NO = "NO";

void solve(ll N, vector<ll> D, ll M, vector<ll> T) {
  unordered_map<ll, ll> problems;
  REP(i, N)
    problems[D[i]]++;

  REP(i, M)
    if (problems[T[i]] > 0)
      problems[T[i]]--;
    else {
      cout << NO << endl;
      return;
    }
  cout << YES << endl;
  return;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> D(N);
  REP(i, N) {
    cin >> D[i];
  }
  ll M;
  cin >> M;
  vector<ll> T(M);
  REP(i, M) {
    cin >> T[i];
  }

  solve(N, move(D), M, move(T));

  return 0;
}


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

int main()
{
  string s;
  cin >> s;
  set<char> st;
  for (int i = 0; i < s.size(); i++)
  {
    st.insert(s[i]);
  }
  vector<int> ans;
  for (auto itr = st.begin(); itr != st.end(); itr++)
  {
    int tmp = 0, cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
      if (s[i] == *itr)
      {
        tmp = max(tmp, cnt);
        cnt = 0;
      }
      else
        cnt++;
    }
    tmp = max(tmp, cnt);
    ans.push_back(tmp);
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}


Measured memory_bytes: 256
s = input()
a_number = 0
z_number = 0

for i in range(len(s)):
    if s[i] == 'A':
        a_number = i
        break

for j in reversed(range(len(s))):
    if s[j] == 'Z':
        z_number = j
        break

print(z_number - a_number + 1)

Measured memory_bytes: 9340
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m;
	// n == even
	// m == odd
	cin >>n >>m;
	// even + even
	// odd + odd
	// nC2 + mC2
	int ans = 0;
	if(n >= 2) {
		ans += (n * (n - 1)) / 2;
	}
	if(m >= 2) {
		ans += (m * (m - 1)) / 2;
	}
	cout <<ans;
	return 0;
}


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

int main(){
  int N; cin >>N;
  int d[N+1];
  for(int i=1; i<=N; i++){
    cin >> d[i];
  }
  int ans = 0;
  for(int i=1; i<=N-1; i++){
    for(int j=i+1; j<=N; j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

bool isAns(string s){
  int len = s.length();
  FOR(i,1,len){
    if(s[0] != s[i]) return false;
  }
  return true;
}

char diffColor(char a, char b){
  if((a == 'r' && b == 'g') || (a == 'g' && b == 'r')){
    return 'b';
  }else if((a == 'g' && b == 'b') || (a == 'b' && b == 'g')){
    return 'r';
  }else{
    return 'g';
  }
}

int main(){

  while(true){
    string s;
    cin >> s;
    if(s == "0") break;

    map<string, int> mp;
    mp[s] = 1;
    queue<string> que;

    que.push(s);
    bool found = false;
    while(!que.empty()){
      s = que.front();
      que.pop();

      if(isAns(s)){
        found = true;
        cout << mp[s] - 1 << "\n";
        break;
      }

      int len = s.length();
      REP(i,len-1){
        if(s[i] != s[i+1]){
          string v = s;
          char tmp = diffColor(s[i], s[i+1]);
          v[i] = tmp; v[i+1] = tmp;
          if(mp[v] == 0){
            mp[v] = mp[s] + 1;
            que.push(v);
          }
        }
      }
    }
    if(!found){
      cout << "NA\n";
    }
  }
  return 0;
}



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

int main(){
    int n; cin >> n;
    int a,b,c;
    vector<vector<long long>> dp(n,vector<long long>(3));
    for(int i=0; i<n; i++){
        cin >> a >> b >> c;
        dp[i][0] = a;
        dp[i][1] = b;
        dp[i][2] = c;
    }

    for(int i=1; i<n; i++){
        dp[i][0] += max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] += max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] += max(dp[i-1][0],dp[i-1][1]);   
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;

}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    int ret = 0;
    int loop = sqrt(N);
    REP(i, 1, loop) {
        int right = N - i;
        if (right % i == 0) {
            int num = right / i;
            if (N / num == N % num) {
                ret += num;

                cerr << "i:" << i << " num=" << num << " right:" << right << endl;
            }
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 888
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"
#include <time.h>


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
#define lo long long int
#define  NN cout << "No"<<endl;
#define  YY cout << "Yes"<<endl;

int h,w,a[500][500],n=0,x[250000],y[250000],d[250000];




int main() {
	cin >> h>> w;
	fori0(h)forj0(w) {
		cin >> a[i][j];
	}

	fori0(h) {
		forj0(w-1) {
			if (a[i][j] % 2 == 1) {
				a[i][j + 1]++;
				x[n] = i;
				y[n] = j;
				d[n] = 1;
				n++;
			}
		}
	}
	fori0(h-1) {
		if (a[i][w-1] % 2 == 1) {
			a[i+1][w-1]++;
			x[n] = i;
			y[n] = w-1;
			d[n] = 2;
			n++;
		}
	}
	cout << n << endl;
	fori0(n) {
		printf("%d %d %d %d\n", x[i]+1, y[i]+1,x[i]+1+dx[d[i]],y[i]+1+dy[d[i]] );
		
	}
	system("pause");
	return 0;

}


Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N * 3); rep(i, 0, N * 3) { cin >> a[i]; }
	int ans = 0;
	sort(all(a));
	for (int i = N; i < N * 3; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (a + b >= k) {
    ans = min(a, k);
  } else {
    ans = a - (k - (a + b));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
n = str(input())
n = list(n)

ans = 0
for i in range(3):
    if n[i] == '1':
        ans += 9 * (10 ** (2 - i))
    elif n[i] == '9':
        ans += 1 * (10 ** (2 - i))
    else:
        ans += int(n[i]) * (10 ** (2 - i))

print(ans)


Measured memory_bytes: 3060
N, M = map(int, input().split())
H = list(map(int, input().split()))
peaks = [1] * N
for i in range(M):
    A, B = map(int, input().split())
    if H[A - 1] > H[B - 1]:
        peaks[B - 1] = 0
    elif H[B - 1] > H[A - 1]:
        peaks[A - 1] = 0
    else:
        peaks[A - 1] = 0
        peaks[B - 1] = 0

print(sum(peaks))


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

using namespace std;


int main() {
    string divide[4] = {"dream", "dreamer", "erase", "eraser"};

    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for(int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;

    for(int i = 0; i < S.size();){
        bool can2 = false;

        for(int j = 0; j < 4; ++j){

            if(S.substr(i, divide[j].size()) == divide[j]){
                can2 = true;
                i += divide[j].size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

const int MAX=200001; //nCrのnのMAX+1
ll fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
ll COM(int n,int k){
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
//main関数にCOMinit();
int main(){
  COMinit();
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  sort(all(A));
  ll minsum=0;
  ll maxsum=0;
  for(int i=0;i<=N-K;i++){
    minsum+=A[i]*COM(N-1-i,K-1)%MOD;
  }
  reverse(all(A));
  for(int i=0;i<=N-K;i++){
    maxsum+=A[i]*COM(N-1-i,K-1)%MOD;
  }
  cout << (maxsum-minsum)%MOD << endl;
  
}

Measured memory_bytes: 5376
#include <stdio.h>
#define LEN 100005

typedef struct pp {
	char name [100];
	int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head +1) % LEN;
	return x;
}

int min (int a, int b){
	return a < b ? a : b;
}

int main (){
	int elaps = 0,c;
	int i,q;
	P u;
	
	scanf ("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head = 1; tail = n + 1;
	
	while (head != tail){
		u=dequeue();
		c=min(q,u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0) enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
		
	return 0;
}



Measured memory_bytes: 11880
a[5][1<<18],b[2],x,y,j,n;main(i){scanf("%d",&n);for(;++i<5;)for(j=0;j<n;++j){scanf("%d",&a[i][j]);--a[i][j];}for(j=0;j<n;++j){if(a[2][j]/3-a[3][j]/3||a[3][j]/3-a[4][j]/3||a[4][j]/3-a[2][j]/3||a[3][j]%3-1||a[3][j]/3-j&1){b[0]=1;break;}x=y=a[3][j]/3+1;while(x){b[j&1]-=a[j&1][x]%2;x-=x&-x;}b[j&1]+=j/2;while(y<2e5){++a[j&1][y];y+=y&-y;}if(a[2][j]%3)++b[1-j%2];}puts(b[0]&1|b[1]&1?"No":"Yes");}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    ll x , k , d;
    cin >> x >> k >> d;
    x = abs(x - 0);
    if(x / d >= k){
        cout << x - k * d << endl;
    }
    else{
        ll A = x - x / d * d;
        k = k - x / d;
        ll n = k % 2;
        if(n == 0){
            cout << abs(A - 0) << endl;
        }
        if(n == 1){
            cout << abs((A - d) - 0) << endl;
        }
    }
}

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

int main() {
  int N, K;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int kyori = 0, mark = 0;
  for (int i = 0; i < N; i++) {
    if (i==0) {
      kyori = max(A.at(i)-A.at(N-1)+K, kyori);
    }
    else {
      kyori = max(A.at(i)-A.at(i-1), kyori);
    }
  }
  
  cout << K - kyori << endl;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
string s;
int flag[3];
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); ++i) {
		if (s[i] == 'C') flag[1] = 1;
		if (s[i] == 'F' && flag[1] == 1)  flag[2] = 1;
	}
	if (flag[2] == 0) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    char s[2*10*10*10*10*10+1];
    char t[2*10*10*10*10*10+1];
    scanf("%s",s);
    scanf("%s",t);
    
    int t_len=strlen(t);
    int count=0;

    for(int i=0; i<t_len; i++){
        if(s[i]!=t[i]){
            s[i]=t[i];
            count++;
        }
    }

printf("%d",count);
return 0;
}

Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
  int a[3],K;
  cin >> a[0] >> a[1] >> a[2];
  cin >> K;
  sort(a,a+3);
  cout << a[0]+a[1]+(a[2]*pow(2,K)) << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main(){
    int n;
    cin >> n;
    int arr[n];
    long long int sum =0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        sum+=arr[i]%mod;
        sum%=mod;
    }
    long long count=0;
    long long ans=0;
    for(int i=0;i<n;i++){
        count+=arr[i];
        count %= mod;
        long long tsum = sum-count;
        if(tsum<0) tsum+=mod;
        ans += (long long)arr[i] * tsum;
        ans%=mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B,C,D;cin >> A >> B >> C >> D;
  if(B>D){
    swap(B,D);
    swap(A,C);
  }
  cout << max(0,B-C - max(0,A-C)) << endl;
  return 0;
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String sa = br.readLine() + " ";
		String sb = br.readLine() + " ";
		String sc = br.readLine() + " ";
		int sai = 0;
		int sbi = 0;
		int sci = 0;
		char prec = 'a';

		label: while (true) {
			switch (prec) {
			case 'a':
				if (sa.charAt(sai) == ' ')
					break label;
				prec = sa.charAt(sai++);
				break;
			case 'b':
				if (sb.charAt(sbi) == ' ')
					break label;
				prec = sb.charAt(sbi++);
				break;
			case 'c':
				if (sc.charAt(sci) == ' ')
					break label;
				prec = sc.charAt(sci++);
				break;
			default:
			}
		}

		System.out.println((char) (prec - 32));

	}

}


Measured memory_bytes: 23252
#include <iostream>

using namespace std;

bool less_than(const string a, const string b) {
    return a[1] < b[1];
}

void bubble_sort(string* a, int length) {
    for (int i = 0; i < length; ++i) {
        for (int j = length - 1; j > i; --j) {
            if (less_than(a[j], a[j - 1])) {
                swap(a[j], a[j - 1]);
            }   
        }   
    }   
}

void select_sort(string* a, int length) {
    for (int i = 0; i < length; ++i) {
        int min = i;
        for (int j = i; j < length; ++j) {
            if (less_than(a[j], a[min])) {
                min = j;
            }   
        }   
        swap(a[i], a[min]);
    }   
}

void print(string* a, int length) {
    bool is_first = true;
    for (int i = 0; i < length; ++i) {
        if (is_first) {
            is_first = false;
        } else {
            cout << " ";
        }   
        cout << a[i];
    }   
    cout << endl;
}

bool stable(string* a, string* b, int length) {
    for (int i = 0; i < length; ++i) {
        if (a[i].compare(b[i]) != 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int length;
    cin >> length;
    std::string* data = new std::string[length];
    std::string* data_copy = new std::string[length];
    for (int i = 0; i < length; ++i) {
        cin >> data[i];
        data_copy[i] = data[i];
    }
    bubble_sort(data, length);
    select_sort(data_copy, length);

    print(data, length);
    cout << "Stable" << endl;

    print(data_copy, length);
    cout << (stable(data, data_copy, length)? "Stable" : "Not stable") << endl;

    return 0;
}                                                                                                                                             

Measured memory_bytes: 3152
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;
ll ggcd(ll a,ll b){
	if(b==0)return a;
	if(a<b){
		ll temp=a;
		a=b;
		b=temp;
	}
	ll x=a%b;
	return ggcd(b,x);
}

int main(void){
	int N;
	ll C,K;
	cin>> N>> C>> K;
	vector<ll> t(N);
	rep(i,N)cin>>t[i];
	sort(t.begin(),t.end());
	int ans=1;
	int i=0;
	ll now=t[0]+K;
	int cnt=0;
	while(i<N){
		if(cnt==C||t[i]>now){
			ans++;
			cnt=0;
			now=t[i]+K;
			//cout<<t[i]<<endl;
		}else{
			i++;
			cnt++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int X[3]; cin >> X[0] >> X[1] >> X[2];
    int x = 0, y = 0;
    rep(i, 3){
        if(X[i] == 5) x++;
        else if(X[i] == 7) y++;
    }
    if(x == 2 and y == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(b%a==0) cout<<(a+b)<<"\n";
	else cout<<(b-a)<<"\n";
	return 0;
}

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

int main(void){

    int N; cin>>N;
    vector<int> ans;
    int x[N+1],y[N+1],h[N+1], t;

    for (int i = 0; i < N; ++i) {
        cin>>x[i]>>y[i]>>h[i];
        if(h[i]>0) t=i;
    }

    int X,Y,H;int k;
    for (int X = 0; X <= 100; ++X) {
        for (int Y = 0; Y <= 100; ++Y) {
            H = h[t]+abs(x[t]-X)+abs(y[t] - Y);
            for(k=0;k<N;k++) {
                if (h[k] != max(H - abs(x[k] - X) - abs(y[k] - Y), 0))
                    break;
            }
            if(k==N){
                cout << X << " " << Y << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	char ch;
	cin >> ch;
	ch++;
	cout << ch;
	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split(" ");

  var input0 = input[0];
  var input1 = input[1];
  var input2 = input[2];
  var result = 0;

  if(input0 * input1 <= input2){
    result = input0 * input1;
  }
  else {
    result = input2;
  }
  
 	console.log(result);
 }
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372