akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let a : i32 = read();
    let b : i32 = read();
    let ans = if a-2*b > 0 {a-2*b} else {0};
    println!("{}", ans);
}

Measured memory_bytes: 4476
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  long long arr[n];
  long long Sum = 0, arai = 0, com = 0, ads = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];

    Sum += arr[i];
  }
  arai = arr[0];
  com = abs(Sum - 2 * arai);
  for (int i = 1; i < n - 1; i++) {
    arai += arr[i];
    ads = abs(Sum - 2 * arai);

    if (ads < com) {
      com = ads;
    }
  }

  cout << com << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
	int [] hash;
	boolean flg;
	HashSet<String> hs;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			int [] data = new int[10];
			for(int i = 0; i < s.length(); i++){
				int res = s.charAt(i) - '0';
				data[res]++;
			}
			
			StringBuilder sb = new StringBuilder();
			for(int i = 1 ; i < 10; i++){
				hash = data.clone();
				hash[i]++;
				if(hash[i] >= 5){
					continue;
				}
				flg = false;
				hs = new HashSet<String>();
				dfs(0);
				if(flg){
					sb.append(" " + i);
				}
			}
			if(sb.length() == 0) System.out.println(0);
			else System.out.println(sb.substring(1));
		}
	}

	private void dfs(int deep) {
		String str = Arrays.toString(hash);
		if(hs.contains(str)){
			return;
		}
		hs.add(str);
		boolean isfin = true;
		boolean ishead = false;
		for(int i = 1; i < hash.length; i++){
			if(hash[i] == 0 || hash[i] == 2){
				if(hash[i] == 2){
					if(ishead){
						isfin = false;
						break;
					}
					else{
						ishead = true;
					}
				}
			}
			else{
				isfin = false;
				break;
			}
		}
		if(isfin && ishead){
			flg = true;
			return;
		}
		
		for(int i = 1; i < hash.length; i++){
			
			if(hash[i] >= 3){
				hash[i] = hash[i] - 3;
				dfs(deep + 1);
				hash[i] = hash[i] + 3;
			}
			
			if(i + 2 < hash.length){
				if(hash[i] > 0 && hash[i+1] > 0 && hash[i+2] > 0){
					hash[i]--; hash[i+1]--; hash[i+2]--;
					dfs(deep + 1);
					hash[i]++; hash[i+1]++; hash[i+2]++;
				}
			}
		}
	}
	
	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &p : a) cin >> p;
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    cout << binary_search(a.begin(), a.end(), k) << endl;
  }
  return 0;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  
  int x, y;
  int ans = 0;
  
  for(x = 0; x <= k; x++) {
    
    for(y = 0; y <= k; y++) {
      
      int z = s - x - y;
      if(z < 0 || z > k) continue;
      ans++;
    }
  }
  cout << ans << endl;
}  

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

using namespace std;
typedef long long ll;

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n ;
    cin >> n ;
    ll ans = 0 ;
    ll a, b ;
    REP(i,n){
        cin >> a ;
        if(i==0){
            ans += a/2 ;
            b = a%2 ;
            continue ;
        }
        if(a==0){
            b = 0 ;
            continue ;
        }
        ans += b ;
        a -= b ;
        ans += a/2 ;
        b = a%2 ;
    }
    
    cout << ans << endl ;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  ll a;
  cin >> a;
  cout << a + (int)pow(a,2) + (int)pow(a,3) << endl;
  return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pi           acos(-1)
using namespace std;
ll arr[100005];
ll t;
vector<string>v;
map<string,ll>mp;
map<string,string>np;
int main()
{
    ll a,b,c,d,e,f=0,i,j;
    cin>>a>>b>>c;
    if(a==b)f++;
    if(a==c)f++;
    if(f==1)cout<<"Yes"<<endl;
    else if(b==c&&f==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);i++)

long long int bag_size[51];
long long int num_patty[51];
long long int count_patty(long long n, long long x){
    if(n==0&&x==1) return 1;
    else if(x <= 1) return 0;
    else if(x <= 1 + bag_size[n-1]) return count_patty(n-1,x-1);
    else if(x == 2 + bag_size[n-1]) return 1 + num_patty[n-1];
    else if(x <= 2 + bag_size[n-1]*2) return 1 + num_patty[n-1] + count_patty(n-1, x-2-bag_size[n-1]);
    else return 1 + num_patty[n-1]*2;
}

int main(){
    long long int n,x; cin >> n >> x;
    rep(i,51){
        if(i==0){
            bag_size[i] = 1;
            num_patty[i]=1;
        }
        else{
            bag_size[i] = 3 + 2 * bag_size[i-1];
            num_patty[i] = 1 + 2 * num_patty[i-1];
        }
    }
    cout << count_patty(n,x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second
using namespace std;

void solve(){
	string s;
	cin >> s;
	if(s[s.length()-1] == 's'){
		s.append("es");
	}
	else{
		s.append("s");
	}
	cout << s << endl;
}

int main(){

/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif*/
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//int t;cin >> t;while(t--){solve();}
	solve();
	return 0;
}

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

int main() {
    int N,M;
    cin>>N>>M;
    int counter=0;
    int count, counter1;
    int a[M]={};
    for(int i=0;i<M;i++){
    cin>>a[i];}
    int dp[100010]{};
    dp[0]=1;
    dp[1]=1;
    if(a[0]==1){
    dp[1]=0;
    counter++;}
    for(int i=2;i<=N;i++){
    dp[i]=(dp[i-1]+dp[i-2])%1000000007;
    if(i==a[counter]){
    dp[i]=0;
    counter++;}}
    cout<<dp[N]<<endl;}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 1000003;

ll h,w,n,ans[101][101];
vector<ll> a;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>h>>w>>n;
	a.resize(n);
	FOR(i,0,n){
		cin>>a[i];
	}
	ll k=0;
	FOR(i,0,h){
		if(i%2==0){
			FOR(j,0,w){
				ans[i][j]=k+1;
				a[k]--;if(a[k]==0)k++;
			}
		}else{
			for(ll j=w-1;j>=0;j--){
				ans[i][j]=k+1;
				a[k]--;if(a[k]==0)k++;
			}
		}
	}
	FOR(i,0,h){
		cout<<ans[i][0];
		FOR(j,1,w){
			cout<<" "<<ans[i][j];
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
int main()
{
	int t;
	scanf("%d",&t);
	char z[200]={'\0'};
	char y[200]={'\0'};
	scanf("%s",z);
	int u=0;
	for(int i=t/2;i<t;i++)
	{
		y[u++]=z[i];
		z[i]='\0';
	}
	if(strcmp(y,z)==0)
	printf("Yes\n");
	else
	printf("No\n");
}

Measured memory_bytes: 128
n, m = map(int, input().split())

height = list(map(int, input().split()))
ansList = [1] * n

route = [[0] * 2] * m
for i in range(m):
    a, b = map(int, input().split())
    route[i] = a, b
'''
rouSet = set(route)
print(rouSet)
'''
for i in range(m):
    aa = route[i][0]
    bb = route[i][1]

    heiA = height[aa - 1]
    heiB = height[bb - 1]

    if (heiA == heiB):
        ansList[aa - 1] = 0
        ansList[bb - 1] = 0
    elif (heiA > heiB):
        ansList[bb - 1] = 0
    else:
        ansList[aa - 1] = 0

ans = sum(ansList)
print(ans)


Measured memory_bytes: 27312
import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))

    mod = 10 ** 9 + 7
    ans = 0
    v = sum(A)
    for a in A:
        v -= a
        ans += a * v
        ans %= mod

    return ans
    

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		boolean ans = true;
		int n = sc.nextInt();
		int []a = new int [n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 0) {
				if (a[i] % 3 == 0 || a[i] % 5 == 0) {

				} else {
					ans = false;
					break;
				}
			}
		}

		if (ans) {
			System.out.println("APPROVED");
		} else {
			System.out.println("DENIED");
		}

	}

}


Measured memory_bytes: 22608
#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;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }
	int ans = 0;
	if (A[0] != 1)ans = A[0] - 1, A[0] = 1;
	int m = 1;
	rep(i, 1, N) {
		int d = m + 1;
		if (A[i] == d) {
			chmax(m, A[i]);
			continue;
		}
		if (A[i] % d == 0) {
			A[i] -= d + 1;
			ans++;
		}
		int a=A[i] / d;
		ans += a;
		A[i] -= a * d;
		chmax(m, A[i]);
	}
	cout << ans << endl;
	dump(A);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
typedef long long ll;

int n;
vector<int> wl[maxN], wr[maxN];

void process() {
  ll ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k, l, r;
    cin >> k >> l >> r;
    if (l >= r) {
      wl[k].push_back(l-r);
    } else {
      wr[n-k].push_back(r-l);
    }
    ans = ans + min(l, r);
  }
  priority_queue<int, vector<int>, greater<int> > pq;
  for (int i = 1; i <= n; ++i) {
    for (auto v : wl[i]) {
      pq.push(v);
      ans += v;
    }
    while (pq.size() > i) {
      int x = pq.top(); pq.pop();
      ans -= x;
    }
  }
  while (!pq.empty()) pq.pop();
  for (int i = 1; i <= n; ++i) {
    for (auto v : wr[i]) {
      pq.push(v);
      ans += v;
    }
    while (pq.size() > i) {
      int x = pq.top(); pq.pop();
      ans -= x;
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; ++i) {
    wl[i].clear(); wr[i].clear();
  }
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  int t; cin >> t;
  while (t--) process();
  return 0;
}


Measured memory_bytes: 17700
H,W=map(int,input().split())
a=[[] for _ in range(H)]

for i in range(H):
    a[i]=list(map(int,input().split()))
    
n=0
ans=[]

for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j+1]+=1
            
for i in range(H-1):
    if a[i][-1]%2==1:
        n+=1
        ans.append([i+1,W,i+2,W])
        a[i+1][-1]+=1
        
print(n)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))





Measured memory_bytes: 64348
x = list(map(int,input().split()))
ans = 0
while x[0]!=x[1] or x[1]!=x[2]:
    x = sorted(x,reverse=True)
    if x[0]==x[1]:
        x[2]+=2
        ans+=1
    else:
        x[1]+=1
        x[2]+=1
        ans+=1
print(ans)


Measured memory_bytes: 3060
import std.stdio;
import std.string:replace, chomp;

void main(){
	int n;
	string s;
	readf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		s = chomp(readln());
		s = replace(s, "Hoshino","Hoshina");
		writeln(s);
	}
}

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

int main() {
  int K,S,ans=0;
  cin >> K >> S;
  for (int x=0; x<=K; x++) {
    for (int y=0; y<=K; y++) {
      if (S-x-y >=0 && S-x-y<= K) {
        ans++;
      }
    }
  }
  cout << ans << endl; 
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int p, q;
  cin >> p >> q;
  q /= __gcd(p, q);
  int res = 1;
  for (int i = 2; i * i <= q; ++i) {
    if (q % i == 0) {
      res *= i;
      while (q % i == 0) {
        q /= i;
      }
    }
  }
  if (q > 1) {
    res *= q;
  }
  cout << res << '\n';
}



Measured memory_bytes: 3212
#include <iostream>
using namespace std;
int main(){
	int i,n;
	int a[100];

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

	for( i=n-1; i>=0; i-- ){
		if( i != n-1 ) cout << " ";
		cout << a[i];
	}
	cout << endl;

	return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

vector<int> primes;
void erat(unsigned int limit) {
    vector<bool> prime(limit + 1, true);
    const unsigned int n = sqrt(limit);
    unsigned int i, j;
    primes.push_back(2);
    for(i = 3; i <= n; i += 2) {
        if(prime[i]) {for(j = i * i; j <= limit; j += 2*i) prime[j] = false;}
    }
    for(i = 3; i <= limit; i += 2) {if(prime[i]) primes.push_back(i);}
}

void fact(int n,map<int,int> &ret) { //O (cant primos)
    int idx=0;
    int p=primes[0];
    while (p*p<=n) {
        while(!(n % p)) {
            ++ret[p];//divisor found
            n /= p;
        }
        p = primes[++idx];
    }
    if(n > 1) ++ret[n];
}

void merge(map<int,int> &source,const map<int,int> &otro){
    auto it=source.begin();
    auto it2=otro.begin();
    while(it!=source.end() && it2!=otro.end()){
        if (it->first<it2->first) ++it;
        else if (it2->first<it->first){
            source.insert(it,*it2);
            ++it2;
        }else{
            it->second = max(it->second,it2->second);
            ++it; ++it2;
        }
    }
    while(it2!=otro.end()){
        source.insert(*it2);
        ++it2;
    }
}

void add(ui &x, ll y){
    x += y;
    if (x>=MOD) x-=MOD;
}

ui getb(ll b,const map<int,int> &a){
    ll div=1;
    for(const auto p:a){
        div = div * powmod(p.first,p.second,MOD)%MOD;
    }
    return b * powmod(div,MOD-2,MOD)%MOD;
}

int main() {
    READ(0);
    erat(2000);
    int n;cin>>n;
    vi a(n);
    vector<map<int,int> > f(n);
    FOR(i,n) {cin>>a[i]; fact(a[i],f[i]);}
    map<int,int> lcm=f[0];
    for(int i=1;i<n;++i){
        merge(lcm,f[i]);
    }
    ll b=1;
    for(auto p:lcm) b = b*powmod(p.first,p.second,MOD)%MOD;

    ui ret=0;
    for(int i=0;i<n;++i){
        add(ret,getb(b,f[i]));
    }
    cout << ret;
    return 0;
}



Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>
using namespace std;
int N;
long long P[100001], total, unit, n, san;
int main(){
    scanf("%d", &N);
    for(int i = 0; i < N; ++i){
        scanf("%lld", &P[i]);
        total += P[i];
        unit += i+1;
    }
    n = total/unit;
    if(total % unit != 0){
        printf("NO\n");
        return 0;
    }
    for(int i = 0; i < N; ++i){
        long long d = P[i] - P[(i+N-1)%N] + n* (N-1);
        if(d % N != 0){
            printf("NO\n");
            return 0;
        }
        long long t = d / N;
        if(t < 0 || t > n){
            printf("NO\n");
            return 0;
        }
        san += n-t;
    }
    //printf("%lld %lld\n", san, n);
    if(san != n) printf("NO\n");
    else printf("YES\n");
}


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

using namespace std;
vector<int>pos,baad;

int main()
{
    long long n;
    cin>>n;
    long long arr[5];

    for(int i=0 ; i<5 ; i++) cin>>arr[i];
    sort(arr,arr+5);

    cout<<((n+arr[0]-1)/arr[0])+4<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N=0;
  string X;
  cin >> N>>X;
  string hikaku="ABC";
  int count=0;
  for (int i = 0;i<N-2;i++){    
    if (X.substr(i,3)=="ABC"){
      count++;
    }
  }
  cout << count <<endl;
}

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

using namespace std;

string O, E;


int main()
{
	// 入力
	cin >> O >> E;

	char s[101];
	for (int i = 0;; i++) {
		if (i >= O.size()) break;
		s[i * 2 + 0] = O[i];
		if (i >= E.size()) break;
		s[i * 2 + 1] = E[i];
	}
	s[O.size() + E.size()] ='\0';
	cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

typedef struct node{
	int key;
	int priority;
	struct node *left;
	struct node *right;
}node;

node * Delete(node **,int);
node * _delete(node **,int);

int find(node *p,int x){

	while(p!=NULL){
		if(p->key == x)return 1;
		else if(p->key > x)p=p->left;
		else p=p->right;
	}
	
	return 0;
	
}


node * makenode(int x,int y){
	node *new=malloc(sizeof(node));
	new->key=x;
	new->priority=y;
	new->left=NULL;
	new->right=NULL;
	return new;
}

node *rightRotate(node *p){
	node *q=p->left;
	p->left=q->right;
	q->right=p;
	return q;
}

node *leftRotate(node *p){
	node *q=p->right;
	p->right=q->left;
	q->left=p;
	return q;
}


node* insert(node **t,int key,int priority){
	node *new;
	
	if((*t)==NULL)
		return new=makenode(key,priority);
	if ((*t)->key==key)
		return *t;
	
	if(key < (*t)->key){
		(*t)->left=insert(&(*t)->left,key,priority);
		if((*t)->priority < (*t)->left->priority)
			(*t)=rightRotate((*t));
	}
	else {
		(*t)->right=insert(&(*t)->right,key,priority);
		if((*t)->priority < (*t)->right->priority)
			(*t)=leftRotate((*t));
	}
	
	return *t;
}


node * Delete(node **t,int key){
	if((*t)==NULL)
		return NULL;
		
	if(key < (*t)->key)
		(*t)->left=Delete(&((*t)->left),key);
		
	else if(key > (*t)->key)
		(*t)->right=Delete(&((*t)->right),key);
		
	else return _delete(t,key);
	
	return *t;
}

node * _delete(node **t,int key){
	if((*t)->left==NULL && (*t)->right==NULL)
		return NULL;
	else if((*t)->left==NULL)
		(*t)=leftRotate(*t);
	else if((*t)->right==NULL)
		(*t)=rightRotate(*t);
	else {
		if((*t)->left->priority > (*t)->right->priority)
			(*t)=rightRotate(*t);
		else
			(*t)=leftRotate(*t);
	}
	return Delete(t,key);
}



int main(){
	int q,x,com;
	int num=0;
	node *root=NULL;
	srand((unsigned)time(NULL));
	
	scanf("%d",&q);
	
	for(int i=0;i<q;i++){
		scanf("%d %d",&com,&x);
		
		if(com==0){
			if(!find(root,x)){
				root=insert(&root,x,rand()%200001);
				num++;
			}
			printf("%d\n",num);
		}
		else if(com==1){
			if(find(root,x))printf("1\n");
			else printf("0\n");
		}
		
		else {
			if(find(root,x)){
				root=Delete(&root,x);
				num--;
			}
		}
		
	}
		
	return 0;
	
}


Measured memory_bytes: 7932
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int MOD = pow(10, 9) + 7;
int main() {
  int N; cin >> N;
  vector<int> last(3, -1);
  long long ans = 1;
  REP(i, N) {
    int A; cin >> A;
    int cnt = 0;
    REP(j, 3) {
      if (last[j] + 1 == A) cnt++;
    }
    REP(j, 3) {
      if (last[j] + 1 == A) {
        last[j] = A;
        break;
      }
    }
    ans = (ans * cnt) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int  main(void)
{
	int x, y, kotae;
	char mozi[10];
	scanf("%d %s %d", &x, &mozi, &y);
	if (strcmp(mozi, "-") == 0)
	{
		kotae = x - y;
	}
	else
	{
		kotae = x + y;
	}
	printf("%d", kotae);
        return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define rep(i, n) for(int i = 0;i < n;i++)
#define reprb(i, n) for(int i = n;i >= 0;i--)
#define reps(i, m, n) for(int i = m;i < n;i++)
#define repsb(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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
vector<int> a;

int fBig(int n,int m){
	int z;
	vector<int>b;
	rep(i,n){
		cin>>z;
		b.pb(z);
	}
	z=0;
	rep(i,n){
		rep(j,n){
			if(i!=j&&b[i]+b[j]<=m)	z=max(z,b[i]+b[j]);
		}
	}	
	return z;

}
int main(int argc,char const *argv[]) {
	bool flg=true;
	int n,m,temp;
	while(flg){
		cin>>n>>m;
		if(n==0&&m==0)	break;
		temp=fBig(n,m);
		a.pb(temp);
	}

	rep(i,a.size()){
		if(a[i]==0)	cout<<"NONE"<<endl;
		else cout<<a[i]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3172
#include <iostream>

using namespace std;

int main(void) {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    long long cnt = 0;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if ((500 * i + 100 * j + 50 * k) == x) {
                    cnt++;
                }
            }
        }
    }

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

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

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

    int t = n[0] + n[1] + n[2] + n[3] + n[4];
    int min = (n[0] % 10) == 0 ? 10 : (n[0] % 10);
    int target;
    for (int i= 1; i < 5; i++)
    {
        target = (n[i] % 10) == 0 ? 10 : (n[i] % 10);
        if (min > target)
        {
            if (min > 0)
                t += (10 - min);
            min = target;
        }
        else
        {
            if (target > 0)
                t += (10 - target);
        }
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second
const lint N = (lint)1e5;
int isPrime[N+100] = {1};
lint Count[N+100];
void init(){
    REP(i, N+50) isPrime[i] = 1;
    isPrime[0] = isPrime[1] = 0;
    for(int i=2; i<=N; i++){
        if(!isPrime[i])continue;
        for(int j=2; i*j<=N; j++){
            isPrime[i*j] = 0;
        }
    }
    REP(i, N+1){
        if(isPrime[i] && isPrime[(i+1)/2]) Count[i]++;
    }
    REP(i, N){
        Count[i+1] += Count[i];
    }
}
void debug() {
    REP(i, 100){
        cout << isPrime[i] << " ";
    }
    cout << endl;
    REP(i, 100){
        cout << Count[i] << " ";
    }
    cout << endl;
}
signed main(){
    lint Q; cin >> Q;
    init(); 
    REP(i, Q){
        lint l, r; cin >> l >> r;
        cout << Count[r] - Count[l-1] << endl;
    }
    //debug();
    return 0;
}


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

using namespace std;

int main() {
	int n;
	int maxv = -1;
	int sum = 0;
	int x;
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> x;
		maxv = max(maxv, x);
		sum+=x;
	}
	sum -= maxv;
	if (maxv < sum) cout << "Yes"; else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


string s, t;
int a, b;
string u;


signed main(){
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if(s == u) cout << a-1 << ' ' << b << endl;
    if(t == u) cout << a << ' ' << b-1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main()
{
	int n, a;
	cin >> n >> a;
	
	cout << ((n % 500 <= a) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N, M; cin >> N >> M; pair<int, int>P[M];
  rep(i, M){
    int a, b; cin >> a >> b; a--; b--;
    P[i] = {b, a};
  }
  sort(P, P+M); int Last = -1, ans = 0;
  rep(i, M){
    if(P[i].second<Last) continue;
    else{
      ans++;
      Last = P[i].first;
      //cout << Last << " " << i << endl;
    }
  }
  cout << ans << endl; 
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
	int main()
	{
	ll n;cin>>n;
	map<string,ll> mp;
	for(ll i=0;i<n;i++)
	{
		string s;cin>>s;
		mp[s]++;
	}

	cout<<"AC"<<" "<<"x"<<" "<<mp["AC"]<<"\n";
	cout<<"WA"<<" "<<"x"<<" "<<mp["WA"]<<"\n";
	cout<<"TLE"<<" "<<"x"<<" "<<mp["TLE"]<<"\n";
	cout<<"RE"<<" "<<"x"<<" "<<mp["RE"]<<"\n";

	return 0;
	}


Measured memory_bytes: 3640
from sys import stdin
readline = stdin.readline
# read = stdin.read
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    A, B, C, D = i_map()
    if B <= 0 and D <= 0:
        ans = A * C
    elif B < 0 and C < 0:
        ans = A * C
    elif A < 0 and D < 0:
        ans = A * C
    elif B <= 0 and C >= 0:
        ans = B * C
    elif D <= 0 and A >= 0:
        ans = A * D
    elif A * C > B * D:
        ans = A * C
    else:
        ans = B * D
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 61912
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

const int maxN = 1e6 + 6;
int divi[maxN];

void solve(){
    int n;
    cin >> n;
    const int up = 1e6 + 1;
    for(int i = 0; i <= up; i++){
        divi[i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j * i <= n; j++){
            divi[i * j]++;
        }
    }
    ll res = 0;
    for(int i = 1; i < n; i++){
        res += divi[i];
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7564
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    string s = to_string(n);

    rep(i, 3)
    {
        if (s[i] == '7')
        {
            OP("Yes");
            return 0;
        }
    }

    OP("No");
    return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int ans = 0;
  rep(i, size(S)) {
    if (S[i] != T[i]) {
      ans ++;
    }
  }
  cout << ans << endl;
}

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

int main()
{

	int n; cin >> n;
	int v[n], num=1;
	for(int i=0;i<n;i++){
		cin >> v[i];
		if(v[i] == num){
			num++;
		}
	}

	if(num == 1){
		cout << -1 << endl;
	}else{
		cout << n-(num-1) << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t=1;
	// cin>>t;
	while(t--)
	{
		string s, t;
		cin>>s>>t;
		int ans = INT_MAX, curr = 0;
		for(int i = 0; i < s.size()-t.size()+1; i++)
		{
			curr = 0;
			for(int j = i; j < i+t.size(); j++)
			{
				if(s[j]!=t[j-i]) curr++;
			}
			ans = min(curr, ans);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3640
n = gets.to_i
heep = gets.split.map(&:to_i)

heep.each_with_index{|val, j|
  i = j + 1
  str = "node #{i}: key = #{val}, "
  str << "parent key = #{heep[i/2-1]}, " if j > 0
  str << "left key = #{heep[2*i-1]}, " if 2 * i - 1 < n
  str << "right key = #{heep[2*i]}, " if 2 * i < n
  puts str
}

Measured memory_bytes: 8652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

int main() {
  int N, M, L; cin >> N >> M >> L;
  vector<vector<P>> edge(N);
  rep(i,M) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    edge[a].push_back(P(c, b));
    edge[b].push_back(P(c, a));
  }

  rep(i,N) sort(all(edge[i]));

  Graph move(N);
  rep(i,N) {
    priority_queue<P> pq;
    vi fuel(N, -1);
    pq.push(P(L, i));
    fuel[i] = L;

    while (!pq.empty()) {
      auto p = pq.top(); pq.pop();
      int f, v; tie(f, v) = p;
      if (fuel[v] > f) continue;

      for (auto np : edge[v]) {
        int d, nv; tie(d, nv) = np;
        if (f < d) break;
        if (fuel[nv] >= f-d) continue;
        fuel[nv] = f-d;
        pq.push(P(f-d, nv));
      }
    }

    fuel[i] = -1;
    rep(j,N) {
      if (fuel[j] != -1) move[i].push_back(j);
    }
  }

  Graph query(N, vi(N, -1));
  rep(i,N) {
    queue<int> q;
    q.push(i);
    query[i][i] = 0;

    while (!q.empty()) {
      auto v = q.front(); q.pop();

      for (auto nv : move[v]) {
        if (query[i][nv] != -1) continue;
        query[i][nv] = query[i][v] + 1;
        q.push(nv);
      }
    }
  }

  int Q; cin >> Q;
  rep(i,Q) {
    int s, t; cin >> s >> t; --s; --t;
    if (query[s][t] == -1) cout << -1 << endl;
    else cout << query[s][t] - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 2676
#include <stdio.h>
int main(void){
  int n,a,b,c,x,y[100],i,cnt;
  while(1){
  BACK:
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&x);
    if(!n)
      break;
    for(i=0;i<n;i++)
      scanf("%d",&y[i]);
    cnt=0;
    i=0;
    while(1){
      if(x==y[i])
	i++;
      if(i==n)
	break;
      x=(a*x+b)%c;
      cnt++;
      if(cnt>10000){
	puts("-1");
	goto BACK;
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int array[n];
 
    for (int i = 0; i < n; i++)
        cin >> array[i];

    cout << array[n-1];

    for (int i = n - 2; i >= 0; i--)
        cout << ' ' << array[i];

    cout << endl;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
int main(){
    scanf("%d%d",&n,&m);
    ll ans=1;
    if(abs(n-m)>=2)ans=0;
    else{
        for(int i=1;i<=n;i++)ans=ans*i%mod;
        for(int i=1;i<=m;i++)ans=ans*i%mod;
        if(n==m)ans=ans*2%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n;
    cin>>n;
    int ans=1;
    ll cur=3;
    while(cur<n){
        cur*=3;
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll ans=0;
  string ABC="ABC";
  for(ll i=0;i<N-2;i++){
    string T="";
    for(ll j=i;j<i+3;j++){
      T+=S[j];
    }
    if(T==ABC){
      ans++;
    }
  }
  cout << ans <<  endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<bitset<62>> A(N);
    for(size_t i=0;i<N; i++)
    {
        ll a;
        cin >> a;
        A[i] = bitset<62>(a);
    }
    ll total = 0;
    for(size_t b=0;b<62; b++)
    {
        ll zero_count = 0;
        ll one_count = 0;
        for(size_t i=0;i<N; i++)
        {
            if(A[i][b]) one_count++;
            else zero_count++;
        }
        total += (one_count * zero_count % DIV) * ((ll)pow(2, int(b)) % DIV) % DIV;
    }
    cout << total % DIV << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 2560
#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=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int a=0,b=0,c=0,d=0;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='N') a++;
		if(s[i]=='S') b++;
		if(s[i]=='W') c++;
		if(s[i]=='E') d++;
	}
	if(((a!=0&&b==0)||(a==0&&b!=0))||((c!=0&&d==0)||(c==0&&d!=0))){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<ll> l;
    rep(i, n){
        ll x;
        cin >> x;
        l.push_back(x);
    }

    int cnt = 0;
    rep(i, n-2){
        rep2(j, i+1, n-1){
            if(l[i]==l[j]){
                continue;
            }
            rep2(k, j+1, n){
                if(l[i]==l[k]||l[j]==l[k]){
                    continue;
                }
                int sum = l[i] + l[j] + l[k], maxim = max(l[i], max(l[j], l[k]));
                if(maxim < sum - maxim){
                    cnt++;
                }
            }
        }
    }

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

Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;
class DNotDivisible {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin>>n;
        int a[n];
        map<int,int> m;
        vector<int> v(1000005,0);
        for (int i=0;i<n;i++){
            cin>>a[i];
            m[a[i]]++;
        }
//        for (int i=0;i<n;i++)
//            cout<<a[i]<<" ";
        for (int i=0;i<n;i++){
            if (m[a[i]]>=1){// to avoid repeated marking
                if (m[a[i]]>1)
                    m[a[i]]=-1;//to avoid counting repeated numbers
                for (int j=a[i];j<1000005;j+=a[i]){
                    v[j]++;
                }
            }
        }
//        for (int i=1;i<=24;i++)
//            cout<<v[i]<<" ";
        int count=0;
        for (int i=0;i<n;i++){
//            cout<<a[i]<<": "<<m[a[i]]<<" "<<v[a[i]]<<endl;
            if (m[a[i]]==1&&v[a[i]]==1)
                count++;
        }
        cout<<count;
        v.clear();
	}
};


int main() {
	DNotDivisible solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 17192
a_1 = input().split()
a_2 = input().split()
a_3 = input().split()
a = [a_1,a_2,a_3]
n = int(input())
b = []
for i in range(n):
    b.append(input())



def ana(card,nums):
    for i in range(len(card)):
        for n in nums:
            replaced = ["0" if k == n else k for k in card[i]]
            card[i] = replaced





def bingo_or_not(list):
    flag = 0
    if len(set(list[0])) == 1 or len(set(list[1])) == 1 or len(set(list[2])) == 1:
        flag = 1
    elif list[0][0] == list[1][0] and list[0][0] == list[2][0]:
        flag = 1
    elif list[0][1] == list[1][1] and list[0][1] == list[2][1]:
        flag = 1
    elif list[0][2] == list[1][2] and list[0][2] == list[2][2]:
        flag = 1
    elif list[0][0] == list[1][1] and list[0][0] == list[2][2]:
        flag = 1
    elif list[0][2] == list[1][1] and list[0][2] == list[2][0]:
        flag = 1
    if flag == 0:
        return False
    else:
        return True


ana(a,b)


if bingo_or_not(a) == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

string S[105];

vector<string>vec;

int main(){

	int N,L;

	scanf("%d %d",&N,&L);

	int i;

	for(i=0;i<N;i++){
	cin>>S[i];
	vec.push_back(S[i]);
	}

	sort(vec.begin(),vec.end());

	for(i=0;i<vec.size();i++){
	cout<<vec[i];
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    String a[] = new String[n];
    String b[] = new String[m];
    boolean ju = false;
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.next();
    }
    for(int i = 0 ; i < m ; ++i){
      b[i] = sc.next();
    }
    
    for(int i = 0; i <= n-m; i++){
      for(int j = 0; j <= n-m; j++){
        int count = 0;
        for(int k = 0; k < m; k++){
          if(b[k].equals(a[i+k].substring(j,j+m))){
            count++;
          }
        }
        if(count == m){
          ju = true;
          break;
        }
      }
      if(ju) break;
    }
    
    if(ju) System.out.println("Yes");
    else System.out.println("No");
    
  }
}

Measured memory_bytes: 36992