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

void sieve(bool *primes, int n)
{
  int m = ceil(sqrt(n));
  int k = 2;

  for (int i=0;i<=n;i++) primes[i]=true;
  primes[0] = primes[1] = false;

  for (int i=2;i<=m;i++)
  {
    if (primes[i])
    {
      for (int k=2*i; k<=n; k+=i)
        primes[k] = false;
    }
  }
}

int main()
{
  bool primes[10001];
  int ns[10000];
  int num = 0;
  int maxn = 0;
  int n;

  while (cin >> n)
  {
    ns[num] = n;
    maxn = max(maxn, n);
    num++;
  }

  sieve(primes, maxn);

  for (int i=0;i<num;i++)
  {
    int p = 1;
    int q = ns[i];
    int ans = 0;
    for (int j=0;j<ns[i];j++)
    {
      if (primes[p] && primes[q]) ans++;
      p++;
      q--;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
import java.util.Scanner;

public class Main {
	
	static class Vec{
		int x, y;
		Vec(int x, int y){
			this.x=x;
			this.y=y;
		}
	}
	
	static double value(Vec v) {
		return Math.sqrt(v.x*v.x+v.y*v.y);
	}
	static double scalar(Vec v1, Vec v2) {
		return v1.x*v2.x+v1.y*v2.y;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int x1=sc.nextInt();
			int y1=sc.nextInt();
			int x2=sc.nextInt();
			int y2=sc.nextInt();
			Vec p1=new Vec(x1, y1);
			Vec p2=new Vec(x2, y2);
			Vec a=new Vec(x2-x1, y2-y1);
			int q=sc.nextInt();
			for(int i=0; i<q; i++) {
				int xp=sc.nextInt();
				int yp=sc.nextInt();
				Vec b=new Vec(xp-x1, yp-y1);
				double k=scalar(a, b)/(value(a)*value(a));
				double ansx=k*a.x+p1.x;
				double ansy=k*a.y+p1.y;
				System.out.printf("%.9f %.9f\n", 2*ansx-xp, 2*ansy-yp);
			}

		}
	}
}


Measured memory_bytes: 37664
function Main(input) {
	let inputs = input.split(' ').map((n) => (parseInt(n, 10)));
	let a = inputs[0];
	let b = inputs[1];
	let k = inputs[2];

	let large = a > b ? a : b;
	let small = a > b ? b : a;
	let mod = large % small;

	while(mod) {
		let tmp = mod;
		mod = small % mod;
		small = tmp;
	}

    // この時点のsmallが最小公倍数
  
	let cnt = 0;
	for(let i = small; i >= 0; i--) {
		if((a%i === 0) && (b%i === 0)) cnt++;
		if(cnt === k) {
			console.log(i);
			return
		}
	}

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

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

    int n, m;

    cin >> n >> m;

    int x, y;
    vector<int> indeg(n + 1);
    vector<vector<int>> to(n + 1);

    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        ++indeg.at(y);
        to.at(x).push_back(y);
    }

    vector<int> dp(n + 1);
    queue<int> q;

    for(int i = 1; i <= n; ++i) {
        if(indeg.at(i) == 0) {
            q.push(i);
        }
    }

    int qf, ans = 0;

    while(!q.empty()) {
        qf = q.front();
        q.pop();
        ans = max(ans, dp.at(qf));
        for(int qft: to.at(qf)) {
            dp.at(qft) = max(dp.at(qft), dp.at(qf) + 1);
            if(--indeg.at(qft) == 0) q.push(qft);
        }
    }

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

    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>

using namespace std;

static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;

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

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}

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

int D,N,T[210],A[210],B[210],C[210];
int dp[210][210] = {{0}};
int main(){
	cin >> D >> N;
	for(int i=1;i<=D;i++) cin >> T[i];
	for(int i=1;i<=N;i++){
		cin >> A[i] >> B[i] >> C[i];
		dp[0][i] = 0;
	}
	for(int i=1;i<=D;i++){
		for(int j=1;j<=N;j++){
			if(A[j]<=T[i] && T[i]<=B[j]){
				if(i==1) dp[i][j] = 0;
				else{
					for(int k=1;k<=N;k++){
						if(dp[i-1][k]!=-1){
							dp[i][j] = max(dp[i][j],dp[i-1][k]+abs(C[j]-C[k]));
						}
					}
				}
			}else dp[i][j] = -1;
		}
	}
	int ans = 0;
	for(int i=1;i<=N;i++){
		ans = max(ans,dp[D][i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3248
n = int(input())
l = list(map(int,input().split()))

for i in range(n):
    l[i] = l[i] - i-1
l.sort()
if n % 2 == 1:
    print(sum(list(map(lambda x: abs(x-l[((n//2))]),l))))
else:
    print(min(sum(list(map(lambda x: abs(x-l[(n//2)-1]),l))),sum(list(map(lambda x: abs(x-l[(n//2)]),l)))))


Measured memory_bytes: 31192
import java.util.*;

public class Main {
    static long count = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //数列の長さ
        int[] a = new int[n]; //数列A
        int max = 0;
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }
        int[] b = new int[n];
        countingSort(a, b, max);
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<n; i++) {
            if(i==0) sb.append(b[i]);
            else sb.append(" " + b[i]);
        }
        System.out.println(sb); //出力
    }
    /**
     * 計数ソート
     */
    static void countingSort(int[] a, int[] b, int k) {
        int[] c = new int[k+1];
        for(int x : a) c[x]++;
        for(int i=1; i<=k; i++) c[i] += c[i-1];
        for(int i=a.length-1; i>=0; i--) { //数列Aの後ろから詰める
            b[c[a[i]]-1] = a[i];
            c[a[i]]--;
        }
    }
}


Measured memory_bytes: 558404
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()

    val E = Vector.fill(N)(new scala.collection.mutable.ArrayBuffer[(Int, Byte)]())
    val ru, rv, rw = sc.nextInt()
    E(ru-1).append((rv-1, (rw % 2).toByte))
    E(rv-1).append((ru-1, (rw % 2).toByte))
    (0 until N - 2) foreach { _ =>
      val u, v, w = sc.nextInt()
      E(u-1).append((v-1, (w % 2).toByte))
      E(v-1).append((u-1, (w % 2).toByte))
    }

    def dfs(root: Int, E: IndexedSeq[Seq[(Int, Byte)]]): IndexedSeq[Int] = {
      import scala.collection.immutable.Queue
      val visited = new Array[Boolean](N)
      val color = new Array[Int](N)
      visited(root) = true

      def recursive(queue: Queue[Int]): Unit =
        if (queue.nonEmpty) {
          val (u, dequeued) = queue.dequeue
          recursive(
            E(u). collect {
              case (v, w) if !visited(v) =>
                visited(v) = true
                if (w == 0)
                  color(v) = color(u)
                else
                  color(v) = 1 - color(u)
                v
            }. foldLeft(dequeued)((q, n) => q.enqueue(n)))
        }

      recursive(Queue[Int]().enqueue(root))
      color
    }

    println(dfs(ru, E).mkString("\n"))
  }

}

Measured memory_bytes: 124092
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define float long double 

int32_t main()
{
  IOS;
  char c;
  cin>>c;

  if(islower(c))
  cout<<'a'<<endl;
  else
  {
    cout<<'A'<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A+B+C >=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
K,N = map(int,input().split())
a = list(map(int,input().split()))
maxl = 0
for i in range(N):
    if i != N-1:
        if a[i+1]-a[i] > maxl:
            maxl = a[i+1]-a[i]
    else:
        if K-a[i] + a[0] > maxl:
            maxl = K-a[i] + a[0]
print(K-maxl)

Measured memory_bytes: 26436
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9;

int dfs(const vector< vector<int> > &G, vector<int> &d, int v){
  if(d[v] >= 0) return d[v];
  for(size_t i = 0; i < G[v].size(); ++i){
    int t_ = dfs(G,d,G[v][i]);
    d[v] = max(d[v],t_+1);
  }
  return d[v];
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> D(N,0);
  vector< vector<int> > G_(N);
  for(int i = 0; i < N-1+M; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    ++D[b];
    G_[b].push_back(a);
  }
  int r = -1;
  for(int i = 0; i < N; ++i){
    if(D[i]) continue;
    r = i;
  }
  vector<int> d(N,-1);
  d[r] = 0;
  for(int i = 0; i < N; ++i){
    if(d[i] < 0) dfs(G_,d,i);
  }
  //for(int i = 0; i < N; ++i) cerr << d[i] << " ";cerr << endl;
  vector<int> ans(N,0);
  for(int i = 0; i < N; ++i){
    for(size_t j = 0; j < G_[i].size(); ++j){
      int v = G_[i][j];
      if(d[i] == d[v]+1) ans[i] = v+1;
    }
    
  }
  for(int i = 0; i < N; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 10496
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)

N, M = map(int, input().split())

h = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    h[x-1].append(y-1)

dp = [0]*N


def dist(v):
    if dp[v] > 0:
        return dp[v]
    dp[v] = 0
    for nv in h[v]:
        dp[v] = max([dp[v], dist(nv)+1])
    return dp[v]


ans = 0
for v in range(N):
    ans = max([ans, dist(v)])

print(ans)


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

typedef long long ll;

int main() {
    ll H, W;
    cin >> H >> W;
    ll ans = 1e18, S1, S2, S3, d;
    for (int i = 1; i < H; i++) {
        S1 = W * i;
        S2 = W / 2 * (H - i);
        S3 = W * H - S1 - S2;
        d = max({S1, S2, S3}) - min({S1, S2, S3});
        if (d < ans ) ans = d;
        if (i == H - 1) continue;
        S2 = W * ((H - i) / 2);
        S3 = W * H - S1 - S2;
        d = max({S1, S2, S3}) - min({S1, S2, S3});
        if (d < ans ) ans = d;
    }
    for (int i = 1; i < W; i++) {
        S1 = H * i;
        S2 = H / 2 * (W - i);
        S3 = W * H - S1 - S2;
        d = max({S1, S2, S3}) - min({S1, S2, S3});
        if (d < ans ) ans = d;
        if (i == W - 1) continue;
        S2 = H * ((W - i) / 2);
        S3 = W * H - S1 - S2;
        d = max({S1, S2, S3}) - min({S1, S2, S3});
        if (d < ans ) ans = d;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    n=1
    par=[0]
    rnk=[0]
    def __init__(self,size):
        self.n=size
        self.par=[i for i in range(self.n)]
        self.rnk=[0 for i in range(self.n)]
    def find(self,vertex1):
        if self.par[vertex1]==vertex1:
            return vertex1
        else:
            self.par[vertex1]=self.find(self.par[vertex1])
            return self.par[vertex1]
    def unite(self,vertex1,vertex2):
        vertex1=self.find(vertex1)
        vertex2=self.find(vertex2)
        if vertex1==vertex2:
            return
        if (self.rnk[vertex1]<self.rnk[vertex2]):
            self.par[vertex1]=vertex2
        else:
            self.par[vertex2]=vertex1
            if(self.rnk[vertex1]==self.rnk[vertex2]):
                self.rnk[vertex1]+=1
    def same(self,vetrex1,vertex2):
        return self.find(vetrex1)==self.find(vertex2)
N=int(input())
P=[(i,)+tuple(map(int,input().split())) for i in range(N)]
G=UnionFind(N)
P.sort(key=lambda x:x[1])
for i in range(N-1):
    if P[i][1]==P[i+1][1]:
        G.unite(P[i][0],P[i+1][0])
P.sort(key=lambda x:x[2])
for i in range(N-1):
    if P[i][2]==P[i+1][2]:
        G.unite(P[i][0],P[i+1][0])
P.sort(key=lambda x:x[0])
Dx=dict()
Dy=dict()
for i in range(N):
    j=G.find(i)
    if j in Dx:
        Dx[j].add(P[i][1])
    else:
        Dx[j]={P[i][1]}
    if j in Dy:
        Dy[j].add(P[i][2])
    else:
        Dy[j]={P[i][2]}
ans=-N
for j in Dx:
    ans+=len(Dx[j])*len(Dy[j])
print(ans)

    

Measured memory_bytes: 30756
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a*b > a+b && a*b > a-b {
		fmt.Print(a * b)
	} else if a+b > a-b {
		fmt.Print(a + b)
	} else {
		fmt.Print(a - b)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

const ll MOD = 1000000000LL + 7LL;
inline ll add(ll a, ll b) { return (a+b)%MOD; }
inline ll sub(ll a, ll b) { return (a+MOD-b)%MOD; }
inline ll mul(ll a, ll b) { return (a*b)%MOD; }
inline void chadd(ll &a, ll b) { a = add(a, b); }
inline void chmul(ll &a, ll b) { a = mul(a, b); }

ll solve(const int N, const int M, const vector<int> &A, const vector<int> &B) {
  //  REP(i,N) cout << " " << A[i];                                                    
  //  cout << endl;                                                                    
  //  REP(i,M) cout << " " << B[i];                                                    
  //  cout << endl;                                                                    
  REP(i,N-1) if(A[i] == A[i+1]) return 0;
  REP(i,M-1) if(B[i] == B[i+1]) return 0;
  ll ans = 1;
  int sum = N*M;
  int m	= 0, n = 0;
  for(int i = N*M; i >=	1; i--) {
    if(n < N && A[n] == i && m < M && B[m] == i) {
      // 両方あるから交点に置く                                              
      chmul(ans, 1LL);
      n++, m++;
    }
    else if(n < N && A[n] == i &&( (m < M && B[m] != i) || m >= M)) {
      // 行にだけある                                                                  
      chmul(ans, m);
      n++;
    }
    else if(m < M && B[m] == i &&( (n < N && A[n] != i) || n >= N)) {
      // 列にだけある                                                              
      chmul(ans, n);
      m++;
    } else {
      // どちらにもない                                                      
      int rem = m * n - (sum - i);
      //      cout << rem << endl;                                                     
      if(rem <= 0) return 0;
      chmul(ans, rem);
    }
  }
  return ans;
}


int main() {
  int N, M;
  cin>>N>>M;
  vector<int> A(N), B(M);
  REP(i,N) cin>>A[i];
  REP(i,M) cin>>B[i];
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  ll ans = 0;
  if(N >= M) ans = solve(N, M, A, B);
  else ans = solve(M, N, B, A);
  //  cout << "Answer=";                                                               
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

const int lim = 2e5 + 5;
int ma[lim];

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++)
	{
		int num; cin >> num;
		++ma[num];
	}
	for(int i = 1; i <= n; i++)
	{
		cout << ma[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4300
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int H,W,K;
  cin>>H>>W>>K;
  
  string S[H];
  for(int i=0;i<H;i++){
    cin>>S[i];
  }
  
  int ans=0;
  
  
  for(int i=0;i<((1<<H)-1);i++){
    for(int j=0;j<((1<<W)-1);j++){
      int check=0;
      for(int l=0;l<H;l++){
        for(int m=0;m<W;m++){
          if(((i>>l)&1)==0&&((j>>m)&1)==0&&S[l][m]=='#'){
            check++;
          }
        }
      }
      if(check==K){
        ans++;
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		int i = 1;
		StringBuilder sb1 = new StringBuilder();
		for(i = 1 ; i <= n ; i++){
			int k = i;
			if(i%3 == 0 ){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 == 3){
				sb1.append(" "+i);
				continue;
			}
			if(i%10 != 3 && i%3 != 0){
			for(int m = 1; m <=3 ; m++){
			k /=10;
			if(k%10 == 3){
				sb1.append(" "+i);
				break;
			}
			}
			}
			}
		System.out.println(sb1);
	}
}

Measured memory_bytes: 22960
def main():
    a = input()

    if a == "MON":
        print(6)
    elif a == "TUE":
        print(5)
    elif a == "WED":
        print(4)
    elif a == "THU":
        print(3)
    elif a == "FRI":
        print(2)
    elif a == "SAT":
        print(1)
    elif a == "SUN":
        print(7)


if __name__ == '__main__':
    main()


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

int main() {
	bool check[4];
	int n;

	for (int i = 0; i < 4; i++) {
		check[i] = false;
	}

	for (int i = 0; i < 4; i++) {
		cin >> n;
		if (n == 1) {
			check[0] = true;
		}
		else if (n == 9) {
			check[1] = true;
		}
		else if (n == 7) {
			check[2] = true;
		}
		else if (n == 4) {
			check[3] = true;
		}
	}

	if (check[0] && check[1] && check[2] && check[3]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
def main():
    n = int(input())
    ab = [list(map(int,input().split())) for _ in range(n)]
    res = 0
    for a,b in ab[::-1]:
        a += res
        if a%b != 0:
            res += b-a%b
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61016
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector <int> v;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);int cnt=1,d;
  for(int i=0;i<n-1;i++){
    if(cnt==1) d=a[i];
    if (d==a[i+1]) {
      cnt++;
      if(i+1==n-1) v.push_back(cnt);
    }
    if(d!=a[i+1]) {
      v.push_back(cnt);
      if(i+1==n-1) v.push_back(1);
      cnt=1;
    }
  }
  int ans=0;
    for(int i=0;i<v.size();i++) {
      if(v[i]%2) ans++;
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;

int main() {
 
int N,a,b,ans=0;
cin >>N;
// vector<int> A(N);
  cin>>a;
  ans+=a;
 for(int i=1; i<N-1; i++){cin>>b; ans+=min(a,b); a=b;}
cout<<ans+a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)

#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lin "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
// #define lin puts("");
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
void solve()
{
    int k;
    string s;
    cin>>k;
    cin >> s;
    if (s.size() <= k)
    {
        cout << s << lin;
    }
    else
    {
        rep(i, k)
        {
            cout << s[i];
        }
        cout << "..." << lin;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    auto start = clock();
    fast_io;
    //freopen("test.txt", "r", stdin);
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    auto stop = clock();
    cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}


Measured memory_bytes: 3844
#include <stdio.h>
#include <stdlib.h>
typedef struct{
  int cell;
  int befcell;
  int atime;
  int btime;
  int frag;
}node;
int main(){
  int i,j,n,m,sel,k,time=0,a=0;
  int **Adj;
  node *V;
  scanf("%d",&n);
  V = malloc(n*sizeof(node));
  Adj = malloc(n*sizeof(int *));
  for(i=0;i<n;i++)
    {
      Adj[i] = malloc(n*sizeof(int));
      V[i].cell = i+1;
      V[i].atime = 0;
      V[i].btime = 0;
      V[i].frag = 0;
    }
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  Adj[i][j] = 0;
	}
    }
  for(j=0;j<n;j++)
    {
      scanf("%d%d",&sel,&m);
      for(i=0;i<m;i++)
	{
	  scanf("%d",&k);
	  Adj[sel-1][k-1]++;
	}
    }

  V[a].befcell = -1;
  for(i=0;i<n;i++)
    {
      if(i==0 && V[a].frag ==0)
	{
	  time++;
	  V[a].atime=time;
	}
      if(Adj[a][i]>=1 && V[i].frag == 0)
	{
	  
	  V[a].frag = 1;
	  V[i].befcell=a;
	  a=i;
	  i=-1;	  
	  continue;
	}
      if(i==n-1)
	{
	  time++;
	  V[a].btime=time;
	  if(V[a].befcell == -1) break;
	  V[a].frag = 1;
	  a=V[a].befcell;
	  i=-1;
	  
	}
    }
  for(j=0;j<n;j++)
    {
      if(V[j].frag == 0)
	{
	  
	  a=j;
	  V[a].befcell = -1;
	  for(i=0;i<n;i++)
	    {
	      if(i==0 && V[a].frag ==0)
		{
		  time++;
		  V[a].atime=time;
		}
	      if(Adj[a][i]>=1 && V[i].frag == 0)
		{
		  V[a].frag = 1;
		  if(i != a){
		    V[i].befcell=a;}
		  a=i;
		  i=-1;	  
		  continue;
		}
	      if(i==n-1)
		{
		  time++;
		  V[a].btime=time;
		  if(V[a].befcell == -1) break;
		  V[a].frag = 1;
		  a=V[a].befcell;
		  i=-1;
	  
		}
	    }
	}
    }
  
  
  for(i=0;i<n;i++)
    printf("%d %d %d\n",V[i].cell,V[i].atime,V[i].btime);
  
  return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T>
class WeightedUnionFind {
    vector<int> uni;
    vector<T> weights;
    int n;
public:
    explicit WeightedUnionFind(int n, T SUM_UNITY = 0) :
    uni(static_cast<u32>(n), -1) , n(n), weights(n,  SUM_UNITY){};

    int root(int a) {
        if (uni[a] < 0) return a;
        else {
            int r = root(uni[a]);
            weights[a] += weights[uni[a]];
            return (uni[a] = r);
        }
    }

    bool unite(int a, int b, T w) {
        w += weight(a); w -= weight(b);
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b), w = -w;
        uni[a] += uni[b];
        uni[b] = a;
        weights[b] = w;
        return true;
    }

    int size(int a){
        return -uni[root(a)];
    }

    T weight(T a){
        root(a);
        return weights[a];
    }
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    WeightedUnionFind<int> un(n);
    for (int i = 0; i < m; ++i) {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        if (un.root(l-1) == un.root(r-1)){
            if(un.diff(l-1, r-1) != d){
                cout << "No" << "\n";
                return 0;
            }
        }else {
            un.unite(l-1, r-1, d);
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>

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

using namespace std;
const int inf = 1001001000;

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

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

//UnionFind木のテンプレ.parentには根のindexが入っている.
//根には連結成分のサイズが入っている.nはノード数.
class UnionFind{
public:
	vector<int> parent;
	UnionFind(){}
	UnionFind(int n){
		this->parent = vector<int>(n,-1);
	}
	int root(int x){
		if (this->parent[x] < 0) return x;
		this->parent[x] = root(this->parent[x]);
		return this->parent[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return false;
		if (this->parent[rx] > this->parent[ry]) swap(rx, ry);
		this->parent[rx] += this->parent[ry];
		this->parent[ry] = rx;
		return true;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->parent[this->root(x)];
	}
};


int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> bridge;
	vector<long long int> ans(m, 0);
	UnionFind uf(n);
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		bridge.push_back(pair<int, int>(a-1, b-1));
	}
	ans[m-1] = (long long int)n * (n - 1) / 2;
	for (int i = m - 2; i >= 0; i--)
	{
		pair<int, int> b = bridge.back();
		bridge.pop_back();
		int bf = b.first, bs = b.second;
		if (uf.same(bf,bs))
			ans[i] = ans[i + 1];
		else
			ans[i] = ans[i + 1] - (long long int)uf.size(bf) * (long long int)uf.size(bs);
		uf.unite(bf, bs);
	}
	rep(i, m) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cmath>
#include <climits>
using namespace std;

int N, A = 0, B;

int main()
{
    cin >> N;
    while (N--) {
        int Ai, Bi;
        cin >> Ai >> Bi;
        if (Ai > A) {
            A = Ai; B = Bi;
        }
    }
    cout << A + B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> a >> b >> c;

    if(c>=a && c<=b) cout << "Yes"; 
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	cin>>n;
	vector<ip> town(n);
	rep(i,n)cin>>town[i].first>>town[i].second;
	int perm[8] = {0,1,2,3,4,5,6,7};
	double ans = 0;
	int cnt = 0;
	do{
		++cnt;
		rep(i,n-1){
			double x = pow((town[perm[i]].first - town[perm[i+1]].first),2);
			double y = pow((town[perm[i]].second - town[perm[i+1]].second),2);
			ans += sqrt(x+y);
		}
	}while(next_permutation(perm, perm+n));
	cout<<fixed<<setprecision(10)<<ans/cnt<<endl;
	return 0;
}


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

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<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll P, Q, R; cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, R + P)) << endl;
}

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


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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias A = Tuple!(int, "x", int, "y", int, "h");

void main() {
    int n = readint;
    A[] a;
    for (int i = 0; i < n; i++) {
        auto xyh = readints;
        a ~= A(xyh[0], xyh[1], xyh[2]);
    }

    // 中心位置を全探索
    for (int x = 0; x <= 100; x++) {
        for (int y = 0; y <= 100; y++) {

            bool found = true;
            bool[int] set; // 高さ候補
            foreach (e; a) {
                // 高さ 0 以下はキャップされるので、正しい h が得られない
                if (e.h == 0) continue;

                int h = abs(x - e.x) + abs(y - e.y) + e.h;
                set[h] = true;
                if (set.length > 1) { // NG(候補が複数ある)
                    found = false;
                    break;
                }
            }

            if (set.length != 1) continue;
            int h = set.keys.front; // ただ一つの h の候補
            // h <= 0 以下のものも含めて答え合わせする
            foreach (e; a) {
                if (e.h != max(0, h - abs(x - e.x) - abs(y - e.y))) {
                    // 答え不一致
                    found = false;
                    break;
                }
            }

            if (found) {
                writeln(x, " ", y, " ", h);
                return;
            }
        }
    }
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
char s[100010];
int n;
long long k[30],ans=1;

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) k[s[i]-'a'+1]++;
	for(int i=1;i<=26;i++){
		ans*=(k[i]+1);
		ans%=mod;
	}
	ans--;
	ans%=mod;
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n, m, c;
    cin >> n >> m >> c;
    int b[m], a[n][m];
    REP(i,m)cin >> b[i];
    REP(i,n){
        REP(j,m){
            cin >> a[i][j];
        }
    }
    int ans = 0;
    REP(i, n){
        int code=0;
        REP(j,m){
            code += a[i][j] * b[j];
        }
        if (code + c > 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
nodes = None


class Node:
    def __init__(self, key=None, parent=None, left=None, right=None):
        self.key = key
        self.parent = parent
        self.left = left
        self.right = right


def insert(z):
    global nodes
    y = None
    x = nodes

    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    z.parent = y

    if y is None:
        nodes = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z


def get_inorder(inorder, node):
    if node.left is not None:
        get_inorder(inorder, node.left)
    inorder.append(node.key)
    if node.right is not None:
        get_inorder(inorder, node.right)
    return inorder


def get_preorder(preorder, node):
    preorder.append(node.key)
    if node.left is not None:
        get_preorder(preorder, node.left)
    if node.right is not None:
        get_preorder(preorder, node.right)
    return preorder


def p(node):
    print("", " ".join([str(i) for i in get_inorder([], node)]))
    print("", " ".join([str(i) for i in get_preorder([], node)]))


n = int(input())
for _ in range(n):
    s = input().split()
    if s[0] == "insert":
        key = int(s[1])
        insert(Node(key=key))
    else:
        p(nodes)



Measured memory_bytes: 140404
// 2011/01/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;
		if(n==0&&m==0)
			break;

		int cst[101][101];
		int tim[101][101];
		for(int i=1; i<=m; i++)
			for(int j=1; j<=m; j++)
				if(i==j)
					cst[i][j] = tim[i][j] = 0;
				else
					cst[i][j] = tim[i][j] = 200000;

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			cst[a][b] = cst[b][a] = c;
			tim[a][b] = tim[b][a] = t;
		}

		for(int h=1; h<=m; h++)
			for(int i=1; i<=m; i++)
				for(int j=1; j<=m; j++){
					if(cst[i][j]>cst[i][h]+cst[h][j])
						cst[i][j] = cst[i][h]+cst[h][j];
					if(tim[i][j]>tim[i][h]+tim[h][j])
						tim[i][j] = tim[i][h]+tim[h][j];
				}

		int k;
		cin >> k;

		for(int i=0; i<k; i++){
			int p, q, r;
			cin >> p >> q >> r;
			if(r==0)
				cout << cst[p][q] << endl;
			else
				cout << tim[p][q] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> H(n);
    rep(i,n) cin >> H[i];
    vector<int> g(n, 1);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (H[a] <= H[b]) g[a] = 0;
        if (H[b] <= H[a]) g[b] = 0;
    }
    ll ans = 0;
    rep(i,n) if(g[i] == 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
signed main(){
	ll n,s;
	cin>>n>>s;
	if(n<s){
		cout<<-1<<endl;
		return 0;
	}
	if(n==s){
		cout<<n+1<<endl;
		return 0;
	}
	for(int i=2;i*i<=n;i++){
		ll sum = 0;
		ll cur = n;
		while(cur>0){
			sum += cur%i;
			cur /= i;
		}
		if(sum == s){
			cout<<i<<endl;
			return 0;
		}
	}
	vector<ll> ldiv;
	for(int i=1;i*i<=n;i++){
		if( (n-s)%i == 0){
			ldiv.pb((n-s)/i + 1);
			//cout<<ldiv[ldiv.size()-1]<<endl;
		}
	}
	sort(ldiv.begin(),ldiv.end());
	for(int i=0;i<ldiv.size();i++){
		ll ct = ldiv[i];
		double sq = sqrt(1.0*n);
		if(1.0*ct>sq && n/ct+n%ct==s){
			cout<<ct<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
using ll=long long int;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

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

	int cnt = 0;

	for (int i = 0; i < n - 2; i++) {
		if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2])
			|| (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
			cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=Integer.parseInt(sc.next());
        int Y=Integer.parseInt(sc.next());
        for (int a=0;a<=N;a++){
            for (int b=0;b<=N-a;b++){
                if (a*10000+b*5000+(N-a-b)*1000==Y){
                    System.out.println(a+" "+b+" "+(N-a-b));
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl


int main(){
	cout << fixed << setprecision(5);
	int n;
	cin >> n;
	vector<float> v;
	for(int i(0);i<n;++i){
		double x;
		cin>>x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	float ans=0;
	for(int i(1);i<n;++i){
		ans+=(v[i]/pow(2,n-i));
	}
	ans+=(v[0]/pow(2,n-1));
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PR pair<int, int>
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
//constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//
int ary[] = {105,3*5*11,3*5*13,3*3*3*5,3*3*3*7};
signed main()
{
  ios();
  sort(ary,ary + 5);
  int N ;
  cin >> N;
  cout << count_if(ary,ary+5,[=](auto x){return x <= N;}) <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> A(N);vector<int>X(N);
  for(int i=1;i<N;i++){
    cin>>A.at(i);
    X.at(i)=0;
  }
  for(int i=1;i<N;i++){
    X.at(A.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    cout<<X.at(i)<<endl;
  }
}

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

int main( int argc, char *argv[] )
{
int i;
char A[ 100 ];
char B[ 100 ];
char C[ 100 ];

	cin >> A;
	cin >> B;
	cin >> C;

	i = strlen( A );
	if( A[ i - 1 ] != B[ 0 ] )
	{
		cout << "NO" << endl;

		return 0;
	}

	i = strlen( B );
	if( B[ i - 1 ] != C[ 0 ] )
		cout << "NO" << endl;
	else
		cout << "YES" << endl;

	return 0;
}






Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AIntegerProduct solver = new AIntegerProduct();
        solver.solve(1, in, out);
        out.close();
    }

    static class AIntegerProduct {
        private static final int K = 9;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = Math.round(in.nextDouble() * 1e9);
            }

            long[][] count = new long[2 * K + 1][2 * K + 1]; // [#twos][#fives]
            for (long x : a) {
                int t = 0;
                while (x % 2 == 0) {
                    t++;
                    x /= 2;
                }
                int f = 0;
                while (x % 5 == 0) {
                    f++;
                    x /= 5;
                }
                t = Math.min(t, 2 * K);
                f = Math.min(f, 2 * K);
                count[t][f]++;
            }

            long answer = 0;
            for (int i = 0; i < count.length; i++) {
                for (int j = 2 * K - i; j < count.length; j++) {
                    for (int x = 0; x < count.length; x++) {
                        for (int y = 2 * K - x; y < count.length; y++) {
                            answer += count[i][x] * count[j][y];
                            if (i == j && x == y)
                                answer -= count[i][x];
                        }
                    }
                }
            }
            answer /= 2;

            out.println(answer);
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}



Measured memory_bytes: 49588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << ' ' << x << ' ' << y << endl;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	int N; cin >> N;
	string ans;


	while(N != 0){
		if(N % 2 != 0){
			N--;
			ans = '1' + ans;
		}else ans = '0' + ans;
		N /= -2;
	}
	if(ans == "") ans = '0';
	
	cout << ans << endl;


	return 0;

}


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

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[] array=new int[n];
        StringTokenizer st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++){
            array[i]=Integer.parseInt(st.nextToken());
        }for(int i=1;i<=n;i++){
            System.out.print(array[n-i]);
            if(i!=n) System.out.print(" ");
        }System.out.println();
    }
}

Measured memory_bytes: 24168
N,T=(int(x) for x in input().split())
cost_list=[]
for i in range(0,N):
    c,t=(int(x) for x in input().split())
    if(t<=T):
        cost_list.append(c)
if(len(cost_list)>0):
    print(min(cost_list))
else:
    print("TLE")

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    vector<int> a(n);
    int k = 1;
    reprev (i, n) {
        a[i] = ((int)(s[i] - '0') * k) % 2019;
        k = (k * 10) % 2019;
    }
    map<int, int> m;
    m[0] = 1;
    int sum = 0;
    rep (i, n) {
        sum = (sum + a[i]) % 2019;
        m[sum]++;
    }
    ll ans = 0;
    for (auto p : m) {
        ans += (ll)p.second * (p.second - 1) / 2;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4348
import numpy as np

NK=np.array(input().split(),dtype=np.int32)

N=NK[0]
K=NK[1]

H=np.array(input().split(),dtype=np.int32)
H=np.sort(H)[::-1]

count=0
for i in range(N):
    if(H[i]>=K):
        count+=1
    else:
        break

print(count)

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

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

ll f(int n, int j, vector<vector<ll> > &dp, vector<ll> &v, vector<ll> &wt) {
	if(j == 0) return 0;
	if(n < 0) return INF;
	if(dp[n][j] != -1) return dp[n][j];
	ll x = f(n - 1, j, dp, v, wt);
	if(j >= v[n]) x = min(x, wt[n] + f(n - 1, j - v[n], dp, v, wt));
	dp[n][j] = x;
	return x;
}

void solve() {
	int n, w;
	cin >> n >> w;
	vector<ll> wt(n), v(n);
	int value = 0;
	for(int i = 0; i < n; ++i) {
		cin >> wt[i] >> v[i];
		value += v[i];
	}
	vector<vector<ll> > dp(n, vector<ll>(value + 1, -1));
	for(int j = value; j >= 0; j--) {
		ll x = f(n - 1, j, dp, v, wt);
		if(x <= w) {
			cout << j << "\n";
			return;
		}
	}
	cout << "0\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	solve();
	
	return 0;
}


Measured memory_bytes: 82172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}

int main(){
    int N, K;
    cin>>N>>K;
    int b;
    int a[N+1];
    a[0]=0;
    rep(i, N){
        cin>>a[i+1];
    }
    sort(a, a+N+1);
    int c;
    rep(i, N+1){
        if(a[i]==0){
            c=i;
            break;
        }
    }
    int d;
    int e;
    int ans=1000000000;
    for(int j=max(0, c-K);j<=min(c, N-K);j++){
        d=min(abs(a[j]), a[j+K]);
        e=max(abs(a[j]), a[j+K]);
        ans=min(ans, e+d*2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<pair<int, int>> vec, ans;
int main(){
	int n;
	cin >> n;
	if (n % 2 == 0) {
		for (int i = 1; i <= n / 2; i++) {
			vec.emplace_back(make_pair(i, n - i + 1));
		}
	}
	else {
		for (int i = 1; i <= n / 2; i++) {
			vec.emplace_back(make_pair(i, n - i));
		}
	}
	sort(vec.begin(), vec.end());
	int co = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (co >= vec.size()) {
				ans.emplace_back(make_pair(i, j));
			}
			else if (i == vec[co].first && j == vec[co].second) {
				co++;
				continue;
			}
			else {
				ans.emplace_back(make_pair(i, j));
			}
		}
	}
	cout << ans.size() << endl;
	for (int k = 0; k < ans.size(); k++) {
		cout << ans[k].first << " " << ans[k].second << endl;
	}
	return 0;
}

Measured memory_bytes: 384
N=int(input())
D=[]
for i in range(N):
    S=list(map(int,input().split()))
    S=len(set(S))
    D.append(S)
for i in range(len(D)-2):
    if D[i]==D[i+1]==D[i+2] and D[i]==1:
        print("Yes")
        exit()
print("No")


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

int gcd(int a,int b){
   if(b==0){
       return a;
   }else{
       return gcd(b,a%b);
   }
}

int main(){
  ll a,b,ans;
  cin>>a>>b;
  ans=a*b/gcd(a,b);
  cout<<ans<<endl;
}


Measured memory_bytes: 256