akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict

input = sys.stdin.readline
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


uf = UnionFind(N)
for a, b in AB:
    uf.union(a - 1, b - 1)
d = defaultdict(lambda :0)
for i in range(N):
    g = uf.find(i)
    d[g] += 1

ans = max(d.values())
print(ans)


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

int main() {
  int N, l, r, a;
  cin >> N;
  a = 0;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    a += r-l + 1;
  }
  cout << a << endl;
}


Measured memory_bytes: 256
mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
def per(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[n - r] % mod
n, m = map(int, input().split())
fa = [1] * (m + 1)
fi = [1] * (m + 1)
for i in range(1, m + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(n + 1):
    if i % 2 == 0:
        ans += comb(n, i) * per(m, i) % mod * (per(m - i, n - i) ** 2) % mod
        ans %= mod
    else:
        ans += comb(n, i) * -1 * per(m, i) % mod * (per(m - i, n - i) ** 2) % mod
        ans % mod
print(ans % mod)

Measured memory_bytes: 103196
from collections import defaultdict
N = int(input())
MOD = 10 ** 9 + 7

def prime_factor(n):
    d = defaultdict(int)
    for i in range(2, n + 1):
        if i * i > n:
            break
            
        while n % i == 0:
            d[i] += 1
            n //= i
            
    if n != 1:
        d[n] = 1
            
    return d

d = defaultdict(int)
for i in range(1, N + 1):
    for j, v in prime_factor(i).items():
        d[j] += v

ans = 1
for v in d.values():
    ans = ans * (v + 1) % MOD
print(ans)




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

int main() {
  int num_query; cin >> num_query;
  multimap<string, int> dic;
  
  while (num_query--) {
    int command; scanf("%d", &command);
    char key[20]; scanf("%s", key);
    
    switch (command) {
      case 0:
        int value; scanf("%d", &value);
        dic.insert(make_pair(key, value));
        break;
        
      case 1:
        {
          pair<multimap<string, int>::iterator, multimap<string, int>::iterator> 
            range = dic.equal_range(key);
          while (range.first != range.second) {
            printf("%d\n", range.first -> second);
            range.first++;
          }
          break;
        }
        
      case 2:
        dic.erase(key);
        break;
        
      case 3:
        char key2[20]; scanf("%s", key2);
        multimap<string, int>::iterator it = dic.lower_bound(key);
        multimap<string, int>::iterator last = dic.upper_bound(key2);
        while (it != last) {
          printf("%s %d\n", ((*it).first).c_str(), (*it).second);
          it++;
        }
        break;
    }
  }
}


Measured memory_bytes: 24884
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
#define inf 20021225
#define N 1010
#define M 200010 
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
vector<int> ed[N];
void add(int x,int y,int &id){id=ed[x].size(); ed[x].push_back(y);} 
int con[N][N],s,noc[N][N],n,m; bool vis[N][N]; bool ok[M];
void dfs(int *a,int x,int v)
{
	if(~a[x]||x==s)	return; a[x]=v; vis[s][x]=1;
	for(int i=0;i<ed[x].size();i++)	dfs(a,ed[x][i],v);
}
void solve()
{
	memset(con,-1,sizeof(con)); memset(noc,-1,sizeof(noc));
	for(int x=1;x<=n;x++)
		for(int i=0;i<ed[x].size();i++)
			s=x,dfs(con[x],ed[x][i],i);
	for(int x=1;x<=n;x++)
		for(int i=(int)ed[x].size()-1;~i;i--)
			s=x,dfs(noc[x],ed[x][i],i);
}
int u[M],v[M],id[M];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=m;i++)
		u[i]=read(),v[i]=read(),add(u[i],v[i],id[i]);
	solve();
	for(int i=1;i<=m;i++)
	{
		if((vis[v[i]][u[i]])^((con[u[i]][v[i]]<id[i]&&~con[u[i]][v[i]])||noc[u[i]][v[i]]>id[i]))
			printf("diff\n");
		else
			printf("same\n");
	}
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#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++)

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int M = min(A * N, B);
  cout << M;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()
#define ld long double
void solve();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}
void solve()
{
	string s, t; cin >> s >> t;
	ll n = s.size();
	ll m = t.size();
	ll res = INT_MAX;
	for (int i = 0; i + m - 1 < n; i++)
	{
		string tp = s.substr(i , m);
		ll ans = 0;
		for (int j = 0; j < m; j++)
		{
			if (tp[j] != t[j]) ans++;
		}
		res = min(res , ans);
	}
	cout << res;

	cout << "\n";
	return ;
}

Measured memory_bytes: 3644
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int N, A[200'010], ans;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		ans ^= A[i];
	}
	for (int i = 0; i < N; ++i)
		cout << (ans ^ A[i]) << " ";
}

Measured memory_bytes: 4388
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }


int dp[4001][4001];
int main(void){
    char s[4001],t[4001];
//  printf("%d\n",4000*4000);
    while(scanf("%s",s)!=EOF){
        scanf("%s",t);
//      dp[0][0]=s[0]==t[0];
        for(int i=0;i<4001;i++)dp[i][0]=dp[0][i]=0;
        int sl = strlen(s),tl = strlen(t);
        int ans = 0;
        for(int i=1;i<=sl;i++){
            for(int j=1;j<=tl;j++){
                if(s[i-1]==t[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                    ans = max(ans,dp[i][j]);
                }else dp[i][j]=0;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 63676
from bisect import bisect_left

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-2):
  a=L[i]
  for j in range(i+1,N-1):
    b=L[j]
    """
    lo=0
    hi=N
    x=a+b
    while lo<hi:
      mid=(lo+hi)//2
      if L[mid]<x: lo=mid+1
      else: hi=mid
    ans+=lo-(j+1) 
    """
    ans+=bisect_left(L,a+b)-(j+1)
print(ans)


Measured memory_bytes: 9236
n,m = map(int,input().split())
P = list(map(int,input().split()))
XY = [list(map(int,input().split())) for _ in range(m)]

UF = list(range(n+1))

def search(uf,i):
    if uf[i] == i:
        return i
    else:
        uf[i] = uf[search(uf,uf[i])]
        return uf[i]

for x,y in XY:
    i = search(UF,x)
    j = search(UF,y)
    UF[x] = min(x,y,i,j)
    UF[y] = UF[x]
    UF[i] = UF[x]
    UF[j] = UF[x]
for i in range(1,n+1):
    UF[i] = search(UF,i)
ans = 0
for p,j in zip(P,range(1,n+1)):
    if p == j:
        ans += 1
    elif UF[p] == UF[j]:
        ans += 1
print(ans)

Measured memory_bytes: 35268
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
void solve()
{
    ll n;cin>>n;
    ll rem=n%10;
    if(rem==2 or rem==4 or rem==5 or rem==7 or rem==9)
        cout<<"hon\n";
    else if(rem==0 or rem==1 or rem==6 or rem==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";
    return;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
        solve();
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
a = [int(i) for i in input().split()]

#a_b = []
dic = {}
m = 0
for i in range(len(a)):
    if a[i] in dic.keys():
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

ls = list(dic.keys())

if len(ls) <= 2 and 0 in ls:
    ls.sort()
    #2種類の時...0と何か
    if len(ls) == 2:
        #0の数が他の数の半分
        if 2 * dic[ls[0]] == dic[ls[1]]:
            print("Yes")
        else:
            print("No")
    #1種類の時...0だけ
    else:
        print("Yes")
#3種類の時...全ての個数が揃っていて2つが1つの排他的論理和になっている
elif len(ls) == 3:
    ls.sort()
    if  dic[ls[0]] == dic[ls[1]] and dic[ls[0]] == dic[ls[2]]:
        if list(ls)[0] ^ list(ls)[1] == list(ls)[2]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
#4種類以上の時...ダメ
else:
    print("No")

"""
for i in a:
    if i == max(a):
        m = i
    #print(bin(i))
for i in a:
    a_b.append(bin(i)[:2]+'0'*(len(bin(m))-len(bin(i)))+bin(i)[2:])

#for i in range(len(a_b)):
#    print(a_b[i])


a = int("0b" + "0" * (len(bin(m))-2),2)

for i in range(len(a_b)):
    a = a ^ int(a_b[i],2)
if a == 0:
    print("Yes")
else:
    print("No")
"""


Measured memory_bytes: 14116
H, W = map(int, input().split())
N = int(input())
A = [int(i) for i in input().split()]

align = [(i+1) for i, a in enumerate(A) for _ in range(a)]
# print("align: {}".format(align))
count = 0
ans = []
for i in range(H):
    tmp = align[W*i:W*(i+1)]
    if i % 2 != 0:
        tmp = tmp[::-1]
    print(*tmp)


Measured memory_bytes: 3884
import java.util.Scanner;

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

		int sum = 0;
		for (int i = 0; i < N.length(); i++) {
			sum += Integer.valueOf(N.substring(i, i+1));
		}

		System.out.println(Integer.valueOf(N) % sum == 0? "Yes" : "No");
	}
}


Measured memory_bytes: 21844
k, a, b = map(int, input().split())

if b-a <= 2 or k-(a-1) < 2:
    print(k+1)

else:
    cycle = (k-(a-1))//2
    if (k-(a-1))%2 == 0:
        print(a + cycle *(b-a))
    else:
        print(a + cycle *(b-a) +1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

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


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

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

const int MN = 200010;

int N;
pii P[MN];
ll ans;

int Xn;
vector<int> X;
map<int, int> dx;

struct Fenwick {
    vector<int> tree;
    void init() {
        tree = vector<int>(Xn + 1, 0);
    }
    void upd(int idx, int val) {
        for(int i = idx + 1; i <= Xn; i += (i & -i)) tree[i] += val;
    }
    int quer(int a) {
        int ret = 0;
        for(int i = a + 1; i >= 1; i -= (i & -i)) ret += tree[i];
        return ret;
    }
    int quer(int a, int b) {
        return quer(b) - quer(a - 1);
    }
    int kquer(int k) {
        int ret = 0;
        for(int i = 20; i >= 0; i--) {
            if(ret + (1 << i) > Xn) continue;
            if(tree[ ret + (1 << i) ] < k) {
                k -= tree[ ret + (1 << i) ];
                ret += (1 << i);
            }
        }
        return ret;
    }
} fw;

vector<pii> E[MN << 1];

int main() {
    scanf("%d", &N);

    int mn1 = 1e9;
    int mn2 = 1e9;
    int mx1 = -1e9;
    int mx2 = -1e9;
    for(int i = 0; i < N; i++) {
        scanf("%d %d", &P[i].first, &P[i].second);
        if(P[i].first > P[i].second) swap(P[i].first, P[i].second);
        mn1 = min(mn1, P[i].first);
        mx1 = max(mx1, P[i].first);
        mn2 = min(mn2, P[i].second);
        mx2 = max(mx2, P[i].second);

        X.push_back(P[i].first);
        X.push_back(P[i].second);
    }

    ans = 1LL * (mx1 - mn1) * (mx2 - mn2);

    sort(X.begin(), X.end());
    X.resize(unique(X.begin(), X.end()) - X.begin());
    Xn = X.size();
    for(int i = 0; i < Xn; i++) dx[X[i]] = i;
    for(int i = 0; i < N; i++) {
        P[i].first = dx[ P[i].first ];
        P[i].second = dx[ P[i].second ];

        E[ P[i].first ].push_back({ P[i].first, 1 });
        E[ P[i].first ].push_back({ P[i].second, -1 });
        E[ P[i].second ].push_back({ P[i].second, 1 });
    }

    fw.init();
    for(int i = Xn - 1; i >= 0; i--) {
        for(int j = 0; j < E[i].size(); j++) {
            fw.upd(E[i][j].first, E[i][j].second);
        }
        int x = fw.kquer(N);
        if(x == Xn) continue;

        //cout << i << ' ' << X[i] << ' ' << X[x] << endl;

        ans = min(ans, 1LL * (mx2 - mn1) * (X[x] - X[i]));
    }
    printf("%lld", ans);
}


Measured memory_bytes: 45552
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	ls := make([]int,n)
	for i := 0; i < n; i ++ {
		var l int
		fmt.Scan(&l)
		ls[i] = l
	}

	sort.Sort(sort.Reverse(sort.IntSlice(ls)))

	sum := -ls[0]
	for _,v := range ls {
		sum += v
	}

	if ls[0] < sum {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))

max = 0
cnt = 0

for i in range(len(h)):
  if i == len(h) - 1 or h[i] < h[i + 1]:
    if cnt > max:
      max = cnt
    cnt = 0
  else:
    cnt += 1

print(max)

Measured memory_bytes: 15020
import java.io.*;
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.nextLine();
    String str = sc.nextLine();
    String[] chars = str.split("");
    ArrayList<String> lefts = new ArrayList<String>();
    int leftCount = 0;
    int rightCount = 0;
    for(int i = 0; i < n; i++) {
      String curr = chars[i];
      if(curr.equals("(")){
        lefts.add("(");
      }
      else {
        if(lefts.size() > 0) {
          lefts.remove(lefts.size()-1);
        } else {
          rightCount++;
        }
      }
      leftCount = lefts.size();
    }
    String ans = "";
    for(int i = 0; i < rightCount; i++) {
      ans += "(";
    }
    ans += str;
    for(int i = 0; i < leftCount; i++) {
      ans += ")";
    }
    System.out.println(ans);
  }
}


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

using namespace std;

int main() {
    int n;

    scanf("%d", &n);

    vector<int> a(n - 1);
    vector<int> b(n);

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

    for(int i : a) {
        b.at(i - 1)++;
    }

    for(int i = 0; i < n; i++) {
        printf("%d\n", b.at(i));
    }

    return 0;
}

Measured memory_bytes: 4840
import math
d,g=map(int,input().split())
p=[list(map(int,input().split())) for _ in range(d)]
ans=sum([i[0] for i in p])
for i in range(2**d-1):
    bit=bin(i)[2:].zfill(d)
    c,s,a=0,0,0
    for j in range(d):
        if bit[j]=='1':
            c+=p[j][0]
            s+=p[j][1]+100*(j+1)*p[j][0]
        else:
            a=max(a,j)
    short=g-s
    pc=max(math.ceil(short/((a+1)*100)),0)
    if pc<p[a][0]:
        ans=min(c+pc,ans)
print(ans)

Measured memory_bytes: 9208
#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 VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#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;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<int> x(m);
  REP(i,m) cin>>x[i];
  VSORT(x);
  vector<int> y(m-1);
  REP(i,m-1){
    y[i] = x[i+1] - x[i];
  }
  VSORT(y);
  ll ans=0;
  REP(i,m-n){
    ans+=y[i];
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge(int to, int cost):to(to), cost(cost){}
};
using Graph = vector<vector<edge>>;

vint dijkstra(int s, const Graph& g) {
  int n = g.size();
  vint res(n, inf);
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  res[s] = 0;
  que.emplace(0, s);
  while(!que.empty()) {
    Pi p = que.top(); que.pop();
    int v = p.second;
    if(res[v] < p.first) continue;
    for(auto&& e : g[v]) {
      if(res[v]+e.cost < res[e.to]) {
	res[e.to] = res[v]+e.cost;
	que.emplace(res[e.to], e.to);
      }
    }
  }

  return res;
}

#define MAX_N 100010

int ord[MAX_N], low[MAX_N];
void dfs(int u, int p, int k, const Graph& g) {
  ord[u] = low[u] = k++;
  for(auto&& e : g[u]) {
    if(e.to == p) continue;
    if(ord[e.to] == -1) {
      dfs(e.to, u, k, g);
      chmin(low[u], low[e.to]);
    } else {
      chmin(low[u], ord[e.to]);
    }
  }
}
bool is_bridge(int u, int v) {
  if(ord[u] > ord[v]) swap(u, v);
  return ord[u] < low[v];
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  Graph g(n);
  Graph rg(n);
  vint a(m), b(m), c(m);
  rep(i, m) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i], --b[i];
    g[a[i]].emplace_back(b[i], c[i]);
    rg[b[i]].emplace_back(a[i], c[i]);
  }
  vint d0 = dijkstra(0, g);
  vint d1 = dijkstra(1, rg);
  Graph h(n);
  vint used(m, 0);
  rep(i, m) {
    //cout<<d0[a[i]]<<" "<<d1[b[i]]<<" "<<c[i]<<endl;
    if(d0[a[i]]+d1[b[i]]+c[i] == d0[1]) {
      h[a[i]].emplace_back(b[i], 0);
      h[b[i]].emplace_back(a[i], 0);
      used[i] = 1;
    }
  }
  memset(ord, -1, sizeof(ord));
  dfs(0, -1, 0, h);
  rep(i, m) {
    int d = d0[b[i]]+d1[a[i]]+c[i];
    //cout<<d<<" "<<d0[1]<<endl;
    if(d == d0[1]) {
      cout << "SOSO" << endl;
    } else if(d < d0[1]) {
      cout << "HAPPY" << endl;
    } else if(!used[i]) {
      cout << "SOSO" << endl;
    } else if(is_bridge(a[i], b[i])) {
      cout << "SAD" << endl;
    } else {
      cout << "SOSO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 33832
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int D,X;
	cin >> D >> X;
	vector<int> A(N);
	int ans = X;
	for(int i=0;i<N;i++){
		cin >> A[i];
		ans += 1 + (D-1)/A[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char check(string s, int &pos){
    return s[pos++];
}
int main(){
    int posa = 0, posb = 0, posc = 0;
    string a, b, c;
    cin>>a>>b>>c;
    char temp = a[0];
    while(temp){
        if(temp=='a'){
            temp = check(a, posa);
        }
        else if(temp == 'b'){
            temp = check(b, posb);
        }
        else{
            temp = check(c, posc);
        }
    }
    if(posa>a.size())cout<<"A"<<endl;
    else if(posb>b.size())cout<<"B"<<endl;
    else cout<<"C"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int H[300],W[300],i=0,j,k;

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

    i=0;
    while(H[i]!=0&&W[i]!=0||H[i]!=0&&W[i]==0||H[i]==0&&W[i]!=0){
        for(j=0;j<H[i];j++){
            for(k=0;k<W[i];k++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        i++;
    }

    return 0;
}

Measured memory_bytes: 572
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e5 + 10;
string s;
int n;

void solve() {
	cin >> n;
	cin >> s;
	vector <int> sufR(n), sufG(n), sufB(n);

	for (int i = n - 1; i >= 0; --i) {
		sufR[i] += (s[i] == 'R') + (i == n - 1 ? 0 : sufR[i + 1]);
		sufG[i] += (s[i] == 'G') + (i == n - 1 ? 0 : sufG[i + 1]);
		sufB[i] += (s[i] == 'B') + (i == n -1 ? 0 : sufB[i + 1]);
		// cout << sufR[i] << " " << sufG[i] << " " << sufB[i] << "\n";
	}

	ll ans = 0LL;
	for (int i = 0; i < n - 2; ++i) {
		char c = s[i];
		for (int j = i + 1; j < n - 1; ++j) {
			if (s[j] != c) {
				if ('R' != c && 'R' != s[j]) {
					ans += sufR[j + 1];
					if (2*j - i < n && s[j + j - i] == 'R')	--ans;
				}
				else if ('G' != c && 'G' != s[j]) {
					ans += sufG[j + 1];
					if (2*j - i < n && s[j + j - i] == 'G')	--ans;
				}
				else if ('B' != c && 'B' != s[j]) {
					ans += sufB[j + 1];
					if (2*j - i < n && s[j + j - i] == 'B')	--ans;
				}
			}
		}
	}


	cout << ans;
}
int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> B(N, 1);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  int a, b;
  while (cin >> a >> b) {
    a--, b--;
    if (H.at(a) < H.at(b)) B.at(a) = 0;
    else if (H.at(a) > H.at(b)) B.at(b) = 0;
    else B.at(a) = B.at(b) = 0;
  }
  int cnt = 0;
  for (auto b : B) cnt += b;
  cout << cnt << "\n";
}

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

#define inf 2000000000  // 1e17
template <class T>
struct Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
  };
  vector<vector<edge>> edges;
  vector<int> id;
  vector<int> d;
  Dinic(int n = 1) {
    edges.clear();
    edges.resize(n);
    id.resize(n);
    d.resize(n);
  }
  bool add(int start, int goal, T capacity) {
    edges[start].push_back((edge){goal, capacity, (int)edges[goal].size()});
    edges[goal].push_back((edge){start, 0, (int)edges[start].size() - 1});
    return 1;
  }
  void bfs(int st) {
    d.assign(d.size(), -1);
    queue<int> qu;
    d[st] = 0;
    qu.push(st);
    while (qu.size()) {
      int now = qu.front();
      qu.pop();
      for (auto e : edges[now])
        if (e.cap > 0 && d[e.to] < 0) {
          d[e.to] = d[now] + 1;
          qu.push(e.to);
        }
    }
  }
  T pathdfs(int now, int goal, T nf) {
    if (now == goal) return nf;
    for (int& i = id[now]; i < (int)edges[now].size(); ++i) {
      edge* e = &edges[now][i];
      if (e->cap > 0 && d[now] < d[e->to]) {
        T res = pathdfs(e->to, goal, min(nf, e->cap));
        if (res > 0) {
          e->cap -= res;
          edges[e->to][e->rev].cap += res;
          return res;
        }
      }
    }
    return 0;
  }
  T solve(int start, int goal) {
    T res = 0, nf = 0;
    while (1) {
      bfs(start);
      if (d[goal] < 0) return res;
      id.assign(id.size(), 0);
      while ((nf = pathdfs(start, goal, inf)) > 0) res += nf;
    }
    return -1;
  }
};

int n, m;
int d[] = {0, 1, 0, -1};
string c1 = ">v<^", c2 = "<^>v";
vector<string> s;
Dinic<int> din;

bool isvalid(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && s[x][y] == '.';
}

int main() {
  cin >> n >> m;
  s.resize(n);
  for (auto& p : s) cin >> p;
  // if (n == m && n == 1) {
  //   cout << 0 << endl;
  //   cout << s[0] << endl;
  //   return 0;
  // }
  din = Dinic<int>(n * m + 2);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] == '.') {
        if ((i ^ j) & 1)
          din.add(i * m + j, n * m + 1, 1);
        else {
          din.add(n * m, i * m + j, 1);
          for (int k = 0; k < 4; ++k) {
            int nx = i + d[k], ny = j + d[k ^ 1];
            if (isvalid(nx, ny)) din.add(i * m + j, nx * m + ny, 1);
          }
        }
      }
  cout << din.solve(n * m, n * m + 1) << endl;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (!((i ^ j) & 1)) {
        for (auto e : din.edges[i * m + j])
          if (e.cap == 0) {
            int nx = e.to / m, ny = e.to % m;
            for (int k = 0; k < 4; ++k)
              if (i + d[k] == nx && j + d[1 ^ k] == ny && isvalid(nx, ny)) {
                s[i][j] = c1[k];
                s[nx][ny] = c2[k];
              }
          }
      }
  for (auto p : s) cout << p << endl;
  return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL A, B, C;
  cin >> A >> B >> C;
  for(int i=1;i<1000;++i){
	if(A*i%B == C){
	  cout << "YES" << endl;
	  return 0;
	}
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size());
#define pb push_back;
#define all(x) (x).begin(),(x).end()
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vll A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    vll asum(N);
    ll a = 0;
    for(int i=0; i<N; i++){
        a += A[i];
        asum[i] = a;
    }
    ll c = 1;
    for(int i=N-1; i>0; i--){
        if(A[i] <= 2*asum[i-1]){
            c++;
        }else{
            break;
        }
    }
    cout << c;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

struct Edge {
    ll to, cost;
};


class Dijkstra {
    ll vector_count;

    vector<ll> distances;
    vector<vector<Edge>> edges;

public:
    Dijkstra(ll n) {
        vector_count = n;
        distances.resize(n, INF);
        edges.resize(n);
    }

    void insertTowWay(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
        edges[to].push_back({from, cost});
    }

    void insert(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
    }

    void dijkstra(ll k) {
        distances[k] = 0;  // 始点sへの最短距離は0

        priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
        que.push(P(0, k));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
            if (distances[v] < p.first) {
                continue;
            }
            for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
                if (distances[e.to] > distances[v] + e.cost) {
                    distances[e.to] = distances[v] + e.cost;
                    que.push(P(distances[e.to], e.to));
                }
            }
        }
    }

    ll distance(ll to) {
        return distances[to];
    }

};

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

    Dijkstra dijkstra(n);

    rep(i, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dijkstra.insertTowWay(a, b, c);
    }

    int q, k;
    cin >> q >> k;
    k--;
    dijkstra.dijkstra(k);

    rep(i, q) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dijkstra.distance(x) + dijkstra.distance(y) << endl;
    }

}

Measured memory_bytes: 11120
import std.stdio, std.algorithm, std.conv, std.array, std.string;

bool check(const char[] arr) {
    auto p = arr[0];
    foreach (e; arr[1..$]) {
        if (p != e) return false;
    }
    return true;
}

void main()
{
    auto s = readln.chomp;

    if (check(s)) {
        writeln(0);
        return;
    }

    auto cs = s.uniq();

    auto min = int.max;
    foreach (c; cs) {
        int cnt;
        auto ss = s.dup;
        while (!check(ss)) {
            ++cnt;
            foreach (i, sc; ss) {
                if (i == ss.length - 1) {
                    ss.length -= 1;
                } else {
                    ss[i] = sc == c ? sc : ss[i+1];
                }
            }
        }
        if (cnt < min) min = cnt;
    }
    writeln(min);
}

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

eki = []
for i in range(N - 1):
    eki.append([int(_) for _ in input().split()])

for i in range(N - 1):
    s = eki[i][0] + eki[i][1]
    for j in range(i + 1, N - 1):
        tmp = s - eki[j][1]
        if tmp < 0:
            s = eki[j][1]
        elif tmp % eki[j][2] != 0:
            s += eki[j][2] - (tmp % eki[j][2])
        s += eki[j][0]

    print(s)
print(0)

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , k;
	cin>>n>>k ;
	int ans = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		int x ;
		cin>>x ;
		if(x >= k)
			ans++ ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int a[100000];
int main(void)
{
	int n,i;
	ll res=0,sum;
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",&a[i]);
	FOR(i,0,n){
		sum=0;
		while(a[i]!=0) sum+=a[i++];
		res+=sum/2;
	}
	printf("%lld\n",res);
	return 0;
}
    
    


Measured memory_bytes: 512
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
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; 
}
ll power(ll x, ll y) { 
    ll res = 1;       
    while (y > 0) {    
        if (y & 1) 
            res = (res*x) ;  
        y = y>>1; 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve(){
    int n;cin>>n;
    vector<ll> v(n);fr(i,0,n-1)cin>>v[i];
    ll ans=0;
    frr(i,n-2,0){
        ans=(ans+v[i]*v[i+1])%mod;
        v[i]=(v[i]+v[i+1])%mod;
    }
    cout<<ans<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 4768
import scala.collection.mutable.ListBuffer
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().trim.toInt
  var root: Node = null
  val buff = ListBuffer.empty[String]
  case class Node(key: Int, var parent: Node, var left: Node, var right: Node){
    private def getDefaultKey(p: Node) = if(p == null) -1 else p.key
    override def toString: String = s"Node($key, ${getDefaultKey(parent)} ${getDefaultKey(left)} ${getDefaultKey(right)})"
  }
  
  (0 until n).foreach { _ =>
    val command = StdIn.readLine()
    command.split(' ') match {
      case Array("insert", key) => insert(Node(key.toInt, null, null, null))
      case Array("find"  , key) => {
        buff += (if(find(root, key.toInt) == null) f"no%n" else f"yes%n")
      }
      case _ => {
        // print
        inorder(root)
        buff += f"%n"
        preorder(root)
        buff += f"%n"
      }
    }
  }
  
  
  def insert(z: Node) = {
    var y:Node = null
    var x:Node = root
    while(x != null){
      y = x
      if(z.key < x.key){
        x = x.left
      } else {
        x = x.right
      }
    }
    z.parent = y
    
    if(y == null){
      root = z
    } else if(z.key < y.key){
      y.left = z
    } else {
      y.right = z
    }
  }
  
  def preorder(n: Node): Unit = {
    buff += " " + n.key
    if(n.left != null) preorder(n.left)
    if(n.right != null) preorder(n.right)
  }

  def inorder(n: Node): Unit = {
    if(n.left != null) inorder(n.left)
    buff += " " + n.key
    if(n.right != null) inorder(n.right)
  }
  
  def find(x: Node, key: Int) = {
    var temp = x
    while(temp != null && key != temp.key){
      if(key < temp.key){
        temp = temp.left
      } else {
        temp = temp.right
      }
    }
    temp
  }
  
  print(buff.mkString(""))
}


Measured memory_bytes: 547416
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

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

Measured memory_bytes: 256
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

X=int(input())
A=int(input())
B=int(input())

X = X - A
print(X%B)

Measured memory_bytes: 22308
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
N,M = map(int,input().split())
A = list(map(int,input().split()))
for i in A:
    N -= i
if N >= 0:
    print(N)
else:
    print(-1)



Measured memory_bytes: 10192
A=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

N=int(input())
S=input()
ANS=""
for i in range(len(S)):
    for j in range(26):
        if S[i]==A[j]:
            ANS+=A[(j+N)%26]
print(ANS)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N,K;
ll a[100000];
ll s[100001], p[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
    rep(i,0,N) cin>>a[i];
    rep(i,0,N){
        s[i+1]=s[i]+a[i];
        p[i+1]=p[i]+(a[i]>0?a[i]:0);
    }
    ll ans=0;
    rep(i,0,N-K+1){
        ans=max(ans,s[i+K]-s[i]+p[i]+p[N]-p[i+K]);
        ans=max(ans,p[i]+p[N]-p[i+K]);
    }
    cout <<ans<<"\n";
}

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

int main(){
    int N;
    cin >> N;
    string S[N];
    int a=0,w=0,t=0,r=0;
    for(int i=0;i<N;i++){
        cin >> S[i];
        
        if(S[i]=="AC")a++;
        else if(S[i]=="WA")w++;
        else if(S[i]=="TLE")t++;
        else if(S[i]=="RE")r++;
    } 
    cout << "AC x " << a << endl ;
    cout << "WA x " << w << endl ;
    cout << "TLE x " << t << endl ;
    cout << "RE x " << r  << endl ;
}


Measured memory_bytes: 6688
#include <iostream>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
int main(){
  ll n,m,k,i,j,result=0;
  ll a[200010],b[200010];
  ll sumA[200010]={0},sumB[200010]={0};
  
  cin >> n >> m >> k;
  rep(i,n){
    cin >> a[i];
    sumA[i+1] = sumA[i]+(ll)a[i];
  }
  rep(i,m){
    cin >> b[i];
    sumB[i+1] = sumB[i]+(ll)b[i];
  }
  j = m;
  for(i=0;i<=n;i++){
    if(sumA[i]>k) break;
    while(sumA[i]+sumB[j]>k) j--;
    
    result = max(result, i+j);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

const int inf = 1<<29;
int N, A, B, C;
vector<int> l;

int dfs(int cur, int a, int b, int c, int mp){
    if(cur == N){
        if(a>0 && b>0 && c>0) return abs(a-A) + abs(b-B) + abs(c-C) + mp - 30;
        else return inf;
    }

    int res = inf;
    chmin(res, dfs(cur+1, a, b, c, mp));
    chmin(res, dfs(cur+1, a+l[cur], b, c, mp+10));
    chmin(res, dfs(cur+1, a, b+l[cur], c, mp+10));
    chmin(res, dfs(cur+1, a, b, c+l[cur], mp+10));
    return res;
}


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

    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];
    
    cout << dfs(0, 0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static StringBuilder t;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		t = new StringBuilder();
		for(int i = 0; i < n; i++) {
			t.append("x");
		}
		System.out.println(t);
	}

}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm> 
#include <cmath>
//#include <bitset>
//#include <deque>
#include <iterator>
#include <map> 
//#include <queue>
//#include <stack>
#include <string>
#include <vector>
#include <array>
//#include <tuple>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

typedef long long ll;
struct __{__(){ios_base::Init i;ios_base::sync_with_stdio(0);cin.tie(0);}}__; 



int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		if (i) {
			v[i] = v[i] + v[i - 1];
		}
	}
	vector<ll> a = v;
	ll ans = 0;
	ll curr = 0;
	for (int i = 0; i < n; ++i) {
		v[i] = curr + v[i];
		if (i % 2 == 0 && v[i] <= 0) {
			curr += abs(v[i]) + 1;
		    ans += abs(v[i]) + 1;
		}
		if (i % 2 == 1 && v[i] >= 0) {
			curr -= v[i] + 1;
			ans += v[i] + 1;
		}
	}
	v = a;
	ll ans2 = ans;
	ans = 0;
	curr = 0;
	for (int i = 0; i < n; ++i) {
		v[i] = curr + v[i];
		if (i % 2 == 1 && v[i] <= 0) {
			curr += abs(v[i]) + 1;
		    ans += abs(v[i]) + 1;
		}
		if (i % 2 == 0 && v[i] >= 0) {
			curr -= v[i] + 1;
			ans += v[i] + 1;
		}
	}
	cout << min(ans,ans2);
	
}




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

//thanks to pyf ...
//thanks to qhl ...

long long n;

int judge(int x, int y)
{
	int l = 1, r = 3500;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		long long tar = 1LL * n * x * y;
		long long cur = 4LL * x * y * mid - 1LL * n * y * mid - 1LL * n * x * mid;
		if (tar == cur)
			return mid;
		if (cur < tar)
			l = mid + 1;
		else
			r = mid - 1;
	}
	return -1;
}

int main()
{
	while (cin >> n)
	{
		int flag = 0;
		for (int i = 1; i <= 3500; i++)
		{
			for (int j = 1; j <= 3500; j++)
			{
				int tar = judge(i, j);
				if (tar != -1)
				{
					flag = 1;
					cout << i << " " << j << " " << tar << endl;
					break;
				}
			}
			if (flag)
				break;
		}
	}
}

Measured memory_bytes: 256