akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    
    int N;
    bool* prime;
    long long* n;
    long long ans = 1;
    
    cin >> N;
    
    prime = new bool[N+1];
    n = new long long[N+1];
    
    for ( int i = 0; i < N+1; i++ ) {
        prime[i] = true;
        n[i] = 0;
    }
    
    for ( int i = 2; i <= N; i++ ) {
        if ( prime[i] ) {
            for ( int j = 2; i*j <= N; j++ ) {
                prime[i*j] = false;
            }
        }
    }
    
    for ( int i = 2; i <= N; i++ ) {
        if ( prime[i] ) {
            long long count = 1;
            n[i] = 1;
            for ( int j = 2; i*j <= N; j++ ) {
                n[i*j] = n[j] + 1;
                count += n[j] + 1;
            }
            
            ans *= count + 1;
            
            ans = ans % ( 1000000000 + 7 );
            
            for ( int k = 0; k < N+1; k++ ){
                n[k] = 0;
            }
        }
    }
    
    cout << ans << endl;
    
    delete[] prime;
    delete[] n;
    
    return 0;
}

Measured memory_bytes: 256
//#define LOCAL

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define SIZE 50000

using namespace std;

int map[8];
int factor[8];
int result[SIZE];
int dir[] = {-1, 1, -4, 4};

int cantor(){
	int ans = 0;

	for(int i = 0; i < 8; i++){
		int num = 0;
		for(int j = i + 1; j < 8; j++){
			if(map[i] > map[j])
				num++;
		}

		ans += factor[7 - i] * num;
	}

	return ans;
}

void inv_cantor(int num){
	bool visited[8] = {false};

	for(int i = 0; i < 8; i++){
		int divv = num / factor[7 - i];
		num %= factor[7 - i];

		int j;
		for(j = 0; j < 8; j++){
			if(visited[j] == false){
				if(divv == 0)
					break;
				divv--;
			}
		}

		map[i] = j;
		visited[j] = true; 
	}
}

void init(){
	factor[0] = 1;
	for(int i = 1; i < 8; i++)
		factor[i] = factor[i - 1] * i;

	memset(result, 0, sizeof(result));

	/*for(int i = 0; i < 8; i++)
		printf("%d ", factor[i]);
	printf("\n");*/
}

inline void updata(queue<int> &q, int cur,int p0,int p1)
{
    swap(map[p0], map[p1]);
    int s = cantor();
    if(!result[s]){
        result[s] = result[cur]+1;
        q.push(s);
    }
    swap(map[p0], map[p1]);
}

void bfs(){
	result[0] = 1;
	queue<int> q;
	q.push(0);

	while(!q.empty()){
		int temp = q.front();
		q.pop();

		inv_cantor(temp);
		/*for(int i = 0; i < 8; i++)
			printf("%d ", map[i]);
		printf("\n");*/

		int zero_pos;
		for(int i = 0; i < 8; i++){
			if(map[i] == 0){
				zero_pos = i;
				break;
			}
		}

		int r = zero_pos%4;
        if(r) {
            updata(q, temp,zero_pos-1,zero_pos);
        }
        if(r<3){
            updata(q, temp,zero_pos+1,zero_pos);
        }
        updata(q, temp,zero_pos,zero_pos+(zero_pos>3?-4:4));
		/*for(int i = 0; i < 4; i++){
			int new_pos = zero_pos + dir[i];

			if(0 <= new_pos && new_pos < 8 
				&& !(zero_pos == 2 && new_pos == 3) &&
				!(zero_pos == 3 && new_pos == 2)){
				swap(map[zero_pos], map[new_pos]);
				
				int r = cantor();
				if(result[r] == 0){
					result[r] = result[temp] + 1;
					q.push(r);
				}

				swap(map[zero_pos], map[new_pos]);
			}
		}*/
	}

}

int main(void){
#ifdef LOCAL
	freopen("data.in", "r", stdin);
#endif
	init();
	bfs();

	while(scanf("%d", &map[0]) != EOF){
		for(int i = 1; i < 8; i++)
			scanf("%d", &map[i]);

		int x = cantor();
		printf("%d\n", result[x] - 1);
	}

	return 0;
}


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





#define rrep(i,a,b) for(int i=a;i>=b;i--)
int N;
//-----------------------------------------------------------------
int main() {
	cin >> N;

	int l = 1, r = 10000;
	while (l + 1 != r) {
		int c = (l + r) / 2;
		
		int sm = c * (c - 1) / 2;
		if (N <= sm)
			r = c;
		else
			l = c;
	}

	rrep(i, l, 1) {
		if (i <= N) {
			printf("%d\n", i);
			N -= i;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

using namespace std;


int main(){
   ll n;
   cin>>n;
   vector<int> a(n,0);

   rep(i,n){
      cin>>a[i];
   }
   ll ans=a[0];

   rep(i,n){
      ans=gcd(ans,a[i]);
   }

   cout<<ans;

return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
     
int main(){
int n;
int r,g,b;
  
scanf("%d %d %d", &r, &g, &b);

n = 100*r + 10*g + b;
     
if(n % 4 == 0){
   printf("YES\n");
   } else {
    printf("NO\n");
}
     
return 0;
}

Measured memory_bytes: 128
import sys
s= input()
n =len(s)
Al = [chr(_)  for _ in range(97,124)]
if s[0] == "A" and s[2:n-1:1].count("C")==1:
    for i in range(1,n):
        if not(s[i] in Al or s[i]=="C"):
            print('WA')
            sys.exit()
    print('AC')
    sys.exit()
else:
    print('WA')




Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int H,W;
    cin >> H >> W;
    char a[H][W];
    REP(i,H){
        REP(j,W){
            cin >> a[i][j];
        }
    }
    REP(i,W+2){
        cout << "#";
    }
    cout << "\n";
    REP(i,H){
        cout << "#";
        REP(j,W){
            cout << a[i][j];
        }
        cout << "#" << "\n";
    }
    REP(i,W+2){
        cout << "#";
    }
}

Measured memory_bytes: 256
#include <iostream>

int main(){

  using namespace std;
  
  long long x, money;
  money = 100;
  
  cin >> x;
  int i = 0;
  
  if(money>=x) cout<<"0"<<endl;
  while(1){
    i = i+1;
    money = money * 1.01;
    if (money >= x){
      cout << i << endl;
      break;
    }
  }
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,ll> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n), b(n), c(n);
	rep(i, n) cin >>a[i];
	
	rep2(i, 1, n){
		if(a[i-1] < a[i]) b[i]=1; 
		if(a[i-1] > a[i]) b[i]=2; 
	}
	for(auto x :b) cerr<<x<<" "; dbg();
	ll kin=1000;
	rep(i, n){
		if(b[i]==1){
			ll z= kin /a[i-1];
			kin += z *(a[i] - a[i-1]);
		}
		
	}
	cout << kin <<"\n";
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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 a = n / 10;
		int b = n % 10;
		if (a == 9 || b == 9) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int MIN = 1;
    rep(i, n){
        MIN = min(MIN*2, MIN+k);
    }
    cout << MIN << endl;
    return 0;
}

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

int main(){
  long n,a,b; cin>>n>>a>>b;
  long ans;
  if(a>b) ans=0;
  else if(a==b) ans=1;
  else{
    if(n==1) ans=0;
    else ans=(b-a)*(n-2)+1;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
	int k;
	char s[101];
	cin >> k >> s;
	int i;
	for (i = 0; i < k + 1; i++) {
		if (s[i] == 0) {
			cout << s << endl;
			return 0;
		}
	}
	int j;
	for (i = i - 1, j = 0; j < 3; i++, j++) {
		s[i] = '.';
	}
	s[i] = 0;
	cout << s << endl;
	return 0;
}

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

using i64 = int64_t;

constexpr i64 INF = 1e9;

struct Edge {
    i64 from, to, cost;
};

using Graph = vector<vector<Edge>>;

bool bellman_ford(int v, int e, int s, std::vector<i64> &mini, const std::vector<Edge> &edges) {
    for(int i = 0; i < 2*v; i++) {
        bool update = false;
        for (auto e: edges) {
            if (mini[e.from] != INF && mini[e.to] > mini[e.from] + e.cost) {
                mini[e.to] = mini[e.from] + e.cost;
                update = true;
            }
        }
        if (!update)
            break;
        else if(i >= 2*v - 1)
            return false;
    }
    return true;
}

int main(){
    i64 n, m, p;
    cin >> n >> m >> p;
    Graph reversed_graph(n+1, vector<Edge>());
    for(int i=0;i<m;++i){
        i64 a, b, c;
        cin >> a >> b >> c;
        reversed_graph[b].push_back({b, a, c});
    }

    queue<int> que;
    deque<bool> visited(n+1);
    visited[n] = true;
    que.push(n);
    while(!que.empty()){
        int cur = que.front(); que.pop();
        for(auto e: reversed_graph[cur]){
            if(visited[e.to])continue;
            visited[e.to] = true;
            que.push(e.to);
        }
    }

    vector<Edge> edges;
    for(int i=1;i<=n;++i){
        if(!visited[i])continue;
        for(auto e: reversed_graph[i]){
            if(!visited[e.to])continue;
            edges.push_back({e.to, e.from, -e.cost+p});
        }
    }

    vector<i64> mini(n+1, INF);
    mini[1] = 0;
    if(bellman_ford(n, m, 1, mini, edges))cout << max((i64)0, -mini[n]) << endl; 
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>

const int mod = 1e9+7;
const int MAXN = 1e5+5;
const int N = 1e5+5;

int fac[N];
int spf[MAXN]; 

void pre(int p) {
    fac[0] = 1;
    for(int i=1; i<N; i++) {
        fac[i] = (fac[i-1] * i) % p;
    }
}


void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; 
        } 
    } 
} 

vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 

unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCr(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) return 1; 
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}

///////////////////////////////////////////////////////////////////////////////////////////////////
 
void solve(int TC) { 
    int n, a; cin >> n >> a;
    cout << n*n - a;
}
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);
 
 
    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve(i);
    }
    return 0;
 
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e7+10;
const ll MOD=10;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int divisor[MAXN];
void solve()
{
    int N;
    cin>>N;
    for(int u=1;u<=N;u++)divisor[u]=1;
    ll ans=1;
    for(int u=2;u<=N;u++){
        for(int v=u;v<=N;v+=u){
            divisor[v]++;
        }
        ans+=(ll)u*divisor[u];
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

int digit(int x){
  int z=0;
  while(x>0){
    z+=x%10;
    x/=10;
  }
  return z;
}

int main(){
  int n;
  cin>>n;
  int ans=10000;
  for(int i=1;i<=n/2;i++){
    ans=min(ans,digit(i)+digit(n-i));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  
  cin >> A >> B >> C >> D;
  
  if (A+B>C+D) {
    cout << "Left" << endl;
  }
  
  if (A+B==C+D) {
    cout << "Balanced" << endl;
  }
  
  if (A+B<C+D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  const int N = 1000000;
  int table[N+1];
  REP(i,N+1)
    table[i] = INF;
  REP(i,1001) {
    for (int j=0; i*i+j*j*j<=N; ++j) {
      table[i*i+j*j*j] = min(table[i*i+j*j*j], i+j);
    }
  }
  int n;
  while(cin>>n,n) {
    int res = INF;
    REP(i,n+1) {
      if (table[n-i] != INF) {
        res = min(res,  table[n-i] + i);
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 4772
object Main {

	def main(arg:Array[String]) = {
		val Array(n, m, x) = scala.io.StdIn.readLine().trim.split(" ").map(_.toInt);
		val a = scala.io.StdIn.readLine().split(' ').map(_.toInt);
		var left = 0;
		var right = 0;
		for (i <- a) {
			if (i < x) left = left + 1;
			else if (i > x) right = right + 1;
		}
		if (left < right) println(left);
		else println(right);
	}
}

Measured memory_bytes: 25516
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  string s;
  cin >> s;
  
  if (s[s.size()-1] == 's')
    cout << s + "es" << endl;
  else
    cout << s + "s" << endl;

  return 0;
}


Measured memory_bytes: 3628
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

const int N = 1e7;  


bool p[N];
int main(){
   IOS

   ll n; cin>>n;


   vector<ll> pr;

   for(int i = 0; i < N; i++)p[i] = true;

   p[0] = p[1] = false;

    ll sq = sqrt(n);
   for(ll i = 2; i  <= sq; i++){
       if(p[i]){
           for(ll j = i * i; j <= sq; j += i){
               p[j] = false;
           }
       }
   }

   for(ll i = 2; i <= sq; i++)
    if(p[i])pr.pb(i);


    unordered_map<ll, int> mp;
    ll t = n;
    for(ll d : pr){
        if(d * d > t)
            break;
        while(t % d  == 0){
            mp[d]++;
            t /= d;
        }
    }

    if(t > 1)mp[t]++;

    ll ans = 0;

    ll lo, hi, mid, x;
    for(auto it : mp){
        lo = 0, hi = it.second, x = -1;

        while(lo <= hi){
            mid = lo + (hi - lo)/2;
            if((mid * (mid + 1))/2 <= it.second){
                lo = mid + 1;
                x = mid;
            }else{
                hi = mid - 1;
            }
        }

        ans += x;
    }

    cout<<ans<<"\n";

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

class Main
{
    public static void main(String[] args)
    {
	for (int i = 1; i <= 9; i++) {
	    for (int j = 1; j <= 9; j++) {
		System.out.println(i + "x" + j + "=" + i*j);
	    }
	}
    }
}

Measured memory_bytes: 23776
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
    
#####
N, M = map(int, input().split())
uf = UnionFind(N+1)
for i in range(M):
    ui, vi, wi = map(int, input().split())
    uf.unite(ui, vi)
print(sum([t < 0 for t in uf.table[1:]]))

Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;   
typedef unsigned long long ull;
inline long long read()//inline 加速读入
{
	long long x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
 inline void write(ll x)
 {
     char F[200];
      int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
            F[cnt++]=tmp%10+'0';
            tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
 }
struct haha{
	int k,v;
}p[300006];
int cmp(haha x,haha y)
{
	return x.v>y.v;
}
int x,y,a,b,c;
int main() {
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		p[i].v=read();
		p[i].k=1;
	}
	for(int i=a+1;i<=a+b;i++)
	{
		p[i].v=read();
		p[i].k=2;
	}
	for(int i=a+b+1;i<=a+b+c;i++)
	{
		p[i].v=read();
		p[i].k=3;
	}
	sort(p+1,p+1+a+b+c,cmp);
	ll aum=0,ans=0,xx=0,yy=0,zz=0;
	for(int i=1;i<=a+b+c;i++)
	{
		if(p[i].k==1)
		{
			if(xx==x)continue;
			xx++;
		}
		else if(p[i].k==2)
		{
			if(yy==y)continue;
			yy++;
		}
		aum++;
		ans+=p[i].v;
		if(aum==x+y)break;
	}
	cout<<ans<<endl;
}


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

connect = [[] for _ in range(N)]
visited = [False for _ in range(N)]
cord = [0 for _ in range(N)]

for _ in range(M):
    l,r,d = map(int,input().split())
    l -= 1
    r -= 1
    connect[l].append((r,d))
    connect[r].append((l,-d))

def dfs(i):
    q = [i]
    
    while q:
        x = q.pop()
        for nx, d in connect[x]:
            if not visited[nx]:
                visited[nx] = True
                cord[nx] = cord[x] + d
                q.append(nx)
            else:
                if cord[nx] != cord[x] + d:
                    return False
            
    return True

for i in range(N):
    if not visited[i]:
        visited[i] = True
        flag = dfs(i)
    if not flag:
        break

if flag:
    print('Yes')
else:
    print('No')

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

int n, c[200005];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int A;
		scanf("%d",&A);
		c[A] = c[A-1] + 1;
	}
	int M = 0;
	for(int i=1;i<=n;i++) {
		M = max(M, c[i]);
	}
	printf("%d\n",n-M);
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;

    int output = 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) {
                    output++;
                }
            }
        }
    }
    cout << output << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {

    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if(b-a <= k && c-a <= k && d-a <=k && e-a<=k && c-b <=k && d-b<=k && e-b<=k && d-c <=k && e-c <= k && e-d<=k){
        cout << "Yay!\n";
    }else {
        cout << ":(\n";
    }
    
}



Measured memory_bytes: 256
import java.util.Scanner;

//Lightest Mobile
public class Main{

	static long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}

	class R{
		long p, q;
		R l, r, parent;
		long get;
		public R() {
			get = -1;
			l = r = parent = null;
		}
		long solve(){
			long val = get();
			long x = val;
			while(true){
				long s = x/(p+q);
				if(l.f(s*q)&&r.f(s*p))break;
				x+=val;
			}
			return x;
		}
		long get(){
			if(p==0)return 1;
			int k = 1;
			long w1 = l.get();
			long w2 = r.get();
			while(true){
				if((k*q)%w1==0&&(k*p)%w2==0)break;
				k++;
			}
			return k*(p+q);
		}
		boolean f(long x){
			if(p==0)return true;
			if(x%(p+q)!=0)return false;
			long s = x/(p+q);
			return l.f(s*q)&&r.f(s*p);
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			R[] s = new R[n+1];
			for(int i=0;i<=n;i++)s[i]=new R();
			for(int i=1;i<=n;i++){
				s[i].p = sc.nextLong();
				s[i].q = sc.nextLong();
				long g = gcd(s[i].p, s[i].q);
				s[i].p/=g;
				s[i].q/=g;
				int l = sc.nextInt();
				int r = sc.nextInt();
				s[i].l = s[l];
				s[i].r = s[r];
				s[l].parent = s[i];
				s[r].parent = s[i];
			}
			R root = null;
			for(int i=1;i<=n;i++)if(s[i].parent==null)root = s[i];
			System.out.println(root.get());
		}
	}

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

Measured memory_bytes: 12000
n = int(input())
mi = 10**9

def f(n):
    sums = 0
    while n>0:
        sums += n%10
        n //= 10
    return sums

for a in range(1, n+1):
    b = n-a
    if mi > f(a)+f(b) and b>0:
        mi = f(a)+f(b)
print(mi)

Measured memory_bytes: 3060
#include <deque>
#include <iostream>
#include <algorithm>

int main()
{
        using namespace std;
        deque<int> edge;
        int iedge[3];
        int j;
        int a,b,c;

        cin >> j;

        for(int l=0;l<j;l++){
                for(int i=0;i<3;i++){
                        cin >> iedge[i];
                edge.push_back(iedge[i]);
                }

                sort(edge.begin(),edge.end());
                a = edge[0];
                b = edge[1];
                c = edge[2];
                if(c*c == (a*a+b*b))cout << "YES\n";
                else cout << "NO\n";

                edge.clear();

        }

        return 0;
}

Measured memory_bytes: 1176
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <random>
using namespace std;


int main() {
	char c[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

	map<char, char> dic;

	for (int i = 0; i < 26; i++) {
		dic[c[i]] = c[i];
	}
	string str;
	cin >> str;

	for (int i = 0; i < str.length(); i++) {
		dic[str[i]] = '0';
	}

	for (auto i = dic.begin(); i != dic.end(); i++) {
		
		if (i->second != '0') {
			cout << i->second << endl;
			return 0;
		}

	}

	cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 888
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        h: usize,
        w: usize,
        aa: [String; h],
    }

    let mut map = HashMap::new();

    for line in aa {
        for c in line.chars() {
            *map.entry(c).or_insert(0usize) += 1;
        }
    }

    let mut has_center = false;

    let u = 
        match (h % 2 == 1, w % 2 == 1) {
            (true, true) => {
                has_center = true;
                h + w - 1
            },
            (true, false) => {
                w
            },
            (false, true) => {
                h
            },
            (false, false) => {
                0
            }
        };

    let mut u = u as isize;

    for (_, value) in map.iter_mut() {
        let rem = *value % 4;
        *value = rem;

        if rem % 2 != 0 {
            if has_center {
                has_center = false;
            } else {
                println!("No");
                return;
            }
        }

    }

    for (_, value) in map {
        u -= value as isize;
    }

    if u >= 0 && u % 2 == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2168
#include<stdio.h>
	   const int MAX_V = 1000000;
	   int prime[MAX_V+1];
	   int main(){
	   	int i,k,v,m=2;
	   	for(i=m;i<=MAX_V;i++){
	   		prime[i]=1;
	   	}
	   	for(i=m;i*i<=MAX_V;i++){
	   		if(prime[i]){
	   			for(k=2*i;k<=MAX_V;k+=i){
	   				prime[k]=0;
	   			}
	   		}
	   	}
	   	while(scanf("%d",&v)!=EOF){
	   		if(v==0)break;
	   		for(i=v;i>=m;i--){
	   			if(prime[i]==1 && prime[i-2]==1){
	   				printf("%d %d\n",i-2,i);
	   				break;
	   			}
	  	   	}
	  	}
	   	return 0;
	  }

Measured memory_bytes: 6632
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define MN(a,b,c)  min(a,min(b,c))
#define pr         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)   for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
  int n;cin>>n;
  vector <int> v(n);
  f(i,n)cin>>v[i];
  sort(all(v));
  ll ans=0;
  int x=n-1;
  f2(i,n-1,0)
  {
    if(i==(n-1))
      {ans+=v[i];x--;}
    else
    {
      if(x>1)
        {ans+=(2*v[i]);x-=2;}
      else
        {ans+=v[i];x--;}
    }
    if(x==0)break;
  }
  cout<<ans;
 }




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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


template<typename T>
struct UnionFind {
    i64 sz;

    vector<T> parent;
    vector<i64> rank;

    UnionFind(i64 n) : sz(n) {
        parent.assign(n, 0);
        REP(i, n) {
            parent[i] = i;
        }
        rank.assign(n, 1);
    }

    T find(T t) {
        if (parent[t] == t) return t;
        return parent[t] = find(parent[t]);
    }

    bool unite(T t1, T t2) {
        t1 = find(t1);
        t2 = find(t2);
        if (t1 == t2) return false;

        if (rank[t1] < rank[t2]) swap(t1, t2);
        parent[t2] = t1;
        rank[t1] += rank[t2];
        return true;
    }

    bool same(T t1, T t2) {
        return find(t1) == find(t2);
    }
};

using P = pair<i64, i64>;

int main() {
    i64 N, M; cin >> N >> M;
    vector<i64> A(N);
    REP(i, N) { cin >> A[i]; A[i]--; }

    UnionFind<i64> uf(N);
    REP(i, M) {
        i64 a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a, b);
    }

    unordered_map<i64, set<i64>> scc;
    REP(i, N) {
        scc[uf.find(i)].insert(i);
    }

    i64 cnt = 0;
    REP(i, N) {
        if (scc[uf.find(i)].count(A[i]) > 0) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 16164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int a[200005];
map<int,int> now;

int main()
{
	ios::sync_with_stdio(false);
	int n,k,w;
	ll ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans+=now[i-1-a[i]];
		now[a[i]+i-1]++;
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 21348
#include <iostream>
#include <cstdio>
#include <cstring>
#define MN 25100
#define MK 410
#define mod 1000000007

int f[MN][MK], g[MN][MK], F[MN], G[MN];
int n, k, m, cnt[MN], fac[MN], a[MN], mi[MN], inv[MN];

int inc(int a, int b) {return (a += b) >= mod ? a - mod : a;}
int dec(int a, int b) {return (a -= b) < 0 ? a + mod : a;}

void solve(int f[MN][MK], int *F, int s)
{
	f[0][0] = 1;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < k; j++)
		{
			if(j < k - 1) f[i + 1][j + 1] = inc(f[i + 1][j + 1], f[i][j]);
			else f[i + 1][j] = inc(f[i + 1][j], 1ll * f[i][j] * k % mod);
			if(i + 1 >= s) f[i + 1][0] = dec(f[i + 1][0], 1ll * f[i][j] * fac[j + 1] % mod);
			F[i] = inc(F[i], 1ll * f[i][j] * mi[j] % mod);
		}
	}
}

int qpow(int x, int p)
{
	int ans = 1;
	for(; p; p >>= 1, x = 1ll * x * x % mod) if(p & 1) ans = 1ll * ans * x % mod;
	return ans;
}

int main()
{
	scanf("%d%d%d", &n, &k, &m);
	for(int i = 1; i <= m; i++) scanf("%d", &a[i]);
	fac[0] = 1; for(int i = 1; i <= k; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[0] = inv[1] = 1; for(int i = 2; i <= k; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i <= k; i++) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
	mi[0] = 1; for(int i = 1; i <= n; i++) mi[i] = 1ll * mi[i - 1] * k % mod;
	
	int L = 1; bool ok = 0;
	for(int i = 1; i <= m; i++)
	{
		while(cnt[a[i]]) cnt[a[L++]]--;
		cnt[a[i]]++;
		if(i - L + 1 == k) {ok = 1; break;}
	}
	
	int ans = 1ll * mi[n - m] * (n - m + 1) % mod;
	if(ok)
	{
		printf("%d\n", ans);
	}
	else
	{
		memset(cnt, 0, sizeof(cnt));
		int A = 0, B = 0;
		for(int i = 1; i <= m; i++)
		{
			if(cnt[a[i]]) {A = i - 1; break;}
			cnt[a[i]]++;
		}
		if(!A)
		{
			f[0][0] = 1;
			for(int i = 1; i <= n; i++)
			{
				int Sf = 0, Sg = 0;
				for(int j = k - 1; j >= 1; j--)
				{
					Sf = inc(Sf, f[i - 1][j]); Sg = inc(Sg, g[i - 1][j]);
					f[i][j] = inc(f[i][j], 1ll * f[i - 1][j - 1] * (k - (j - 1)) % mod);
					g[i][j] = inc(g[i][j], 1ll * g[i - 1][j - 1] * (k - (j - 1)) % mod);
					f[i][j] = inc(f[i][j], Sf);
					g[i][j] = inc(g[i][j], Sg);
					if(j >= m) g[i][j] = inc(g[i][j], f[i][j]);
					if(i == n) ans = dec(ans, 1ll * g[i][j] * fac[k - m] % mod * inv[k] % mod);
				}
			}
			printf("%d\n", ans);
		}
		else
		{
			memset(cnt, 0, sizeof(cnt));
			for(int i = m; i >= 1; i--)
			{
				if(cnt[a[i]]) {B = m - i; break;}
				cnt[a[i]]++;
			}
			solve(f, F, k - A); solve(g, G, k - B);
			for(int i = 1; i <= n - m + 1; i++)
				ans = dec(ans, 1ll * F[i - 1] * G[n - (i + m - 1)] % mod);
			printf("%d\n", ans);
		}
	}
	
}

Measured memory_bytes: 81024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    pii temp; pii f=pii(0,0);
    pii ans=pii(0,-INF);
    while(cin>>temp.first>>temp.second,temp!=f){
        ans=pii(0,temp.first+temp.second);
        for(int i=1;i<=4;i++){
            cin>>temp.first>>temp.second;
            if(temp.first+temp.second>ans.second){ans.first=i; ans.second=temp.first+temp.second;}
        }
        char u[]={"ABCDE"};
        cout<<u[ans.first]<<" "<<ans.second<<endl;
        }
    
}

Measured memory_bytes: 3052
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		String syaink = sc.nextLine();
       if(Character.isUpperCase(syaink.charAt(0))){
         System.out.println("A");
       }else{
         System.out.println("a");
         }
}
}

Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int x; cin >>x;

    if (x < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    } 

    return 0;
}




Measured memory_bytes: 256
x=int(input())
if 400<=x<600:
  print('8')
elif 600<=x<800:
  print('7')
elif 800<=x<1000:
  print('6')
elif 1000<=x<1200:
  print('5')
elif 1200<=x<1400:
  print('4')
elif 1400<=x<1600:
  print('3')
elif 1600<=x<1800:
  print('2')
else:
  print('1')

Measured memory_bytes: 9180
def main():
    N, L = map(int, input().split())

    if 0 < L:
        s = (N-1) * (2 * L + N) // 2
    elif L + N - 1 < 0:
        s = (N-1) * (2 * L + N - 2) // 2
    else:
        s = N * (2 * L + N - 1) // 2
    print(s)


main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;
constexpr ll modsize = 0;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc() {
	if (modsize == 0) abort();
	fac[0] = 1; fac[1] = 1; inv[1] = 1;
	facinv[0] = 1; facinv[1] = 1;
	for (ll i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modinv(ll a) {
	if (a == 0) abort();
	ll b = mod, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0 || n == 0 && k > 0) return 0;
	if (n == 0 && k == 0) return 1;
	return fac[n + k - 1] * facinv[k] % mod * facinv[n - 1] % mod;
}

ll dp[3010][3010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) rep(j, n) if (a[i] > a[j]) dp[i][j] = 1;
	ll inv2 = (mod + 1) / 2;
	rep(_, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		dp[l][r] = dp[r][l] = (dp[l][r] + dp[r][l])*inv2%mod;
		rep(i, n) {
			if (i != l && i != r) {
				dp[l][i] = dp[r][i] = (dp[l][i] + dp[r][i])*inv2%mod;
				dp[i][l] = dp[i][r] = (dp[i][l] + dp[i][r])*inv2%mod;
			}
		}
	}
	ll ans = 0;
	rep(i, n) {
		rep(j, i) {
			ans += dp[j][i];
			if (ans > mod) ans -= mod;
		}
	}
	cout << ans * modpow(2, q) % mod << endl;
}

Measured memory_bytes: 70912
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don’t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         String input1 = st.nextToken();
         String input2 = infile.readLine();
         char[] arr = input1.toCharArray();
         char[] arr2 = input2.toCharArray();
         int N = arr.length;
         int M = arr2.length;
         //edge
         HashSet<Character> set = new HashSet<Character>();
         for(char c: arr)
            set.add(c);
         for(char c: arr2)
            if(!set.contains(c))
            {
               System.out.println(-1);
               return;
            }
         //define
         HashMap<Character, Integer> map = new HashMap<Character, Integer>();
         int boof = 0;
         for(char c: arr)
         {
            if(!map.containsKey(c))
               map.put(c, boof++);
         }
         //bst
         TreeSet<Integer>[] bts = new TreeSet[set.size()];
         for(int i=0; i < bts.length; i++)
            bts[i] = new TreeSet<Integer>();
         for(int i=0; i < N; i++)
         {
            int dex = map.get(arr[i]);
            bts[dex].add(i);
         }
         //query
         long res = 0L;
         for(int i=0; i < M; i++)
         {
            int check = map.get(arr2[i]);
            int dex = (int)(res%N);
            if(bts[check].last() < dex)
               res += (N-dex)+bts[check].first();
            else
            {
               int next = bts[check].ceiling(dex);
               if(next != dex || i > 0 && arr2[i] != arr2[i-1] || i == 0)
                  res += next-dex;
               else
               {
                  //neighbors
                  int temp = dex+1;
                  if(bts[check].last() < temp)
                     res += (N-temp)+bts[check].first();
                  else
                     res += bts[check].ceiling(temp)-temp;
                  res++;
               }
            }
         }
         System.out.println(res+1);
      }
   }

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

int main() {
  long long a, b, n;
  cin>>a>>b>>n;
  if (b - 1 > n) {
    cout<<(a * n) / b - a * (n / b)<<endl;
    return 0;
  }
  long long s = 1;
  long long x1 = b - 1;
  long long x2 = b * (n / b) - 1;
  long long ans1 = (a * x1) / b - a * (x1 / b);
  long long ans2 = (a * x2) / b - a * (x2 / b);
  cout<<max(ans1, ans2)<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int l,r,d;
  scanf("%d%d%d",&l,&r,&d);
  int ans=r-l+1;
  for(int i=l;i<=r;i++){
    ans-=!!(i%d);
  }
  printf("%d\n",ans);
}

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

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

    for(int i=0; i<s.size(); ++i){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
        if(i + 1 == k) break;
    }

    cout << '1' << endl;
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

fn check(mut x: usize, a: &Vec<usize>, f: bool) -> bool {
    for i in 0..a.len() {
        let rem = x % a[i];
        x -= rem;
    }
    if f {
        x >= 2
    } else {
        x <= 2
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut l = 0;
    let mut r = 1 << 60;
    while r - l > 1 {
        let mid = (l + r) >> 1;
        if check(mid, &a, true) {
            r = mid;
        } else {
            l = mid;
        }
    }

    let ans = r;

    l = 0;
    r = 1 << 60;
    while r - l > 1 {
        let mid = (l + r) >> 1;
        if check(mid, &a, false) {
            l = mid;
        } else {
            r = mid;
        }
    }
    if ans < l {
        println!("{} {}", ans, l);
    } else {
        println!("-1",);
    }
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 100000007;
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2)%bg;	
	h=(h*h)%bg;
	if(y%2==1)
	  return (x*h)%bg;
	else
	  return h%bg;  
}
ll modinv(ll m)
{
	return power(m,bg-2)%bg;
}
ll sum(ll i)
{
	ll s = (i*(i+1))/2;
	return s;
}
int main()
{ 
	ll t;
	t = 1;
	while(t--)
	{
		ll a,b,c,d,e;
		cin>>a>>b>>c>>d>>e;
		ll dd = (c*60 + d - a*60 - b + 24*60)%(24*60) - e;
		cout<<dd; 
	}
	return 0;
}

Measured memory_bytes: 3624
n = gets.to_i
arr = [0]
n.times{arr << gets.to_i}

arr2 = [nil]
i = 1
c = 0
while true
    c += 1
    i = arr[i]
    if i == 2
        puts c
        break
    else
        if arr2[i]
            puts -1
            break
        else
            arr2[i] = true
        end
    end
end

Measured memory_bytes: 3892
#include <iostream>
using namespace std;
const int MAXN = 8005;
char a[MAXN];
int r[MAXN], g[MAXN], b[MAXN], n;

int main()
{
    cin >> n >> a;
    for (int i = n - 1; i >= 0; i--)
    {
        r[i] = r[i + 1] + (a[i] == 'R');
        g[i] = g[i + 1] + (a[i] == 'G');
        b[i] = b[i + 1] + (a[i] == 'B');
    }
    
    long long ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] == a[j]) continue;
            if (a[i] == 'R' && a[j] == 'G') ans += b[j + 1] - (2 * j - i < n && a[2 * j - i] == 'B');
            if (a[i] == 'R' && a[j] == 'B') ans += g[j + 1] - (2 * j - i < n && a[2 * j - i] == 'G');
            if (a[i] == 'G' && a[j] == 'R') ans += b[j + 1] - (2 * j - i < n && a[2 * j - i] == 'B');
            if (a[i] == 'G' && a[j] == 'B') ans += r[j + 1] - (2 * j - i < n && a[2 * j - i] == 'R');
            if (a[i] == 'B' && a[j] == 'R') ans += g[j + 1] - (2 * j - i < n && a[2 * j - i] == 'G');
            if (a[i] == 'B' && a[j] == 'G') ans += r[j + 1] - (2 * j - i < n && a[2 * j - i] == 'R');
        }
    }
    cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 1);
    for (int i = 1; i < N; i++) {
        cin >> A.at(i);
    }
    map<int, int> cnt;
    for (int i = 1; i < N; i++) {
        cnt[A.at(i) - 1]++;
    }

    for (int i = 0; i < N; i++) {
        cout << cnt[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 13552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, n) for(long long (i) = (a); (i) < (n); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define GET(v) cin >> (v)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b , c) cin >> (a) >> (b) >> (c)
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    
    if(s.size() == 2) {
        cout << s << endl;
    }
    else {
        cout << s[2] << s[1] << s[0] << endl;
    }
    
    return 0;
}


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

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;
        (p(m) ? r : l) = m;
    }
    return r;
}

bool solve01(int n, vector<bool> const & a) {
    ll cnt[2] = {};
    map<int, int> acc;
    int base = 0;
    int pos = 0, neg = 0;
    for (int a_i : a) {
        assert (a_i == 0 or a_i == 1);
        if (a_i) {
            neg -= acc[base - 1];
            pos += acc[base - 1];
            base -= 1;
            acc[base + 1] += 1;
            pos += 1;
        } else {
            pos -= acc[base];
            neg += acc[base];
            base += 1;
            acc[base - 1] += 1;
            neg += 1;
        }
        cnt[0] += neg;
        cnt[1] += pos;
    }
    return cnt[1] >= cnt[0];
}

int solve(int n, vector<int> const & a) {
    return binsearch(0, 1e9 + 7, [&](int m) {
        vector<bool> b(n);
        REP (i, n) b[i] = (a[i] > m);
        return not solve01(n, b);
    });
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];
    cout << solve(n, a) << endl;
    return 0;
}


Measured memory_bytes: 7424