akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int 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;
	}
}

// 二項係数計算
long long COMB(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;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int n, m;
int p[114514];
signed main() {
	COMinit();
	cin >> n >> m;
	rep(i, n)cin >> p[i];
	int ans = 0;
	sort(p, p + n);
	rep(i, n - 1) {
		ans += ((COMB(n, m) - (COMB(i + 1, m) + COMB(n - i - 1, m)) + mod) % mod) * ((p[i + 1] - p[i]) % mod) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	ggr
}


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


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

    ll x,y;
    cin>>x>>y;
    if(x%y==0){
        cout<<-1<<endl;
        return 0;
    }
    ll ans=x;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    s = input()
    
    arr = []
    if s[0] == '0':
        arr.append(0)
    cnt = 1
    i = 1
    while i != n:
        if s[i] != s[i - 1]:
            arr.append(cnt)
            cnt = 1
        else:
            cnt += 1
        i += 1
    arr.append(cnt)
    if s[-1] == '0':
        arr.append(0)
    
    ans = 0
    curr = arr[0]
    j = 1
    if len(arr) - 1 <= 2 * k:
        print(n)
        return 0
    for i in range(1, len(arr), 2):
        curr += arr[i] + arr[i + 1]
        if i - j == 2 * k:
            curr -= arr[j] + arr[j - 1]
            j += 2
        ans = max(ans, curr)
    print(ans)
    return 0
main()

Measured memory_bytes: 4092
N = 2
a = []
for i in range(N):
    a.append((input()))
    
N = int(a[0])
A = a[1]
weights = []
abs_weights = []

A = A.split(" ")
for n in A:
    n = int(n)
    weights.append(n)

for i in range(N):
    right = sum(weights[0:i])
    left = sum(weights[i:])
    abs_weight = abs(right - left)
    abs_weights.append(abs_weight)
    
print(min(abs_weights))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  char b;
  scanf("%c",&b);

  if(b == 'A')printf("T\n");
  if(b == 'C')printf("G\n");
  if(b == 'T')printf("A\n");
  if(b == 'G')printf("C\n");
  
  return 0;
}

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

#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define pii pair<int, int>
#define mod 1000000007
#define pi 3.141592653589
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T>
// using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//(*****FOR USING ORDERED SET CHANGE INT*******)

int power(int x, int y) ;
int gcd(int a, int b) ;


signed main() {
    quickie
    int n, k, d; 
    cin >> n >> k >> d ;
    n = abs(n) ;
    int tt = n/d ;
    tt = min(k, tt) ;
    k -= tt ;
    n -= tt*d ;
    if(k%2 == 0) {
        cout << n << "\n" ;
    }
    else {
        cout << abs(n-d) << "\n" ;
    }
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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



Measured memory_bytes: 3640
n,*z=`dd`.split.map &:to_i
t=(e=[*0...n]).dup
f=->a{(0...n).map{|i|a[t[i]]}}
a=z.shift n+1
n.downto(1){|i|a[i]-=a[i-1]}
k,*z=z
z.map{|x|t[x-2],t[x-1]=t[x-1],t[x-2]}
(k%2>0&&e=f[e];t=f[t];k/=2)while k>0
k,*a=a
n.times{|i|p k;k+=a[e[i]]}

Measured memory_bytes: 72468
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)
#define MAX_N 100000
int main() {
	string s; cin >> s;
	int ans = INF;
	for (int i = 0; i < s.length() - 2; i++) {
		int tmp = (s[i] - '0') * 100;
		tmp += (s[i+1] - '0') * 10;
		tmp += (s[i+2] - '0');
		ans = min(ans, max(tmp-753, 753-tmp));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  set<string> ss;
  for (int i = 0; i < N; ++i) {
    string S;
    cin >> S;
    ss.insert(S);
  }
  cout << ss.size() << endl;
  return 0;
}


Measured memory_bytes: 15700
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n-k){
    if (a[i] < a[i+k]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}
    
    

Measured memory_bytes: 4848
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m;
    int ans[60];
    cin >> n >> m;
    fill(ans, ans + n, 0);
    imfor(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        ans[a]++;
        ans[b]++;
    }
    imfor(i, n) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
lit = [int(x) for x in input().split()]
lit2 = []
for i in range(N):
    if lit[i] % 2 == 0:
        lit2.append(lit[i])
N2 = len(lit2)
lit3 = []
for j in range(N2):
    if lit2[j] % 3 == 0:
        lit3.append(lit[j])
    elif lit2[j] % 5 == 0:
        lit3.append(lit[j])
if len(lit2) == len(lit3):
    print("APPROVED")
else: print("DENIED")

Measured memory_bytes: 3064
import itertools
n = input()
number = list("753")
N = []
flag = False
for i in range(3, 10):
  for v in itertools.product(number, repeat=i):
    if "7" in v and "5" in v and "3" in v:
      if int("".join(v)) <= int(n): N.append(int("".join(v)))
print(len(N))

Measured memory_bytes: 4060
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int sum = 0;
    REP(i, n) sum += a[i] -1;
    cout << sum << endl;
}


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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    while (1) {
        string T;
        cin >> T;
        if (T == "END_OF_TEXT") break;
        for (int i = 0; i < T.size(); i++) {
            if ('A' <= T[i] && T[i] <= 'Z') T[i] += 'a' - 'A';
        }
        if (T == S) ans++;
    }
    cout << ans << endl;
}


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

int main() {
  int A,B,C ; 
  cin >> A >> B >> C;
  
 if (A + B + C >= 22) {
   cout << "bust" << endl;
 }
 else if (A + B + C < 22) {
   cout << "win" << endl;
 } 
  
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdlib.h>  
using namespace std;

int main(){
	unsigned long long int N;
	cin >> N;


	if( N % 2 == 0){
		cout<< N<<endl;
	}

	else
		cout << N*2<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M, XX, YY; cin >> N >> M >> XX >> YY;
  vector<int> X(N+1), Y(M+1);

    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    X[N] = XX;
    
    for (int i = 0; i < M; i++) {
        cin >> Y[i];
    }
    Y[M] = YY;
    
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    cout << ((X[X.size()-1] < Y[0]) ? "No War" : "War") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	int length = 0;
	for (int i = 0; i < n+1; i++)
	{
		if (s.substr(n - i, i) == t.substr(0, i)) length = i;

	}
	
	cout << n * 2 - length << endl;

	return 0;
}



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

using namespace std;

int main(void){
    long long L, R;
    cin >> L >> R;
    if(R - L >= 2019){
        cout << 0 << endl;
        return 0;
    }
    long long ans = 2019;
    for(long long i = L; i < R; i++){
        for(long long j = i + 1; j <= R; j++){
            ans = min(ans, (i * j) % 2019LL);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    if x <= c_xs[center]:
        print(c_xs[center+1])
    else:
        print(c_xs[center])


Measured memory_bytes: 29972
from math import gcd

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

L,R = [0],[0]

for i in range(N-1):
    L += [gcd(L[i],A[i])]
    R += [gcd(R[i],A[-i-1])]

print(max(gcd(L[i],R[-i-1])for i in range(N)))



Measured memory_bytes: 21632
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int n = cin.nextint;
        var H = new HashSet<string>();

       char before ='a';
        for (int i = 0; i < n; i++)
        {
            var S = ReadLine();
            if (H.Contains(S))
            {
                WriteLine("No");
                return;
            }
            if (i > 0 && S[0] != before)
            {
                WriteLine("No");
                return;
            }
            H.Add(S);
            before = S[S.Count() - 1];
        }
        WriteLine("Yes");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13280
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string s;
map<char, int> mp;
int main()
{
	cin >>s;
	for (int i=0;i<4;i++) mp[s[i]]++;
	if (mp.size()!=2)
	{
		cout <<"No";
		return 0;
	}
	for (map<char, int>::iterator it=mp.begin();it!=mp.end();it++)
	{
	    if (it->second!=2)
	    {
	    	cout <<"No";
	    	return 0;
		}
	}
	cout <<"Yes";
	return 0;
} 

Measured memory_bytes: 256
#https://atcoder.jp/contests/abc109/tasks/abc109_c
import numpy as np
import math
from functools import reduce

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

N,X = map(int,input().split())
City = np.array(list(map(int,input().split())))
City = np.sort(np.append(City,[X]))
kaisa = np.diff(City)
print(gcd_list(kaisa))



Measured memory_bytes: 37968
N, A, B = list(map(int, input().split()))
S = input()

an = 0  # 今までaが何人いたか
bn = 0  # 今までbが何人いたか
bn2 = 0

total = 0
overseas = 0

for si in S:
    if si == 'c':
        print('No')
    elif si == 'a':
        if total < A + B:
            total += 1
            print('Yes')
        else:
            print('No')
    else:
        if total < A + B and overseas + 1 <= B:
            total += 1
            overseas += 1
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 4016
package main

import (
	"fmt"
)

func main() {
	var a,b,c,k int
	fmt.Scan(&a,&b,&c,&k)

	if k <= a {
		fmt.Println(k)
		return
	}
	if k <= a+ b {
		fmt.Println(a)
		return
	}

	fmt.Println(a-(k-a-b))
	return
}




Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) a.begin(),a.end()

const double EPS = 1e-6;

int main(){
    string S, T; cin >> S >>T;
    ll nt = T.size();
    ll ns = S.size();
    unordered_map<char,int> mps, mpt;
    for(int i = 0; i < S.size(); i++) mps[S[i]]++;
    for(int i = 0; i < T.size(); i++) mpt[T[i]]++;
    double max = 0;
    //vector<char> ans;
    for(auto e: mpt){
        if(mps[e.first] == 0){
            cout << -1 << endl;
            return 0;
        }
        /* if(max + EPS < (double)e.second / (double)mps[e.first]){
            max = (double)e.second / (double)mps[e.first];
            ans.clear;
            ans.push_back(e.first);
        }else if(max + EPS > (double)e.second / (double)mps[e.first] && max - EPS < (double)e.second / (double)mps[e.first]){
            ans.push_back(e.first);
        } */
    }
    vector<int> tmp[26];
    for(int i = 0 ; i < S.size(); i++){
        int x = S[i] - 'a';
        tmp[x].push_back(i);
    }
    ll ans = 0;
    ll pre = 0;
    for(int i = 0; i < T.size(); i++){
        int x = T[i] - 'a';
        auto it = lower_bound(tmp[x].begin(), tmp[x].end(), pre);
        if(it == tmp[x].end()){
            ans += ns - pre + 1;
            ans += tmp[x][0];
            pre = tmp[x][0];
        }else{
            ans += *it -pre + 1;
            pre = *it;
        }
        pre++;
        //cout << " pre " <<  pre << "ans " << ans <<endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
int main(){
	int i,j=0,n;
	for(cin>>n;j<n;j++){
		string s;cin>>s;map<string,int> m;
		for(i=1;i<s.length();i++){
			string s1=s.substr(0,i),s2=s.substr(i),r1=s1,r2=s2;
			reverse(r1.begin(),r1.end());
			reverse(r2.begin(),r2.end());
			m[s1+s2]=1;
			m[s1+s2]=1;
			m[r1+s2]=1;
			m[s1+r2]=1;
			m[r1+r2]=1;
			m[s2+s1]=1;
			m[r2+s1]=1;
			m[s2+r1]=1;
			m[r2+r1]=1;
		}
		cout<<m.size()<<endl;
	}
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  ll N, A, B; cin >> N >> A >> B;
  if (A > B) {
    cout << 0 << CRLF;
    return;
  }
  if (N < 2) {
    cout << ((A == B) ? 1 : 0) << CRLF;
    return;
  }
  auto min = A*(N-1) + B;
  auto max = A + B*(N-1);
  cout << (max - min) + 1 << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <cmath>

#define INF 1e17

using namespace std;

int main(void){
	long long int n, m, s, t;

	cin >> n >> m >> s >> t;

	vector< vector< pair<long long int, pair<long long int, long long int> > > > edge(n + 1, vector< pair<long long int, pair<long long int, long long int> > >(0));


	long long int u, v, a, b;

	for (int i = 0; i < m; i++){
		cin >> u >> v >> a >> b;


		edge[u].push_back(pair<long long int, pair<long long int, long long int> >(v, pair<long long int, long long int>(a, b)));
		edge[v].push_back(pair<long long int, pair<long long int, long long int> >(u, pair<long long int, long long int>(a, b)));
	}

	cout << endl;

	vector<long long int> ds(n + 1, 0), dt(n + 1, 0);
	priority_queue<pair<long long int, int> > Qt, Qs;

	for (int i = 1; i < n+1; i++){
		if (i == s)
			ds[i] = 0;
		else
			ds[i] = INF;

		if (i == t)
			dt[i] = 0;
		else
			dt[i] = INF;
		
		Qt.push(pair<long long int, int>(-dt[i], i));
		Qs.push(pair<long long int, int>(-ds[i], i));
	}
	
	while (!Qs.empty()){
		pair<long long int, int> p = Qs.top();
		Qs.pop();

		long long int U = p.second;
		long long int dis = -p.first;

		if (dis > ds[U])
			continue;

		for (int i = 0; i < edge[U].size(); i++){
			long long int temp = ds[U] + edge[U][i].second.first;
			if (ds[edge[U][i].first] > temp){
				ds[edge[U][i].first] = temp;
				Qs.push(pair<long long int, int>(-temp, edge[U][i].first));
			}
		}
	}

	while (!Qt.empty()){
		pair<long long int, int> p = Qt.top();
		Qt.pop();

		long long int U = p.second;
		long long int dis = -p.first;

		if (dis > dt[U])
			continue;

		for (int i = 0; i < edge[U].size(); i++){
			long long int temp = dt[U] + edge[U][i].second.second;
			if (dt[edge[U][i].first] > temp){
				dt[edge[U][i].first] = temp;
				Qt.push(pair<long long int, int>(-temp, edge[U][i].first));
			}
		}
	}


	vector<long long int> res(n + 2, 0);

	res[n] = pow(10, 15) - (ds[n] + dt[n]);



	for (int i = n - 1; i > 0; i--){
		if (pow(10, 15) - (ds[i] + dt[i]) < res[i+1])
			res[i] = res[i+1];
		else
			res[i] = pow(10, 15) - (ds[i] + dt[i]);

	}

	for (int i = 1; i < n + 1; i++)
		cout << res[i] << endl;



}


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

#define int long long
int n, a, b;
int x[101010];

int dp[101010];
int dfs(int i=1, int c=0)
{
        if (i == n){
                return 0;
        }

        int &ret = dp[i];
        if (ret != -1) return ret;
        ret = min(dfs(i + 1, c) + a * (x[i] - x[i - 1]), dfs(i + 1, c + 1) + b);
        return ret;
}
main()
{
        cin >> n >> a >> b;

        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < n; i++){
                cin >> x[i];
        }

        /*
        for (int i = 1; i < n; i++){
                ans += min(b, a * (x[i] - x[i - 1]));
        }
        */

        cout << dfs() << endl;
}



Measured memory_bytes: 6528
#include <stdio.h>

int main(void)
{
    int a, b, c[100000], i;

    scanf("%d %d", &a, &b);

    for (i = 0; i < b; ++i){
        scanf("%d", &c[i]);
    }

    for (i = 0; i < b; ++i){
       a -= c[i]; 
    }
    
    if (a < 0) printf("-1\n");

    else printf("%d\n", a);

    return 0;

}

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

const int N = 50 + 5;

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

vector<pii> g[N];
int d[N], p[N], pid[N], lca[N], col[N];

void init(int u, int from = -1, int depth = 0){
	d[u] = depth;
	for(pii v:g[u]){
		if(v.first == from)continue;
		p[v.first] = u;
		pid[v.first] = v.second;
		init(v.first,u,depth+1);
	}
}

int calc_lca(int x,int y){
	while(x != y){
		if(d[x] < d[y]){
			y = p[y];
		}
		else{
			x = p[x];
		}
	}
	return x;
}

void color(int x,int tar){
	while(x != tar){
		col[pid[x]] = 1;
		x = p[x];
	}
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int a,b;
	for(int i = 0;i < n-1; ++i){
		cin >> a >> b;
		--a,--b;
		g[a].push_back({b,i});
		g[b].push_back({a,i});
	}
	init(0);
	int m;
	cin >> m;
	vector<pii> r(m);
	for(int i = 0;i < m; ++i){
		cin >> r[i].first >> r[i].second;
		--r[i].first, --r[i].second;
		lca[i] = calc_lca(r[i].first, r[i].second);
	}
	ll ans = 1LL << (n-1);
	for(int msk = 1;msk < (1 << m); ++msk){
		memset(col, 0, sizeof(col));
		ll sgn = __builtin_popcount(msk) % 2 == 0 ? 1 : -1;
		for(int i = 0;i < m; ++i){
			if((msk >> i)&1){
				color(r[i].first, lca[i]);
				color(r[i].second, lca[i]);
			}
		}
		int cnt = accumulate(col,col+n,0);
		ans += sgn * (1LL << (n-1-cnt));
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main(){
    cin >> n >> k;
    int l[n];
    for (int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l,l+n);
    cout << accumulate(l+n-k,l+n,0);
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
for i in range(1000, 11000, 1000):
    if i >= N:
        print(i-N)
        break

Measured memory_bytes: 68164
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	int a,b;
	cin>>s;
	a=(s[0]-'0')*10+(s[1]-'0');
	b=(s[2]-'0')*10+(s[3]-'0');
	if(a>0 && a<13){
		if(b>0 && b<13){
			cout<<"AMBIGUOUS"<<endl;
			return 0;
		}
		else{
			cout<<"MMYY"<<endl;
			return 0;
		}
	}
	else{
		if(b>0 && b<13){
			cout<<"YYMM"<<endl;
			return 0;
		}
		else{
			cout<<"NA"<<endl;
			return 0;
		}	
	}
}

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

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

        System.out.println(n % k == 0 ? 0 : 1);
    }
}

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

int main(){
    while(1){
        int n;  cin>>n;
        if(n==0)break;
        int score[n];   for(int i=0;i<n;i++)cin>>score[i];

        for(int i=0;i<n;i++){
            bool flag=false;
            for(int j=i;j<n;j++){
                int minj=i;
                if(score[i]>score[j]){
                    minj=j;
                    flag=true;
                }
                if(flag==true)swap(score[i],score[minj]);
            }
        }

        //for(int i=0;i<n;i++)cout<<score[i]<<" ";
        int min=1000000;

        for(int i=0;i<n-1;i++){
            if(min>abs(score[i]-score[i+1]))min=abs(score[i]-score[i+1]);

        }
        cout<<min<<endl;
    }


    return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>
#include <queue>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef std::pair <ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

bool sq(ll num){
    double n = num;
    double m = pow(n, 0.5);
    ll mm = m;
    if(pow(mm, 2) == num) return true;
    else return false;
}

int main()
{
    ll n, d;
    cin >> n >> d;
    vector< vector<ll> > v(n);
    rep(i, n) v[i].resize(d);

    ll cnt = 0;

    rep(i, n){
        rep(j, d){
            cin >> v[i][j];
        }
    }

    rep(i, n){
        for(ll j = i+1; j<n; j++){
            ll pp = 0;
            rep(k, d){
                pp += (v[i][k] - v[j][k])*(v[i][k] - v[j][k]);
            }
            if(sq(pp)) cnt++;
        }
    }

    cout << cnt;



}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

/*
 * L - Deque
 */
public class Main
{
long[][] cache;

public static void main( String[] args ) throws Exception
{
	new Main().run();
}

public void run() throws Exception
{
	final Scanner sc = new Scanner( getInputStream() );
	final int N = sc.nextInt();
	cache = new long[ N ][ N ];
	long[] data = new long[ N ];
	for( int i = 0; i < N; ++i )
	{
		data[ i ] = sc.nextLong();
	}
	long sum = sum( data, 0, N - 1 );
	long x = getScore( data, 0, N -1 );
	long y = sum - x;
	/*
	p( x );
	p( y );
	p( sum );
	*/
	p( sum - 2*y );
}

public long getScore( final long[] data, int start, int end )
{
	if( start == end )
	{
		return data[ start ];
	}
	else
	{
		long cached = cache[ start ][ end ];
		if( cached != 0 )
		{
			return cached;
		}
		else
		{
			long sum = sum( data, start, end );
			long leftScore = sum - getScore( data, start + 1, end );
			long rightScore = sum - getScore( data, start, end -1 );
			
			long result = leftScore > rightScore ? leftScore : rightScore;
			cache[ start ][ end ] = result;
			return result;
		}
	}
}

public static long sum( long[] data, int start, int end )
{
	long sum = 0;
	for( int i = start; i <= end; ++i )
	{
		sum += data[ i ];
	}
	return sum;
}

public static void p( Object o )
{
	System.out.println( o );
}

public static InputStream getInputStream() throws IOException
{
	//p( System.getProperties() );
	if( System.getProperty( "test" ) != null )
	{
		return new FileInputStream( "1" );
	}
	else
	{
		return System.in;
	}
}

}


Measured memory_bytes: 111980
h,w,d = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]

b = [[0,0] for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        b[a[i][j]] = [i,j]

c = [0]*d
for i in range(len((b))-d):
    c.append(abs(b[i+d][0]-b[i][0])+abs(b[i+d][1]-b[i][1])+c[-d])

q = int(input())
for i in range(q):
    l,r = map(int,input().split())
    print(c[r]-c[l])

Measured memory_bytes: 69508
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
// use std::cmp::{max, min};

fn main() {
    input! { s: String };
    let mut t:Vec<u8> = s.as_bytes().iter().cloned().collect();
    t.sort();
    t.dedup();
    if s.len() == t.len() { println!("yes") }
    else { println!("no")}
}


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

typedef long long ll;
typedef long double ld;

priority_queue <int> q;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        int x;
        cin >> x;
        q.push(x);
    }
    while(m--){
        int x = q.top();
        q.pop();
        q.push(x/2);
    }
    ll res = 0;
    while(!q.empty()){
        res += q.top();
        q.pop();
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 892
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#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 loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
	is >> p.first >> p.second;
	return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
	os << p.first << " " << p.second;
	return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
  if (s) {
	__uint128_t tmp = value < 0 ? -value : value;
	char buffer[128];
	char *d = std::end(buffer);
	do {
	  --d;
	  *d = "0123456789"[tmp % 10];
	  tmp /= 10;
	} while (tmp != 0);
	if (value < 0) {
	  --d;
	  *d = '-';
	}
	int len = std::end(buffer) - d;
	if (dest.rdbuf()->sputn(d, len) != len) {
	  dest.setstate(std::ios_base::badbit);
	}
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
	if ('0' <= s[i] && s[i] <= '9')
	  ret = 10 * ret + s[i] - '0';
  return ret;
}
*/

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
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 (a > b) {
		a = b;
		return true;
	}
	return false;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	string s; cin >> s;
	int r=count(all(s), 'R');
	Yes(r > (N - r));
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

    char num[3];
    int x=0; 

    scanf("%s",&num);
    for(int i = 0;i < 3;++i){

        if (num[i] == '7'){
            
            i = 4;
            ++x;
        }
    }

    if (x == 1)
        puts("Yes");
    else 
        puts("No");

    return 0;
}
//todo
// !
// ?
// * 

Measured memory_bytes: 1612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
ll n, k;
ll ans = 1LL << 62;
vector<P> v;
bool check(ll x1, ll x2, ll y1, ll y2)
{
    int cnt = 0;
    rep(i, n)
    {
        if (v[i].first < x1)
            continue;
        if (v[i].first > x2)
            return false;
        if (v[i].second >= y1 && v[i].second <= y2)
            cnt++;
        if (cnt >= k)
            return true;
    }
    return false;
}
int main()
{
    cin >> n >> k;
    vector<ll> x(n);
    vector<ll> y(n);
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        x[i] = a;
        y[i] = b;
        v.push_back(P(a, b));
    }
    sort(v.begin(), v.end());
    sort(y.begin(), y.end());
    sort(x.begin(), x.end());
    rep(i, n)
    {
        rep(j, n)
        {
            if (j <= i)
                continue;
            rep(k, n)
            {
                rep(l, n)
                {
                    if (check(x[i], x[j], y[k], y[l]))
                    {
                        ans = min(ans, (x[j] - x[i]) * (y[l] - y[k]));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var a = cin.ReadInt();
            var b = cin.ReadInt();
            var c = cin.ReadInt();
            if (b - a == c - b)
                WriteLine("YES");
            else
                WriteLine("NO");
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Trim().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }
}


Measured memory_bytes: 11220
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

		Scanner sc = new Scanner(System.in);
		String moji = sc.next();
		// System.out.println(moji);

		for (int i = 0; i < moji.length(); i++) {
			char c = 'x';
			System.out.print(c);
		}

	}
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

	// 106-A
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int totalArea = a * b;
		int verticalPathArea = a * 1;
		int horizontalPathArea = 1 * b;

		// 全体面積から縦の道と横の道の面積を引き、重複分(1*1)の面積を追加する
		System.out.println(totalArea - verticalPathArea - horizontalPathArea + 1);

		sc.close();
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int a;
    cin>>a;
    if(a<1200)
    {
        cout<<"ABC"<<nl;
    }
    else if(a<2800)
    {
        cout<<"ARC"<<nl;
    }
    else
    {
        cout<<"AGC"<<nl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

int n, C;
int d[30][30];
int c[500][500];
int cal[3][30];

void init() {

}

void input() {
	cin >> n >> C;
	REP(i, C) REP(j, C) cin >> d[i][j];
	REP(i, n) REP(j, n) {
		cin >> c[i][j];
		c[i][j]--;
	}
}

void solve() {
	int res = 1<<30;
	MSET(cal, 0);
	REP(a, 3) REP(i, n) REP(j, n) if((i+j)%3 == a) REP(col, C) cal[a][col] += d[c[i][j]][col];
	REP(c0, C) REP(c1, C) REP(c2, C) {
		if (c0 == c1) continue;
			if (c1 == c2) continue;
				if (c2 == c0) continue;
		 chmin(res, cal[0][c0] + cal[1][c1] + cal[2][c2]);
	}
	cout << res << endl;
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
int main(void){
	std::string s;
	std::cin>>s;
	for(int i=0;i<12;i++){
		std::cout<<s[i];
		if(i==3){
			std::cout<<' ';
		}
	}
	std::cout<<std::endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
N,M,X=map(int,input().split())
ans=13*10**5
List=[]
for _ in range(N):
  List.append([int(i) for i in input().split()])
for i in range(0,N):
  for j in itertools.combinations(range(N),i+1):
    tmp=[0]*(M+1)
    for k in j:      
      for l in range(M+1):
        tmp[l]+=List[k][l]
    if len([m for m in tmp[1:] if m>=X])==M:
      ans=min(ans,tmp[0])
if ans==13*10**5:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9232
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let h: usize = input();
    let w: usize = input();
    let s: Vec<Vec<char>> = (0..h)
        .map(|_| input::<String>().chars().collect())
        .collect();

    let mut row = vec![vec![0; w + 1]; h];
    for i in 0..h {
        let mut j = 0;
        while j < w {
            if s[i][j] == '#' {
                j += 1;
                continue;
            }

            let start = j;
            let mut cnt = 0;
            while j < w && s[i][j] == '.' {
                cnt += 1;
                j += 1;
            }

            row[i][start] = cnt;
            row[i][j] = -cnt;
        }

        for j in 1..w + 1 {
            row[i][j] += row[i][j - 1];
        }
    }

    let mut col = vec![vec![0; w]; h + 1];
    for j in 0..w {
        let mut i = 0;
        while i < h {
            if s[i][j] == '#' {
                i += 1;
                continue;
            }

            let start = i;
            let mut cnt = 0;
            while i < h && s[i][j] == '.' {
                cnt += 1;
                i += 1;
            }

            col[start][j] = cnt;
            col[i][j] = -cnt;
        }

        for i in 1..h + 1 {
            col[i][j] += col[i - 1][j];
        }
    }

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            ans = std::cmp::max(ans, row[i][j] + col[i][j] - 1);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 53628
<?php
fscanf(STDIN, "%d %d %d %d %d", $A, $B, $C, $D, $E);

$array = [$A, $B, $C, $D, $E];

foreach ($array as $key => $value) {
  if ($value == 0) {
    $ans = $key + 1; 
  }
}
print_r ($ans);
?>

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);

  ll S; cin >> S;
  ll x1,x2,x3,y1,y2,y3;

  if(S==1000000000000000000){
    x1 = 0;
    x2 = 1000000000;
    x3 = 0;
    y1 = 0;
    y2 = 0;
    y3 = 1000000000;
  } else {
    x1 = 0;
    y1 = 0;
    x2 = 1; 
    y2 = 1000000000;
    
    y3 = y2 - S % y2;
    x3 = (S - S % y2) / (y2) + 1;
  }


  cout << x1 << " " << y1 << " ";
  cout << x2 << " " << y2 << " ";
  cout << x3 << " " << y3 << endl;

  cerr << abs(x3 * y2 -  x2 * y3) << endl;
}



Measured memory_bytes: 3636
n = int(input())
w = input().split(" ")

a = []
m = 0
k = False
for i in range(n):
    a.append(int(w[i]))
    if a[i] < 0:
        a[i] *= -1
        k = not (k)
    if i == 0:
        m = a[i]
    if a[i] < m:
        m = a[i]

sum = sum(a)
if k:
    sum -= m*2
print(sum)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;cin>>N;
    vint P(N);rep(i,N)cin>>P[i];

    int num=0;
    string ans;
    stack<int>s;

    rep(i,N){
        while(num<P[i]){
            num++;s.push(num);ans+="(";
        }
        if(s.empty()||s.top()!=P[i]){
            cout<<":("<<endl;
            return 0;
        }
        ans+=")";s.pop();
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4256