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

typedef double D;
const D EPS = 1e-8;

struct P {
  D x, y;
  P() { }
  P(D x_, D y_) : x(x_), y(y_) { }
};

P operator +(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P operator -(P a, P b) { return P(a.x - b.x, a.y - b.y); }
P operator *(P a, D b) { return P(a.x * b, a.y * b); }
P operator /(P a, D b) { return P(a.x / b, a.y / b); }
P vec(P from, P to) { return to - from; }
D inp(P a, P b) { return a.x*b.x + a.y*b.y; }
D outp(P a, P b) { return a.x*b.y - a.y*b.x; }
D norm(P p) { return inp(p, p); }

int sig(D a, D b) {
  if(a < b - EPS) return -1;
  if(a > b + EPS) return +1;
  return 0;
}

int ccw(P a, P b, P c) { // 重なっている点があるとうまく動かないと思われる
  b = vec(a, b); c = vec(a, c);

  // a - b - c が折れ曲がるとき
  if(sig(outp(b, c),0.0) > 0) return +1; // 反時計回り
  if(sig(outp(b, c),0.0) < 0) return -1; // 時計回り

  // a - b - c が直線上に並ぶとき
  // sigを使わない実装が主流っぽい？
  if(sig(inp(b, c),0.0) < 0)   return +2; // c - a - b
  if(sig(norm(b),norm(c)) < 0) return -2; // a - b - c
  return 0;                               // a - c - b
}

// ON = 0, IN = 1, OUT = -1
int containsGP(vector<P> g, P p) {
  int side = -1;
  for(int i = 0; i < (int)g.size(); i++) {
    if(ccw(g[i], g[(i+1)%g.size()], p) == 0) return 0;
    P a = vec(p, g[i]);
    P b = vec(p, g[(i+1)%g.size()]);
    if(a.y > b.y) swap(a, b);
    if(sig(a.y, 0.0) <= 0 && sig(b.y, 0.0) > 0 && sig(outp(a, b), 0.0) > 0) side *= -1;
  }
  return side;
}

int main() {
  int N; cin >> N;
  while(N--) {
    vector<P> tri(3);
    for(int i = 0; i < 3; ++i) {
      cin >> tri[i].x >> tri[i].y;
    }
    P k, s;
    cin >> k.x >> k.y;
    cin >> s.x >> s.y;
    int side = containsGP(tri, k);
    side *= containsGP(tri, s);
    cout << (side == -1 ? "OK" : "NG") << endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    int N, M;
    cin >> N >> M;

    vector<bool> from1(N, false);
    vector<bool> toN(N, false);

    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a == 0){
            from1[b] = true;
        }else if(b == N - 1){
            toN[a] = true;
        }
    }

    for(int i=0;i<N;i++){
        if(from1[i] && toN[i]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var N=arr.shift()-0;
var k=arr.shift()-0;
while(k--){
   var ary=arr.shift().split(" ").map(Number);
   var a=ary[0];
   var b=ary[1];
   a=Math.min(a,N-a+1);
   b=Math.min(b,N-b+1);
   var max=Math.min(a,b);
   console.log((max-1)%3+1);
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

typedef pair<double, double> P;

double arct(P x) {
  double a = x.first, b = x.second;
  if (a==0&&b==0) return 0;
  double result = acos(a/sqrt(a*a+b*b));
  if (b<0) result = 2*M_PI - result;
  return result;
}

double rad(P x, P y) {
  double rx = arct(x), ry = arct(y);
  if (rx>ry) ry += 2*M_PI;
  return ry-rx;
}

int main() {
  int N; cin >> N;
  P pos[N];
  rep(i,N) cin >> pos[i].first >> pos[i].second;
  sort(pos, pos+N, [](const P& x, const P& y) {return arct(x) < arct(y);});
  // rep(i,N) cout << pos[i].first << " " << pos[i].second << endl;
  double result = 0;
  rep(i,N) {
    double nx = 0, ny = 0;
    int now = i, count = 0;
    while (rad(pos[i],pos[now])<=M_PI&&count!=N) {
      nx += pos[now].first; ny += pos[now].second;
      double dis = sqrt(nx*nx+ny*ny);
      result = max(result, dis);
      now++; now%=N;
      count++;
    }
  }
  cout << fixed << setprecision(10) << result << endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC_110_C solver = new ABC_110_C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC_110_C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            String sourceStr = in.next();
            String targetStr = in.next();
            char[] source = sourceStr.toCharArray();
            char[] target = targetStr.toCharArray();
            Map<Character, Character> mapper1 = new HashMap<>();
            Map<Character, Character> mapper2 = new HashMap<>();

            for (int i = 0; i < source.length; i++) {
                if (mapper1.containsKey(source[i])) {
                    if (mapper1.get(source[i]) != target[i]) {
                        out.print("No");
                        return;
                    }
                }
                if (mapper2.containsKey(target[i])) {
                    if (mapper2.get(target[i]) != source[i]) {
                        out.print("No");
                        return;
                    }
                }
                mapper1.put(source[i], target[i]);
                mapper2.put(target[i], source[i]);
            }
            out.print("Yes");
        }

    }
}



Measured memory_bytes: 29648
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define forout(i,a,b) for(int i=a;i>=b;--i)
#define task ""
#define pii pair<int,int>
#define fi first
#define se second
#define sz(s) (int)(s.size())
#define pb push_back
#define int long long
using namespace std;
const int N=1e5+1,M=101;
int n,W,w[M],v[M],f[M][N];
main()
{
    cin>>n>>W;
    forinc(i,1,n) cin>>w[i]>>v[i];
    memset(f,0,sizeof f);
    forinc(i,1,n)
    {
        forout(j,W,0)
        {
            f[i][j]=f[i-1][j];
            if(j+w[i]<=W) f[i][j+w[i]]=max(f[i-1][j]+v[i],f[i][j+w[i]]);
        }
    }
    cout<<f[n][W];
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 

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

    ll a;
    long double b;
    cin >> a >> b;

    long double ans = a*b;
    cout << ll(a*b) << endl;



    return 0;
}



Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  for(int i=0; i<n ; i++){
    int tmp;
    cin>>tmp;
    h.at(i)=tmp;
  }
  sort(h.begin(),h.end());
  ll ans=0;
  for(int i=0; i<n-k; i++){
    ans += h.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;
lli a[1000005];
lli n, k;
int main()
{
    lli x, y;
    lli ans;
    cin >> x >> y;
    lli a = y - x;
    lli INF = 1e18;
    if (a == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (a <= 0)
        a = INF;
    lli b = y + x + 1;
    if (b <= 0)
        b = INF;
    lli c = -y - x + 1;
    if (c <= 0)
        c = INF;
    lli d = -y + x + 2;
    if (d <= 0)
        d = INF;
    ans = min(a, min(b, min(c, d)));
    cout << ans << endl;
}


Measured memory_bytes: 256
// If you want something you've never had, you must be willing to do s
// something you've never done

//  When the going gets tough,  the tough get going
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}

// ----------------------------------------------------------

const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = 2e9;

signed main() {
    ll n;
    cin >> n;
    ll sum = n*(n+1)/2;
    ll x = n/3;
    if(x)
        sum -= x*(6+(x-1)*3)/2;
    x = n/5;
    if(x)
        sum -= x*(10+(x-1)*5)/2;
    x = n/15;
    if(x)
        sum += x*(30+(x-1)*15)/2;
    cout << sum << '\n';
    return 0;
}

// A telephone line whose bandwidth is 1638 Hz is connected from point A to point B. What will be the channel capacity if signal-to-noise ratio is 22 db?


Measured memory_bytes: 3636
n = int(input())
a = tuple(map(int,input().split()))

res = 0
p = 0
cnt = 0

for i in range(n):

    while cnt < n:
        if p&a[cnt] == 0:
            p = p^a[cnt]
            cnt += 1
        else:
            break
    
    p = p^a[i]
    res += cnt-i

print(res)

Measured memory_bytes: 82252
#include <bits/stdc++.h>
typedef long long LL;
const int maxn = 300010;
const int inf = 1 << 30;
const int mod = 1e9+7;

inline int read() {
	register int x = 0, neg = 1;
	register char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') neg = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { x = (((x << 2) + x) << 1) + (ch ^ '0'); ch = getchar(); }
	return x * neg;
}

int n;
LL a[maxn], pre[maxn];
LL fac = 1, ans = 0;

inline LL qpow(LL a, LL n) {
	if(n == 0) return 1;
	LL res = 1;
	while(n) {
		if(n & 1) res = (res * a) % mod;
		n >>= 1;
		a = (a * a) % mod;
	} 
	return res;
}

inline LL inv(LL x) {
	return qpow(x, mod - 2);
}

int main() {
	n = read();
	for(register int i = 1; i <= n; ++i) a[i] = read();
	for(register int i = 1; i <= n; ++i) {
		pre[i] = (pre[i - 1] + inv(i)) % mod;
		fac = fac * i % mod;
	}
	for(register int i = 1; i <= n; ++i) {
		ans = (ans + a[i] * (pre[i] + pre[n - i + 1] - 1) % mod) % mod;
	}
	printf("%lld\n", fac * ans % mod);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
//#include<iostream>
using namespace std;
#define int long long



#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int sx,sy,tx,ty;

signed main() {
    cin>>sx>>sy>>tx>>ty;
    rep(i,0,abs(tx-sx)){
        if(tx>sx)cout<<"R";
        else cout<<"L";
    }
    rep(i,0,abs(ty-sy)){
        if(ty>sy)cout<<"U";
        else cout<<"D";
    }
    rep(i,0,abs(tx-sx)){
        if(tx>sx)cout<<"L";
        else cout<<"R";
    }
    rep(i,0,abs(ty-sy)){
        if(ty>sy)cout<<"D";
        else cout<<"U";
    }
    
    if(ty>sy)cout<<"D";
    else cout<<"U";
    
    repe(i,0,abs(tx-sx)){
        if(tx>sx)cout<<"R";
        else cout<<"L";
    }
    repe(i,0,abs(ty-sy)){
        if(ty>sy)cout<<"U";
        else cout<<"D";
    }
    
    if(tx>sx)cout<<"L";
    else cout<<"R";
    
    if(ty>sy)cout<<"U";
    else cout<<"D";
    
    repe(i,0,abs(tx-sx)){
        if(tx>sx)cout<<"L";
        else cout<<"R";
    }
    repe(i,0,abs(ty-sy)){
        if(ty>sy)cout<<"D";
        else cout<<"U";
    }
    
    if(tx>sx)cout<<"R";
    else cout<<"L";
    
    cout<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int S[1000000];

int binarySearch(int left, int right, int p) {
  int mid = (left + right) / 2;
  if ( S[mid] == p ) return 1;
  if ( mid == left ) return 0;
  if ( p < S[mid] ) return binarySearch(left, mid, p);
  else return binarySearch(mid + 1, right, p);
}

int main() {
  int n, q, t, sum = 0;

  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) scanf("%d", &S[i]);
  scanf("%d", &q);

  for ( int i = 0; i < q; i++ ) {
    scanf("%d", &t);
    if (binarySearch(0, n, t)) sum++;
  }

  printf("%d\n", sum);

  return 0;
}



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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k,a,b;
	cin >> k >> a >> b;
	if( a / k != b / k )
	{
		cout << "OK" << '\n';
	}else if( a % k == 0 || b % k == 0 )
	{
		cout << "OK" << '\n';
	}else
	{
		cout << "NG" << '\n';
	}
	return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < m; i++) {
	int s, t;
	cin >> s >> t;
	a[s - 1]++;
	a[t - 1]++;
  }
  for (int i = 0; i < n; i++) {
	cout << a[i] << endl;
  }
  return 0;
}



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

#define TOP 0
#define SOUTH 1
#define EAST 2
#define WEST 3
#define NORTH 4
#define BOTTOM 5
#define DIRECTIONS 6

int main()
{
  int n,i,t,top;
  string s;
  int die[DIRECTIONS];
  while(cin>>n,n){
    for(i=0;i<DIRECTIONS;i++)die[i]=i+1;

    top=1;
    for(i=0;i<n;i++){
      cin>>s;
      if(s=="North"){
	t=die[TOP];
	die[TOP]=die[SOUTH];
	die[SOUTH]=die[BOTTOM];
	die[BOTTOM]=die[NORTH];
	die[NORTH]=t;
      }
      if(s=="West"){
	t=die[TOP];
	die[TOP]=die[EAST];
	die[EAST]=die[BOTTOM];
	die[BOTTOM]=die[WEST];
	die[WEST]=t;
      }
      if(s=="East"){
	t=die[TOP];
	die[TOP]=die[WEST];
	die[WEST]=die[BOTTOM];
	die[BOTTOM]=die[EAST];
	die[EAST]=t;
      }
      if(s=="South"){
	t=die[TOP];
	die[TOP]=die[NORTH];
	die[NORTH]=die[BOTTOM];
	die[BOTTOM]=die[SOUTH];
	die[SOUTH]=t;
      }
      if(s=="Left"){
	t=die[NORTH];
	die[NORTH]=die[EAST];
	die[EAST]=die[SOUTH];
	die[SOUTH]=die[WEST];
	die[WEST]=t;
      }
      if(s=="Right"){
	t=die[NORTH];
	die[NORTH]=die[WEST];
	die[WEST]=die[SOUTH];
	die[SOUTH]=die[EAST];
	die[EAST]=t;
      }
      top+=die[TOP];
    }
    cout<<top<<endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	long long int a,b,c=0,n,i;
	scanf("%lld",&n);
	a=2; b=1;
	if(n!=1){
		for(i=0;i<n-1;i++){
			c=a+b;
			a=b;
			b=c;
		}
		printf("%lld\n",c);
	}
	else printf("%lld\n",b);
	return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=1e9+7;
//
int main(){
	long long n,k;
	long long a[200000];
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	vector<int> nii;
	int now=0;
	nii.push_back(now);
	bool used[200000]={};
	while(!used[now]){
		used[now]=1;
		now=a[now];
		nii.push_back(now);
	}
	int b=0;
	for(int i=0;i<nii.size();i++){
		if(nii[i]==now){
			b=i;
			break;
		}
	}
	long long m=nii.size();
	if(k<=m-1){
		cout<<nii[k]+1<<endl;
	}else{
		k-=m-1;
		k%=(m-b-1);
		cout<<nii[b+k]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 6016
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> table(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> table[i][j];
        }
    }

    int ret = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (table[i][k] - table[j][k]) * (table[i][k] - table[j][k]);
            }
            int rt = (int)floor(sqrt(sum));
            if (rt * rt == sum) ret++;
        }
    }

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

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

using namespace std;

void solve()
{
	string str;
	int count = 0;
	while(cin >> str)
	{
		if(str.size() == 1)
		{
			count++; continue;
		}
		int size = str.size() - 1;
		int halfsize = str.size() / 2;
		bool flag = true;
		for(int i = 0; i < halfsize; ++i)
		{
			if(str[i] != str[size - i])
			{
				flag = false;
				break;
			}
		}
		if(flag)
		{
			++count;
		}
	}
	cout << count << endl;
}

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

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

// lcm = a*(b/gcd) least common multiple          
// gcd: greatest common divisor                   
//                                                
int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


int main() {
  int R,G,B,N;
  cin >> R >> G >> B >>N;
  int ans=0;

  for(int r=0; r*R<=N ; r++){
    for(int g=0; g*G<=(N-r*R) ; g++){
      if(floor(((double)(N-r*R-g*G))/((double)B)) == ceil( ((double)(N-r*R-g*G))/((double) B))){
	ans++;
	//	cout << r << " " << g << " " << (N-r*R-g*G)/B << endl;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=10005;
int n,m,p,q;
db x[N],y[N];
struct edge {
    int x,y;
    db val;
    bool operator<(const edge& rhs) const {
        return val<rhs.val;
    }
};
int dsu[N];

int fi(int x) {
    return x==dsu[x]?x:(dsu[x]=fi(dsu[x]));
}

db dis(int i,int j) {
    db dx=x[i]-x[j];
    db dy=y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {
        scanf("%lf%lf",x+i,y+i);
    }
    vector<edge> vec;
    for (int i=1;i<=m;i++) {
        scanf("%d%d",&p,&q);
        vec.pb({p,q,-dis(p,q)});
    }
    sort(vec.begin(),vec.end());
    for (int i=1;i<=n;i++) {
        dsu[i]=i;
    }
    db ans=0;
    for (auto e:vec) {
        int r1=fi(e.x);
        int r2=fi(e.y);
        if (r1==r2) {
            ans-=e.val;
        } else {
            dsu[r1]=r2;
        }
    }
    printf("%.4lf\n",ans);
}


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

const int N_MAX = 200010;
vector<vector<int>> tr(N_MAX);
vector<bool> used(N_MAX, false);
vector<ll> ans(N_MAX);
map<int, int> ma;


void dfs(int n, ll point) {
    used[n] = true;
    point += ma[n];
    ans[n] += point;

    stack<int> st;
    for (auto it : tr[n]) {
        if (!used[it]) st.push(it);
    }

    while (!st.empty()) {
        n = st.top(); st.pop();
        dfs(n, point);
    }
}


int main() {
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n - 1; ++i) {
        int a, b; cin >> a >> b;
        tr[a].push_back(b);
        tr[b].push_back(a);
    }

    for (int i = 0; i < q; ++i) {
        int p, x; cin >> p >> x;
        if (ma.count(p) == 0) {
            ma[p] = x;
        } else {
            ma[p] += x;
        }
    }

    dfs(1, 0);
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 193024
package main

import (
        "bufio"
        "fmt"
        "math"
        "os"
        "strconv"
)

var sc *bufio.Scanner

func init() {
        // 100MB
        bufsize := 100 * 1024 * 1024
        sc = bufio.NewScanner(os.Stdin)
        sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
        sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
        s := readStringArray(n)
        a := make([]int, n)
        for i := range a {
                a[i], _ = strconv.Atoi(s[i])
        }
        return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
        a := make([]string, n)
        for i := 0; i < n; i++ {
                sc.Scan()
                a[i] = sc.Text()
        }
        return a
}
func max(ns ...int) int {
        max := ns[0]
        for _, n := range ns {
                if n > max {
                        max = n
                }
        }
        return max
}
func min(ns ...int) int {
        min := ns[0]
        for _, n := range ns {
                if n < min {
                        min = n
                }
        }
        return min
}
func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

func main() {
        n, k := readInt2()
        hs := readIntArray(n)

        dp := make([]int, n)
        dp[0] = 0
        dp[1] = abs(hs[1] - hs[0])

        for i := range dp {
                if i <= 1 {
                        continue
                }
                dp[i] = math.MaxInt64
                for j := 1; j <= k; j++ {
                        if i-j >= 0 {
                                dp[i] = min(dp[i], abs(hs[i]-hs[i-j])+dp[i-j])
                        }
                }
        }

        fmt.Println(dp[n-1])
}

Measured memory_bytes: 4480
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}


template<class T>
struct Dinic{
  const static int N = 10101 * 2 , M = N * 10;
  int s , t , n , h[N] , cur[N] , level[N] , q[N] , e , ne[M] , to[M];
  T cap[M] , flow;
  void liu(int u,int v,T w){ to[e] = v;ne[e] = h[u];cap[e] = w;h[u] = e++;}
  void link(int u,int v,T w){ liu(u , v , w);liu(v , u , 0);}
  void ini(int _n = N) { fill(h , h + (n=_n) , -1);e = 0;}
  bool bfs(){
    int L = 0 , R = 0;
    fill(level , level + n , -1);
    level[q[R++] = s] = 0;
    while(L < R && level[t] == -1){
      int c = q[L++];
      for(int k=h[c];~k;k=ne[k])
        if(cap[k] > 0 && level[to[k]] == -1)
          level[q[R++] = to[k]] = level[c] + 1;
    }
    return ~level[t];
  }
  T dfs(int c,T mx){
    if(c == t) return mx;
    T ret = 0;
    for(int &k = cur[c];~k;k = ne[k]){
      if(level[to[k]] == level[c] + 1 && cap[k] > 0){
        T flow = dfs(to[k] , min(mx , cap[k]));
        ret += flow;cap[k] -= flow , cap[k^1] += flow;mx -= flow;
        if(!mx) return ret;
      }
    }
    level[c] = -1;
    return ret;
  }
  T run(int _s,int _t){
    s = _s , t = _t;
    flow = 0;
    while(bfs()){
      copy(h , h + n , cur);
      flow += dfs(s,~0U>>1);
    }
    return flow;
  }
};

Dinic<int> it;
const int N = 110 , inf = N * N;
int h , w;
char s[N][N];

int id(int a,int b,int c) {
  return (a * w + b) << 1 | c;
}

int main(){
  scanf("%d%d",&h,&w);
  rep(i,0,h) scanf("%s",s[i]);
  int S = h * w * 2;
  int T = S + 1;
  it.ini(T + 1);
  rep(i,0,h) rep(j,0,w) {
    if(s[i][j] == 'X') {
      it.link(S , id(i , j , 1) , inf);
    } else {
      it.link(id(i , j , 0) , id(i , j , 1) , 1);
    }
    if(i == 0 || i + 1 == h || j == 0 || j + 1 == w)
      it.link(id(i , j , 1) , T , inf);
    rep(d,0,4) {
      int ni = i + (d == 2) - (d == 0);
      int nj = j + (d == 3) - (d == 1);
      if(0 <= ni && ni < h && 0 <= nj && nj < w) {
        it.link(id(i , j , 1) , id(ni , nj , 0) , inf);
      }
    }
  }
  int flow = it.run(S , T);
  if(flow >= inf) puts("-1");
  else printf("%d\n",flow);
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie();
	ll a,b,n;
	cin>>a>>b>>n;
	ll mx=min(b-1,n);
	ll ans=(a*mx/b)-a*(mx/b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;

namespace tenka1_2019_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var s = CIn.Read().ToCharArray();

      var w = new int[n + 1];
      var b = new int[n + 1];

      for (var i = 0; i < n; i++)
      {
        w[i + 1] = w[i];
        b[i + 1] = b[i];

        if (s[i] == '.')
        {
          w[i + 1]++;
        }
        else
        {
          b[i + 1]++;
        }
      }

      var ans = n;

      for (var i = 0; i <= n; i++)
      {
        var v = b[i] + w[n] - w[i];

        if (v < ans) ans = v;
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[4][4],b[N],k,q,u,v,x,y,tc,c,l,r,ans,p,cnt;

char s[N];

bool ok[N];

int main(){
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		ok[x]=true;
	}
	bool ans=false;
	for(int i=0;i<3;i++){
		if (ok[a[i][0]] && ok[a[i][1]] && ok[a[i][2]])
			ans=true;
		if (ok[a[0][i]] && ok[a[1][i]] && ok[a[2][i]])
			ans=true;
	}
	ans|=ok[a[0][0]] && ok[a[1][1]] && ok[a[2][2]];
	ans|=ok[a[0][2]] && ok[a[1][1]] && ok[a[2][0]];
	if (ans)
		printf("Yes\n");
	else
		printf("No\n");
}



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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<vector<int>> V, W;
    rep(i, N) {
        cin >> S[i];
        int total = 0, mint = 0, mint2 = 0, total2 = 0;
        rep(j, S[i].size()) {
            if (S[i][j] == '(') {
                total++;
            } else {
                total--;
                mint = min(mint, total);
            }
        }
        rep(j, S[i].size()) {
            if (S[i][S[i].size() - 1 - j] == ')') {
                total2++;
            } else {
                total2--;
                mint2 = min(mint2, total2);
            }
        }
        if (mint >= mint2) {
            V.push_back({mint, total});
            //cout << "V " << mint << " " << total << "\n";
        } else {
            W.push_back({mint2, total2});
            //cout << "W " << mint2 << " " << total2 << "\n";
        }
    }
    sort(V.begin(), V.end());
    sort(W.begin(), W.end());
    int T = 0;
    for (int i = V.size() - 1; i >= 0; i--) {
        int mint = V[i][0], total = V[i][1];
        if (T + mint < 0) {
            cout << "No\n";
            return 0;
        }
        T += total;
    }
    int U = 0;
    for (int i = W.size() - 1; i >= 0; i--) {
        int mint = W[i][0], total = W[i][1];
        if (U + mint < 0) {
            cout << "No\n";
            return 0;
        }
        U += total;
    }
    if (T == U) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 89016
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll dp[3005][3005];
ll mod = 998244353;
ll a, b, c, d;
ll calc(ll x, ll y){
	if (dp[x][y] != -1) return dp[x][y];
	if ((x > c) || (y > d)) return dp[x][y] = 0;
	if ((x == c) && (y == d)) return dp[x][y] = 1;
	dp[x][y] = ((calc(x + 1, y) * y) + (calc(x, y + 1) * x) - calc(x + 1, y + 1) * x * y);
	dp[x][y] %= mod; dp[x][y] += mod; if (dp[x][y] > mod) dp[x][y] -= mod;
	return dp[x][y];
}
int main(){
	for (ll i = 0; i < 3005; i++) for (ll j = 0; j < 3005; j++) dp[i][j] = -1;
	cin >> a >> b >> c >> d; cout << calc(a, b) << endl;
}


Measured memory_bytes: 74540
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

const int mod = 1e9 + 7;

int n;

void add(int &a, int b){
    a += b;
    if(a >= mod){
        a = a - mod;
    }
}

int32_t main(){
   // ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    vector<vector<int>>can(n, vector<int>(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin >> can[i][j];
    vector<int>dp((1 << n));

    dp[0] = 1;

    for(int i=1;i<(1<<n);i++){
        int curr = __builtin_popcount(i);
        for(int j=0;j<n;j++){
            if(i & (1 << j) && can[curr - 1][j] == 1){
                add(dp[i],dp[i ^ (1 << j)]);
            }
        }
    }
    cout << dp[(1 << n) - 1] << '\n';
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
  return x;

}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u=u->left;
    else
      u=u->right;
  }
  return u;
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left==NIL ||z->right ==NIL)
    y=z;
  else
    y=treeSuccessor(z);
  if(y->left!=NIL)
    x=y->left;
  else
    x=y->right;
  if(x!=NIL)
    x->parent=y->parent;
  if(y->parent==NIL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else
    y->parent->right=x;
  if(y!=z)
    z->key=y->key;
  
  
}

 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
 
    else
      x = x->right;
  }
   
  z->parent = y;
 
  if(y == NIL)
    root = z;
 
  else if(z->key < y->key)
    y->left = z;
 
  else
    y->right = z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
   
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include"bits/stdc++.h"
using namespace std;

int main(){
    int n;
    cin >> n;
    string *s;
    s = new string[n];
    for (int i=0;i<n;i++){
        cin >> s[i];
    }

    int flag = 1;

    for (int i=1;i<n;i++){
        if (s[i-1][s[i-1].length()-1]!=s[i][0]){
            flag = 0;
            break;
        }
        for (int j=0;j<i;j++){
            if (s[j]==s[i]){
                flag = 0;
                break;
            }
        }
        if (flag==0){break;}
    }

    string ans;

    if (flag){
        ans = "Yes";
    }
    else{
        ans = "No";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

llong N, M;
int main(int argc, char **argv) {
    cin >> N >> M;

    priority_queue<llong> pq;
    for(int i = 0; i < N; ++i) {
        llong a;
        cin >> a;
        pq.push(a);
    }

    for(int i = 0; i < M; ++i) {
        llong m = pq.top();   pq.pop();
        m /= 2;
        pq.push(m);
    }

    llong res = 0;
    while(!pq.empty()) {
        int m = pq.top();   pq.pop();
        res += m;
    }

    cout << res << endl;    
}

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

main(){
    int S,W;
    cin>>S>>W;
    if(S==W){
        cout<<"unsafe"<<endl;
    }else if(S<W)
    {
        cout<<"unsafe"<<endl;
    }else
    {
        cout<<"safe"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var x = o.l();
  x.sort((a,b)=>a-b);
  var a = [];
  for(var i = 1; i < m; i++)a[i-1] = x[i] - x[i-1];
  a.sort((a,b)=>b-a);
  var ans = 0;
  for(i = n-1; i < m-1; i++)ans += a[i];
  return ans;
}

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

int main()
{
  int n;
  cin >> n;
  map<int, int> mp;
  ll sum = 0;
  rep(i,n)
  {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  
  int q;
  cin >> q;
  rep(i,q)
  {
    int b, c;
    cin >> b >> c;
    sum = sum + (c - b) * mp[b];
    cout << sum << "\n";
    mp[c] += mp[b];
    mp[b] = 0;
  }
  
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

string S;

int main(){
  cin >> S;
  if(S == "SUN"){
    cout << 7<<endl;
  }
  if(S == "MON"){
    cout << 6<<endl;
  }
  if(S == "TUE"){
    cout << 5<<endl;
  }
  if(S == "WED"){
    cout << 4<<endl;
  }
  if(S == "THU"){
    cout << 3<<endl;
  }
  if(S == "FRI"){
    cout << 2<<endl;
  }
  if(S == "SAT"){
    cout << 1<<endl;
  }
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

class Node:
    nodes = {}
    max_c = 0
    @classmethod
    def get_root_node(cls):
        n = Node.nodes[1]
        for _ in range(1000000):
            if n.parent is None:
                return n
            else:
                n = n.parent

    @classmethod
    def dump_all_nodes(cls):
        for key, node in Node.nodes.items():
            print(str(node))

    @classmethod
    def get_instance(cls, id, parent):
        if id in Node.nodes:
            if Node.nodes[id].parent is None:
                Node.nodes[id].parent = parent
            return Node.nodes[id]
        else:
            return Node(id, parent)

    @classmethod
    def color_childs(clf, start_node):
        c = 1
        list_to_visit = deque(start_node.childs)
        list_to_visit.append(-1)
        ap = list_to_visit.append

        while(len(list_to_visit)>0):
            if list_to_visit[0]==-1:
                c = 1
                list_to_visit.popleft()
                continue
            node = list_to_visit[0]
            list_to_visit.popleft()
            if c == node.parent.parent_edge_color:
                c += 1
            node.parent_edge_color = c
            if c > Node.max_c:
                Node.max_c = c
            list_to_visit += deque(node.childs)
            ap(-1)
            c += 1

    def __init__(self, id, parent):
        self.id = id
        self.parent = parent # None if root Node
        self.parent_edge_color = None
        self.childs = []
        Node.nodes[id] = self
        self.used_color = []

    def __str__(self):
        x = self.parent.id if self.parent else "None"
        #return f"id: {self.id}, parent: {x}, parent_edge_color: {self.parent_edge_color} ,num_child {len(self.childs)}, num_color {self.num_color}"
        return str(self.id)

    def append_child(self, node):
        self.childs.append(node)

    @property
    def num_color(self):
        if self.parent_edge_color is None:
            return len(self.childs)
        else:
            return len(self.childs) + 1

N = int(input())

Edges = []
Edges_color = []
ap = Edges.append
for i in range(N-1):
    edge = list(map(int, input().split()))
    ap(edge)
    pnode = Node.get_instance(edge[0], None)
    cnode = Node.get_instance(edge[1], pnode)
    pnode.append_child(cnode)

root = Node.get_root_node()

Node.color_childs(root)
#Node.dump_all_nodes()
K = Node.max_c
print(K)

for edge in Edges:
    print(Node.get_instance(edge[1], edge[0]).parent_edge_color)

Measured memory_bytes: 99888
fun main(args: Array<String>){
    val n = Integer.parseInt(readLine())
    val input: List<String> = readLine()!!.split(" ")
    val a = Integer.parseInt(input[0])
    val b = Integer.parseInt(input[1])
    val pListInput: List<String> = readLine()!!.split(" ")
    val num = arrayOf(0, 0, 0)
    for (pInput in pListInput){
        val p = Integer.parseInt(pInput)
        when {
            p <= a -> num[0]++
            p <= b -> num[1]++
            else -> num[2]++
        }
    }

    println(num.min())
}

Measured memory_bytes: 36128
# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

#整数値龍力　複数の入力(配列で1つずつ渡される)
def input_multiple_number_as_list_sep(N):
    ins = []
    for i in range(N):
        ins.append(input())
    return ins

#2次元配列入力
def input_map():
    return [list(map(int,list(input()))) for i in range(h)]

#リスト出力
def print_list(list):
    print(*list)
    return

#2次元配列出力
def print_map(maplist):
    for i in maplist:print(*i, sep='')
    return

#素数生成
def generate_primenums():
    n = 100
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes.difference_update(range(i*2, n+1, i))
    primes=list(primes)
    return primes

def memo():
    a=[0]*5
    b=a  #良くない配列のコピー
    b2=a[:]  #1次元のときはコピーはこれで良い
    a[1]=3
    print('b:{}, b2:{}'.format(b,b2))  #b:[0, 3, 0, 0, 0], b2:[0, 0, 0, 0, 0]
    
    import copy
    a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
    b=copy.deepcopy(a)  #2次元配列はこうコピーする
    
    #内包表記奇数のみ
    odd=[i for i in range(100) if i%2==1] #[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

    #二部探索
    import bisect
    a = [1, 2, 3, 5, 6, 7, 8, 9]
    b=bisect.bisect_left(a, 8)

    #combinations、組み合わせ、順列
    from itertools import permutations, combinations,combinations_with_replacement,product
    a=['a','b','C']
    print(list(permutations(a)))
    print(list(combinations(a,2)))
    print(list(combinations_with_replacement(a,3)))


#階乗
def kaijo(n):
    import math
    return math.factorial(n)

#選び方（コンビネーション nCr）
def num_combination(n,r):
    import math
    return math.factorial(n) // math.factorial(n - r)


#最大公約数、最小公倍数
def calc_gcd(a,b):
    import fractions
    GCD=fractions.gcd(a,b)
    lcm=a*b//gcd
    return gcd,lcm

#複数の最大公約数
def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = fractions.gcd(gcd, l[i])
    return gcd

#各桁の和
def sum_digit(n):
    sum = 0
    while n > 0:
        sum += n%10
        n //= 10
    return sum

H,N = input_multiple_number()
lst_a = input_multiple_number_as_list()

damage = 0
for a in lst_a:
    damage += a

if H <= damage:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 14012
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtcoderSubmit
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();
            if(b.Length == a.Length + 1 && b.Substring(0, a.Length) == a) {
                Console.WriteLine("Yes");
            }
            else {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25684
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long INF = 1e10;

int f(int n,int k){
	if(n==1)return 0;
	return (f(n-1,k)+k)%n;
}
int main(){
	int n,k,m;
	while(cin>>n>>k>>m){
		if(n==0&&k==0&&m==0)break;
		m=(m-k+1+n)%n;
		cout<<(f(n,k)+m-1+n)%n+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[100010];

		for (int i = 1; i < 100001; i++) {
			if (i % 2 == 0)
				continue;
			if (isPrime(i) && isPrime((i + 1) / 2)) {
				a[i] = 1;
			}
		}

		int s[] = new int[100010];
		s[0] = a[0];

		for (int i = 1; i < 100010; i++) {
			s[i] = s[i - 1] + a[i - 1];
		}

		for (int i = 0; i < n; i++) {
			String str[] = br.readLine().split(" ");
			int l = Integer.parseInt(str[0]);
			int r = Integer.parseInt(str[1]);

			System.out.println(s[r + 1] - s[l]);
		}

	}

	static boolean isPrime(int n) {
		if (n == 1) {
			return false;
		}

		for (int i = 2; i * i <= n; i++) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

Measured memory_bytes: 58780