akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int n,m,a,b,cost,time,k,p,q,r;
  int t[100][100],c[100][100];

  for(;;){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;

    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
	if(i==j){
	  t[i][j] = 0;
	  c[i][j] = 0;
	}else{
	  t[i][j] = 1000000;
	  c[i][j] = 1000000;
	}
      }
    }

    for(int i=0;i<n;i++){
      scanf("%d %d %d %d",&a,&b,&cost,&time);
      t[a-1][b-1] = time;
      t[b-1][a-1] = time;
      c[a-1][b-1] = cost;
      c[b-1][a-1] = cost;
    }

    for(int x=0;x<m;x++){
      for(int i=0;i<m;i++){
	for(int j=0;j<m;j++){
	  t[i][j] = min(t[i][j],t[i][x] + t[x][j]);
	  c[i][j] = min(c[i][j],c[i][x] + c[x][j]);
	}
      }
    }

    scanf("%d",&k);
    for(int i=0;i<k;i++){
      scanf("%d %d %d",&p,&q,&r);
      if(r)printf("%d\n",t[p-1][q-1]);
      else printf("%d\n",c[p-1][q-1]);
    }
  }
}

Measured memory_bytes: 844
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	x := ReadInts(N)

	ans := 1 << 60
	for i := 0; i+K-1 < N; i++ {
		l := x[i]
		r := x[i+K-1]

		var v int
		if r <= 0 {
			v = -l
		} else if l >= 0 {
			v = r
		} else {
			v = Min(2*(-l)+r, 2*r-l)
		}
		ans = Min(ans, v)
	}
	fmt.Println(ans)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.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 ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    int a[3],ans=0;
    rep(i,3){
        cin >> a[i];
    }
    sort(a,a+3);
    
    ans+=a[1]-a[0];
    ans+=a[2]-a[1];

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

Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 100000

int A[MAX_N];

void swap(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

int partition(int p, int r) {
    int x = A[r];
    int i = p-1;

    int j;
    for (j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            swap(&A[i], &A[j]);
        }
    }
    swap(&A[i+1], &A[r]);

    return i+1;
}

int main(void) {
    int i, n;
    scanf("%d", &n);

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

    int q = partition(0, n-1);
    for (i = 0; i < n; i++) {
        if (i) printf(" ");
        if (i == q) printf("[");
        printf("%d", A[i]);
        if (i == q) printf("]");
    }
    putchar('\n');

    return 0;
}

Measured memory_bytes: 996
//bfs
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<limits>
#include<utility>

#define c11
#ifdef c11
#include<unordered_set>
#include<unordered_map>
#endif

using namespace std;
typedef long long ll;
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define cls(x) memset(x,0,sizeof(x))
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define fore(i, l, r) for(int i = (int) l; i <= (int) r; ++i)
#define rforn(i, n) for(int i = (int) n - 1; i>= 0; ++i)

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

const int INF = 0x3f3f3f3f;
const int SZ = 100;

map<string, int> memo;

int direction[]={1,-1,4,-4};

void bfs() {
  queue<string> q;
  string cur = "01234567";
  memo[cur] = 0;
  q.push(cur);
  while(!q.empty()) {
    cur = q.front(); q.pop();
    int pos = 0;
    forn(i, 8) {
      if(cur[i] == '0') {
        pos = i;
        break;
      }
    }

    forn(d, 4) {
      int nxt = pos + direction[d];
      if(nxt >= 0 && nxt < 8 && !(pos == 3 && d == 0) && !(pos == 4 && d == 1)) {
        string update = cur;
        swap(update[pos], update[nxt]);
        if(memo.find(update) == memo.end()) {
          memo[update] = memo[cur] + 1;
          q.push(update);
        }
      }
    }
  }
}

int main() {
  bfs();
  string input;
  while(getline(cin, input)) {
    input.erase(remove(input.begin(), input.end(), ' '), input.end());
    cout << memo[input] << endl;
  }
	return 0;
}


Measured memory_bytes: 5344
#include <iostream>
#include <algorithm>
#include <string.h>

int n;
int m;
int ms[50];
int INF = 1000000000;
int dp[50010];

int pay ( int remained )
{
	if ( remained == 0 )
		return 0;
	if ( remained < 0 )
		return INF;
	if ( dp[remained] != -1 )
		return dp[remained];

	int result = INF;
	for ( int i = 0; i < m; ++i )
	{
		result = std::min( result, pay( remained - ms[ i ] ) + 1 );
	}
	return dp[ remained ] = result;	
}

int main()
{
	memset( dp, -1, sizeof( dp ) );
	std::cin >> n >> m;
	for ( int i = 0; i < m; ++i )
		std::cin >> ms[ i ];

	std::cout << pay( n )  << std::endl;
	return 0;
}

Measured memory_bytes: 3704
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf  1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
//*//signed main(){
//    int n,s;cin>>n>>s;
//    for(int i=2;i*i<=n;i++){
//        int count=0;
//        int t=n;
//        while(t){
//            count+=t%i;
//            t/=i;
//        }
//        if(count==s){
//            cout<<i<<endl;
//            return 0;
//        }
//    }
//    for(int i=1;i*i<=n;i++){
//        int h=(n-s)/i+1;
//        int count=0;
//        int t=h;
//        while(t){
//            count+=t%h;
//            t/=h;
//        }
//        if(count==s){
//            cout<<h<<endl;
//            return 0;
//        }
//    }
//    cout<<-1<<endl;
//    return 0;
//            }
signed main(){
    int n,d;cin>>d>>n;
    if(n!=100)rep(i,0,d)n*=100;
    else if(d==0)n=101;
    else if(d==1)n=10100;
    else n=1010000;
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nhw = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nhw[ 0 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nhw[ 1 ], nhw[ 2 ], abs );
}

auto solve( long h, long w, long[ 2 ][] abs )
{
	auto ans = 0L;
	foreach( ab; abs )
	{
		if( h <= ab[ 0 ] && w <= ab[ 1 ] ) ans++;
	}
	return ans;
}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
#define standardVar ll n,m,k,num,num1,num2,flag=0
#define nn <<"\n"
#define __ <<" "<<
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define ittr(x,v) for(auto x=v.begin();x!=v.end();x++)                  //COMMON FOR LOOP (ITERATOR)
#define itr(x,n) for(int x=0;x<n;x++)                                   //COMMON FOR LOOP (VARIABLE)
#define itrab(x,a,b) for(int x=a;x<b;x++)                               //FOR LOOP WITH SPECIFIED START/END
#define itpr(v) ittr(x,v)cout<<*x<<" "; cout nn                         //PRINTS VECTOR,SET,MAP OF INTS
#define itppr(v) ittr(x,v)cout<<(*x).ff<<" "<<(*x).ss<<"  "; cout nn    //PRINTS VECTOR,SET,MAP OF PAIRS
#define sz(x) (ll)((x).size())

#define pi   3.14159265359
#define dTor(x) ((x)*pi)/180.0
#define INF  1000000000
#define INFF 1000000000000000000

typedef long long int ll;               //TYPEDEFS
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef map<ll,ll> ml;
typedef set<ll> sl;
typedef string str;
typedef pair<ll, ll> pl;
typedef vector< pl > vpl;
typedef map<pl,ll> mpl;
typedef set< pl > spl;
typedef vector<str> vst;
typedef vector<vl> vvl;
typedef vector<vb> vvb;

const ll M=1000000007;                  //COMMON MODULO PRIMES
const ll N=998244353;

ll power(ll x, ll y, ll p){             //MODULAR EXPONENTIATION
    ll res=1;
    x=x%p;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x)%p;
        y=y>>1;
        x=(x*x)%p;
    }
    return res;
}
ll inv(ll x, ll m){                     //FERMAT INVERSE
    return power(x,m-2,m);
}
ll nCr(ll n, ll r){                     //nCr MOD P  
    vl fac(10);
    if (r==0) 
        return 1;
    return (fac[n]*inv(fac[r],M)%M*inv(fac[n-r],M)%M)%M;
}
struct comp{                            //COMPARISON ON PAIRS
    template<typename T>        
    bool operator()(const T &a, const T &b){
        if (a.ff==b.ff)
            return (a.ss<b.ss);
        else
            return (a.ff<b.ff);
    }
};
bool mod(const pair<ll,ll> &a, const pair<ll,ll> &b){   //COMPARATOR FOR PAIRS (SORTING)
    if(a.ff!=b.ff)
        return (a.ff<b.ff);
    else
        return (a.ss>b.ss);
}
void sieve(){                           //SIEVE OF ERATOSTHENES
    vector<bool> pr(1000000+1,1);
    for(ll i=2;i*i<=1000000;i++)
        if(pr[i]==1)
            for(ll j=i*i;j<=1000000;j+=i)
                pr[j]=0;
}
bool isValid(ll i, ll j, ll n, ll m){   //CHECKS FOR OVERFLOW
    if(i>=0&&i<n&&j>=0&&j<m){
        return true;
    }
    return false;
}

//MAIN FUNCTION STARTS HERE

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    standardVar;
    cin>>n>>m>>k;
    cout<<((n+m-1)/m)*k;
    return 0;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool DP(vector<int> dx,int x,int n){
    bool dp[4*n][dx.size()+1];
    dp[2*n][0]=true;
    for(int i=0;i<2*n;i++) dp[i][0]=false;
    for(int i=2*n+1;i<4*n;i++) dp[i][0]=false;
    for(int i=1;i<dx.size()+1;i++){
        for(int j=n;j<3*n;j++){
            dp[j][i]=(dp[j+dx.at(i-1)][i-1]||dp[j-dx.at(i-1)][i-1]);
        }
    }
    return dp[x+n*2][dx.size()];
}
int main(void){
    string s;cin>>s;
    int n=s.size(),x,y;cin>>x>>y;
    vector<int> dx,dy,t;
    
    for(int i=0;i<n;i++){
        if(s.at(i)=='T') t.push_back(i);
    }
    if(t.size()==0){
        if(n==x&&0==y) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
    else{
        x-=t.at(0);
        int i=1;
        for(;i<t.size();i++){
            if(i%2==0){
                dx.push_back(t.at(i)-t.at(i-1)-1);
            }
            else if(i%2==1){
                dy.push_back(t.at(i)-t.at(i-1)-1);
            }
        }
        i--;
        if(i%2==1){
            dx.push_back(n-t.at(i)-1);
        }
        else if(i%2==0){
            dy.push_back(n-t.at(i)-1);
        }        
        /*for(auto j:dx) cout<<j<<endl;
        for(auto j:dy) cout<<j<<endl;*/
        bool flagx=DP(dx,x,n),flagy=DP(dy,y,n);
        bool flag=flagx&&flagy;
        //cout<<flagx<<" "<<flagy;
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
}


Measured memory_bytes: 123264
#include <iostream>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

typedef unsigned long long ull;

const ull B = 100000007ULL;
const ull invB = 5840524504965430455ULL;

int n, m, l = 0, r = 0;
ull h, data[300001];
string str, ope;
set<ull> ans;

main(){
  cin >> n >> m;
  data[0] = 1;
  for(int i=1;i<=n;i++) data[i] = data[i-1] * B;
  cin >> str;
  h = str[0];
  for(int i=0;i<m;i++){
    cin >> ope;
    if(ope == "L++"){
      h = h - str[l] * data[r - l];
      ++l;
    }
    if(ope == "L--"){
      --l;
      h = h + str[l] * data[r - l];
    }
    if(ope == "R++"){
      h = h * B + str[++r];
    }
    if(ope == "R--"){
      h = (h - str[r]) * invB;
      --r;
    }
    ans.insert(h);
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 17880
import sys
input = sys.stdin.readline
import numpy as np

A, B, C, K= map(int, input().split())
ans = 0

if A < K:
    ans += A
    K -= A
else:
    ans += K
    K -= K
    
if (K != 0) and (B < K):
    K -= B
else:
    K -= K

if (K != 0) and (C < K):
    K -= C
    K -= C
else:
    ans -= K
    K -= K

print(ans)

Measured memory_bytes: 26876
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>

using namespace std;

int binarySearch(int a[], int len, int key) {

	int left = 0, right = len;
	
	while (left < right)
	{
		int mid = (right + left) / 2;
		if (key == a[mid]) return 1;
		else if (key < a[mid]) right = mid;
		else left = mid + 1;
	}
	return 0;

}

int main() {
	
	int n; cin >> n;
	int* arr = new int[n];
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}

	int count = 0;
	int q; cin >> q;
	for (int i = 0; i < q; i++)	{
		int key;
		scanf("%d", &key);
		count += binarySearch(arr, n, key);
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

void solve()
{
    ll d[5];
    mset(d);
    rep(i,0,3)
    {
        ll a,b; cin>>a>>b;
        d[a]++,d[b]++;
    }
    ll d1=0,d2=0;
    rep(i,1,5) { if(d[i]==1) d1++; else if(d[i]==2) d2++; }
    if(d1==2 && d2==2) { cout<<"YES"; exit(0); }
    cout<<"NO";
}

int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
  char c, cp;
  int ans;
  int count=0;
  int len[100000];
  int sum=0, psum=0;
  int ind=0;
  int temp;
  while(c!='0'&&c!='1'){
    scanf("%c", &c);
  }
  cp=c;
  count=1;
  sum++;
  while(cin>>c){
    if(c=='0' || c=='1'){
      sum++;
      if(c!=cp){
        cp=c;
        len[ind]=count;
        count=1;
        ind++;
      }else{
        count++;
      }
    }
  }
  len[ind]=count;
  ans=sum;
  for(int i=0; i<ind;i++){
    psum+=len[i];
    temp=(sum-psum<psum)?psum:sum-psum;
    ans=(ans<temp) ? ans :temp;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll dp[101][100001];
ll w[101], v[101];

ll q(int i, ll val) {
    if(val == 0) return 0;
    
    if(i == n) return 1e12;
    
    if(dp[i][val] != -1) return dp[i][val];
    
    ll an = 1e12;
    
    if(v[i] <= val) {
        ll te = q(i + 1, val - v[i]);
        if(te != 1e12)
    	    an = min(an, w[i] + te);
    }
    
    ll tm = q(i + 1, val);
    
    if(tm != 1e12)
        an = min(an, tm);
    
    return dp[i][val] = an;
}

int main() {
    int we;
    cin>>n>>we;
    for(int i = 0; i < n; i++) cin>>w[i]>>v[i];
    
    memset(dp, -1, sizeof(dp));
    
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 100001; j++) {
          q(i, j);
      }
    }
    
    int an;
    
    for(int j = 100000; j >= 0; j--) {
      if(dp[0][j] != -1 && dp[0][j] <= we) {
    	    an = j;
            break;
        }
    }
    
    cout<<an<<endl;
  
    return 0;
}

Measured memory_bytes: 79104
mod = 10**9 + 7
max_num = 2 * 10**5 + 3
facts = [1 for i in range(max_num)]
invs = [1 for i in range(max_num)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max_num):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,k):
    return facts[n]*invs[k] * invs[n-k] % mod

def nHk(n, k):
  return nCk(n-1+k, n-1)

N, K = map(int, input().split())
ans = 0
for i in range(K, N + 2):
    res = (i*(2*N-i+1))//2 - (i**2-i)//2 + 1
    ans += res
    ans %= mod
print(ans)

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

int main() {
    int n,a,b; cin >> n >> a >> b;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int d = i; int sum = 0;
        while (d > 0) {
            sum += d%10;
            d /= 10;
        }
        if (a <= sum && sum <= b)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
int main(){
  int N;
  std::cin >> N;
  long double d=0, x[9], y[9];
  int i=0;
  while(std::cin>>x[i]>>y[i])++i;
  for(int i=0;i<N-1;++i){
    for(int j=i+1;j<N;++j){
      d += std::sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
    }
  }
  d = 2*d/N;
  std::cout << std::setprecision(10) << d;
}
  

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

//??????????????§
int a,d,n;

//prime?????¨???true
bool isPrime[1001];

//prime number ??????
int prime[200];

//2~1000????????§??????prime number????????°
int primeNum=0;

int main() {
	//?????????
	for(int i=0;i<2;i++)isPrime[i]=false;
	for (int i = 2; i < 1001; i++)isPrime[i]=true;
	
	//??????1000??\???????´???°??¨???????????????
	for (int i = 2; i < 1001; i++) {
		//????????°???????´???°?????£?????´???
		if (isPrime[i]) {
			//??????????????°????´???°??????????????¨?±????????????????
			int j=2;
			while (i*j < 1001) {
				isPrime[i*j]=false;
				j++;
			}
		}
	}

	//?´???°??????????§????????????????
	for (int i = 2; i < 1001; i++) {
		if(isPrime[i])prime[primeNum++]=i;
	}

	while (true) {
		//??\???
		cin>>a>>d>>n;
		//??????
		if(a==0 && d==0 && n==0)break;

		//??\????????????????´???°?????????????????????
		
		//????????§????????????????´???°????????°
		int primeCount=0;

		//?´???°?????????????????????
		bool isPrimeB=true;

		if(a==1)a+=d;

		while (true) {
			//?????????
			isPrimeB=true;
			//1000??\???????´???°??§?????£????????????
			for (int i = 0; i < primeNum; i++) {
				//??????????????????
				if(a%prime[i]==0){

					//????????°????????£????????????(?´???°?????????????????§)
					if(a!=prime[i])isPrimeB = false;
					break;
				}
			}
			//?´???°?????´???
			if(isPrimeB){
				primeCount++;
				if(primeCount==n)break;
			}
			
			//?¬??????????????????????
			a+=d;
		}

		//n??????????´???°???????????£????????§???????????????
		cout<<a<<endl;


	}

	return 0;
}

Measured memory_bytes: 2980
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	static int count=1;
	static boolean[] isPrime = new boolean[10001];
	static int[] primes = new int[100000];
	static int[] sum = new int[100000];
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 0; i*i<=isPrime.length; i++){
			if(isPrime[i]){

				for(int j = i+i; j < isPrime.length; j+=i){
					isPrime[j]=false;
				}
			}
		}
		for(int i = 0; i < isPrime.length;i++){
			if(isPrime[i]){
				primes[count]=i;
				sum[count]=sum[count-1]+primes[count];
				count++;				
			}
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			int cnt=0;
			if(n==0){
				break;
			}
			for(int i = 0; i < count; i++){
				for(int j = i+1;j < count; j++){
					if(sum[j]-sum[i]==n){
						cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int a[100010];

int main(){
	int n;
	cin>>n;
	rep(i, n) cin>>a[i];
	vi s(n+1), t(1);
	for(int i = 1; i < n; i++){
		if(a[i] != a[i-1]) s[i] = s[i-1]+1;
		else t.pb(i);
	}
	int ans = 2;
	if(t.size()==1) ans = n;
	t.pb(n);
	for(int i = 0; i + 1 < t.size(); i++){
		int tmp = t[i+1]-t[i];
		//cout<<" "<<i<<" "<<tmp;
		if(i + 2 < t.size()) tmp += t[i+2]-t[i+1];
		if(i + 3 < t.size()) tmp += t[i+3]-t[i+2];
		//cout<<" "<<tmp<<endl;
		ans = max(tmp, ans);
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 3936
N = int(input())
S = list(input())

countE = S.count('E')
countW = 0
min = countE + countW
for i in range(N):
    if S[i] == 'E':
        countE -= 1
    elif S[i] == 'W':
        countW += 1

    if countE + countW < min:
        min = countE + countW

print(min)

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

vector<int> data;
vector<int> diff_weight;

int find( int x )
{
	if ( data[ x ] < 0 ) {
		return x;
	}
	else {
		int par = data[ x ];
		data[x] = find( data[ x ] );
		diff_weight[ x ] += diff_weight[ par ];
		return data[ x ];
	}
}

int weight( int x )
{
	find( x );
	return diff_weight[ x ];
}

bool unite( int x, int y, int w )
{
	w += weight( x );
	w -= weight( y );
	x = find( x );
	y = find( y );
	bool no_union = x != y;
	if( no_union ) {
		if ( data[ x ] > data[ y ] ) {
			swap( x, y );
			w = -w;
		}
		data[ x ] += data[ y ];
		data[ y ] = x;
		diff_weight[ y ] = w;
	}
	else {
		if ( weight( y ) - weight( x ) == w ) {
			return true;
		}
	}
	return no_union;
}

int main()
{
	int ans = 0;
	int n, m;
	int l, r, d;

	cin >> n >> m;

	data.resize( n, -1 );
    diff_weight.resize( n, 0 );

	for( int i = 0; i < m; i++ ) {
		cin >> l >> r >> d;
		l--;
		r--;
		bool bret = unite( l, r, d );
		if( bret == false ) {
			ans = 1;
			break;
		}
	}

	if( ans == 0 ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 200020;
int a[N], n;
int main() {
	cin >> n; repn(i, n) cin >> a[i];
	int mn = INF, ans = 0;
	repn(i, n) if (a[i] <= mn) mn = a[i], ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for (int i = 0; i < b; i++)
            if (a * (i + 1) % b == c) {
                System.out.println("YES");
                return;
            }
        System.out.println("NO");
    }
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

vector<ll> dijkstra(ll s, vector<vector<pll>>& cost_map){
    vector<ll> d(cost_map.size(), MAXINF);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, s));
    d[s] = 0;
    while(!q.empty()){
        pll f = q.top();q.pop();
        if(d[f.se] < f.fi) continue;
        for(auto&& v : cost_map[f.se]){
            ll value = f.fi + v.se;
            if(value < d[v.fi]) {
                q.push(pll(d[v.fi] = f.fi + v.se, v.fi));
            }
        }
    }
    return d;
}

int main(void)
{
    ll n,m;
    cin >> n >> m;
    ll s,t;
    cin >> s >> t;
    s--;t--;

    vector<vector<pll>>Y(n);
    vector<vector<pll>>S(n);
    REP(i, m){
        ll u,v;
        cin >> u >> v;
        ll a,b;
        cin >> a >> b;
        u--;v--;
        Y[u].pb(make_pair(v, a));
        Y[v].pb(make_pair(u, a));
        S[u].pb(make_pair(v, b));
        S[v].pb(make_pair(u, b));
    }

    auto yen = dijkstra(s, Y);
    auto snk = dijkstra(t, S);

    vector<ll> ans(n+1,MAXINF);
    RREP(i, n){
        ans[i]=min(ans[i+1], yen[i] + snk[i]);
    }

    // DEBUG_VEC(yen);
    // DEBUG_VEC(snk);
    // DEBUG_VEC(ans);

    REP(i, n){
        pr(1'000'000'000'000'000 - ans[i]);
    }
}

Measured memory_bytes: 19012
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nの約数を返す関数.sortされてない.
vector<long long int> divisors(long long int n){
	vector<long long int> res;
	for (long long int i = 1; i * i <= n;i++){
		if (n % i == 0){
			res.push_back(i);
			if(i * i != n){
				res.push_back(n / i);
			}
		}
	}
	return res;
}


int main()
{
	long long int n;
	cin >> n;
	int ans = 0;

	for (auto x : divisors(n))
	{
		if (x == 1)
			continue;
		long long int temp = n;
		while(temp%x == 0)
			temp /= x;
		temp %= x;
		if (temp == 1)
			ans++;

	}
	ans += divisors(n - 1).size() - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double a,l,x;
	while(cin>>a>>l>>x){
		printf("%.10lf\n",sqrt(l*l-(a/2)*(a/2))*a/2+sqrt(((l+x)/2)*((l+x)/2)-(l/2)*(l/2))*l);
	}
	return 0;
}

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

const int nMatch[10] = {0,2,5,5,4,5,6,3,7,6};

string append(string s, string t){
    if(s=="") return t;

    int n = s.length();
    for(int i=0; i<n; i++){
        if(s[i] <= t[0]){
            s.insert(i,t);
            break;
        }
    }

    return s;
}

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

    vector<string> dp(N+1,"");
    for(int i=0; i<M; i++){
        int ii = nMatch[A[i]];
        if(ii > N) continue;
        if(dp[ii] == "" || dp[ii] < to_string(A[i])) 
            dp[ii] = to_string(A[i]);
    }

    for(int i=1; i<=N; i++){
        if(dp[i]=="") continue;
        for(int j=0; j<M; j++){
            int nxt = i + nMatch[A[j]];
            if(nxt > N) continue;
            if(dp[nxt] == "" || dp[nxt].length() < dp[i].length() + 1){
                dp[nxt] = append(dp[i], to_string(A[j]));
            }else if(dp[nxt].length() == dp[i].length() + 1){
                string tmp = append(dp[i], to_string(A[j]));
                if(dp[nxt] < tmp) dp[nxt] = tmp;
            }
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 53632
n, l = map(int, input().split())
value_list = [i + l for i in range(n)]
min_num = min(value_list)
max_num = max(value_list)
if min_num <= 0 and max_num > 0:
    print(sum(value_list))
elif max_num <= 0:
    print(sum(value_list) - max_num)
elif min_num >= 0:
    print(sum(value_list) - min_num)

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

int main(int argc, char const* argv[])
{
    int n, m;
    std::cin >> n >> m;

    auto vec = std::vector<int>(n, 0);

    for (int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        vec[a - 1]++;
        vec[b - 1]++;
    }

    for (auto v : vec) {
        std::cout << v << std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int n,cnt=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if(i&1&&a[i]&1) cnt++;
	}
	cout << cnt << endl;
	return 0;
} 

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

int main()
{
	int a,b;
	cin >> a >> b;
	if (a<b) {
		cout << "a < b" << endl;
	}
	if (a > b) {
		cout << "a > b" << endl;
	}
	if(a==b) {
		cout << "a == b" << endl;
	}
	return 0;
}

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

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

  int n;
  cin >> n;

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

  int now = 1, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == now) ++now;
    else ++ans;
  }

  if (ans == n) cout << -1 << '\n';
  else cout << ans << '\n';

  return (0);
}

Measured memory_bytes: 3964
//鏁扮粍榛樿浠?寮€濮嬬紪鍙?
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,dk,q,vn,a[N],nmax;
struct st{int v,pos;}s[N];
bool cmp1(st a,st b){return a.v>b.v;}
int v[N],fa[N],t[N],siz[N];
int find(int x){return fa[x]==x? x : fa[x]=find(fa[x]);}
void update(int k,int f){nmax+=f*max( 0 , min(v[k],siz[k]-dk+1) );}
void insert(int k){
	v[k]=t[k]=siz[k]=1;
	if(t[k-1]) {
		update(find(k-1),-1);
		siz[k]+=siz[fa[k-1]],v[k]+=v[fa[k-1]],fa[fa[k-1]]=k;
	}
	if(t[k+1]){
		update(find(k+1),-1);
		siz[k]+=siz[fa[k+1]],v[k]+=v[fa[k+1]],fa[fa[k+1]]=k;
	}
	update(find(k),1);
}
void erase(int k){
	update(find(k),-1);
	v[fa[k]]--;
	update(fa[k],1);
	t[k]=2;
}
bool judge(){
	int l,r=0; nmax=0;
	for(int i=1;i<=n;i++) fa[i]=i,v[i]=t[i]=0;
	for(l=1;l<=n;erase(s[l++].pos)){
		while(s[l].v-s[r+1].v<=vn&&r<n) 
			{insert(s[++r].pos);}
		if(nmax>=q) return 1;
	}
	return 0;
}
int main()
{
	
	scanf("%d%d%d",&n,&dk,&q);
	int l=0,r=0;
	for(int i=1;i<=n;i++) {scanf("%d",&a[i]);r=max(r,a[i]);}
	for(int i=1;i<=n;i++) s[i]=(st){a[i],i};
	sort(s+1,s+n+1,cmp1);
	while(l<r){
		vn=(l+r)>>1;
		if(judge()) r=vn;
		else l=vn+1;
	//	printf("%d %d\n",l,r);
	}
	while(!judge()){
		vn++;
	}
	while(1&&vn>1){
		vn--;
		if(!judge()) {vn++;break;}
	}
	printf("%d",vn);
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

signed main(){
  int n,m;
  cin>>n>>m;
  string s,t;
  cin>>s>>t;
  int x=lcm(n,m);
  int y=lcm(x/n,x/m);
	if(s[0]!=t[0]){
		cout<<-1<<endl;
		return 0;
	}
  for(int i=1;i*y<=x;i++){
		//cout<<y/(x/n)*i<<" "<<y/(x/m)*i<<endl;
		if(s[y/(x/n)*i]!=t[y/(x/m)*i]){
      cout<<-1<<endl;
      return 0;
    }
  }

  cout<<x<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	cout << (n%1000==0?0:1000-(n%1000));
}



Measured memory_bytes: 3652
n,a,b = gets.chomp.split(" ").map(&:to_i)

def sum(num)
  s=num%10
  s+=sum(num/10) if num/10>0
  return s
end

ret=0
n.times{|i|
  tmp=sum(i+1)
  ret+=(i+1) if tmp>=a && tmp<=b
}
puts ret

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;

    int N = (int)S.length();
    string pre = "";
    string now = "";
    int i = 0;
    for(; i < N;i++){
        now += S[i];
        if(now == pre){
            continue;
        }else{
            res++;
            pre = now;
            now = "";
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 720
import sys

n, m = [int(w) for w in input().split()]

digit = [""] * n
check = True
for i in range(m):
    s, c = input().split()
    s = int(s) - 1
    if digit[s] == "" or digit[s] == c:
        digit[s] = c
    else:
        check = False
        print(-1)
        sys.exit()


if n == 1:
    if digit[0] == "":
        print(0)
    else:
        print(digit[0])
else:
    ans = ""

    if digit[0] == "0":
        print(-1)
        sys.exit()
    elif digit[0] == "":
        ans += "1"
    else:
        ans += digit[0]

    for d in digit[1:]:
        if d == "":
            ans += "0"
        else:
            ans += d
    print(ans)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int N, A[3003];
ll M[3003][3003];

ll f(int l, int r) {
    ll &re = M[l][r];
    if (re > -1)RT re;
    if (l == r)RT re=0;
    RT re = max(A[l] - f(l + 1, r), A[r - 1] - f(l, r - 1));
}


void solve() {
    MEM(M, -1);

    cin >> N;
    rep(i, N)cin >> A[i];
    cout << f(0, N) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 70912
function Main(input) {
  const lines = input.split('\n');
  const a = lines[0];
  const s = lines[1];
  let ans = 1;
  for (let i = 1; i < a; i++) {
    if (s[i - 1] != s[i]) ans++
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n,l[210];
  cin>>n;

  for (int i=0; i<2*n; i++) cin>>l[i];
  sort(l,l+2*n);
  int ans=0;
  for (int i=0; i<n; i++) ans+=l[i*2];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M = map(int,input().split())
graph = [list() for _ in range(N)]

for _ in range(M):
    u, k=[int(x) for x in input().split()] # uは頂点番号、kは隣接頂点の個数
    graph[u-1].append(k-1)
    graph[k-1].append(u-1) # 無向グラフ
#print(graph)

sign = [0]*(N-1)#どこを通るか
dist=[N]*N#距離
dist[0]=0#startは0

q=deque()
q.append(0)
while q:#qが空になるまで
    v=q.popleft()
    for x in graph[v]:
        if dist[x] > dist[v]+1:#更新
            dist[x]=dist[v]+1
            sign[x-1]=v+1
            q.append(x)
#print(dist)
print("Yes")
for i in sign:
    print(i)

Measured memory_bytes: 37712
def c_cat_snuke_and_a_voyage(N, M, I):
    p = [False] * N  # 島1と島iに辺があるならTrue,なければFalse(0-indexed)
    q = [False] * N  # 島iと島Nに辺があるならTrue,なければFalse(0-indexed)
    for a, b in I:
        if a == 1:  # 出発地が島1なら
            p[b] = True
        elif b == N:  # 目的地が島Nなら
            q[a] = True
    ans = 'IMPOSSIBLE'
    for i in range(N):
        if p[i] and q[i]:
            ans = 'POSSIBLE'
            break  # 1つでもあればいい
    return ans

N,M = [int(i) for i in input().split()]
I = [[int(i) for i in input().split()] for j in range(M)]
print(c_cat_snuke_and_a_voyage(N, M, I))

Measured memory_bytes: 42524
//Aleksander Łukasiewicz
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int INF = 1000000009;
const int MAXN = 2*100*1000;

char tab[MAXN + 3];
int ff[2*MAXN + 3], bb[2*MAXN + 3];

int main(){
    int n, k, c;
    scanf("%d %d %d", &n, &k, &c);
    scanf("%s", tab+1);
    for(int i=n; i>=1; i--)
        if(tab[i] == 'o')
            ff[i] = 1 + ff[min(n+1, i+c+1)];
        else
            ff[i] = ff[i+1];
    vector<int> ans;
    int last = -c;
    for(int i=1; i<=n; i++){
        if(tab[i] == 'o'){
            if(bb[max(last, 0)] + ff[max(i+1, last+c+1)] < k)
                ans.pb(i);
            if(i > last + c){
                bb[i] = bb[max(last, 0)]+1;
                last = i;
            }
        }
    }

    for(auto a : ans)
        printf("%d\n", a);
    
return 0;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int; 

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
  int w, h;
  cin >> w >> h;

  if (w == 1 || h == 1) {
    cout << 1 << endl;
    return 0;
  }

  LL num = (LL)w * (LL)h;
  cout << (num + 1) / 2 << endl; 
}


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

int main(){
    long long n,k,s;
    cin >> n >> k >> s;
    long long a[n];
    if(s == 1000000000){
        for(int i=0; i<k; i++){
            a[i] = s;
        }
        for(int i=k; i<n; i++){
            a[i] = 1;
        }
    }
    else{
        for(int i=0; i<k; i++){
            a[i] = s;
        }
        for(int i=k; i<n; i++){
            a[i] = 1000000000;
        }
    }
    for(int i=0; i<n; i++){
        cout << a[i] << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    string S = in<string>();
    vector<int> R(0);
    vector<int> G(0);
    vector<int> B(N);
    REP(i,N){
        if(S[i] == 'R')R.pb(i);
        if(S[i] == 'G')G.pb(i);
        if(S[i] == 'B')B[i] = 1;
    }
    ll sum = 0;
    REP(i,R.size()){
        REP(l,G.size()){
            int minus = 0;
            if(max(G[l],R[i])+abs(R[i] - G[l]) < N){
                if(B[max(G[l],R[i])+abs(R[i] - G[l])] == 1)minus++;
            }
            if(min(G[l],R[i])-abs(R[i] - G[l]) >= 0){
                if(B[min(G[l],R[i])-abs(R[i] - G[l])] == 1)minus++;
            }
            if(abs(R[i] - G[l])%2 == 0){
                if(B[min(G[l],R[i]) + abs(R[i] - G[l])/2]==1)minus++;
            }
            sum += N-R.size()-G.size()-minus;
        }
    }
    cout << sum << "\n";
}

Measured memory_bytes: 3704
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    long long H,N;
    cin >> H >> N;
    long long sum = 0;
    string out = "No";
    for(int i=0;i<N;i++){
        int A = 0;
        cin >> A;
        sum += A;
        if(sum >= H){
            out = "Yes";
            break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n>>x>>y;
    for(i=x;i<=y;i++)
    {
        if(i%n==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

lli x[100] = {};

int main(void) {

	lli n;
	cin >> n;

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

	lli ans = 100 * 100 * 100;

	for (int i = 0; i <= 100; i++) {
		lli sum = 0;
		for (int j = 0; j < n; j++) {
			sum += pow(i - x[j], 2);
		}
		ans = min(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define READ(FILE) freopen(FILE,"r",stdin)
#define WRITE(FILE) freopen(FILE,"w",stdout)
#define loop(i,s,e) for(int i=s;i<e;i++)
#define mego fast();
using namespace std;
void fast()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll lcm(ll x, ll y)
{
    return (x*y)/__gcd(x,y);
}
int sum(string s)
{
    int x=0,sz=s.size();
    loop(i,0,sz)x+=(s[i]-'0');
    return x;
}
int main()
{
    mego
ll x,y=1;
cin>>x;
string ans="";
while(x)
{
    x--;
    ans+=('a'+((x%26)));
    x/=26;
}
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}
/*26*/


Measured memory_bytes: 3652