akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vector<int> t(d);
    rep(i, d) {
        int tmp_t;
        cin >> tmp_t;
        --tmp_t;
        t[i] = tmp_t;
    }
    //cout << "test" << endl;
    int ans = 0;
    vector<int> last_d(26, 0);
    for (int i = 1; i <= d; ++i) {
        //cout << i << " " << t[i-1] << endl;
        rep(j, 26) {
            if (j == t[i-1]) {
                //cout << i << " " << j << " "<< "test" << " " << s[i-1][t[i-1]] << endl;
                ans += s[i-1][t[i-1]];
                last_d[j] = i;
            }
            else {
                //cout << i << " " << j << " " << c[j] << " " << i - last_d[j] << endl;
                ans -= c[j] * (i - last_d[j]);
            }
            //cout << i << " " << ans << endl;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
main(){
  char str[100];
  int upper[100],lower[100],right[100],left[100],back[100],current[100],i=0,tmp[4],kaisu,tmp2[25][2],hoge,flag=0,count,j;
  srand((unsigned)time(NULL));
  scanf("%d",&kaisu);
  for(i=0;i<kaisu;i++)
    scanf("%d%d%d%d%d%d",&current[i],&lower[i],&right[i],&left[i],&upper[i],&back[i]);
  for(i=0;i<kaisu;i++){
    for(j=i+1;j<kaisu;j++){
      /* printf("i:%d j:%d\n",i,j); */
      count=0;
      while(count++<200){
	hoge=rand()%4;
	if(hoge==0){
	  tmp[0]=current[i];
	  tmp[1]=upper[i];
	  tmp[2]=back[i];
	  tmp[3]=lower[i];
	  current[i]=tmp[1];
	  upper[i]=tmp[2];
	  back[i]=tmp[3];
	  lower[i]=tmp[0];
	}
	if(hoge==1){
	  tmp[0]=current[i];
	  tmp[1]=upper[i];
	  tmp[2]=back[i];
	  tmp[3]=lower[i];
	  current[i]=tmp[3];
	  upper[i]=tmp[0];
	  back[i]=tmp[1];
	  lower[i]=tmp[2];
	}
	if(hoge==2){
	  tmp[0]=current[i];
	  tmp[1]=right[i];
	  tmp[2]=left[i];
	  tmp[3]=back[i];
	  current[i]=tmp[2];
	  right[i]=tmp[0];
	  left[i]=tmp[3];
	  back[i]=tmp[1];
	}
	if(hoge==3){
	  tmp[0]=current[i];
	  tmp[1]=right[i];
	  tmp[2]=left[i];
	  tmp[3]=back[i];
	  current[i]=tmp[1];
	  right[i]=tmp[3];
	  left[i]=tmp[0];
	  back[i]=tmp[2];
	}
	if(current[i]==current[j]&&lower[i]==lower[j]&&upper[i]==upper[j]&&back[i]==back[j]&&left[i]==left[j]&&right[i]==right[j]){
	  flag=1;
	  /* printf("match!!\n"); */
	  break;
	}
      }
      if(flag==1)
	break;
    }
    if(flag==1)
      break;
  }
  if(flag==0)
    printf("Yes\n");
  else 
    printf("No\n");
  return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
int main(void){
    int N,count;
    int Ax,Bx;
    int A,B,C,D;
    
    scanf("%d",&N);
    
    count = 0;
    A = N/1000;
    Ax = N%1000;
    B = Ax/100;
    Bx = Ax%100;
    C = Bx/10;
    D = Bx%10;
    
    if(A == 2) count++;
    if(B == 2) count++;
    if(C == 2) count++;
    if(D == 2) count++;
    
    printf("%d",count);
    
}

Measured memory_bytes: 128
#include<iostream>  
#include<cstdio>
#include<stdio.h>
#include<cstring>  
#include<cstdio>  
#include<climits>  
#include<cmath> 
#include <bitset>
#include<algorithm>  
#include <queue>
using namespace std;
unsigned long long int a[100008], n, i, sum;
int main()
{
	cin >> n;
	sum = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] % 2 != 0)
		{
			sum++;
		}
	}
	if (sum % 2 == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1656
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#define cost first
#define node second
using namespace std;
typedef pair <int,int> P;
int n,m;
vector <P> V[101];

int prim(int mn){
  int D[101]={},visited[101]={};
  for(int i=0;i<=n;i++) D[i] = 100000;
  priority_queue <P, vector<P>, greater<P> > Q;
  Q.push((P){0,1});

  int cnt=0,mxc=0,mnc=10000;
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    if(visited[t.node] == 1) continue;
    visited[t.node] = 1, cnt++;

    if(cnt!=1)mxc = max(mxc,t.cost),mnc=min(mnc,t.cost);
    if(cnt == n && mnc == mn) return mxc;
    if(cnt ==n) return -1;
    for(int i=0;i<V[t.node].size();i++){
      int nn = V[t.node][i].node, ncost = V[t.node][i].cost;
      if(ncost < mn || visited[nn]==1|| D[nn]<=ncost)continue;
      D[nn] = ncost;
      Q.push((P){ncost,nn});
    }
  }
  return -1;
}

int main() {
  while(1) {
    cin >>n>>m;
    int cost[5001];
    if(n==0 &&m==0) break;
    for(int i=0;i<=n;i++) V[i].clear();
    for(int i=0;i<m;i++){
      int a,b,c;
      cin >> a  >> b >> c;
      V[a].push_back((P){c,b});
      V[b].push_back((P){c,a});
      cost[i] = c;
    }
    sort(cost,cost+m);
    int ans = 100000;
    for(int i=0;i<m;i++) {
      int res = prim(cost[i]);
      if(res!=-1)ans = min(ans,res-cost[i]);      
    }
    if(ans == 100000) ans = -1;
    cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1380
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	if(n>9||m>9)cout<<-1,exit(0);
	cout<<n*m;
	
}


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

#define maxPN 1000000
#define PNs  1000100
int countPN = 0, countPNs = 0;
long long PrimeNum[maxPN], temp;
bool PN[PNs];

bool IsPrimeNumber(long long x);

void PrimeN(){
	int i, j;
	PrimeNum[0] = 2;
	PN[2] = true;PrimeNum[countPN++] = 2;
	PN[3] = true;PrimeNum[countPN++] = 3;
//	PN[5] = true;PrimeNum[countPN++] = 5;
	
	for(i = 6; i  < PNs;i+=6){
		if(IsPrimeNumber(i-1)){
			PrimeNum[countPN++] = i-1;
			PN[i-1] = true;//cout<<i-1<<endl;
		}
		if(IsPrimeNumber(i+1)){
			PrimeNum[countPN++] = i+1;
			PN[i+1] = true;//cout<<i+1<<endl;
		}
		countPNs = i+1;//cout<<i-1<<" "<<PN[i-1]<<endl;
	}
}

bool IsPrimeNumber(long long x){
	//if(x == 2 || x == 3) return true;
	//if(x <= 4 || x%2 == 0 || x%3 == 0)   return false;
	//if(x < countPNs) return PN[x];
	for(long long i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
		if(x%PrimeNum[i] == 0)return false;
	return true;
}


int main(){
	clock_t start, end;
	long long n = true, counta;
	start = clock();
	PrimeN();
//	cout<<PrimeNum[countPN-1]<<" "<<countPNs<<endl;
//	cout<<clock()-start<<"ms"<<endl;
	
	while(cin>>n){
		counta = 1;
		
		
		//cout<<(IsPrimeNumber(n)?"yes":"no")<<endl;
		start = clock();
		//cout<<IsPrimeNumber(n)<<endl;
		for(int i = 1; i <= n; i+=2){
			if(PN[i])counta++;
		//	cout<<i<<" "<<PN[i]<<endl;
		}
		if(n == 1) counta = 0;
		cout<<counta<<endl;
	//	cout<<clock()-start<<"ms"<<endl;
	}
	return 0;
}


Measured memory_bytes: 4644
import sys
input = lambda: sys.stdin.readline().rstrip()

n, m = map(int, input().split())
h = list(map(int, input().split()))
max_h = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    max_h[a] = max(max_h[a], h[b])
    max_h[b] = max(max_h[b], h[a])

cnt = 0
for i in range(n):
    if max_h[i] < h[i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 85036
#include <bits/stdc++.h>
#define fname "D"
#define bug(x) cerr << (#x) << " = " << (x) << endl
#define ll long long
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define ARR0(a, n) {cerr <<(#a)<< ": ["; REP0(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define ARR1(a, n) {cerr <<(#a)<< ": ["; REP1(i, n) cerr<< ' ' << a[i] <<','; cerr<<']'<<endl;}
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define LB lower_bound
#define UB upper_bound
#define X first
#define Y second

using namespace std;
template<typename T, typename V>
inline void bugp(const pair<T, V> &x) {cerr << '{' << x.X << ", " << x.Y << '}' << endl;}
template<typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {cerr << '{' << x.X << ", {" << x.Y.X << ", " << x.Y.Y << "}}" << endl;}
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ll, int> li;
typedef pair<ll, ii> lii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int N = 5005;
int c[N], p[N], leng[N];
ll d[N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n, k;
    cin >> n >> k;
    REP1(i, n) cin >> p[i];
    REP1(i, n) cin >> c[i];
    int id, prev, len, cnt, s;
    ll w, ans = LLONG_MIN, val;
    REP1(i, n) {
        memset(leng, 0, sizeof leng);
        d[i] = cnt = 0;
        id = p[i];
        prev = i;
        while(!leng[id] && id != i) {
            leng[id] = leng[prev] + 1;
            d[id] = d[prev] + c[id];
            ++cnt;
            if(cnt <= k) ans = max(ans, d[id]);
            else break;
            prev = id;
            id = p[id];
        }
        if(cnt >= k) continue;
        ans = max(ans, d[prev] + c[id]);
        ++cnt;
        w = d[prev] + c[id] - d[id];
        len = leng[prev] + 1 - leng[id];
        if(w > 0 && (k - cnt)) {
            if((k - cnt) % len == 0) {
                val = ((k - cnt) / len - 1) * w + d[prev] + c[id];
                ans = max(ans, val);
                s = id;
                do {
                    s = p[s];
                    ans = max(ans, val + c[s]);
                    val += c[s];
                } while(s != id);
            }
            else {
                val = (k - cnt) / len * w + d[prev] + c[id];
                ans = max(ans, val);
                s = p[id];
                cnt = (k - cnt) % len;
                while(cnt) {
                    --cnt;
                    ans = max(ans, val + c[s]);
                    val += c[s];
                    s = p[s];
                }
            }
        }
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 3708
import java.io.*;

class Main{ 
public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] div = str.split(" ");
        int x = Integer.parseInt(div[0]);
        int y = Integer.parseInt(div[1]);
            if(x < y)
                System.out.println("a < b");
            else if(x > y)
                System.out.println("a > b");
            else if(x == y)
                System.out.println("a == b");
 }
}
      

Measured memory_bytes: 17084
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,a[N],cov[N],cnt[N],ans=0;
void add(int x) {
    ++cnt[x];
    if(x-cnt[x]+1>=1) {
        if(!cov[x-cnt[x]+1]) --ans;
        ++cov[x-cnt[x]+1];
    }
}
void dec(int x) {
    if(x-cnt[x]+1>=1) {
        if(cov[x-cnt[x]+1]==1) ++ans;
        --cov[x-cnt[x]+1];
    }
    --cnt[x];
}
void modify(int x,int y) {
    dec(a[x]),a[x]=y,add(a[x]);
}
int main() {
    n=gi(),m=gi(),ans=n;
    for(int i=1;i<=n;i++) a[i]=gi(),add(a[i]);
    while(m--) {
        int x=gi(),y=gi();
        modify(x,y),printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];} 
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";} cout<<endl;
#define S second
#define F first
#define SZ(x) (int)x.size()
typedef long long ll;
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;

ll rec(string& s , int y , string n){
    if(s.size() + 1 == n.size()){
        if(s + char('0' + y) <= n) return 1;
        return 0;
    }
    ll res = 0;
    for(int i = 0 ; i <= 9 ; i++){
        s += ('0' + i);
        res += rec(s , y , n);
        s = s.substr(0 , s.size() - 1);
    }
    return res;
}

ll num(int x , int y , string n){
    ll res = 0;
    if(x == y){
        if(n.size() > 1 || ('0' + x) <= n[0]) res++;
    }

    for(int i = 0; i + 3 <= n.size(); i++){
        res += pow(10 , i);
    }
    
    if(n.size() == 1) return res;
    string s = "";
    s += ('0' + x);
    res += rec(s , y , n);
    return res;
}

int main(){
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    string n;
    cin>>n;
    ll res = 0;
    for(int i = 1 ; i <= 9 ; i++){
        for(int j = 1; j <= 9 ; j++){
            res += num(i , j , n) * num(j , i , n);
            // cout<<i<<" "<<j<<" "<<res<<endl;
        }
    }
    cout<<res<<endl;
    string s = "2";
    // cout<<rec(s , 4 , "2334")<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    x, y = map(int, input().split())

    a = [1, 3, 5, 7, 8, 10, 12]
    b = [4, 6, 9, 11]
    c = [2]

    if x in a and y in a:
        return 'Yes'
    elif x in b and y in b:
        return 'Yes'
    elif x in c and y in c:
        return 'Yes'
    else:
        return 'No'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x-r>=0 && x+r<=w && y-r>=0 && y+r<=h) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 3116
def solve():
    from itertools import product
    from sys import stdin
    f_i = stdin

    # idices of faces
    indices = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5),
               (0, 4, 3, 2, 1, 5), (0, 3, 1, 4, 2, 5),
               (1, 0, 3, 2, 5, 4), (1, 3, 5, 0, 2, 4),
               (1, 5, 2, 3, 0, 4), (1, 2, 0, 5, 3, 4),
               (2, 0, 1, 4, 5, 3), (2, 1, 5, 0, 4, 3),
               (2, 5, 4, 1, 0, 3), (2, 4, 0, 5, 1, 3),
               (3, 0, 4, 1, 5, 2), (3, 4, 5, 0, 1, 2),
               (3, 5, 1, 4, 0, 2), (3, 1, 0, 5, 4, 2),
               (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
               (4, 5, 3, 2, 0, 1), (4, 3, 0, 5, 2, 1),
               (5, 1, 3, 2, 4, 0), (5, 3, 4, 1, 2, 0),
               (5, 4, 2, 3, 1, 0), (5, 2, 1, 4, 3, 0))

    while True:
        n = int(f_i.readline())
        if n == 0:
            break

        cubes = tuple(tuple(f_i.readline().split()) for i in range(n))

        if n == 1:
            print(0)
            continue

        cube1 = cubes[0]
        cubes = cubes[1:]

        cnt = 6 * (n - 1)
        for tpl in product(indices, repeat=n-1):
            tmp = 0
            for idx, color1 in zip(zip(*tpl), cube1):
                d = {color1: 1}
                for c, i in zip(cubes, idx):
                    color = c[i]
                    if color in d:
                        d[color] += 1
                    else:
                        d[color] = 1
                tmp += n - max(d.values())
                if tmp >= cnt:
                    break
            else:
                cnt = tmp

        print(cnt)

if __name__ == '__main__':
    solve()



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

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

Measured memory_bytes: 256
var arr = require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/);
var xx;
for(var i=0;arr[i]*arr[i+1]!=0;i+=2){
	xx = arr[i]*arr[i];
	console.log(arr[i] * Math.sqrt(4*arr[i+1]*arr[i+1] + xx)+ xx);
}

Measured memory_bytes: 15384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
         if(i%3==0||i%10==3||(i/10)%10==3||(i/100)%10==3||(i/1000)%10==3){
            cout<<' '<<i;
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3084
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	p := make([]int, n)
	for i := range p {
		p[i] = scanInt()
	}
	sort.Ints(p)

	ans := 0
	for i := 0; i < k; i++ {
		ans += p[i]
	}
	fmt.Println(ans)
}


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

int main(){
  int i,j,n,num[300000];
  
  for(i = 1; i < 300000; i++){
    num[i]=0;
  }

  for(i = 2; i < 300000; i++){
    if(num[i]==0){
      for(j = 2*i; j < 300000; j+=i){
	num[j]=1;
      }
    }
  }

  while(1){
    int count=0;
    cin >> n;
    if(n==0)break;
    for(i = n+1; i <=n*2; i++){
      if(num[i]==0)count++;
    }
    
    if(n==1){
      cout << 1 << endl;
    }else{
      cout << count << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2332
#include<stdio.h>
int main(){
  double p[8];
  int i;
  while(~scanf("%lf",&p[0])){
    for(i=1;i<8;i++)scanf("%lf",&p[i]);
    if((p[0]<=p[4]&&p[4]<=p[2]||p[4]<=p[0]&&p[0]<=p[6])&&
       (p[1]<=p[5]&&p[5]<=p[3]||p[5]<=p[1]&&p[1]<=p[7]))printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 612
#include <iostream>

using namespace std;

int main() {
    int n;
    cin>>n;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        ans += (i%2!=0 && a%2!=0) ? 1 : 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for ele in arr:
    if ele in d:
        d[ele] += 1
    else:
        d[ele] = 1

q = int(input())
s = sum(arr)
while(q>0):
    a,b = [int(x) for x in input().split()]
    if a in d:
        x = d[a]
        s -= int(x*a)
        s += int(x*b)
        d.pop(a)
        if b in d:
            d[b]+=x
        else:
            d[b] = x
    print(s)

    q-=1

Measured memory_bytes: 20632
#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <complex>
#include <cstring>
#include <set>
using namespace std;
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)

int input[1111][3];
int res[1111];

int main(){
    int a,b,c;
    while(cin>>a>>b>>c && a){
        int n;
        cin>>n;
        rep(i,n){
            rep(j,3){
                cin >> input[i][j];
            }
            cin>>res[i];
        }

        bool ok[1111]={};
        bool bad[1111]={};
        rep(k,2){
            bool fine = true;
            rep(i,n){
                int a=0,b=0;
                int x,y,z;
                tie(x,y,z)=tie(input[i][0],input[i][1],input[i][2]);
                for(int j : {x,y,z}){
                    if(ok[j])a++;
                    if(bad[j])b++;
                }
                if(res[i]){
                    if(a!=3){
                        ok[x]=ok[y]=ok[z]=true;
                        fine = false;
                    }
                }else{
                    if(a==2 && b!=1){
                        for(int j : {x,y,z}){
                            if(!ok[j])bad[j]=true;
                            fine = false;
                        }
                    }
                }
            }
            if(fine) break;
        }
        for(int i=1;i<=a+b+c;i++){
            if(ok[i] && !bad[i])cout<<1;
            else if(!ok[i] && bad[i])cout<<0;
            else cout<<2;
            cout<<endl;
        }
    }
}

Measured memory_bytes: 1176
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=200005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
 set<string>st[maxx];
void solve(){
    rep(i,maxx) st[i].clear();
    int n;
    cin>>n;
    map<string,int>mm;
    rep(i,n){
        string s;
        cin>>s;
        mm[s]++;
    }
    int maxi=-1;
    each(it,mm){
        st[(*it).second].insert((*it).first);
        maxi=max(maxi,(*it).second);
    }
    forch(it,st[maxi]){
        cout<<it<<endl;
    }
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




Measured memory_bytes: 42752
/**
 *      ABC 80 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 04:37:44
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, A, B; cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}



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

using namespace std;

using LL = long long;
const LL MOD = (LL)1e9 + 7;
const LL NS = (LL)1e5 + 4;
LL N;
LL a[NS];
struct fenwick{
    vector < LL > fenw;
    LL N;
    fenwick(){}
    fenwick(LL n):N(n){
        fenw.resize(N);
    }
    void push(LL x, LL val){
        for(LL i = x; i < N; i += (i & -i)){
            fenw[i] += val;
        }
    }
    LL get(LL x){
        LL rv = 0;
        for(LL i = x; i; i -= (i & -i)){
            rv += fenw[i];
        }
        return rv;
    }
}tree;

LL Count(LL low){
    tree = fenwick(NS * 2);
    LL rv = 0, zero = 0;
    for(LL i = 1; i <= N; ++i){
        LL pl = (a[i] >= low ? 1 : -1);
        tree.push(zero + NS, 1);
        zero -= pl;
        rv += tree.get(NS * 2 - 1) - tree.get(zero + NS - 1);
    }
    return rv;
}

int main(){
    scanf("%lld", &N);
    for(LL i = 1; i <= N; ++i){
        scanf("%lld", a + i);
    }
    LL low = 1, high = (LL)1e9, mid;
    while(low < high){
        mid = (low + high) >> 1; ++mid;
        if(Count(mid) >= N * (N + 1) / 4 + N * (N + 1) / 2 % 2){
            low = mid;
        }
        else{
            high = mid - 1;
        }
    }
    printf("%lld\n", low);
    return 0;
}


Measured memory_bytes: 7648
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

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

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

const int maxn = (int) 1e3 + 10;
int ps[maxn];
int cntp;

int notp[maxn];

void precalc() {
  memset(notp, 0, sizeof(notp));
  notp[0] = notp[1] = 1;
  cntp = 0;

  for (int i = 2; i < maxn; ++i) {
    if (!notp[i]) {
      ps[cntp++] = i;
    }

    for (int j = i * i; j < maxn; j += i) {
      notp[j] = 1;
    }
  }
}


int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  return 1;
}

void solve() {
  int res = 1;
  for (int i = 0; i < cntp; ++i) {
    int p = ps[i];
    int cnt = 0;
    for (int x = n; x;) {
      x /= p;
      cnt += x;
    }
    res = mult(res, cnt + 1);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main() {
  string str;
  vector<string> ans;
  cin >> str;

  for (int i = 0; i < str.length(); i++) {
    if (str.at(i) == '0') {
      ans.push_back("0");
    } else if (str.at(i) == '1') {
      ans.push_back("1");
    } else if (str.at(i) == 'B') {
      if (!ans.empty()) ans.pop_back();
    }
  }

  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn = inputs[0][0]

# body
if $debugFlag
end

ans = 1
for i in 2..nn
  tmp = i*i
  while tmp <= nn
    ans = tmp if tmp > ans
    tmp *= i
  end
end

puts ans

Measured memory_bytes: 1788
#include <stdio.h>

int main (){
	int n,a,b,sum=0;
	
	scanf ("%d",&n);
	scanf ("%d %d", &a, &b);
	
	for (int i=a; i<=b; i++){
		if (i%n==0){
			sum=1;
		}
	}
	if (sum==1){
		printf ("OK");
	}
	else {
		printf ("NG");
	}
	
	return 0;
}

Measured memory_bytes: 3228
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, K; cin >> N >> K;
  vector<LL> H(N); cin >> H;
  sort(H.rbegin(), H.rend());

  LL sum = 0;
  for (int i = K; i < N; ++i) sum += H[i];
  cout << sum << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, K, S;
    cin >> N >> K >> S;

    int x = S;
    int y = x+1;
    if (S == 1000000000) {
        y = 1;
    }
    rep(i, K) {
        if (i != 0) cout << ' ';
        cout << x;
    }
    rep(i, N-K) {
        cout << ' ' << y;
    }
    cout << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    #if __APPLE__
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie();
    int n;
    cin >> n;
    int a[n];
    int x = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        x += a[i];
    }
    if (x % 10 == 0) {
        sort(a, a + n);
        for (int i = 0; i < n; ++i) {
            if (a[i] % 10 != 0) {
                x -= a[i];
                break;
            }
        }
    }
    if (x % 10 == 0) x = 0;
    cout << x << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>i) & 1
#define setpre(n) fixed << setprecision((n))
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VP = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  double time = 0;
  cin >> N;
  VVI rule(N, VI(N-1));
  REP(i, N) REP(j, N-1) cin >> rule.at(i).at(N - j - 2);
  VI memo(N, N-1);
  int ans = 0;
  int ct = 0;
  bool check;
  while(ct < N * (N-1) / 2)
  {
    std::chrono::system_clock::time_point  start, end;
    start = std::chrono::system_clock::now();
    check = true;
    VB flg(N, false);
    REP(i, N-1)
    {
        if(flg.at(i)) continue;
        if (memo.at(i) == 0) continue;
        REP2(j, i+1, N)
        {
            if (flg.at(j)) continue;
            if (memo.at(j) == 0) continue;
            if (rule.at(i).back() == j + 1 && rule.at(j).back() == i + 1)
            {
                ct++;
                if (memo.at(i) == 1) rule.at(i).clear();
                else rule.at(i).pop_back();
                if (memo.at(j) == 1) rule.at(j).clear();
                else rule.at(j).pop_back();
                check = false;
                flg.at(i) = true;
                flg.at(j) = true;
                memo.at(i)--;
                memo.at(j)--;
                break;
            }
        }
    }
    if (check)
    {
        cout << -1 << endl;
        return 0;
    }
    ans++;
    end = std::chrono::system_clock::now();
    double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    time += elapsed;
    if (time > 1000)
    {
      cout << N*(N-1)/2 << endl;
      return 0;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

main(){
  ll a, b;
  cin >> a >> b;
  ll ans = 0;
  if(a==1 and b>=2) cout << b-2 << endl;
  else if(a>=2 and b==1) cout << a-2 << endl;
  else if(a==2 or b==2) cout << 0 << endl;
  else if(a==1 and b==1) cout << 1 << endl;
  else{
    ans = a*b - 2*a - 2*(b-2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def main():
    n, m = map(int, input().split())
    g = [[] for i in range(n)]
    deg2 = [0]*n
    atode = []
    for i in range(m):
        s, t = map(int, input().split())
        g[s-1].append(t-1)
        deg2[s-1] += 1
        atode.append((s-1,t-1))

    ee = [-1]*n
    def rec2(cur, s,t):
        if ee[cur] != -1:
            return ee[cur]
        res = 0
        cnt = 0
        for to in g[cur]:
            if cur==s and to ==t:
                continue
            res += rec2(to,s,t)+1
            cnt += 1
        if cnt:
            res /= cnt
        ee[cur] = res
        return ee[cur]

    rec2(0,-1,-1)
    ret = ee[0]

    use = [[-1, -1] for i in range(n)]
    for s,t in atode:
        if deg2[s] < 2:
            continue
        if use[s][1] < ee[t]:
            use[s][0] = t
            use[s][1] = ee[t]

    for s, (t,cost) in enumerate(use):
        if s == -1:
            continue
        ee = [-1]*n
        rec2(0,s,t)
        ret = min(ret, ee[0])
    print(ret)

if __name__ == "__main__":
    main()

Measured memory_bytes: 86364
#include<stdio.h>
int main(void)
{
int a,b;
    scanf("%d",&a);
    scanf("%d",&b);

if(a>b){
 printf("a > b\n");
}

else if(a<b){
 printf("a < b\n");
}
else{
printf("a == b\n");

}
	 return 0;
}


Measured memory_bytes: 2124
from math import ceil, floor
import statistics

N = int(input())
A = list(map(int, input().split()))

Ai_i = [0 for i in range(len(A))]

for i in range(len(A)):
    Ai_i[i] = A[i] - (i+1)

n = 5

b_ceil = ceil(sum(Ai_i) / len(Ai_i))

bs = list(range(b_ceil-n, b_ceil+n))

bs = [int(statistics.median(Ai_i))]
abss_ls = [ 0 for i in range(len(bs)) ]
for i in range(len(bs)):
    for j in range(len(Ai_i)):
        abss_ls[i] += abs(Ai_i[j] - bs[i])

min_abs = min(abss_ls)
print(min_abs)

Measured memory_bytes: 27232
#include<bits/stdc++.h>
using namespace std;
#define fori(i,a,n) for(i=a;i<=n;i++)
#define ford(i,n,a) for(i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
const int N=1001;
const int M=31;
ll f[N][M],ff[N],tot,t,i,j,num,ans[N],anss,len;
int main()
{
	cin>>t;
	fori(i,0,9)
	f[1][i]=1;
	for (i=2;i<=30;i++)
	{
		ff[i]=ff[i-1];
		fori(j,1,9)
		ff[i]+=f[i-1][j];
		fori(j,1,8)
		f[i][j]=f[i-1][j]+f[i-1][j-1]+f[i-1][j+1];
		f[i][9]=f[i-1][9]+f[i-1][8];
		f[i][0]+=f[i-1][0]+f[i-1][1];
	}
	fori(i,1,30)
	if (t<=ff[i]) break;
	i--;
	num=i;
	len=i;
	tot=ff[i];
	fori(j,1,9)
	{
		tot+=f[i][j];
		if (t<=tot) 
      	{
    		ans[num]=j;
    		t-=tot-f[i][j];
	    	break;
     	}
	}
	
	while (--num)
	{
		if (ans[num+1]==0)
		{
			if (t<=f[num][0])
			{
				ans[num]=0;
				continue;
			} else {
				t-=f[num][0];
				ans[num]=1;
				continue;
			}
		} else 
		if (ans[num+1]==9)
		{
			if (t<=f[num][8])
			{
				ans[num]=8;
				continue;
			} else {
				t-=f[num][8];
				ans[num]=9;
				continue;
			}
		} else {
			anss=ans[num+1];
			if (t<=f[num][anss-1])
			{
				ans[num]=anss-1;
				continue;
			} else if (t<=f[num][anss-1]+f[num][anss])
			{
				t-=f[num][anss-1];
				ans[num]=anss;
				continue;
			} else {
				t-=f[num][anss-1]+f[num][anss];
				ans[num]=anss+1;
				continue;
			}
		}
	}
	ford(i,len,1)
	printf("%d",ans[i]);
}

Measured memory_bytes: 256
N = int(input())

P = list(map(int, input().split()))
Q = list(map(int, input().split()))

#  iの階乗
x = [1] * (N + 1)

for i in range(1, N + 1):
    x[i] = x[i - 1] * i
    

res1 = 1
res2 = 1

s1 = [i for i in range(1, N + 1)]
s2 = [i for i in range(1, N + 1)]

for p in P:
    for i in range(len(s1)):
        if p == s1[i]:
            s1.pop(i)
            t = i - 1
            break

    res1 += t * x[len(s1)]

for q in Q:
    for i in range(len(s2)):
        if q == s2[i]:
            s2.pop(i)
            t = i - 1
            break

    res2 += t * x[len(s2)]

print(abs(res1 - res2))


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

int main() {
	int N;
	cin >> N;
	
	map<string, int> M;
	int max = 1;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		M[s]++;
		if (M[s] > max) {
			max = M[s];
		}
	}

	for (auto it = M.begin(); it != M.end(); it++) {
		if (it->second == max) {
			cout << it->first << endl;
		}
	}
}

Measured memory_bytes: 25216
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N,M;
int K[11];
int p[11];
int s[11][11];
bool F[11];
int cnt[11];

signed main(){
	cin>>N>>M;
	REP(i,M){
		cin>>K[i];
		REP(j,K[i]){
			cin>>s[i][j];
		}
	}
	REP(i,M){
		cin>>p[i];
	}
	int ans=0;
	REP(Bit,1<<N){
		int cnt2=0;
		REP(i,N){
			F[i]=false;
		}
		REP(i,M){
			cnt[i]=0;
		}
		REP(i,N){
			if(Bit&(1<<i)){
				F[i]=true;
			}
			else{
				F[i]=false;
			}
		}
		REP(i,M){
			REP(j,K[i]){
				if(F[s[i][j]-1]==true){
					cnt[i]++;
				}
			}
			if(cnt[i]%2==p[i]){
				cnt2++;
			}
		}
		if(cnt2==M){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<ll, ll>;

ll N, M;
std::vector<P> ps;

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, N )
  {
    ll A, B;
    scanf( "%lld%lld", &A, &B );

    ps.push_back( P( A, B ) );
  }

  std::sort( all(ps) );

  ll ans = 0;

  for( auto p : ps )
  {
    ans += p.first*std::min( p.second, M );
    M -= p.second;

    if( M <= 0 )
      break;
  }

  printf( "%lld\n", ans );
  
  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
#define lnt(s) (ll)s.length()
#define mt(cnt) cnt.empty()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;
using pl = pair<ll, pll>;
using tll = tuple<ll, ll, ll>;

const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<pll> adjlist[n+1];
	ll x, y, w;
	for(ll i=0; i<n-1; i++){
		cin >> x >> y >> w;
		adjlist[x].emplace_back(mp(y, w));
		adjlist[y].emplace_back(mp(x, w));
	}
	ll q, k;
	cin >> q >> k;
	vector<ll> dst(n+1, INF);
	dst[k] = 0;
	priority_queue<pll, vector<pll>, greater<pll>> pql;
	pql.push(mp(dst[k], k));
	while(!pql.empty()){
		pll tp = pql.top();
		pql.pop();
		for(auto edge : adjlist[tp.s]){
			ll to = edge.f;
			ll len = edge.s;
			if(dst[to] > len + dst[tp.s]){
				dst[to] = len + dst[tp.s];
				pql.push(mp(dst[to],to));
			}
		}
	}
	while(q--){
		cin >> x >> y;
		cout << dst[x]+dst[y] << "\n";
	}
	return 0;
}

Measured memory_bytes: 14068
n = int(input())
a_list = list([0])
for _ in range(n):
    a_list.append(int(input()))
    
count = 0
bangou = 1

while bangou > 0:
    if a_list[bangou] == 0:
        print("-1")
        break
    bangou_next = a_list[bangou]
    count += 1
    if bangou_next == 2:
        print(count)
        break
    
    a_list[bangou] = 0
    bangou = bangou_next


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

#define REP(i,n) for(ll i = 0;i < n;++i)

using namespace std;
typedef long long ll;

int main(){
	int r,D,x;
	cin >> r >> D >> x;
	REP(i,10)
		cout << (x=r*x-D) <<endl;
}


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

int main() {
  int N,M;
  cin >> N>>M;
  vector<int> cities(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a>>b;
    cities.at(a-1) ++;
      cities.at(b-1) ++;
      }
  for(int i=0;i<N;i++){
    cout << cities.at(i) << endl;
  }

  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

using ll = long long;
using P = pair<int, int>;

struct Sieve
{
  int n;
  vector<int> f, primes;
  Sieve(int n = 1) : n(n), f(n + 1)
  {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i)
    {
      if (f[i])
        continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i * i; j <= n; j += i)
      {
        if (!f[j])
          f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x)
  {
    vector<int> res;
    while (x != 1)
    {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x)
  {
    vector<int> fl = factorList(x);
    if (fl.size() == 0)
      return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl)
    {
      if (res.back().first == p)
      {
        res.back().second++;
      }
      else
      {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};
int main()
{
  int N;
  cin >> N;
  Sieve sieve(N);
  vector<int> num(N + 1, 0);
  FOR(i, 1, N)
  {
    vector<P> prime = sieve.factor(i);
    rep(j, prime.size())
    {
      num[prime[j].first] += prime[j].second;
    }
  }

  int mod = 1e9 + 7;
  long long ans = 1;
  rep(i, num.size())
  {
    if (num[i] != 0)
    {
      //cout << i << ":" << num[i] << endl;
      ans *= (num[i] + 1) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int length=200000;
        char[][] ans=new char[length][n];
        int count=0;
        int oldcount=1;
        ans[0][0]='a';
        char[] usedhigh=new char[length];
        char tmphigh;
        for(int i=0;i<length;i++){
            usedhigh[i]='a';
        }
        for(int i=1;i<n;i++){
            for(int j=0;j<oldcount;j++){
                ans[j][i]='a';
                tmphigh=usedhigh[j];
                for(int k=98;k<tmphigh+2;k++){
                    count++;
                    for(int l=0;l<i;l++){
                        ans[count][l]=ans[j][l];
                    }
                    ans[count][i]=(char)k;
                    usedhigh[count]=(char)Math.max(usedhigh[j],ans[count][i]);
                }
            }
            oldcount=count+1;
        }
        String[] finalans=new String[length];
        for(int i=0;i<length;i++){
            finalans[i]="";
            for(int j=0;j<n;j++){
                finalans[i]+=ans[i][j];
            }
        }
        Arrays.sort(finalans);
        String bad=finalans[0];
        for(int i=0;i<length;i++){
            if(!finalans[i].equals(bad)){
                
                System.out.println(finalans[i]);
            }
        }
        
        
 
    }



}

Measured memory_bytes: 114016
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
double pi = 3.141592653589793;
ll mod = 1000000007;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<pair<int, int> > p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    ll ans = 9223372036854775806;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + K - 1; j < N; j++) {
            ll xlen = p[j].first - p[i].first;
            vector<ll> y;
            for (int k = i; k <= j; k++) {
                y.push_back(p[k].second);
            }
            sort(y.begin(), y.end());
            ll ylen = 9223372036854775806;
            for(ll l = 0; l <= y.size() - K; l++) {
                ll ynum = y[l + K - 1] - y[l];
                if (ynum < ylen) {
                    ylen = ynum;
                }
            }
            if (xlen * ylen < ans) {
                ans = xlen * ylen;
            }
        }
    }    
    cout << ans << endl;
}


Measured memory_bytes: 256