akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<limits.h>
#define N 101
#define WHITE 0
#define BLACK 2
#define GRAY 1

typedef struct Node{
  int num;
  int adj[N];
 
}ver;

void enqueue(int);
int dequeue();
void BFS(int);
int Isempty();

int n,D[N],color[N],Q[N],G[N][N],head=1,tail=1;
ver V[N];

int main(){

  int i,j,a,k;


  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&a,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&V[a].adj[j]);
    }
  }

  BFS(1);

  for(i=1;i<=n;i++){
    if(D[i]==INT_MAX)printf("%d -1\n",i);
    else printf("%d %d\n",i,D[i]);
  }
  return 0;
}

void BFS(int s){

  int i,u;

  for(i=s;i<=n;i++){
    color[i]=WHITE;
    D[i]=INT_MAX;
  
  }

  color[s]=GRAY;
  D[s]=0;

  enqueue(s);

  while(Isempty()){

    u=dequeue();

    for(i=1;V[u].adj[i]!=0;i++){
      if(color[V[u].adj[i]]==WHITE){
	color[V[u].adj[i]]=GRAY;
	D[V[u].adj[i]]=D[u]+1;
	enqueue(V[u].adj[i]);
      }
    }
    color[u]=BLACK;
  }
  
}

void enqueue(int x){

  Q[tail]=x;
  if(tail+1==n+1)tail=1;
  else tail++;

}

int dequeue(){

  int x;

  x=Q[head];
  Q[head]=0;
  if(head+1==n+1) head=1;
  else head++;

  return x;
}

int Isempty(){

  if( Q[head] != 0 )return 1;
  else return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

int main(void){
  int d,t,s;
  scanf("%d %d %d",&d,&t,&s);
  if(t*s>=d) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1732
# https://atcoder.jp/contests/abc084/tasks/abc084_d
from bisect import bisect_left, bisect_right
q = int(input())
queries = []
MAX = 0
for _ in range(q):
    l, r = map(int, input().split())
    queries.append((l, r))
    MAX = max([MAX, l, r])
from datetime import datetime
s = datetime.now()
def eratos(x):
    dp = [True] * (x + 1)
    dp[0] = dp[1] = False
    i = 2
    sqrt = x ** 0.5
    while i <= sqrt:
        if dp[i]:
            for j in range(i ** 2, x + 1, i):
                dp[j] = False
        i += 1
    primes = []
    for i in range(len(dp)):
        if dp[i]:
            primes.append(i)
    return primes, dp

primes, dp = eratos(MAX)
sub_prims = []
for p in primes:
    x = (p + 1) // 2
    if dp[x]:
        sub_prims.append(p)

for l, r in queries:
    left = bisect_left(sub_prims, l)
    right = bisect_left(sub_prims, r + 1)
    print(right - left)

Measured memory_bytes: 75860
fn main() {
    let n: i32 = readln();
    println!("{}", 48 - n);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4352
#include <iostream>
#include<cmath>
using namespace std;
int main(void){
    int N,L;
    cin>>N>>L;
    int A[N];
    int T,m,S,P;
    T=L;
    S=abs(L);
    
    A[0]=L;
    
    for(int i=1;i<N;i++){
        A[i]=L+i;
        T=T+A[i];
        
        P=abs(A[i]);
        
        if(P<S){
            S=P;
            m=i;
        
        }
    }
    if(S==abs(L)){
        m=0;
    }
    cout<<T-A[m]<<endl;
    
    return 0;
    
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

int extGCD(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int d = extGCD(b, a%b, y, x);
  y -= a / b * x;
  return d;
}

inline int mod(int a, int m) {
  return (a % m + m) % m;
}

int modinv(int a, int m) {
  int x, y;
  extGCD(a, m, x, y);
  return mod(x, m);
}

const int TMP = 1000000007;

vector<int> a;

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  a.resize(n);
  REP(i, n) cin >> a[i];

  vector<int> s;
  int su = 0;
  REP(i, n) {
    su = su + modinv(i+1, TMP) % TMP;
    s.pb(su);
  }

  int ans = 0;
  REP(i, n) {
    ans = ans + ((a[i] * ((s[n-1-i] + s[i] - 1) % TMP) % TMP) % TMP);
  }

  REP(i, n) {
    ans = (ans * (i + 1)) % TMP;
  }

  cout << ans << endl;
}
 


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

int A[2009], B[2009], C[2009];

int main() {
    long long ans = 0;
    int N, K; scanf("%d%d",&N,&K);
    for(int i=0; i<N; i++) {
        scanf("%d", &A[i]);
        ++C[A[i]];
        int c = 0;
        for(int j=0; j<i; j++) if(A[j] > A[i]) ++B[i];
    }
    for(int i=0; i<N; i++) {
        int s = 0;
        for(int j=2000; j>A[i]; j--) s += C[j];
        ans += 1LL * B[i] * K; ans %= MOD;
        ans += 1LL * K * (K-1) / 2 % MOD * s; ans %= MOD;
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<long, long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
long long dist[100010];
int hw[105][105];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int H, W, N;
	cin >> H >> W >> N;

	vector<int>a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	bool isStart = true;
	int p = 0;
	for (int i = 0; i < H;++i) {
		if (isStart) {
			for (int j = 0; j < W; ++j) {
				if (a[p] == 0)p++;
				hw[i][j] = p + 1;
				a[p]--;
			}
		}
		else {
			for (int j = W-1; 0 <= j; --j) {
				if (a[p] == 0)p++;
				hw[i][j] = p + 1;
				a[p]--;
			}
		}
		isStart = !isStart;
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << hw[i][j];
			if (j != W - 1) cout << ' ';
		}
		cout << endl;
	}
}


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

int main() {
    int x,y,u,v;
    cin >> x >> y ;
    int d = y-(2*x);
    if(d<0) {
        cout << "No";
        return 0;
    }
    else if(d%2 == 1) {
        cout << "No";
        return 0;
    }
    else {
        d/=2;
        v = d;
        u = x-v;
        if(u >=0 && v >=0 ) {
            cout << "Yes";
        } 
        else {
            cout << "No";
        }
        return 0;
    }
    return 0;
}

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

const int MAX=200010;

int main()
{
   int N; cin>>N;
   vector<int> a(N);
   for(int i=0;i<N;i++) cin>>a[i];

   vector<bool> dp(MAX);
   dp[0]=true;
   for(int i=0;i<N;i++){
      if(dp[a[i]-1]) dp[a[i]]=true;
   }

   int ans=-1;
   for(int i=1;i<MAX;i++) if(dp[i]) ans=i;
   if(ans==-1){
      cout<<-1<<endl;
   }else{
      cout<<N-ans<<endl;
   }
   return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b && b < c) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main(){

    string s;
    cin>>s; if(s.find("a")!=string::npos&&s.find("b")!=string::npos&&s.find("c")!=string::npos){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  REP(i, a) {
    if (s[i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (s[a] != '-') {
    cout << "No" << endl;
    return 0;
  }
  REP(i, b) {
    if (s[a + 1 + i] == '-') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    string a,b;
    cin >> a >> b;
    string suma = a+b;
    bool ok = false;
    int ama = stoi(suma);
    for(int i=0; i<ama; i++){
    	if(i*i == ama){
    		ok = true;
    	}
    }
    if(ok){
    	cout << "Yes\n";
    }else{
    	cout << "No\n";
    }
    return 0;
}



Measured memory_bytes: 3604
//Jai Shree Krishna
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};


ll n,c,k;
const int MAXN = (ll)1e6;
ll arr[MAXN];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("/Users/ashish/Desktop/B-large-practice.in.txt", "r", stdin);
    //freopen("/Users/ashish/Desktop/A-large-practice.out.txt", "w", stdout);
    cin>>n>>c>>k;
    loop2(i, n)
    {
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    ll cnt = 0 ;
    loop2(i, n)
    {
        ll j = i;
        while (j-i+1<=c&&j<=n&&arr[j]<=arr[i]+k) {
            j+=1;
        }
        //cout<<j<<" "<<i<<endl;
        cnt+=1;
        i = j-1;
    }
    
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<set<int> > st(26);
    REP(i,n){
        int c = s[i]-'a';
        st[c].insert(i);
    }
    int q;
    cin >> q;
    REP(i,q){
        int id;
        cin >> id ;
        if(id==1){
            int x;
            char c;
            cin >> x >> c;
            x--;
            if(s[x]==c){

            }else{
                int d = (int)(s[x]-'a');
                st[d].erase(x);
                int e = (int)(c-'a');
                st[e].insert(x);
                s[x]=c;
            }
        }else{
            int l,r;
            cin >> l >> r;
            l--; r--;
            int cnt = 0;
            REP(j,26){
                auto it = st[j].lower_bound(l);
                if(it==st[j].end()){
                    continue;
                }
                if((*it)<=r){
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i); 
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int b=1;
  for(int j=0;j<N-1;j++){
    if(a.at(j)>a.at(j+1)){
     b++; 
    }
  }
  cout << b << endl;
}


Measured memory_bytes: 3608
import java.util.Scanner;

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

        int c = 0;
        for(int i = 0; i < n; i++) {
        	if(sc.nextInt() >= h) {
        		c++;
        	}
        }

        System.out.println(c);
        return;
    }
}

Measured memory_bytes: 47576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt(), x = sc.nextInt(), t = sc.nextInt();
		int ans = (n/x)*t;
		if(n%x != 0) {
			ans += t;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a[12]={1, 0, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  string ans="No";
    cin >> x >> y;
    if(a[x-1]==a[y-1]) ans = "Yes"; 
    cout << ans << endl;

}


Measured memory_bytes: 764
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        
        int a,b;
        
        while (true){
            a = sc.nextInt();
            b = sc.nextInt();
            
            if(a == 0 && b == 0){
                break;
            }
            
            if(a > b) {
                System.out.println(b + " " + a);
            }else{
                System.out.println(a + " " + b);
            }
        }
    }
}


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

typedef pair<int, int> P;

int main() {

    ll n,k;
    cin >> n >> k;
    double ans = 0;

    for(ll i = 1; i <= n; i++){
        double p = 1.0/n;
        int tmp = i;
        while(tmp < k){
            tmp *= 2;
            p /= 2;
        }
        ans += p;
    }

    cout << fixed;
    cout << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  vector<int> dp(N,INT_MAX);
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    for (int j = 1; i-j >= 0 && j <= K; j++) {
      dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout << dp.back();
}

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

// In Need Of GOD
// ASHKAN

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define err(q) cerr << #q << " = " << q << '\n';

const int N = 0, INF = 0, MOD = 0;

int a, b, c;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> a >> b >> c;
	
	ll ans = 2 * min(b, c);
	int x = min(b, c);
	b -= x;
	c -= x;
	ans += b;
	x = min(a, c);
	ans += x;
	c -= x;
	a -= x;
	ans += min(c, 1);
	cout << ans << endl;

	return 0;
}

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

int main(){
    
    int x,t;
    
    cin >> x >> t;
    if(x-t<=0)cout << '0' << endl;
    
    else cout << x-t<< endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	int i,j;
	long long int ans=k;
	for(i=1;i<n;i++){
		ans=ans*(k-1);
	}

	printf("%lld",ans);

	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
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 main(){
string s;
cin>>s;
s.erase(unique(s.begin(),s.end()),s.end());
if(s.size()==4)cout<<"Good"<<endl;
else cout<<"Bad"<<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[] list = new int[n - 1];
		for(int i = 0; i < n - 1; i++) {
          list[i] = sc.nextInt();
        }
        int ans = 0;
        int lastV = 0;
        for(int i = 0; i < n - 1; i++) {
            if (i == 0) {
              ans += list[i];
            }
            else if (list[i] > lastV) {
              ans += lastV;
            } else {
              ans += list[i];
            }
            if (i == n - 2) {
              ans += list[i];
            }
          lastV = list[i];
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
def main():
    N, K = map(int, input().split())
    A_i = list(map(lambda x: int(x)-1, input().split()))

    v = [False] * N
    c = 0

    while True:
        if K == 0:
            print(c+1)
            return
        if v[c]:
            break
        v[c] = True
        c = A_i[c]
        K -= 1

    x = c
    y = 0
    while True:
        if K == 0:
            print(c+1)
            return
        c = A_i[c]
        K -= 1
        y += 1
        if x == c:
            break

    K = K % y
    while True:
        if K == 0:
            print(c+1)
            return
        c = A_i[c]
        K -= 1


main()


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

int main() {
  int min=99999;
  char num[3];
  string S;

  cin >> S;

  for(int i=0; i<=S.size()-3; i++) {
    num[0]=S[i]; num[1]=S[i+1]; num[2]=S[i+2];
    if(abs(atoi(num)-753) < min)
      min = abs(atoi(num)-753);
  }
  cout << min << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int H = input[0];
		int W = input[1];
		string[] pix = new string[H];
        for(var i = 0; i < H; i++)
		{
			pix[i] = Console.ReadLine();
		}
		for (var i = 0; i < W+2; i++) { Console.Write("#"); }
		Console.WriteLine();
        for(var i = 0; i < H; i++)
		{
			Console.Write("#");
			Console.Write(pix[i]);
			Console.Write("#");
			Console.WriteLine();
		}
		for (var i = 0; i < W+2; i++) { Console.Write("#"); }
	}
}


Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){
  int sum;
  int a;
  while(1){
    cin>>sum;
    if(sum==0) break;
    for(int i=0;i<9;i++){
      cin>>a;
      sum=sum-a;
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>

#define N 1000001
#define nil NULL

int n;
void maxHeapify(int *A,int i){
  int l,r,hehe,largest;
  l= left(i);
  r = right(i);
  if(l<=n&&A[l] >A[i])
    largest =l;
  else
    largest =i;
  if(r<=n && A[r] > A[largest])
    largest = r;
  if (largest!=i){
    hehe = A[i];
    A[i] = A[largest];
    A[largest] = hehe;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for( i = n/2;i>=1;i--){
    maxHeapify(A,i);
  }
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

int n;
int main(){
  int i,key;
  scanf("%d",&n);
  int A[n];
  for(i=1;i<=n;i++){
    scanf("%d",&key);
    A[i] = key;
  }
  buildMaxHeap(A);
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        int n;
        cin>>n;
        ll temp[n], x=0, sum = 0, s;
        ifr(i, 0, n) cin>>temp[i],x^=temp[i];
        x^=temp[0]^temp[1];
        sum = temp[0] + temp[1];
        if((sum-x)&1) {
            cout<<"-1\n";
            return 0;
        }
        s = (sum - x)>>1;
        vll v; ll a=0, b=0;
        if((sum-x)<0) {
            cout<<"-1\n";
            return 0;
        }
        bool fx, fs;
        ifr(i, 0, 41) {
            fx = (x>>i)&1; fs = (s>>i)&1;
            if(fx && fs) {
                cout<<"-1\n";
                return 0;
            }
            if(fx && !fs) {
                v.pb(i);
                b|=(1ll<<i);
            }
            else if(!fx && fs) {
                a|=(1ll<<i); b|=(1ll<<i);
            }
        }
        // cout<<a<<" "<<b<<endl;
        if(temp[0]<a) {
            cout<<"-1\n";
            return 0;
        }
        reverse(all(v));
        for(auto it:v) {
            if((a|(1ll<<it))<=temp[0]) {
                a|=(1ll<<it);
                b^=(1ll<<it);
            }
        }
        if(a==0) {
            cout<<"-1\n";
            return 0;
        }
        cout<<(temp[0]-a)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int a[100010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",a+i);
	ll ans=0;
	ll prob=0;
	rep(j,0,n-1){
		int len=a[j+1]-a[j];
		prob+=invp(j+1,MOD);
		prob%=MOD;
		ans=(ans+prob*len)%MOD;
	}
	rep(i,1,n)ans=ans*i%MOD;
	printf("%lld",ans);
}

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    for(int i = 0; i < k; i++){
        if(a + i <= b)cout << a+i << endl;
    }

    for(int i = - k + 1; i <= 0; i++){
        if(b + i >= a + k && b + i >= a) cout << b+i << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, k;
	cin >> n >> k;
	
	if (k <= (n-1)*(n-2)/2){
		int temp = (n-1)*(n-2)/2 - k;
		cout << n-1 + temp << endl;
		for (int i = 2; i <= n; i++){
			cout << 1 << " " << i << endl;
 		}
 		if (temp > 0){
 			 int coun = 0;
 			for (int i = 2; i <= n-1; i++){
 				for (int j = i + 1; j <= n; j++){
 					cout << i << " " << j << endl;
 					coun++;
 					if (coun == temp) return 0;
 				}
 			}
 		}
 		return 0;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
const main = (input) => {
  const lines = input.trim().split("\n")
  const [N, M, C] = lines[0].split(" ").map(str => parseInt(str));
  const B = lines[1].split(" ").map(str => parseInt(str));
  let A = lines.slice(2).map(line => line.split(" "));

  const answer = A.reduce((cnt, a) => cnt + (a.reduce((acc, cur, i) => acc + cur * B[i], C) > 0), 0)
  // const answer = A.filter(a =>
  //   a.reduce((acc, cur, i) => acc + cur * B[i], C) > 0
  // ).length;
  console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include <iostream> 
using namespace std;
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
const int N = 1e5+10;
typedef long long ll;
ll a[N];
ll b[N];

int main()
{
	ll n;
	cin >> n;
	
	ll sum = 0;
	
	for (ll i = 0; i < n+1 ; i ++ ) cin >> a[i];
	
	for (ll i = 0; i < n; i ++ ) cin >> b[i];
	
	for (ll i = 0; i < n; i ++ )
	{
		if(a[i] < b[i])
		{
			sum += a[i];
			ll t = b[i] - a[i];
			if(t >= a[i+1])
			{
				sum += a[i+1];
				a[i+1] = 0;
			}
			else
			{
				sum += t;
				a[i+1] -= t;
			}
		}
		else
		{
			a[i] -= b[i];
			sum += b[i];
		}
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int a,b;
  char op;
  while(1){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '+'){
      printf("%d\n", a+b);
    }
    else if(op == '-'){
      printf("%d\n", a-b);
    }
    else if(op == '/'){
      printf("%d\n", a/b);
    }
    else if(op == '*'){
      printf("%d\n", a*b);
    }
    else if(op == '?'){
      break;
      }
  }
  
  return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b;
	for (auto& e : a) {
		cin >> e;
	}
	b = a;
	sort(begin(b), end(b));
	for (auto e : a) {
		cout << (e < b[n / 2] ? b[n / 2] : b[n / 2 - 1]) << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;



class Main{
	public static void main(String[] main) {
		Scanner sc=new Scanner(System.in);
		boolean[] unko=new boolean[101];
		for(int i=0; i<101; i++) {
			unko[i]=false;
		}
		for(int i=0; i<3; i++) {
			unko[sc.nextInt()]=true;
		}
		int kosu=0;
		for(int i=0; i<=100; i++) {
			if(unko[i]) {
				kosu++;
			}
		}
		System.out.println(kosu);
	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n, m, mx = 0, mi = 100000, ans;;
	cin >> n >> m;
	vector<pair<int, int>> lr(m);
	for (int i = 0;i < m;i++) { 
		cin >> lr[i].first >> lr[i].second;
		if (lr[i].first > mx)mx = lr[i].first;
		if (lr[i].second < mi)mi = lr[i].second;
	}
	if (mi - mx + 1 >= 0 && mi - mx + 1 <= n)ans = mi - mx + 1;
	else if (mi - mx + 1 < 0)ans = 0;
	else ans = n;
	
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int m = max(h, w);
  cout << (n + m - 1) / m << endl;
}


Measured memory_bytes: 256
N = gets.to_i
x = []
y = []
h = []


for i in 0..N-1

    x[i],y[i],h[i] = gets.split.map(&:to_i)

end

for c_x in 0..100

    for c_y in 0..100

        checkanswer = 0
        check = 0

        for i in 0..N-1

            if check == 0

                if h[i] >= 1

                    hh = h[i] + (x[i]-c_x).abs + (y[i]-c_y).abs 
                    check += 1

                end

            elsif check == 1

                if h[i] != [hh-(x[i]-c_x).abs-(y[i]-c_y).abs,0].max

                    checkanswer = 1

                end

            end

            if i == N-1 && checkanswer == 0

                answercx = c_x 
                answercy = c_y 
                answerh = hh 

            end

        end

    end

end

puts "#{answercx} #{answercy} #{answerh}"


Measured memory_bytes: 3836
// luogu-judger-enable-o2
var x:char;
    n,i,s,max:longint;
 begin
  readln(n);
   for i:=1 to n do
    begin
     read(x);
     if x='I' then s:=s+1 else s:=s-1;
     if s>max then max:=s;
    end;
  write(max);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int h,w,n; cin>>h>>w>>n;
    // 中心が{y,x}である3*3マスに含まれる黒マス
    map<pair<int,int>,int> mp;
    rep(i,n){
        int a,b; cin>>a>>b;
        for(int y=max(a-1,2);y<=min(a+1,h-1);y++){
            for(int x=max(b-1,2);x<=min(b+1,w-1);x++){
                mp[{y,x}]++;
            }
        }
    }
    long long ans[10]={}; ans[0]=(long long)(h-2)*(w-2);
    for(auto i:mp){
        ans[i.second]++;
        ans[0]--;
    }
    rep(i,10) cout<<ans[i]<<endl;
    return 0;
}


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

typedef long long ll;

const int maxn = 1e6 + 1e2;
std::vector<int> v[maxn];
int a[maxn];
int appearances[maxn];

int dfs(int pos){
	if(v[pos].size() == 0){
		return 0;
	}

	std::vector<int> res(v[pos].size());
	for(int i = 0; i < v[pos].size(); i++){
		res[i] = dfs(v[pos][i]);
	}
	std::sort(res.begin(), res.end(), std::greater<int>());
	int return_value = 0;
	for(int i = 0; i < res.size(); i++){
		return_value = std::max(return_value, res[i] + i + 1);
	}

	return return_value;
}

int main(){
	std::ios::sync_with_stdio(false);

	int n;
	std::cin >> n;

	a[0] = -1;
	for(int i = 1; i < n; i++){
		std::cin >> a[i];
		a[i]--;

		v[a[i]].push_back(i);
	}

	std::cout << dfs(0) << '\n';
}


Measured memory_bytes: 41984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int h, w;
    cin >> h >> w;
    map<char, int> mp;
    rep(i,0,h)rep(j,0,w){
        char c;
        cin >> c;
        mp[c]++;
    }
    int num1 = (h%2)*(w%2);
    int num2 = (h/2)*(w%2)+(w/2)*(h%2);
    int n1 = 0, n2 = 0;
    for(auto it = mp.begin() ; it != mp.end() ; it++){
        if(it->second%4==1||it->second%4==3) n1++;
        if(it->second%4==2) n2++;
    }
    if(n1 == num1 && n2 <= num2) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def factorial_list_mod(n, modp):
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    invs = [pow(fs[-1], modp-2, modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return fs, invs

def comb_mod(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    N,K=mis()
    A=lmis()
    A.sort()
    #
    fs, invs = factorial_list_mod(N, N1097)
    #
    ans = 0
    for i in range(N):
        if K-1 <= i:
            ans += A[i] * comb_mod(i, K-1, N1097, fs, invs)
    A.reverse()
    for i in range(N):
        if K-1 <= i:
            ans -= A[i] * comb_mod(i, K-1, N1097, fs, invs)
    print(ans % N1097)

main()


Measured memory_bytes: 16988
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for ( int i = 0; i < (int)n; i++)

bool search(string k, string p){
  rep(w, p.size()){
    rep(s, p.size()-k.size()+1){
      int cnt = 0;
      rep(i, k.size()){
	if ( s+i+i*w >= p.size() ) break;
	if ( k[i] == p[s+i+i*w] ) cnt++;
      }
      if ( cnt == k.size() ) return true;
    }
  }
  return false;
}

main(){
  int n, cnt = 0;
  string k, p;
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) {
    cin >> p;
    if ( search(k, p) ) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;
using namespace std;
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;
void dfs(vector<int> v) {
    int length = v.size();

    if (length == n) {
        
        int t = 0;
        for (int i = 0; i < q; i++) {

            if (v[b[i] - 1] - v[a[i] - 1] == c[i]) t += d[i];

        }

        ans = max(ans, t);
        return;
    }

    int now = v[length - 1];
    for (int i = now; i <= m; i++) {
        vector<int> v2 = v;
        v2.push_back(i);
        dfs(v2);
    }
    return;
}

int main() {

    int ai, bi, ci, di;

    cin >> n >> m >> q;


    for (int i = 0; i < q; i++) {
        cin >> ai >> bi >> ci >> di;
        a.push_back(ai);
        b.push_back(bi);
        c.push_back(ci);
        d.push_back(di);
    }

    for (int i = 1; i <= m; i++) {

        vector<int> g;
        g.push_back(i);

        dfs(g);

    }

    cout << ans << endl;

}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    ll mat[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            mat[i][j] = 1ll<<60;
        }
    }
    while(m-- > 0){
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        mat[a][b] = mat[b][a] = c;
    }
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(mat[i][k] == 1ll<<60 || mat[k][j] == 1ll<<60)  continue;
                mat[i][j] = min(mat[i][j], mat[i][k]+mat[k][j]);
            }
        }
    }
    vector<int> path[n];
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(mat[i][j] > l)   continue;
            path[i].push_back(j);
            path[j].push_back(i);
        }
    }
    int q;
    cin >> q;
    while(q-- > 0){
        int s, t;
        cin >> s >> t;
        s--, t--;
        vector<int> dp(n, 1<<30);
        queue<int> q;
        q.push(s);
        dp[s] = -1;
        while(!q.empty()){
            int x = q.front();  q.pop();
            for(int next : path[x]){
                if(dp[next] > dp[x]+1){
                    dp[next] = dp[x]+1;
                    if(next == t){
                        break;
                    }
                    q.push(next);
                }
            }
            if(dp[t] != 1<<30)  break;
        }
        cout << (dp[t] == 1<<30 ? -1 : dp[t]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
# include <iostream>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<int> s(n); for (int i=0; i<n; ++i) cin >> s[i];
    sort(s.begin(), s.end());

    int sum = 0; for (int _s: s) sum += _s;
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    vector<bool> dp(sum+1); fill(dp.begin(), dp.end(), false);
    dp[sum] = true; dp[0] = true;
    for (int _s=sum; _s>=0; --_s) {
        for (int _d: s) {
            dp[sum-_d] = dp[sum];
        }
    }

    for (int _s=sum; _s>=0; --_s) {
        if (dp[_s] and _s % 10 != 0) {
            cout << _s << endl;
            return 0;
        }
    }

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



Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <utility>
using namespace std;

typedef struct {
	char mark;
	int num;
} CARD;

void quickSort(CARD a[], int p, int r);
int partition(CARD a[], int p, int r);
bool isStable(const CARD t1[], const CARD t2[], int n);

int main(void)
{
	int n;
	cin >> n;
	CARD *a = new CARD[n];
	CARD *a0 = new CARD[n];

	for (int i = 0; i < n; i++) {
		cin >> a0[i].mark;
		cin >> a0[i].num;
		a[i] = a0[i];
	}

	quickSort(a, 0, n - 1);

	if (isStable(a0, a, n)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	for (int i = 0; i < n; i++) {
		cout << a[i].mark << " ";
		cout << a[i].num << endl;
	}

	delete[] a, a0;
	return 0;
}

int partition(CARD a[], int p, int r)
{
	int x = a[r].num;
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (a[j].num <= x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i + 1], a[r]);
	return i + 1;
}

void quickSort(CARD a[], int p, int r)
{
	if (p >= r) return;

	int q = partition(a, p, r);
	quickSort(a, p, q - 1);
	quickSort(a, q + 1, r);
}

bool isStable(const CARD t1[], const CARD t2[], int n)
{
	char m2[4] = { "\0" };
	int idx = 0;
	for (int i = 0; i < n; i++) {
		m2[idx] = t2[i].mark;
		idx++;
		if (i == n - 1 || t2[i].num != t2[i + 1].num) {
			idx = 0;
			for (int j = 0; j < n; j++) {
				if (t1[j].num == t2[i].num) {
					if (m2[idx] != t1[j].mark) return false;
					idx++;
					if (idx >= 3) break;
				}
			}
			
			idx = 0;
		}
	}
	return true;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define rep(i,a,b)  for (int i = a; i < b; ++i)
#define rrep(i,z,a) for (int i = z; i >= a; --i)
#define rep0(n)     for(int i = 0 ; i < n; ++i )
#define rep1(n)     for(int i = 1 ; i <= n; ++i )
#define pb          push_back
#define sd(x)       scanf("%d",&x)
#define tc          int test;cin>>test; while(test--)
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define mp          make_pair
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl        "\n"
#define spc         " "
#define mem0(a)     memset(a,0,sizeof(a))
#define extime      cout << endl << endl << "____"<<(float)clock() / CLOCKS_PER_SEC << "s____";
#define maxn        998244353
#define mod         1000000007
//#define ll          long long int
//typedef vector<ll>  vll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
void OJ()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int solve()
{
	string s;
	cin >> s;
	int sum = 0;
	rep0(s.size())
	{
		sum += (s[i] - '0') % 9;
		sum %= 9;
	}
	if (sum == 0)cout << "Yes";
	else cout << "No";
	return 0;
}
signed main()
{
	OJ();
	IOS
	//tc
	solve();
	//extime
	return 0;
}

Measured memory_bytes: 3732
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
s=[0]*a
for i in range(a):
  s[l[i]-1]=i+1
for j in s:
  print(j,end=" ")

Measured memory_bytes: 55344
package main
 
import (
	"fmt"
)
 
func main() {
  	var card [3][3]int
	var bingo [3][3]bool
  	for i := 0; i < 3; i++ {
		fmt.Scanf("%d %d %d", &card[i][0], &card[i][1], &card[i][2])
  	}
  	var n int
  	fmt.Scan(&n)
  	for i := 0; i < n; i++ {
		var temp int
		fmt.Scanf("%d", &temp)
		for y := 0; y < 3; y++ {
			for x := 0; x < 3; x++ {
				if card[y][x] == temp {
					bingo[y][x] = true
				}
			}
		}
	}
	res := "No"
	for y := 0; y < 3; y++ {
		if bingo[y][0] && bingo[y][1] && bingo[y][2] {
			res = "Yes"
		}
		if bingo[0][y] && bingo[1][y] && bingo[2][y] {
			res = "Yes"
		}
	}
	if bingo[0][0] && bingo[1][1] && bingo[2][2] {
		res = "Yes"
	}
	if bingo[0][2] && bingo[1][1] && bingo[2][0] {
		res = "Yes"
	}
	fmt.Printf("%s", res)
}

Measured memory_bytes: 512
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef set<int> si;
typedef priority_queue<int> pqi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define loop(i, a) for (int i = 0; i < (a); i++)
#define loop1(i, a) for (int i = 1; i <= (a); i++)
#define loopr(i, a, b) for (int i = (a); i <= (b); i++)
#define dloop(i, a) for (int i = (a) - 1; i >= 0; i--)
#define dloopr(i, b, a) for (int i = (b); i >= (a); i--)
#define tr(it, container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(container.being(), container.end() ,element) != container.end())
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << (a) << "\n"
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) ((int)x.size())
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
const int MOD = 1000000007;
const double PI = acos(-1);

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	//ios::sync_with_stdio(false);cin.tie(NULL);

	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	a*=100; b*=100;
	bool dio1[f+1], dio2[f+1];
	mem(dio1, false); mem(dio2, false); dio1[0] = dio2[0] = true;
	loop1(i, f) {
		if (i - a >= 0) if (dio1[i-a]) dio1[i] = true;
		if (i - b >= 0) if (dio1[i-b]) dio1[i] = true;
		if (i - c >= 0) if (dio2[i-c]) dio2[i] = true;
		if (i - d >= 0) if (dio2[i-d]) dio2[i] = true;
	}
	int sug = 0, wat = a;
	loop(i, f+1) {
		if (!dio2[i]) continue;
		for (int j = ceil(i*100/e); j+i <= f; j++) {
			if (!dio1[j]) continue;
			if (sug*j < wat*i) sug = i, wat = j;
			break;
		}
	}

	cout << sug+wat << " " << sug << endl;

	return 0;
}


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

int main(void){
    vector<string> a(111000);
    for(int i=0;i<111000;i++){
        cin>>a.at(i);
        if(a.at(i)=="0")break;
    }
    int sum;
    for(int i=0;i<111000;i++){
        sum=0;
        for(int j=0;j<(int)a.at(i).size();j++){
            sum+=a.at(i).at(j)-'0';
        }
        if(sum==0)break;
        cout<<sum<<endl;
    }
}



Measured memory_bytes: 3416