akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

const int MAXN = 1e5;
    
struct FndUn{
    int p[MAXN], sz[MAXN];

    void MakeSet(int x){
        p[x] = x;
        sz[x] = 1;
    }

    int Find(int x){
        if(p[x] != x) p[x] = Find(p[x]);
        return p[x];
    }

    pair<int, int> Union(int x, int y){
        x = Find(x), y = Find(y);
        if(sz[x] > sz[y]) swap(x, y);
        if(p[x] == y || p[y] == x) return make_pair(0, 0);
        p[x] = y;
        int pr1 = sz[x], pr2 = sz[y];
        sz[y] += sz[x];
        return make_pair(pr1, pr2);
    }

    int Size(int x){
        return sz[Find(x)];
    }
};

int main(){
    long long n, m;
    cin >> n >> m;
    vector<pair<long long, long long> > a(m);
    for(int i = 0; i < m; ++i){
        cin >> a[i].first >> a[i].second;
        a[i].first--, a[i].second--;
    }
    FndUn f;
    for(int i = 0; i < n; ++i){
        f.MakeSet(i);
    }
    vector<long long> ans(m);
    ans[m - 1] = n * (n - 1) / 2;
    for(int i = m - 2; i >= 0; --i){
        auto mns = f.Union(a[i + 1].first, a[i + 1].second);
        long long m1 = mns.first, m2 = mns.second;
        ans[i] = ans[i + 1] - (m1 + m2) * (m1 + m2 - 1) / 2;
        ans[i] += m1 * (m1 - 1) / 2;
        ans[i] += m2 * (m2 - 1) / 2;
    }
    for(int i = 0; i < m; ++i) cout << ans[i] << endl;
}


Measured memory_bytes: 4480
require 'prime'
 n=gets.to_i
a=0


factors = n.prime_division

factors.length.times do |m|
  q=factors[m]
  m=1 
until q[1]<m
    
 
  q[1]-=m
    m+=1
   a+=1 
  end
  
end
p a


Measured memory_bytes: 14436
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
      string a;
      cin >> a;
      if(a == "-")break;
      int b;
      cin >> b;
      for(int i = 0; i<b;i++){
          int c;
          cin >> c;
          for(int j = 0; j<c;j++){
            int d = a.size();
              a.push_back(a[0]);
              a.erase(a.begin());
          }
      }
      cout << a << endl;
  }
}


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

using namespace std;

int main(void)
{
	int n,min,max;

	cin>>n;

	int a[n];

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

	sort(a,a+n);

	min=a[0];
	max=a[n-1];

	cout<<max-min<<endl;
  
	return 0;
}


Measured memory_bytes: 256
n=int(input())
d={}
ans=[]
max=1
for i in range(n):
    s=input()
    if s in d:
        d[s]+=1
        if d[s]>max:
            max=d[s]
    else:
        d[s]=1
for word,count in d.items():
    if count==max:
        ans.append(word)
ans.sort()
for word in ans:
    print(word)

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

int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}



int main(void){
    int n,ans=0;
    scanf("%d",&n);
    int a[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    qsort (a,n,sizeof(int),sort);
    
    int count=1;
    for (int i=0; i<n-1; i++){
        if(a[i]==a[i+1]){
            count++;
        } else {
            if (a[i]<count){
                ans+=count-a[i];
                count=1;
            } else if (a[i]>count){
                ans+=count;
                count=1;
            } else{
                count=1;
            }
        }
        
    } 
    if (a[n-1]<count){
            ans+=count-a[n-1];
        } else if (a[n-1]>count){
            ans+=count;
        }
    printf ("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << 180 * (N-2) << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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 f = 0;
	if (n == 0 || n == 1) {
	    f = 1;
	} else {
	    int f1 = 1;
	    int f2 = 1;
	    for (int i = 2; i < n + 1; i++) {
		f = f1 + f2;
		f1 = f2;
		f2 = f;
	    }
	}
	System.out.println(f);
    }
}




Measured memory_bytes: 24220
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int h = scan.nextInt();

		int[] a = new int[h + 1];

		for (int i = 1; i <= h; i++)
			a[i] = scan.nextInt();

		for (int i = 1; i <= h; i++)
			print(a, i);

		scan.close();
		System.exit(0);
	}

	private static void print(int[] a, int i) {
		System.out.print("node " + i + ": ");
		System.out.print("key = " + a[i] + ", ");
		if (i > 1)
			System.out.print("parent key = " + a[i / 2] + ", ");
		if (i * 2 < a.length)
			System.out.print("left key = " + a[i * 2] + ", ");
		if (i * 2 + 1 < a.length)
			System.out.print("right key = " + a[i * 2 + 1] + ", ");
		System.out.print("\n");
	}
}

Measured memory_bytes: 27472
#include<iostream>
#include<variant>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<climits>
#include<set>

using namespace std;

int main() {
	int x, y, n;
	int cnt = 0, yes = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		if (x == y)cnt++;
		else cnt = 0;
		if (cnt >= 3)yes = 1;
	}
	if (yes)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3632
import sys

N = int(input())
m = 1

min = 0
max = 1

if N == 0:
    print("0")
    sys.exit()
elif N == 1:
    print("1")
    sys.exit()

i = 0
while True:
    m *= 2

    if i % 2 == 0:
        min -= m
    else:
        max += m

    if min <= N <= max:
        break

    i += 1

# print(min,max)
# print("i =",i)
# print("m =",m)
ans = []

while True:
    if (min + max)/2 < N:
        if i % 2 == 0:
            ans.append("0")
        else:
            ans.append("1")
        min += m

    elif N < (min + max)/2 :
        if i % 2 == 0:
            ans.append("1")
        else:
            ans.append("0")
        max -= m

    else:
        break

    m /= 2
    i -= 1

print("".join(ans))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());
        int X = Integer.parseInt(sc.next());

        int count = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                for (int k = 0; k <= C; k++) {
                    if (500*i + 100*j + 50*k == X) {
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		
		int n = sc.nextInt(), k =sc.nextInt();
		boolean d[] = new boolean[10];
		for(int i=0;i<k;i++){
			int a = sc.nextInt();
			d[a] = true;
		}
		
		while(!ok(n, d)){
			n++;
		}
		System.out.println(n);
	}
	
	static boolean ok(int n, boolean a[]){
		while(n>0){
			if(a[n%10])
				return false;
			n/=10;
		}
		
		return true;
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int a[4] = { 0,4,6,8 };
    string A = "AKIHABARA";
    string S;
    cin >> S;
    
    bool ans = false;
    for ( int i = 0; i < (1<<4); i++ ) {
        
        string s;
        int y[9] = {0};
        for ( int j = 0; j < 4; j++ ) {             
            if ( i&(1<<j) ) {
                y[a[j]] = 1;
            }
        }
        for ( int j = 0; j < A.length(); j++ ) {            
            if ( !y[j] ) { s += A[j]; }
        }
        if ( s == S ) { ans = true; break; }
    }
    
    cout << ( ans ? "YES" : "NO" ) << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000003;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int q;
	cin>>q;
	vector<int> x(q),d(q),n(q);
	const int SZ=1000011;
	vector<LL> lst(SZ);
	lst[0]=1;
	FOR(i,1,SZ){
		lst[i]=mul(i,lst[i-1]);
	}
	FOR(i,0,q){
		cin>>x[i]>>d[i]>>n[i];
	}
	FOR(i,0,q){
		if(d[i]==0){
			cout<<power(x[i],n[i])<<endl;
		}else{
			LL l=dvs(x[i],d[i]);
			LL r=add(l,sub(n[i],1));
			if(l==0||l+n[i]-1>=mod){
				cout<<0<<endl;
			}else{
				cout<<mul(dvs(lst[r],lst[l-1]),power(d[i],n[i]))<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 9856
n, m = map(int, input().split())
ab = {}
for _ in range(m):
    a_, b_ = map(str, input().split())
    ab.setdefault(a_, []).append(b_)
r = "IMPOSSIBLE"
if "1" in ab.keys():
    for i in ab["1"]:
        if i not in ab.keys():
            continue
        if str(n) in ab[i]:
            r = "POSSIBLE"
            break
print(r)

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

struct Edge {
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;

vector<int> color; // color[i] = 1: 黒確定/ 0: 白確定/ -1:未訪問

// 条件を満たして色を塗れるならtrueを返す
bool dfs(const Graph &G, int v, int current_color = 0) {
    color[v] = current_color;
    for (auto edge : G[v]) {
        // 隣接頂点が未訪問のとき，隣接頂点に塗られている色が条件を満たすかを確認
        if (color[edge.to] != -1) {
            if ((color[edge.to] == current_color && edge.weight%2 == 1)
                || (color[edge.to] != current_color && edge.weight%2 == 0)) { // 重さが奇数なのに同じ色は条件を満たさない
                return false;
            } else {
                continue;
            }
        }
        // 辺の重さについて色を塗っていく
        if (edge.weight%2 == 0) {
            // 辺の重さが偶数なので同じ色を隣に塗る
            if (!dfs(G, edge.to, current_color)) {
                return false;
            }
        } else {
            // 辺の重さが奇数なので反対の色を塗る
            if (!dfs(G, edge.to, 1 - current_color)) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int N; cin >> N;
    Graph G(N);
    for (int i = 0; i < N-1; i++) {
        int u, v, w; cin >> u >> v >> w;
        u -= 1; v -= 1;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    color.assign(N, -1);
    for (int v = 0; v < N; v++) {
        if (color[v] != -1) { // vが訪問済みだったらスルー: 連結でないグラフを考慮
            continue;
        }
        if (dfs(G, v)) {
            break;
        }
    }
    for (int v = 0; v < N; v++) {
        cout << color[v] << endl;
    }
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

const int mod=1e6+7;
bool slot[mod];

void Solve(){
	int n,m;
	string s;
	cin >> n >> m >> s;
	
	ull h[300001],pow[300001],b=1000000007;
	h[0]=0;
	pow[0]=1;
	rep(i,1,n+1){
		h[i]=h[i-1]*b+s[i-1];
		pow[i]=pow[i-1]*b;
	}

	unordered_set<ull> slot;
	int l=0,r=1,ans=0;
	rep(i,0,m){
		string q;
		cin >> q;
		
		int *d;
		if(q[0]=='L') d=&l;
		else d=&r;
		if(q[1]=='+') ++*d;
		else --*d;

		slot.insert(h[r]-h[l]*pow[r-l]);
	}

	cout << slot.size() << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 20228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <cfloat>

using namespace std;

//start of 0uts1de's library

int cin_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}


int cout_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}


int max_int_arr(std::vector<int>& arr, int mode = 0){    //0 -> data  1 -> index
    int maxVal = INT_MIN;       //min of int
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            if (mode == 0){
                maxVal = arr.at(i);
            }
            else if (mode == 1){
                maxVal = arr.at(i);
                maxIndex = i;
            }
            else{
                cout << "Invalid mode." << endl;
                return -1;
            }
        }
    }
    if (mode == 0){
        return maxVal;
    }
    else if (mode == 1){
        return maxIndex;
    }
    return -1;
}

double max_double_arr(std::vector<double>& arr, int mode = 0){    //0 -> data  1 -> index
    double maxVal = -DBL_MAX;       //min of double
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            if (mode == 0){
                maxVal = arr.at(i);
            }
            else if (mode == 1){
                maxVal = arr.at(i);
                maxIndex = i;
            }
            else{
                cout << "Invalid mode." << endl;
                return -1;
            }
        }
    }
    if (mode == 0){
        return maxVal;
    }
    else if (mode == 1){
        return maxIndex;
    }
    return -1;
}

//end of 0uts1de's library

int main(){
    int n, max, ans;
    cin >> n;
    vector<int> p(n);
    cin_int_arr(p);
    max = max_int_arr(p);
    p.erase(p.begin() + max_int_arr(p, 1));
    ans = max / 2 + accumulate(p.begin(), p.end(), 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

  map<long long, int> cnt;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    cnt[-a]++;
  }

  long long ans = 1;
  bool ok = false;
  for (auto kv : cnt) {
    if (kv.second >= 4) {
      if (ans < 0) {
        ans *= kv.first;
      } else {
        ans = kv.first * kv.first;
      }
      ok = true;
      break;
    } else if (kv.second >= 2) {
      ans *= kv.first;
      if (ans > 0) {
        ok = true;
        break;
      }
    }
  }
  if (!ok) ans = 0;

  cout << ans << endl;
}


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

int main() {
	int A,B,C;
  	cin>>A>>B>>C;
  
  	cout<<C<<" "<<A<<" "<<B<<endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

ll DP[100005];
ll w[100005];
ll v[100005];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,W;
    cin>>n>>W;
    for(int i=1; i<=n; i++)
        cin>>w[i]>>v[i];

    for(int i=1; i<=n; i++)
        for(int j=W-w[i]; j>=0; j--)
        DP[j+w[i]]=max(DP[j+w[i]],DP[j]+v[i]);

    cout<<*max_element(DP, DP+W+1);
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        long d=Long.parseLong(str[1]);
        int c=0;
        for(int i=0;i<n;i++)
        {
            str=br.readLine().split(" ");
            long x=Long.parseLong(str[0]);
            long y=Long.parseLong(str[1]);
            if(x*x+y*y<=d*d)
            c++;
        }
        pw.println(c);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 54592
n = int(input())
a = list(map(int,input().split()))

# lcm_num = lcm(a[0], a[1])
# 
# for i in range(2, n):
#     lcm_num = lcm(lcm_num, a[i])

ans = 0
for i in range(n):
    ans += a[i] - 1

print(int(ans))
  


Measured memory_bytes: 3316
#include <iostream>
#include <queue>
#include <vector>
#include <map>

using namespace std;
#define INF 1e+9

struct Edge{
	int to;
	int weight;
};

vector<int> SSSP(vector<vector<Edge> >& G, int r)
{
	int V = G.size();
	vector<int> result(V, INF);

	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > pq;
	pq.push(make_pair(0, r));

	while(!pq.empty()){
		int s = pq.top().first;
		int v = pq.top().second;
		pq.pop();

		if(result[v] == INF){

			result[v] = s;

			for(int i = 0; i < G[v].size(); i++){
				int tgt = G[v][i].to;
				int score = s + G[v][i].weight;
				if( result[tgt] == INF){
					pq.push(make_pair(score, tgt));
				}
			}
			
		}
	}
	return result;
}

int main(void)
{
	int V, E, r;
	cin >> V >> E >> r;

	vector<vector<Edge> > AdjList(V);
	for(int i = 0; i < E; i++){
		int s, t, d;
		cin >> s >> t >> d;
		AdjList[s].push_back(Edge{t,d});
	}

	vector<int> SP = SSSP(AdjList, r);
	for(auto i : SP){
		if(i == INF){
			cout << "INF" << endl;
		}else{
			cout << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 13920
import sys

inf = 2019
L, R = map(int, input().split())

if (R - L) >= 2019:
    print(0)
    sys.exit()

ans = 2019
   
for i in range(L, R):

    for j in range(i + 1, R + 1):
        tmp = int((i * j) % inf)
        ans = min(ans, tmp)
        if ans == 0:
            break
    if ans == 0:
        break

print(ans)


Measured memory_bytes: 3060
while 1:
    n,m = map(int,raw_input().split())
    if n == 0 and m == 0: break
    t = []
    h = []
    pair = []
    score = []
    lst = []
    for i in range(n):
        t.append(int(raw_input()))
    for i in range(m):
        h.append(int(raw_input()))    
    for i in range(n):
        
        for j in range(m):
            #new copy
            tmp_t = list(t)
            tmp_h = list(h)

            #trade
            tmp = tmp_h[j]
            tmp_h[j] = tmp_t[i]
            tmp_t[i] = tmp
            
            #compare
            if sum(tmp_t) == sum(tmp_h):
                pair.append([t[i],h[j]])
                score.append(t[i] + h[j])
    if pair == []:
        print "-1"
    else:
        lst = pair[score.index(min(score))]
        print lst[0],lst[1]

Measured memory_bytes: 7456
#include<stdio.h>
#include<string.h>
#define min(x,y) ((x<y)?x:y)
int main(){
	int n,m,c[105][105],d[105],used[105],i,j,x,y,z,v;
	memset(c,0,sizeof(c));
	
	scanf("%d",&n);
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)c[i][j]=1000000;
	for(i=0;i<n;i++){
		scanf("%d%d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			c[x][z]=1;
		}
	}
	scanf("%d",&m);
	while(m--){
		scanf("%d%d%d",&x,&y,&z);
		//memset(d,-1,sizeof(d));
		for(i=1;i<=n;i++)d[i]=1000000;
		memset(used,0,sizeof(used));
		d[x]=0;
		while(1){
			v=-1;
			for(i=1;i<=n;i++){
				if(used[i]==0 && (v==-1 || d[v]>d[i]))v=i;
			}
			if(v==-1)break;
			used[v]=1;
			//printf("%d:%d\n",v,d[v]);
			for(i=1;i<=n;i++){
				d[i]=min(d[i],d[v]+c[v][i]);
			}
		}
		if(d[y]+1>z)printf("NA\n");
		else printf("%d\n",d[y]+1);
	}
	
	return 0;
}

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

int main() {
  int x, n;
  cin>>x>>n;
  int p[n];
  for (int i=0; i<n; i++) cin>>p[i];
  sort(p, p + n);
  int min_v = 1e9, min_i = -1;
  for (int i=0; i<=101; i++) {
    if (binary_search(p, p + n, i)) {
      continue;
    }
    int tmp = abs(i - x);
    if (tmp < min_v) {
      min_v = tmp;
      min_i = i;
    }
  }
  cout<<min_i<<endl;
}

Measured memory_bytes: 3636
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

num = 1
ans = 0
for i in range(N):
  if num == a[i]:
    ans += 1
    num += 1
if ans == 0:
  print(-1)
else:
  print(N - ans)

Measured memory_bytes: 76364
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int d, n;
  ll ans = 0;
  cin >> d >> n;
  if(n < 100){
    ans += pow(100, d)*n;
  }else{
    ans += pow(100, d)*(n+1);
  }
  cout << ans << endl;
}

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

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

int main(){
	int k;
	int a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;

	return 0;
}





Measured memory_bytes: 3588
open Batteries
let () =
  let h,w = Scanf.scanf "%d %d " (fun a b -> a,b) in

  let mat = Array.init h (fun _ ->
      Array.init w (fun _ -> Scanf.scanf "%c " (fun a -> if a = '.' then '0' else a))
    ) in

  for i=0 to h-1 do
    for j=0 to w-1 do
      if mat.(i).(j) = '#' then (
        for i2=i-1 to i+1 do
          for j2=j-1 to j+1 do
            try
              if mat.(i2).(j2) <> '#' then
                mat.(i2).(j2) <- char_of_int @@ (int_of_char  mat.(i2).(j2)) + 1
            with _ -> ()

          done;
        done;
      ) else ()
    done;
  done;

  Array.iter (fun arr -> Array.iter (print_char) arr; print_endline "") mat;


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

std::string s;
int main()
{
	std::cin >> s;

	std::stack<char> sta;
	int ans = 0;
	for (size_t i = 0, end = s.size(); i < end; ++i) {
		if (!sta.empty()) {
			auto p = sta.top();
			sta.pop();

			if (p != s[i])
				ans += 2;
			else {
				sta.push(p);
				sta.push(s[i]);
			}
		}
		else
			sta.push(s[i]);
	}

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


Measured memory_bytes: 512
n = int(input())
l = [0]*4

for i in range(n):
    a = str(input())
    if a == "AC":
        l[0] += 1
    elif a == "WA":
        l[1] += 1
    elif a == "TLE":
        l[2] += 1
    else:
        l[3] += 1

print("AC x " + str(l[0]))
print("WA x " + str(l[1]))
print("TLE x " + str(l[2]))
print("RE x " + str(l[3]))

Measured memory_bytes: 9208
void main()
{
    string s = rdStr;
    long k = rdElem;

    long idx;
    foreach (i, x; s)
    {
        if (x != '1')
        {
            idx = i;
            break;
        }
    }

    writeln(idx >= k ? s[0] : s[idx]);
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p, ll mo) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mo; p /= 2; } else { a = a * x % mo; p--; } }return a % mo; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2, 0); return k * l % mod; }
ll popcnt(ll v) {
	ll ans = 0;
	while (v) {
		if (v % 2)ans++;
		v /= 2;
	}
	return ans;
}
int main()
{
	ll n, c, k[3] = {0};
	string s;
	cin >> n >> s;
	c = 0;
	int pp = -1, f = 0;
	rep(i2, 0, n) {
		if (s[i2] == '1') {
			if (f == 0)f = 1, pp = i2;
			else pp = -1;
			c++;
		}
	}
	if (c == 0) {
		rep(i, 0, n)puts("1");
		return 0;
	}
	rep(i2, 0, n) {
		if (s[i2] == '1') {
			k[0] += mpower(2, n - i2 - 1, c);
			k[1] += mpower(2, n - i2 - 1, c+1);
			if(c >= 2)k[2] += mpower(2, n - i2 - 1, c-1);
		}
		k[0] %= c;
		k[1] %= c+1;
		if(c >= 2)k[2] %= c-1;
	}
	rep(i, 0, n) {
		ll kk;
		if (c == 1 && s[i] == '1') {
			puts("0");
			continue;
		}
		if (s[i] == '1')kk = k[2] - mpower(2, n - i - 1, c - 1) + c - 1, kk %= c - 1;
		else kk = k[1] + mpower(2, n - i - 1, c + 1), kk %= c + 1;
		int ans = 1;
		while (kk) {
			kk %= popcnt(kk);
			ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

typedef vector<int> vi;

int n, k;
int dp[2000];
vi v[10], sum[10];

int main() {
	cin >> n >> k;
	REP(i, n) {
		int a, b;
		scanf("%d %d", &a, &b);
		v[b - 1].push_back(a);
	}

	REP(i, 10)
		sort(v[i].begin(), v[i].end(), greater<int>());
	REP(i, 10) {
		sum[i].push_back(0);
		REP(j, v[i].size()) {
			sum[i].push_back(sum[i][j] + v[i][j] + j * 2);
		}
	}

	REP(i, 10) {
		for (int j = k; j >= 0; j--) {
			REP(l, sum[i].size()) {
				if (j - l < 0) continue;
				dp[j] = max(dp[j], dp[j - l] + sum[i][l]);
			}
		}
	}
	
	cout << dp[k] << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int ai;
    rep(i,1<<3){
        int ans = s[0]-'0';
        rep(j,3){
            if(i>>j&1){
                ans += s[j+1]-'0';
            }else{
                ans -= s[j+1]-'0';
            }
        }
        if (ans==7){
            ai = i;
            break;
        }
    }
    cout<<s[0];
    rep(i,3){
        if (ai>>i&1) cout<<"+";
        else cout<<"-";
        cout<<s[i+1];
    }
    cout<<"=7\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i <= (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int n, m, x;
  cin >> n >> m >> x;

  bool toll_gates[n+1] = { false };
  rep(i, m-1) {
      int pos = 0;
      cin >> pos; 
      toll_gates[pos] = true;
      // cout << toll_gates[pos];
  }

  int count_to_last = 0;
  for (int i = x; i < n; i++)
  {
    /* code */
    if (toll_gates[i+1] == true)
    {
      /* code */
      count_to_last++;
      // cout << count_to_last << endl;
    }
    // cout << toll_gates[i+1] << endl;
  }
  
  int count_to_head = 0;
  for (int i = x; i > 0; i--)
  {
    /* code */
    if (toll_gates[i-1] == true)
    {
      /* code */
      count_to_head++;
      // cout << count_to_head << endl;
    }
    // cout << toll_gates[i-1] << endl;
  }
  
  cout << min(count_to_last, count_to_head) << endl;
  return 0;
}

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

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 3e3 + 7;
const ld PI = acos(-1);
int n, L, a[N];
ld x, y;

int main() {
	rd(n, L), rda(a, n);
	for (int i = 1; i < n; i++)
		for (int j = i + 1; j <= n; j++)
			x += (n - 2 * (j - i)) * cos(PI * (a[i] + a[j]) / L),
			y += (n - 2 * (j - i)) * sin(PI * (a[i] + a[j]) / L);
	ll k = 1ll * n * (n - 1) * (n - 2) / 6;
	printf("%.20Lf %.20Lf\n", x / k, y / k);
	return 0;
}

Measured memory_bytes: 2304
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
ans = 0
dic = [1, 1, 2, 6, 24, 120, 720, 5040]

for i in range(N-1):
    p = sorted(P[i:])
    q = sorted(Q[i:])
    ans += (p.index(P[i])-q.index(Q[i]))*dic[N-i-1]
    
print(abs(ans))

Measured memory_bytes: 38384
using System;

namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            int[] hill = new int[10];
            for (int i = 0; i < 10; i++) {
                hill[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(hill);
            Console.WriteLine(hill[9]);
            Console.WriteLine(hill[8]);
            Console.WriteLine(hill[7]);
        }
    }
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,w;
    cin>>n>>w;
    int a[n],b[n],mx=0,sum=0,s2=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        sum+=a[i];
        s2+=b[i];
    }
    int dp[100001];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=100000;j>=0;j--)
        {
            if(dp[j]>=0 && j+b[i]<100001)
            {
                if(dp[j+b[i]]==-1)
                {
                    dp[j+b[i]]=dp[j]+a[i];
                    if(dp[j+b[i]]<=w)
                    mx=max(mx,j+b[i]);
                }
                else
                {
                    dp[j+b[i]]=min(dp[j+b[i]],dp[j]+a[i]);
                    if(dp[j+b[i]]<=w)
                    mx=max(mx,j+b[i]);
                }
            }
        }
    }
    cout<<mx;
}

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

/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define endl '\n'

/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

void solve() {
	int n, k; cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < k; i++)
		ans += a[i];
	cout << ans;
}

int32_t main() {

	/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	/* → → → → → → → → → → → → → → → → → → → → → → → → → → → →
	→ → → → → → → → → → → → → → → → → → → → → → → → → → → → */

	//int t;cin>>t;while(t--)
	solve();

	return 0;
}

Measured memory_bytes: 3636
N = int(input())
ans = [0 for _ in range(N+1)]
for x in range(1,101):
  for y in range(x, 101):
    for z in range(y , 101):
      f = x**2 + y**2 + z**2 +x*y + y*z + z*x
      if f > N:
        break
      if x==0 or y==0 or z==0:
        continue
      if x==y and y==z:
        
        ans[f] += 1
      elif x==y or y==z or z==x:
        
        ans[f] += 3
      else:
        
        ans[f] += 6
for a in ans[1:]:
  print(a)

Measured memory_bytes: 68908
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

using namespace std;
typedef pair<long long int, long long int> P;

int main(void) {
	string n;
	long long int total = 0;
	bool flag = true;

	cin >> n;

	FOR(i, 1, n.size() - 1) {
		if (n[i] != '9') {
			flag = false;
			break;
		}
		if (i == n.size() - 1) {
			flag = true;
		}
	}

	if (flag) {
		total = 9 * (n.size() - 1);
		total += n[0] - '0';
	}
	else {
		total = 9 * (n.size() - 1);
		total += n[0] - '0' - 1;
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.emplace_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n,m;
  cin >> n >> m;
  vector< vector<ll> > v(100010);
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    v[x].emplace_back(y);
  }
  ll ans = 0;
  priority_queue<ll> p;
  for(ll i=1; i<=m; i++){
    for(auto j:v[i]){
      p.push(j);
    }
    if(!p.empty()){
      ans += p.top();
      p.pop();
    }
  }
  cout << ans;
    
   
    
 return 0;
}

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

int main() {
   int N,M,C=0,W=0;
   cin >> N >> M;
   vector<int> p(M),P(N),w(N);
   vector<string> S(M);
   for(int i=0;i<M;i++){
       cin >> p.at(i) >> S.at(i);
   }
   for(int i=0;i<M;i++){
       if(P.at(p.at(i)-1) == 0){
           if(S.at(i) == "AC"){
               P.at(p.at(i)-1) = 1;
               C++;
           }
           else{
               w.at(p.at(i)-1)++;
           }
       }
   }
  for(int i=0;i<N;i++){
    if(P.at(i) == 1){
      W = W + w.at(i);
    }
  }
   cout << C << " " << W << endl;
}

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

using namespace std;

int main() {
string S;
long long K;
cin>>S>>K;
for(int i=0;i<K;i++){
   if(S[i]!='1'){
      cout<<S[i]<<endl;
      return 0;
   }
}

   cout<<1<<endl;

   return 0;
}






Measured memory_bytes: 3584
var
    a,b,c,i,ans:longint;
    a1:array[1..100000]of longint;
begin
    read(a,b,c);
    for i:=1 to a do
    begin
        read(a1[i]);
        if(a1[i]<b)or(a1[i]>=c)then inc(ans);//暴力判断
    end;
    writeln(ans);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    sort(ALL(a));
    rep(i,k)ans += a[i];
    cout << ans << endl;
}

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

typedef long long ll;

using namespace std;

const string no = "No";
const string yes = "Yes";

template<class T>
std::ostream& operator<<(std::ostream& st, const std::vector<T>& vec) {
  for (const auto& entry : vec) {
    st << entry << " ";
  }

  return st;
}

void performe_arr(const string& s, vector<int>& arr, int l, int r) {
  int target_spot = -1;
  for (int i = l; i < r; ++i) {
    if (s[i-1] == 'R' && s[i] == 'L') {
      target_spot = i;
    }
  }

  if (target_spot == -1) {
    return;
  }

  int n_even = (r - l) / 2;
  int n_odd = (r - l) - n_even;

  if ((target_spot - l) % 2 == 0) {
    arr[target_spot - 1] = n_even;
    arr[target_spot] = n_odd;
  } else {
    arr[target_spot] = n_even;
    arr[target_spot - 1] = n_odd;
  }
}

int main() {
  string s;
  cin >> s;

  int n = s.length();
  vector<int> positions(n, 0);

  int last_pos = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i-1] == 'L' && s[i] == 'R') {
      performe_arr(s, positions, last_pos, i);
      last_pos = i;
    }
  }

  performe_arr(s, positions, last_pos, n);

  cout << positions << endl;

  return 0;
}






Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  bool card[4][14];
  REP(i, 4) REP(j, 14) card[i][j] = false;
  REP(i, n) {
    char c;
    int num;
    cin >> c >> num;
    if (c == 'S')
      card[0][num] = true;
    else if (c == 'H')
      card[1][num] = true;
    else if (c == 'C')
      card[2][num] = true;
    else
      card[3][num] = true;
  }
  REP(i, 4) REP1(j, 13) {
    if (!card[i][j]) {
      if (i == 0)
        cout << "S " << j << endl;
      else if (i == 1)
        cout << "H " << j << endl;
      else if (i == 2)
        cout << "C " << j << endl;
      else
        cout << "D " << j << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  for(int i = 0;i < n;i++)
  {
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=100001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;
   string s  ;  cin>>s ;
   set<ll>st[26] ;
   for(ll i=0;i<n;i++)
   {
       st[s[i]-'a'].insert(i) ;
   }
   ll q ; cin>>q ;
   for(ll i=0;i<q;i++){
    char c ;
    ll t ; cin>>t ;
    if(t==1)
    {
        ll id ;
        cin>>id>>c ;
        id-- ;
        st[s[id]-'a'].erase(st[s[id]-'a'].find(id)) ;
        st[c-'a'].insert(id) ;
        s[id]=c ;

    }
    else
    {
        ll ans=0 ;
        ll l,p ; cin>>l>>p ;
        l-- ; p -- ;
        for(ll j=0;j<26;j++)
        {
            auto it=st[j].lower_bound(l) ;
            if(it!=st[j].end())
            {
                if(*it<=p) ans++ ;
            }

        }
        cout<<ans<<endl ;
    }
   }

}




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

int main(){
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256