akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    string s;
    cin >> n >> s;
    int all = count(s.begin(), s.end(), '#');
    vector<int> a(n+1, 0);
    for(int i = n-1; i >= 0 ; i--) {
        a[i] = a[i+1] + (s[i] == '#');
    }
    int ans = INF;
    for(int i = 0; i <= n; i++) {
        int now = (n-i-a[i])+(all-a[i]);
        chmin(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define All(v) (v).begin(),(v).end()
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b)) cout<<"A"<<endl;
    if(abs(x-a)>abs(x-b)) cout<<"B"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[6];
int main()
{
	for (int i=1;i<=5;i++) scanf("%d",&a[i]);
	for (int i=1;i<=5;i++)
		if (!a[i])
		{
			printf("%d\n",i);
			break;
		}
	return 0;
}


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

int main() {
	double *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4, xx, yy;
	int n, i, flag;
	scanf("%d",&n);
	x1 = (double *)malloc( sizeof(double) * n );
	y1 = (double *)malloc( sizeof(double) * n );
	x2 = (double *)malloc( sizeof(double) * n );
	y2 = (double *)malloc( sizeof(double) * n );
	x3 = (double *)malloc( sizeof(double) * n );
	y3 = (double *)malloc( sizeof(double) * n );
	x4 = (double *)malloc( sizeof(double) * n );
	y4 = (double *)malloc( sizeof(double) * n );
	
	for(i=0;i<n;i++) {
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
			&x1[i], &y1[i], &x2[i], &y2[i], &x3[i], &y3[i], &x4[i], &y4[i]);
	}
	
	for(i=0;i<n;i++) {
		flag = 0;
		if ( (y2[i]!=y1[i]) && (y4[i]!=y3[i]) ) {
			if ( ((y4[i] - y3[i])*(x2[i] - x1[i])) ==
				((y2[i] - y1[i])*(x4[i] - x3[i])) ) flag = 1;
		}else {
			if ( (y2[i]==y1[i]) && (y4[i]==y3[i]) ) {
				flag = 1;
			}
		}
		if (flag==1) printf("YES\n");
		else printf("NO\n");
	}

	free(x1);
	free(y1);
	free(x2);
	free(y2);
	free(x3);
	free(y3);
	free(x4);
	free(y4);
	return 0;
}

Measured memory_bytes: 0
#愚直な判定
def JudgeStable(inC, outC, N):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if inC[i][1] == inC[j][1] and inC[i] == outC[b] and inC[j] == outC[a]:
                        return False
    return True

def PrintJudge(judge):
    if judge:
        print('Stable')
    else:
        print('Not stable')
        
def BubbleSort(C, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if C[j-1][1] > C[j][1]:
                C[j-1], C[j] = C[j], C[j-1]
                
def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i+1, N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[minj], C[i] = C[i], C[minj]
                
def PrintC(C):
    print(' '.join([''.join([c[0], str(c[1])]) for c in C]))

N = int(input())
C = [[c[0], int(c[1])] for c in input().split()]
C1 = C.copy()
C2 = C.copy()

BubbleSort(C1, N)
SelectionSort(C2, N)

PrintC(C1)
PrintJudge(JudgeStable(C, C1, N))

PrintC(C2)
PrintJudge(JudgeStable(C, C2, N))


Measured memory_bytes: 5616
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long m = 100;
        long count=0;
        
        for(int i=1;;i++){
            if(m>=X){
                break;
            }
            m = m + m/100;
            count++;
        }
        System.out.println(count);
    }
}

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

int n, a[10010][10010], z;
bool vis[10010], flag;
bool ok() {
  for (int i = 1; i <= n; ++i)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  while (1) {
    if (ok()) {
      printf("%d\n", z);
      return 0;
    }
    flag = 0;
    z++;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; ++i) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (a[x][a[x][0]] == i && !vis[i] && !vis[x]) {
        ++a[i][0];
        ++a[x][0];
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      printf("-1\n");
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 39552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define PI 3.14159265358979323846
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a + d - 1) / d >= (c + b - 1) / b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
long long x[1000], y[1000], z[1000];

long long calc(int n, int m, int u, int v, int w) {
    long long dp[n][m+1] = {};
    dp[0][1] = x[0] * u + y[0] * v + z[0] * w;
    for (int i = 1; i < n; i++)
        for (int j = 1; j <= min(m, i+1); j++)
            if (j == i+1) dp[i][j] = dp[i-1][j-1] + x[i] * u + y[i] * v + z[i] * w;
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + x[i] * u + y[i] * v + z[i] * w);
    return dp[n-1][m];
}

int main(int argc, char** argv) {
    int m, n; cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
    long long ans = 0;
    for (int b = 0; b < 8; b++) ans = max(ans, calc(n, m, b&1?1:-1, b&2?1:-1, b&4?1:-1));
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int identity[40];
int f[40];
str s,t,a,b;
int main(){
    cin>>s>>t;
    int idx = 0;
    for(int i=0;i<s.size();i++){
        int x = int(s[i]-'a')+1;
        if(f[x]==0){
            f[x]++;
            idx ++;
            identity[x] = idx;
        }
    }
    for(int i=0;i<s.size();i++){
        int x = int(s[i]-'a')+1;
        a += char(identity[x]+'0');
    }

    for(int i=0;i<=30;i++){
        f[i]=0;
    }

    idx=0;
    for(int i=0;i<t.size();i++){
        int x = int(t[i]-'a')+1;
        if(f[x]==0){
            f[x]++;
            idx ++;
            identity[x] = idx;
        }
    }

    for(int i=0;i<t.size();i++){
        int x = int(t[i]-'a')+1;
        b += char(identity[x]+'0');
    }
    if(a==b)cout<<"Yes\n";
    else cout<<"No\n";

}


Measured memory_bytes: 1168
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

const int Maxn=1e4;
const int num[]={0,2,5,5,4,5,6,3,7,6};

int N,M;
vector<int> canuse;

string f[Maxn+5];

bool comp(string a,string b) {
	if(a.length()>b.length())
		return true;
	if(a.length()<b.length())
		return false;
	return a>b;
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&M);
	for(int i=1;i<=M;i++) {
		int x;
		scanf("%d",&x);
		canuse.push_back(x);
	}
	sort(canuse.begin(),canuse.end());
	for(int i=0;i<canuse.size();i++) {
		char now=canuse[i]+'0';
		f[num[canuse[i]]]=now;
	}
	for(int i=2;i<=N;i++)
		for(int j=0;j<canuse.size();j++) {
			int w=num[canuse[j]];
			char now=canuse[j]+'0';
			if(i-w<0)continue;
			if(f[i-w]==""&&i-w!=0)continue;
			string tmp=now+f[i-w];
			if(comp(tmp,f[i]))f[i]=tmp;
		}
	cout<<f[N]<<endl;
	return 0;
}

Measured memory_bytes: 32384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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


ll dist[1100];
int main()
{
  int N, M; cin >> N >> M;
  vector<vector<P>> v(N);
  REP(i, M) {
    ll a, b, c; cin >> a >> b >> c;
    a--; b--;
    v[a].PB(MP(b, -c));
  }

  REP(i, 1100) dist[i] = LLINF;
  dist[0] = 0;
  REP(i, N - 1) {
    REP(j, N) {
      if (dist[j] == INF) continue;
      for (auto e : v[j]) {
        if (dist[e.first] > dist[j] + e.second) {
          dist[e.first] = dist[j] + e.second;
        }
      }
    }
  }

  ll ans = dist[N - 1];
  REP(j, N) {
    if (dist[j] == INF) continue;
    for (auto e : v[j]) {
      if (dist[e.first] > dist[j] + e.second) {
        dist[e.first] = dist[j] + e.second;
      }
    }
  }
  if (ans != dist[N - 1]) cout << "inf" << endl;
  else cout << -ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>

#define ll long long

using namespace std;

int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2-(y2-y1) << " " << y2+(x2-x1) << " " << x1-(y2-y1) << " " << y1+(x2-x1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll x[100001] = {};
ll d[100001] = {};
int main() {
	ll n, k; cin >> n >> k;
	rep(i, 0, n)cin >> x[i];

	ll minV = MAX_L;
	repe(i, 0, n - k) {
		ll minD = min(abs(x[i]), abs(x[i + k - 1]));
		minV = abs(min(minV, x[i + k - 1] - x[i] + minD));
	}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
    int n, W;
    scanf("%d%d", &n, &W);
    vll v(n), w(n);
    vvll dp(n, vll(W + 1, 0));
    for (int i = 0; i < n; i++) scanf("%lld%lld", &w[i], &v[i]);
    dp[0][w[0]] = v[0];
    for (int i = 1; i < n; i++){
        for (int j = 0; j <= W; j++){
            dp[i][j] = dp[i - 1][j];
        }
        for (int j = 0; j <= W - w[i]; j++){
            dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
        }
    }
    // for (int i = 0; i < n; i++){
    //     for (int j = 0; j <= W; j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    for (int i = 0; i <= W; i++) ans = max(ans, dp[n - 1][i]);
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 82272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define INF 2147483647
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	int a;
	string s1,s2;
	cin >> a;
	cin >> s1 >> s2;
	string ans = "";
	rep(i,a){
		ans += s1[i];
		ans += s2[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,i,j,x;
  scanf("%d",&n);

  for(i=1; ; )
    {
      /*xにiを代入*/
      x=i;
      /*xが3の倍数か*/
      if(x%3==0){printf(" %d",x);}
      /*まずxの1の位が3か。そうでないなら10より小さいかを確認。小さいならbreak。大きいなら10の位が3
の倍数かを確かめる*/
      else
	{for(j=0; ;j++ )
	    {
	if(x%10==3)
	  {
	    printf(" %d",i);
	  break;
	  }
        if(0<=x && x<10){break;}
	else{ x=x/10;}
	    }
	}
      if(++i>n){break;}
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
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();
        
        	if(a < b){
                if(b < c){
                System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }else{
                System.out.println("No");
            }
        sc.close();
    }
}


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

void solve(long long N, std::vector<std::string> s, std::vector<long long> t,
           std::string X) {
    long long ans = 0;
    bool ok = false;
    for (int i = 0; i < s.size(); i++) {
        if(ok) ans += t[i];
        if( X == s[i] ){
            ok = true;
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> s(N);
    std::vector<long long> t(N);
    for (int i = 0; i < N; i++) {
        std::cin >> s[i];
        scanf("%lld", &t[i]);
    }
    std::string X;
    std::cin >> X;
    solve(N, std::move(s), std::move(t), X);
    return 0;
}


Measured memory_bytes: 256
//Multiple Gift

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    ll x,y;cin>>x>>y;
    int i=0;
    for(i=0;x<=y;i++){
        x*=2;
    }
    cout<<i<<nnn;
    return 0;
}

Measured memory_bytes: 3596
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n;
  vll lst(n);

  rep(i, n) cin >> lst[i];

  cin >> m;

  rep(i, m) {
    ll p, x;
    cin >> p >> x;
    p--;
    ll ans = 0;
    rep(j, n) {
      if (j == p)
        ans += x;
      else
        ans += lst[j];
    }
    cout << ans << endl;
  }

  return 0;
}


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

int main(){
string s1,s2;
cin>>s1>>s2;
ll ans=0;
for(ll i=0;i<s1.length();i++){
    if(s1[i]!=s2[i])
        ans++;
}
cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 3912
N=int(input())
A=list(input())
B=list(input())
C=list(input())

answer=0
for i in range(N):
  a=A[i]
  b=B[i]
  c=C[i]
  
  if a==b==c:
    continue
  elif a==b or b==c or c==a:
    answer+=1
  else:
    answer+=2
    
print(answer)

Measured memory_bytes: 9132
count = [0, 0, 0, 0]

for i in range(3):
    a, b = map(int, input().split())
    count[a - 1] += 1
    count[b - 1] += 1

flag = True
for e in count:
    if e == 3:
        print("NO")
        flag = False
        break

if flag:
    print("YES")


Measured memory_bytes: 2940
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, N = il()
    P = il()

    if len(P) == 0:
        print(X)
        exit()

    mx = max(P)
    p = MAX
    ret = 0
    for n in range(mx + 2):
        if n not in P and p > abs(X - n):
            ret = n
            p = X - n
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37544
N, Q = map(int, input().split())
rela = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    rela[a].append(b)
    rela[b].append(a)
hoge = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    hoge[p] += x
from collections import deque
que = deque([[-1, 0]])
while que:
    par, cur = que.popleft()
    for new in rela[cur]:
        if new == par:
            continue
        hoge[new] += hoge[cur]
        que.append([cur, new])
print(*hoge)

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


int main (){
    int N;
    cin>>N;
    vector<double> X(N);
    vector<string> U(N);
    for(int i=0; i<N; i++){
        cin>>X.at(i)>>U.at(i);
    }
    double Sum=0;
    for(int i=0; i<N; i++){
        if(U.at(i)=="JPY"){
            Sum += X.at(i);
        }
        else{
            Sum += X.at(i)*380000;
        }
    }
    cout<<Sum<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = False
b = [False] * 1000010
for i in range(n - 1):
    if a[i] == a[i + 1]:
        if b[a[i]]:
            continue
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

ans = 0
for i in range(n):
    if not b[a[i]]:
        ans += 1
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

print(ans)


Measured memory_bytes: 32036
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = new Tuple<int, int>[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = new Tuple<int, int>(i + 1, cin.ReadInt);
            }

            A = A.OrderBy(a => a.Item2).ToArray();
            var s = "";
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(A[i].Item1);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 32476
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;

#define int long long

const int mod = 1e9+7;

int A(int n)
{
    int t = 1;
    for(int i=1;i<=n;i++){
        t *= i;
        t %= mod;
    }
    return t;
}

signed main()
{
    int n,m;
    scanf("%lld %lld",&n,&m);
    if(abs(n-m) > 1) {
        printf("0\n");
    } else if(n==m){
        printf("%lld\n",(2*(A(n)%mod)*(A(n)%mod))%mod);
    } else {
        printf("%lld\n",((A(n)%mod)*(A(m)%mod))%mod);
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        try {
 
            String str[] = br.readLine().split("\\s+");
            int array[] = new int[str.length];
 
            for(int i = 0; i < str.length; i++){
                array[i] = Integer.parseInt(str[i]);
            }
 
            Dice dice = new Dice();
            dice.setNumber(array[0], array[1], array[2], array[3], array[4], array[5]);
 
            String order = br.readLine();
 
            for(int i = 0; i < order.length(); i++){
                dice.roll(order.charAt(i));
            }
 
            System.out.println(dice.getTop());
 
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
 
class Dice{
 
    private int number[];
    private int work[];
 
    Dice(){
        number = new int[6];
        work = new int[6];
    }
 
 
    public void roll(char dst){
        for(int i = 0; i < 6; i++) work[i] = number[i];
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
            break;
        case 'N':
            setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
            break;
        case 'S':
            setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
            break;
        case 'W':
            setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
            break;
        }
    };
 
    public int getTop(){
        return number[0];
    }
 
    public void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
};


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

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int N;
  std::cin>>N;
  
  std::string result;
  
  int d1,d2;
  int zorome=0;
  for(int i=0;i!=N;i++)
  {
    std::cin>>d1>>d2;
    if(d1==d2)
    {
      zorome++;
    }
    else
    {
      zorome=0;
    }
    
    if(zorome==3)
    {
      break;
    }
  }
  
  if(zorome==3)
  {
    result="Yes";
  }
  else
  {
    result="No";
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3648
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, K, *A = map(int, read().split())

    ans = INF
    for bit in range(1 << N):
        if (not (bit & 1)) or bin(bit).count('1') != K:
            continue

        total = 0
        max_height = A[0]
        for i, a in enumerate(A[1:], 1):
            if a <= max_height:
                if bit & (1 << i):
                    total += max_height - a + 1
                    max_height += 1
            else:
                max_height = a

        if ans > total:
            ans = total

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// d_abc106.cpp
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


vector<vector<int>> sum;
ll N, M, Q;

void makeSumTable(vector<int> L, vector<int> R)
{
    ll i, j;

    sum = vector<vector<int>> (N + 1, vector<int>(N + 1, 0));

    REP(i, M){
        ++sum[L[i]][R[i]];
    }

    FOR(i, 1, N + 1){
        FOR(j, 1, N + 1){
            sum[i][j] += sum[i - 1][j];
            sum[i][j] += sum[i][j - 1];
            sum[i][j] -= sum[i - 1][j - 1];
        }
    }
}

int getSum(int L, int R){
    int ans = sum[R][R] - sum[R][L - 1] - sum[L - 1][R] + sum[L - 1][L - 1];
    return ans;
}

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

    ll i;

    cin >> N >> M >> Q;
    // scanf("%d %d %d", N, M, Q);

    vector<int> L(M);
    vector<int> R(M);
    REP(i, M){
        cin >> L[i] >> R[i];
        // scanf("%d %d", &L[i], &R[i]);
    }

    vector<int> p(Q);
    vector<int> q(Q);
    REP(i, Q){
        cin >> p[i] >> q[i];
        // scanf("%d %d", &p[i], &q[i]);

    }

    makeSumTable(L, R);

    int ans;
    REP(i, Q){
        ans = getSum(p[i], q[i]);
        cout << ans << endl;
        // printf("%d\n", ans);
    }
}


Measured memory_bytes: 5120
/**
 *   created: 09 August 2019  11:55:44
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vector<string> v(n);
		rep(i,0,n){
			string s;
			cin>>s;
			sort(all(s));
			v[i] = s;
		}
		sort(all(v));
		ll ind = 0,prv=0;
		ll res = 0;
		while(prv<n){
			if(ind>=n)
				break;
			// trace1(prv);
			ll ind = upper_bound(all(v),v[prv])-v.begin();
			ll temp = ind - prv;
			prv = ind;
			res += (temp*(temp-1))/2;
			// trace3(ind,res,n);
		}
		cout<<res;
	}
	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

ll f1(ll t){
	return t*(t+1)/2;
}
ll f(ll x){
	ll sum = 0;
	loop(i, 1, x+1){
		sum+=i*f1(x/i);
	}
	return sum;
}

int main() {
	ll n, ans;
	cin >> n;
	cout << f(n) << endl;
	return 0;
}

Measured memory_bytes: 3592
N, L, T = map(int, input().split())
X = [0 for i in range(N)]
W = [0 for i in range(N)]
E = [0 for i in range(N)]
count = 0
for i in range(N):
    X[i], W[i] = map(int, input().split())
    if W[i] == 1:
        end = X[i] + T
        end = end % L
    if W[i] == 2:
        end = X[i]-T
        end = end % L
        if end < 0:
            end += L
    E[i] = end
    shu = L / 2.0
    if i > 0 and W[i] == 2 and  W[0] == 1:
        sa = X[i] -X[0]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count += (T - gikan ) // shu + 1
        if (T - gikan) % shu == 0:
            count -= 1

    if i > 0 and W[i] == 1 and  W[0] == 2:
        sa = X[0] -X[i]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count -= (T - gikan ) // shu + 1

#print(E)
count = count % N
if count < 0:
    count += N
count = int(count)
#print(count)
basho = E[0]
E.sort()
ind = E.index(basho)
result = [0 for i in range(N)]
for i in range(N):
    newind = ind + i
    if newind >= N :
        newind -= N
    result[count] = E[newind]
    count += 1
    if count >= N:
        count -= N

for i in range(N):
    print(result[i])


Measured memory_bytes: 13864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
	const int n;
	int __size;
	vector<int> uf;
public:
	// 初期化 UnionFind uni(n) のように宣言すれば良い
	UnionFind(int _n) : n(_n), __size(_n), uf(_n, -1) {}
	// find (木の根を求める)
	int find(int x) { return (uf[x] < 0) ? x : uf[x] = find(uf[x]); }
	// x と y が同じ集合に属するかどうか
	bool same(int x, int y) { return find(x) == find(y); }
	// x が属する集合の要素数
	int size(int x) { return -uf[find(x)]; }
	// 集合はいくつあるか
	int size() { return __size; }
	// x と y の属する集合を併合
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		__size--;
		if (uf[y] < uf[x]) swap(x, y);
		uf[x] += uf[y]; uf[y] = x;
		return true;
	}
};

using Graph = vector< vector<int> >;


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

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> ab(m);
	rep(i, m) cin >> ab[i].first >> ab[i].second;

	int ans = 0;

	rep(i, m) {
		// 木を作る
		UnionFind uni(n);

		rep(j, m) {
			// 自分以外の辺をつないで連結成分が2となったら橋
			if (i == j) continue;
			uni.unite(ab[j].first - 1, ab[j].second - 1);
		}
		if (uni.size() != 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; 
static const int MAX_N = 1001;
int n, W;
int w[MAX_N], v[MAX_N];
int dp[MAX_N+1][MAX_N+1];
 
void solve(){
  	memset(dp, 0, sizeof(dp));
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<=W; j++){
            if (j<w[i]) {
                dp[i][j] = dp[i+1][j];
            } else {
                dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[0][W] << endl;
}
 
int main(){
    // 入力
    cin >> n >> W;
    for(int i=0; i<n; i++){
        cin >> v[i] >> w[i] ;
    }
    solve();
 
    return 0;
}


Measured memory_bytes: 7044
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int D, N;
    std::cin >> D >> N;

    if (D == 0) {
        if (N == 100) {
            std::cout << 101 << std::endl;
        } else {
            std::cout << N << std::endl;
        }
    } else if (D == 1) {
        if (N == 100) {
            std::cout << 10100 << std::endl;
        } else {
            std::cout << N * 100 << std::endl;
        }
    } else {
        if (N == 100) {
            std::cout << 1010000 << std::endl;
        } else {
            std::cout << N * 10000 << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        for (;;)
        {
            string[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            if (W == 0 && H == 0) { break; }
            for (int i = 0; i < H; i++)
            {
                for (int j = 1; j < W; j++)
                {
                    Console.Write("#");
                }
                Console.WriteLine("#");
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 17956
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

#define P 1000000007
int n, a[210000], tx[210000], ans, now;

bool cmp(int x, int y) {
	return a[x] < a[y];
}

int main() {
	ans = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i + n]);
	for (int i = 1; i <= 2 * n; i++)
		tx[i]= i;
	sort(tx + 1, tx + 2 * n + 1, cmp);
	for (int i = 1; i <= 2 * n; i++) {
		if (now > 0 && tx[i] > n)
			ans = 1LL * ans * now % P, now -= 1;
		else if (now < 0 && tx[i] <= n)
			ans = 1LL * ans * (- now) % P, now += 1;
		else if (tx[i] <= n)
			now += 1;
		else
			now -= 1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
	static int matrix[][];
	static int n;
	static int i, j, m;
	static int c;
	public static void main(String args[]){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		c = 0;
		try{
			while(true){
				n = Integer.parseInt(br.readLine());
				if(n == 0) return;
				c++;

				matrix = new int[n][n];
				i = 0; j = 0; m = 1;
				while(i < n-1 || j < n-1){
					migiue();
					if(j < n-1){
						j++;
					}else{
						i++;
					}

					hidarishita();
					if(i < n-1){
						i++;
					}else{
						j++;
					}
				}
				matrix[n-1][n-1] = m;
				print(matrix);
			}
		}catch(Exception e){
			System.err.println(e);
		}
	}

	static void migiue(){
		while(i > 0 && j < n-1){
			matrix[i][j] = m;
			m++;
			i--;
			j++;
		}
		matrix[i][j] = m;
		m++;
	}

	static void hidarishita(){
		while(j > 0 && i < n-1){
			matrix[i][j] = m;
			m++;
			j--;
			i++;
		}
		matrix[i][j] = m;
		m++;
	}

	static void print(int m[][]){
		System.out.println("Case " + c + ":");
		for(int i = 0; i < m.length; i++){
			for(int j = 0; j < m[i].length; j++){
				System.out.print(String.format("%1$3d", m[i][j]));
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 19064
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    s = list(input_string[0][:])
    c_1 = 0
    for i in range(len(s))[1:]:
        if s[i] == s[i-1]:
            if s[i] == "1":
                s[i] = "0"
            else:
                s[i] = "1"
            c_1 += 1
    c_2 = 0
    for i in range(len(s))[::-1][1:]:
        if s[i] == s[i+1]:
            if s[i] == "1":
                s[i] = "0"
            else:
                s[i] = "1"
            c_2 += 1
    return c_2 if c_2 > c_1 else c_1



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    vl rui(n+1);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        rui[i+1] = rui[i] + a[i];
        sum += a[i];
    }

    ll ans = INF;
    exrep(x, 1, n-1) {  // すぬけ君がx枚取ったとする
        ll snuke = rui[x];
        ll ara = sum - snuke;
        chmin(ans, abs(snuke - ara));
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int N, M, K;
	int cost[100][100], time[100][100];
	while(cin >> N >> M, N || M){
		fill_n( (int*)cost, 100*100, 1e6 );
		fill_n( (int*)time, 100*100, 1e6 );
		int A, B;
		for(int i = 0; i < N; i++){
			cin >> A >> B;
			A--; B--;
			cin >> cost[A][B] >> time[A][B];
			cost[B][A] = cost[A][B]; time[B][A] = time[A][B];
		}
		
		for(int k = 0; k < M; k++){
			for(int i = 0; i < M; i++){
				for(int j = 0; j < M; j++){
					cost[i][j] = min( cost[i][j], cost[i][k] + cost[k][j] );
					time[i][j] = min( time[i][j], time[i][k] + time[k][j] );
				}
			}
		}

		cin >> K;
		int P, Q, R;
		for(int i = 0; i < K; i++){
			cin >> P >> Q >> R; P--; Q--;
			if(R == 0) printf("%d\n", cost[P][Q] );
			else printf("%d\n", time[P][Q] );
		}
	}
	return 0;
}

Measured memory_bytes: 1220
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static char[] str;
	static int I, pos;

	public static void main(String[] arg) {
		while (true) {
			str = sc.next().toCharArray();
			I = sc.nextInt();
			if (str[0] == '0') break;
			pos = 0;
			Mid root = parseMid();
			System.out.println(root.ch(I));
		}
	}

	static Mid parseMid() {
		Mid mid = new Mid();
		while (pos < str.length && str[pos] != ')') {
			if (Character.isDigit(str[pos])) {
				int t = parseInt();
				if (str[pos] == '(') {
					++pos;
					Mid c = parseMid();
					++pos;
					c.times = t;
					mid.child.add(c);
				} else {
					char[] cs = new char[t];
					Arrays.fill(cs, str[pos]);
					Leaf c = new Leaf(String.valueOf(cs));
					++pos;
					mid.child.add(c);
				}
			} else {
				Leaf c = parseLeaf();
				mid.child.add(c);
			}
		}
		return mid;
	}

	static Leaf parseLeaf() {
		int start = pos;
		while (pos < str.length && 'A' <= str[pos] && str[pos] <= 'Z') {
			++pos;
		}
		return new Leaf(String.valueOf(str, start, pos - start));
	}

	static int parseInt() {
		int ret = 0;
		while (pos < str.length && Character.isDigit(str[pos])) {
			ret *= 10;
			ret += str[pos] - '0';
			++pos;
		}
		return ret;
	}

	static abstract class Node {
		abstract long length();

		abstract char ch(int pos);
	}

	static class Mid extends Node {
		ArrayList<Node> child = new ArrayList<Node>();
		int times = 1;

		long length() {
			long ret = 0;
			for (Node c : child) {
				ret += c.length();
				if (ret > I) break;
			}
			return Math.min(ret * times, I + 1);
		}

		char ch(int pos) {
			long oneLen = 0;
			for (Node c : child) {
				oneLen += c.length();
			}
			if (pos / oneLen >= this.times) {
				return '0';
			}
			pos %= oneLen;
			long start = 0;
			for (Node c : child) {
				long len = c.length();
				if (pos < start + len) {
					return c.ch((int) (pos - start));
				}
				start += len;
			}
			return '0';
		}
	}

	static class Leaf extends Node {
		String str;

		Leaf(String s) {
			this.str = s;
		}

		long length() {
			return this.str.length();
		}

		char ch(int pos) {
			return this.str.charAt(pos);
		}
	}

}

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

int main() {
	string s;
	cin >> s;
	int i, status;
		status = 0;
		for (i = 0; i < 3; i++) {
			if (s[i] == s[i + 1]) { status = 1; }
		}
	
		if (status == 1) {
			printf("Bad");
	}
		else {
			printf("Good");
		}

	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	int x = n / 1.08;
	
	if ((int)((x-1)*1.08) == n) cout << x - 1 << endl;
	else if ((int)(x*1.08) == n) cout << x << endl;
	else if ((int)((x+1)*1.08) == n) cout << x + 1 << endl;	
	else cout << ":(\n";
	debug() << imie((x-1)*1.08);
	
	return 0;
}


Measured memory_bytes: 3584
#########
#thiking Face
from itertools import permutations

n,m=map(int,input().split())
path=set()
for _ in range(m):
    u,v=map(int,input().split())
    path|={(u-1,v-1),(v-1,u-1)}

print(sum(all((u,v) in path for u,v in zip(p,p[1:]))
          for p in permutations(range(n)) if p[0]==0))


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

fn main() {
	let n: u32 = read();
	let k: u32 = read();
	let mut h: Vec<u32> = Vec::new();
	for _i in 0..n {
		h.push(read());
	}

	let result: u32 = h.iter().map(|x| {
		if x >= &k { return 1; } else { return 0; }
	}).fold(0, |x, y| x + y);

	println!("{}", result);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define R return
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std;
typedef long long L;
const int N=3e5+50;
const L P=1000000000000000031LL,X=1000000000000000003LL;
L add(L a,L b){ a+=b; R a>=P?a-P:a; }
L sub(L a,L b){ a-=b; R a<0?a+P:a; }
L mul(L a,L b){ L r=0LL;for(;b;b>>=1LL,a=add(a,a))if(b&1LL)r=add(r,a);return r;}
L pw(L a,L k){  L r=1LL;for(;k;k>>=1LL,a=mul(a,a))if(k&1LL)r=mul(r,a);return r;}
L I=pw(X,P-2); 

char s[N]; 
L ans,n,A[N],B[N],u;
L f(char c,L x){
	if(c=='+')R add(x,1); 
	if(c=='-')R sub(x,1); 
	if(c=='<')R mul(x,I);
	if(c=='>')R mul(x,X); 
	exit(-1);
}
void g(char c,L &a,L &b){
	if(c=='+')b=sub(b,a);
	if(c=='-')b=add(b,a);
	if(c=='<')a=mul(a,X);
	if(c=='>')a=mul(a,I); 
}
L F(L a,L b,L x){ R add(mul(a,x),b); }
map<L,L> M;
int main(){
	scanf("%lld%s",&n,s+1); 
	dec(i,n,1)u=f(s[i],u); 
	A[n+1]=1,B[n+1]=0; dec(i,n,1)g(s[i],A[i]=A[i+1],B[i]=B[i+1]); 
	++M[F(A[n+1],B[n+1],0)]; dec(i,n,1)ans+=M[F(A[i],B[i],u)],++M[F(A[i],B[i],0)];
	printf("%lld\n",ans);
	R 0;
}


Measured memory_bytes: 35968