akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10**7)
def MI(): return map(int,sys.stdin.readline().rstrip().split())


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)

    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)

    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x


N,M = MI()
UF = UnionFind(N)
for _ in range(M):
    a,b = MI()
    UF.unite(a,b)

A = UF.par
A = [UF.find(A[i]) for i in range(1,N+1)]

print(len(set(A))-1)


Measured memory_bytes: 86988
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a.at(i);
    if(accumulate(all(a), 0LL) >= h)cout << "Yes";
    else cout << "No";
}
    

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
	int n,x,t,total;
	scanf("%d%d%d",&n,&x,&t);
    if(n%x==0)
    {
           n/=x;
    }
    else
         n=n/x+1;

         printf("%d\n",n*t);

	return 0;
}



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

int counter(vector<string> s, int i, int j, int W) {
    int count = 0;
    if (j > 0)
        if (s[i][j - 1] == '#') count++;
    
    if (s[i][j] == '#') count++;

    if (j < W - 1)
        if (s[i][j + 1] == '#') count++;
    
    return count;
}


int main() {
    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    for (int i = 0; i < S.size(); i++) {
        for (int j = 0; j < S[i].size(); j++) {
            int count = 0;
            if (S[i][j] == '#') continue;
            if (i > 0)
                count += counter(S, i - 1, j, W);
            count += counter(S, i, j, W);
            if (i < H - 1)
                count += counter(S, i + 1, j, W);
            S[i][j] = count + (int)'0';
        }
    }
    for (string s : S)
        cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  string S,T;
  cin >> S;
  cin >> T;
  vector<vector<int> >G(26);
  vector<vector<int> >H(26);
  for(ll i=0;i<S.size();i++){
    /*if(S[i]!=T[i]){
      G[S[i]-'a'].push_back(T[i]-'a');
      G[T[i]-'a'].push_back(S[i]-'a');
    }else{
      G[S[i]-'a'].push_back(T[i]-'a');
      }*/
    G[S[i]-'a'].push_back(T[i]-'a');
    H[T[i]-'a'].push_back(S[i]-'a');
  }
  bool s=true;
  for(int i='a'-'a';i<'z'-'a'+1;i++){
    if(G[i].size()>=0){
      for(ll j=1;j<G[i].size();j++){
	if(G[i][0]!=G[i][j]) s=false;
      }
    }
    if(H[i].size()>=0){
      for(ll j=1;j<H[i].size();j++){
	if(H[i][0]!=H[i][j]) s=false;
      }
    }
  }
  if(s) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 5508
#include<bits/stdc++.h>
#include<vector>
#define N 200005
using namespace std;
vector<int> G[N];
int n,m,v,a[N],r[20][N],f[1<<20],g[1<<20],ufs[20][N];
int find(int op,int x){ return ufs[op][x] ? ufs[op][x]=find(op,ufs[op][x]) : x;}
int main()
{
	int i,j,x,p,y,T;
	scanf("%d %d",&n,&v);
	for(i=v,m=0;i;i>>=1,m++);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<=m;i++){
		for(j=1;j<=n;j++) r[i][j]=j;
		for(j=1;j<n;j++)
			if(a[j+1]-a[j]<=(v>>i))
				x=find(i,j),ufs[i][j+1]=x,r[i][x]=j+1;
	  }
	for(i=1;i<(1<<m);i++)
		for(j=0;j<m;j++)
			if((i>>j)&1){
				x=r[j+1][find(j+1,min(f[i^(1<<j)]+1,n))];
				f[i]=max(f[i],x);
			  }
	for(i=0;i<(1<<m);i++) g[i]=n+1;
	for(i=1;i<(1<<m);i++)
		for(j=0;j<m;j++)
			if((i>>j)&1){
				x=find(j+1,max(g[i^(1<<j)]-1,1));
				g[i]=min(g[i],x);
			  }
	T=(1<<m)-1,p=0,y=-100;
	for(i=0;i<=T;i++)
		G[g[T^i]].push_back(f[i]);
	for(i=1;i<=n;i++){
		x=find(0,i);
		while(p<=r[0][x]+1){
			for(j=0;j<G[p].size();j++)
				y=max(y,G[p][j]);
			p++;
		  }
		if(y<x-1) printf("Impossible\n");
		else printf("Possible\n");
	  }
	return 0;
}


Measured memory_bytes: 48768
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            //人数
            long N = inputLongArray[0];
            //お菓子の種類
            long K = inputLongArray[1];
            List<long> allMem = new List<long>();
            for (long q = 1; q <= N; q++)
            {
                allMem.Add(q);
            }
            for (long i = 0;i<K;i++)
            {
               //お菓子K[i]を持ってる人数
                long dN = long.Parse(Console.ReadLine());
                //お菓子[i]を持ってる人
                long[] lArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
                for(long p = 0; p < dN; p++)
                {
                    allMem.Remove(lArray[p]);
                }
            }
            Console.WriteLine(allMem.Count);
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


Measured memory_bytes: 28640
# include<iostream>
using namespace std;
char a[1000000] = {0};
char flag[79000] = {0};
int q[56];
int prime[79000] = {0};
int abc = 0;
int dfs(int n, int xz)
{
    int i, j, k, h;
    if(abc == 1)
        return 0;
    for(i = 0; i < xz; ++i)
        for(j = i+1; j < xz; ++j)
            for(k = j+1; k < xz; ++k)
                for(h = 0; h < xz; ++h)
                {
                    int sum = q[i] + q[j] + q[k] + q[h] + q[xz-1];
                    int f = lower_bound(prime, prime+10000, sum) - prime;
                    if(prime[f] == sum)
                        return 0;
                }
    if(n == xz)
    {
        int i;
        cout << q[0];
        for(i = 1; i < n; ++i)
        {
            cout <<" " <<q[i];
        }
        cout << endl;
        abc = 1;
        return 0;
    }
    for(i = 0; i <= 300; ++i)
    {
        if(flag[i] == 0)
        {
            flag[i] = 1;
            q[xz] = prime[i];
            dfs(n, xz+1);
            flag[i] = 0;
        }
    }
}
int main(void)
{
    int i, j;
//    for(i = 2; i*i <= 1000000; ++i)
//        for(j = i*i; j <= 1000000; j+=i)
//        {
//            a[j] = 1;
//        }
//    int cnt = 0;
//    for(i = 2; i <= 1000000; ++i)
//    {
//        if(a[i] == 0)
//        {
//            prime[cnt++] = i;
//        }
//    }
int b[60] = {3,13,23,43,53,73,83,103,113,163,173,193,223,233,263,283,293,313,353,373,383,433,443,463,503,523,563,593,613,643,653,673,683,733,743,773,823,853,863,883,953,983,1013,1033,1063,1093,1103,1123,1153,1163,1193,1213,1223,1283,1303};
    int n;
    cin >> n;
cout << b[0];
for(i = 1; i < n; ++i)
    cout << " " <<b[i];
cout <<endl;
    return 0;
}


Measured memory_bytes: 256
// 2011/02/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		// üÍi¶kÌlj
		int n;
		cin >> n;
		if(n==0)
			break;

		// üÍi¶kÌ_jÆ»f
		for(int i=0; i<n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;
			if(pm==100||pe==100||pj==100)		// 100_ÌÈÚª é
				cout << 'A' << endl;
			else if((pm+pe)/2>=90)			// wÆpêÌ½Ï_ª90_Èã
				cout << 'A' << endl;
			else if((pm+pe+pj)/3>=80)		// 3ÈÚÌ½Ï_ª80_Èã
				cout << 'A' << endl;
			else if((pm+pe+pj)/3>=70)		// 3ÈÚÌ½Ï_ª70_Èã
				cout << 'B' << endl;
			else if(((pm+pe+pj)/3>=50)&&(pm>=80||pe>=80))		// 3ÈÚÌ½Ï_ª50_ÈãÅw©pêª80_Èã
				cout << 'B' << endl;
			else					// ãÌðð½³È¢
				cout << 'C' << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

int main(){

    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;

    s[k - 1] = tolower(s[k - 1]);

    cout << s << endl;
 
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int k, a, b, flag = 0;
        Scanner sc = new Scanner(System.in);
        k = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        for(int i = a; i <= b; i++){
            if(i % k == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 1){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }
    }
}

Measured memory_bytes: 35820
package main

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

// 文字列を1行入力
func StrStdin() (stringReturned string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringReturned = scanner.Text()

	stringReturned = strings.TrimSpace(stringReturned)
	return
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}
	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	input, _ := SplitIntStdin(" ")

	fmt.Printf("%d %d %d", input[2], input[0], input[1])
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int tyo = 0, hisi = 0;
	
	while (scanf("%d,%d,%d", &a, &b, &c) != EOF){
		if (a == b){
			hisi++;
		}
		if (a * a + b * b == c * c){
			tyo++;
		}
	}
	printf("%d\n%d\n", tyo, hisi);
	
	return (0);
}

Measured memory_bytes: 596
package main

import "fmt"

func main() {
	var height int
	topHeights := [5]int{}

	for i := 0; i < 10; i++ {
		fmt.Scan(&height)

		for j := 0; j < 3; j++ {
			if topHeights[j] < height {
				topHeights[j+2] = topHeights[j+1]
				topHeights[j+1] = topHeights[j]
				topHeights[j] = height
				break
			}
		}
	}

	for i := 0; i < 3; i++ {
		fmt.Println(topHeights[i])
	}
}



Measured memory_bytes: 1104
#include <stdio.h>

int main(void)
{
	int hill[10];
	int high[3] = {0};
	int i, j, k;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &hill[i]);
		if (i == 0){
			high[i] = hill[i];
			continue;
		}
		for (j = 0; j < 3; j++){
			if (high[j] < hill[i]){
				for (k = 2; k >= j; k--){
					high[k] = high[k - 1];
				}
				high[j] = hill[i];
				break;
			}
		}
	}
	
	for (i = 0; i < 3; i++){
		printf("%d\n", high[i]);
	}
	
	return (0);
}

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

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

    ll ans = 0;
    exrep(i, 1, n) {
        ans += n/i;
    }
    
    out(ans);
    re0;
}

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

int kakuinowa(int N){
  int sum=0; 
  while(true){
    sum += N%10;
    
    if(N<10) break; 
    else N/=10;
  }
  return sum;
}

int main(){
  int N, Sum, min=1000000000;
  cin >> N;
  for(int i=1; i<N; i++){
    Sum=kakuinowa(i)+kakuinowa(N-i);
    if(Sum<min) min=Sum;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
#define maxn 10000007
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	ll cnt = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i)
			cnt += j;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;
import java.util.Map.Entry;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {	
	static char[] tank = new char[] {'^','>','v','<'};
	static int[] vx = new int[] {0,1,0,-1};
	static int[] vy = new int[] {-1,0,1,0};
	static final int INF = 2 << 28;
	static String str;
	static StringBuilder sb;
	static int ID;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int w = sc.nextInt();
			int h = sc.nextInt();
			Data data[] = new Data[n];
			HashMap<String,Integer> map = new HashMap<String,Integer>();
			for(int i = 0; i < n; i++) {
				String name = sc.next();
				map.put(name, i);
				int b = sc.nextInt();
				data[i] = new Data(name,b);
				for(int j = 0; j < b; j++) {
					int AA = sc.nextInt();
					int BB = sc.nextInt();
					int CC = sc.nextInt();
					int DD = sc.nextInt();
					String EE = sc.next();
					data[i].bt[j] = new BT(EE,AA,BB,CC,DD);
				}
			}
			
			int[] bf = new int[10000];
			
			bf[0] = 0;
			int ptr = 0;
			int up  = 0;
			
			int m = sc.nextInt();
			for(int i = 0; i < m; i++) {
				int N = bf[ptr];
				
				Data now = data[N];
				
				String in = sc.next();
				if(in.equals("click")) {
					int x = sc.nextInt();
					int y = sc.nextInt();
					for(int j = 0; j < now.bt.length; j++) {
						int x0 = now.bt[j].x0;
						int x1 = now.bt[j].x1;
						int y0 = now.bt[j].y0;
						int y1 = now.bt[j].y1;
						if(x0 <= x && x <= x1 && y0 <= y && y <= y1) {
							up = ++ptr;
							bf[ptr] = map.get(now.bt[j].name);
							break;
						}
					}
				}
				else if(in.equals("back")) {
					ptr = Math.max(0, ptr-1);
				}
				else if(in.equals("forward")) {
					ptr = Math.min(up, ptr+1);
				}
				else if(in.equals("show")) {
					System.out.println(now.name);
				}
			}
			
			
			
		}
	}
	static class Data {
		String name;
		BT bt[];
		Data(String a, int b) {
			name = a;
			bt = new BT[b];
		}
	}
	static class BT {
		String name;
		int x0;
		int y0;
		int x1;
		int y1;
		BT(String A, int a, int b, int c, int d) {
			name = A;
			x0 = a;
			y0 = b;
			x1 = c;
			y1 = d;
		}
	}
	
	
	
	
	
 }

Measured memory_bytes: 41744
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

vector<vector<int>> g;

int dfs(const int &c, const int &p,const pii &b, vector<bool> &visit) {
    int ret = 1;
    visit[c] = true;
    for(auto x:g[c]) {
        if (visit[x]) continue;
        if (x == p) continue;
        if (make_pair(c,x) == b) continue;
        if (make_pair(x,c) == b) continue;
        ret += dfs(x,c,b,visit);
    }
    return ret;
}

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    g.resize(n);
    vector<pii> v;
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        v.push_back({a,b});
    }

    int ans = 0;
    REP(i,m) {
        vector<bool> visit(n);
        if(dfs(0,-1,v[i],visit) != n) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    long long a, b, c;
    cin >> a >> b >> c;

    if(a == b and b == c and a % 2 == 0){
        printf("-1\n");
        return 0;
    }

    long long tmp_a, tmp_b, tmp_c;
    long long count = 0;
    while(1){
        if(a % 2 != 0 || b % 2 != 0 || c % 2 != 0){
            break;
        }

        tmp_a = (b+c)/2;
        tmp_b = (c+a)/2;
        tmp_c = (a+b)/2;
        a = tmp_a;
        b = tmp_b;
        c = tmp_c;
        count++;
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    string s;cin>>s;
    int n=s.size();
    string s0,s1;
    int tmp0=0;
    rep(i,n){
        s0+=to_string(tmp0);
        tmp0=(tmp0+1)%2;
    }
    int tmp1=1;
    rep(i,n){
        s1+=to_string(tmp1);
        tmp1=(tmp1+1)%2;
    }
    int ans0=0;
    rep(i,n){
        if(s[i]!=s0[i])ans0++;
    }
    int ans1=0;
    rep(i,n){
        if(s[i]!=s1[i])ans1++;
    }
    cout<<min(ans0,ans1)<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi   = vec<int>;
using vvi  = vec<vi>;
using vvvi = vec<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  string s; cin >> s;
  bool fumiyasui = true;
  rep(i,(int)s.size()){
    if(i%2==1 && s[i]=='R') fumiyasui = false;
    if(i%2==0 && s[i]=='L') fumiyasui = false;
  }
  if(fumiyasui) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
  int r,g;
  cin>>r>>g;
  cout<<2*g-r<<"\n";
  return 0;
}


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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 8;
int n, a, b, cnt=1;
int p[max_n], q[max_n];
vector<int> v;

int main(){
    cin >> n;
    rep(i, n) cin >> p[i], v.push_back(i+1);
    rep(i, n) cin >> q[i];

    do{
        bool isp = true, isq = true;
        for(int i=0; i<n; i++){
            if(v[i] != p[i]) {
                isp = false;
                break;
            }
        }
        for(int i=0; i<n; i++){
            if(v[i] != q[i]) {
                isq = false;
                break;
            }
        }
        if(isp) a = cnt;
        if(isq) b = cnt;
        cnt++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>

using namespace std;

int main()
{
    int  a,b;
    scanf("%d%d",&a,&b);
    if(a<=8&&b<=8)
        printf("Yay!\n");
    else
        printf(":(\n");
    return 0;
}


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


int main(){
  int A, B ;
  string S, T, U ;
  cin >> S >> T >> A >> B >> U  ;
  if(S == U) A-- ;
  else B-- ;
  cout << A << " " << B << endl ;
  return 0 ;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		while(s.hasNext()){
			String p=s.nextLine();
			if(p.equals("0"))System.exit(0);
			String []q=p.split(" ");
			int r[]=new int[q.length];
			for(int j=0;j<q.length;j++){
				r[j]=Integer.parseInt(q[j]);
			}
			int one=0;
			int point=0;
			for(int j=0;j<q.length;j++){
				if(r[j]==1)one++;
				else if(r[j]>10)point+=10;
				else point+=r[j];
			}
			point+=one;
			while(one>0&&point+10<=21){
				one--;
				point+=10;
			}
			if(point>21)System.out.println(0);
			else System.out.println(point);
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    string s,t; cin>>s>>t;

    rep(i,0,n) cout<<s[i]<<t[i];
    cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Sum{
        public:
        Sum();
        int doSum(int);
        private:
        int total;
};
Sum::Sum(){
        total = 0;
}
int Sum::doSum(int data){
        total = 0;
        while(data){
                total += data % 10;
                data /= 10;
        }
        return total;
}
Sum sum1 = Sum();
int main(void){
        int  N,A,B;
        int total = 0;
        cin >> N >> A >> B;
        for(int i = 0; i <= N; ++i){
                int sum = sum1.doSum(i);
                if(sum >= A && sum <= B) total += i;
        }
        cout << total << endl;
        return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
 		Scanner scan = new Scanner(System.in);
      	int v = scan.nextInt();
      	int e = scan.nextInt();
      	Solver solver = new Solver(v);
      
      	for(int edge = 0; edge < e; edge++){
          int a = scan.nextInt();
          int b = scan.nextInt();
          solver.graph[a].add(b);
        }
      	scan.close();
      	System.out.println(solver.longestPath());
	}
  
  public static class Solver{
 	public int size; 
    public ArrayList<Integer> graph[]; 
    private int[] memo;
    
    public Solver(int size)  
    { 
        this.size = size; 
        graph = new ArrayList[size+1]; 
        for (int i = 0; i <= size; i++) graph[i] = new ArrayList<>(); 
    } 
        
   private void visit(int node, boolean visited[]) 
    { 
        visited[node] = true; 
  
        for (int i = 0; i < graph[node].size(); i++)  
        { 
            if (!visited[graph[node].get(i)]) visit(graph[node].get(i), visited); 
            memo[node] = Math.max(memo[node], 1 + memo[graph[node].get(i)]); 
        } 
    } 
    
    public int longestPath() 
    { 
        memo = new int[size+1]; 
        boolean[] visited = new boolean[size + 1]; 
      
        for (int i = 1; i <= size; i++)  
         if (!visited[i]) visit(i, visited); 
         
        int answer = 0;   
        for (int i = 1; i <= size; i++)  answer = Math.max(answer, memo[i]); 
        return answer; 
    } 
  }
}


Measured memory_bytes: 95684
def shiritori(N: int, W: list)->bool:
    used = []
    head = W[0][0]

    for w in W:
        if w in used or head != w[0]:
            return False
        used.append(w)
        head = w[-1]

    return True


if __name__ == "__main__":
    N = int(input())
    W = [input() for _ in range(N)]
    yes = shiritori(N, W)
    print('Yes' if yes else 'No')


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

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

  return 0;
}

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

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    int ans = 0;
    while (x) {
        if (N <= ans || x < a.at(ans) ) {
            break;
        }
        x -= a.at(ans);
        ans++;
    }
    if (N <= ans && x != 0) {
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}


int main(){
    ll n=lin(),a=lin(),b=lin();
    ll ans=0;
    if(a%2==b%2){
        ans=abs(a-b)/2;
    }else{
        ans = min((a+b-1)/2,(2*n-a-b+1)/2);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
n, m, x = map(int, input().split())
a = [list(map(int, input().split())) for _i in range(n)]

result = []
for i in range(2**n):
    num = i
    memo = [0 for _ in range(m)]
    cost = 0
    for j in range(n):
        if num%2==1:
            cost += a[j][0]
            for s in range(m):
                memo[s] += a[j][s+1]
        num >>= 1
    if all(i >= x for i in memo):
        result.append(cost)

if len(result)==0:
    print(-1)
else:
    print(min(result))

Measured memory_bytes: 9228
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll ans=1;
    ll lim = 1e18;
    rep(i,n){
        if(a[i]==0){
            cout(0);
            return 0;
        }
    }
    rep(i,n){
        if(lim/ans < a[i]){
            cout(-1);
            return 0;
        }
        ans *= a[i];
    }
    cout(ans);
    return 0;
}





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

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

    vector<int> deq;
    for (int i=0; i<N; i++) {
        int v; cin >> v;
        deq.push_back(v);
    }

    long long ans = 0;
    for (int i=0; i<=N; i++) { // 左からi個
        for (int j=0; j<=N-i; j++) { // 右からj個
            if (i+j > K) break;

            vector<int> tmp;
            for (int t=0; t<i; t++) tmp.push_back(deq[t]);
            for (int t=0; t<j; t++) tmp.push_back(deq[N-t-1]);
            sort(tmp.begin(), tmp.end());

            // 最大 K - (i+j) 個分は戻しても良い
            int k=0;
            while (k < tmp.size() && tmp[k] < 0 && k < (K - (i+j))) {
                k++;
            }

            long long sum = 0;
            for (int t=k; t<tmp.size(); t++) sum += tmp[t];
            ans = max(ans, sum);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 1000005
using namespace std;

int s, d[2][N];
string a;
int main()
{
	int i;
	cin >> a;
	a = '0' + a;
	d[1][0] = 1;
	for (i = 1; i < a.size(); i++) {
		a[i] -= '0';
		d[0][i] = min(d[0][i - 1] + a[i], d[1][i - 1] + 10 - a[i]);
		d[1][i] = min(d[0][i - 1] + a[i] + 1, d[1][i - 1] + 9 - a[i]);
	}
    cout << d[0][a.size() - 1] << endl;
    return 0;
}


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

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

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

template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}
 
int main()
{
    #ifdef Saiyan
  freopen("inp.txt","r",stdin) ;
  freopen("out.txt","w",stdout) ;
  #endif
 
  ios_base::sync_with_stdio(false) ; cin.tie(0) ;
 
   long long int t,i,j,n,temp,a[100005],k,mx=0;
   
   cin>>n>>k;
   
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       mx=max(mx,a[i]);
   }
   
   temp=a[0];
   
   for(i=0;i<n;i++)
   {
       temp=gcd(temp,a[i]);
   }
   
   if(k%temp==0&&k<=mx)
   {
       cout<<"POSSIBLE";
   }
   else
   {
       cout<<"IMPOSSIBLE";
   }
   
   
   return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 2e5 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k,sum;
int a[N], b[N];

int ok(){
    db res=sum/(4.0*m);
    if(a[n-m+1]>=res) return 1;
    return 0;
}

int main(){
    cin>>n>>m;
    rep(i,1,n){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+1+n);
    puts(ok()?"Yes":"No");
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int M = 998244353;
const int mx = 1e6 + 1;
int n;
int a[MAXN];
int f[mx];
int g[mx];
vector<int> divi[mx];
int inv[mx + 10];
int inv2[mx + 10];
int fat[mx + 10];
void solve(){
	fat[0] = inv2[0] = 1;
	for(int i=1;i<=mx+1;i++){
		fat[i] = (fat[i-1]*i)%M;
	}
	inv2[mx + 1 ] = exp(fat[mx+ 1],M-2,M);
	for(int i=mx;i>=1;i--){
		inv2[i] = (inv2[i+1]*(i+1))%M;
		inv[i] = (fat[i-1]*inv2[i])%M;
	}
}


int32_t main(){
	fastio;
	solve();
	for(int i=1;i<=mx;i++){
		for(int j=i;j<=mx;j+=i){
			divi[j].pb(i);
		}
	}
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		for(int j=0;j<divi[a[i]].size();j++){
			int x = divi[a[i]][j];
			f[x] = mod(f[x] + a[i],M);
		}
	}
	int r=0;
	for(int i=mx;i>=1;i--){
		g[i] = (f[i]*f[i])%M;
		for(int d = 2*i;d<=mx;d+=i){
			g[i] = (g[i] - g[d])%M;
		}
		if(g[i]<0)g[i]+=M;
		r = (r + g[i]*inv[i])%M;
	}
	

	for(int i=1;i<=n;i++){
		r = mod(r - a[i],M);
	}
	r = (r*inv[2])%M;
	if(r<0)r+=M;
	cout<<r<<endl;
}

Measured memory_bytes: 221440
#if 0
date +%Y.%m.%d
 
ABC 被这题调自闭了。。。
一个较为方便的 SPFA 做法是一个点被更新 n 次后直接将 dis 设为 inf 但继续増广，
“继续増广”这点很重要，如果直接结束 SPFA 会受局部正环影响，
如果结束当前点则可能导致后面一些受正环影响的点的更新次数不到 n 且 dis 不会更新到 inf 。
另一个不容易错但稍稍麻烦的做法是先根据反边 dfs 出哪些点能到终点，
然后只考虑这些点，一旦有正环就可以直接输 -1 了。
另外直接用 Bellman-Ford 是不对的，对于局部正环处理不当，还是得先 dfs 需要的点。
举个 hack 例子：
3 4 0
1 3 -100
3 2 -100
2 1 -100
2 2 1
#endif
#include <cstdio>
#include <queue>
#include <cassert>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 2505, maxm = 10005;
int head[maxn], nxt[maxm], to[maxm], val[maxm], hp;
int head2[maxn], nxt2[maxm], to2[maxm], hp2;
lolong dis[maxn];
int cnt[maxn];
bool fuck[maxn];
bool inq[maxn];

void dfs(int u) {
	// debug("fuck %d\n", u);
	fuck[u] = true;
	for(int i = head2[u]; i; i = nxt2[i])
		if(not fuck[to2[i]])
			dfs(to2[i]);
}

int main() {
	int n = input(), m = input(), p = input();
	for(int i = 1; i <= m; i++) {
		int u = input(), v = input(), w = input() - p;
		nxt[++ hp] = head[u];
		head[u] = hp;
		to[hp] = v;
		val[hp] = w;
		nxt2[++ hp2] = head2[v];
		head2[v] = hp2;
		to2[hp2] = u;
	}
	dfs(n);
	std::queue<int> q;
	q.push(1);
	for(int i = 2; i <= n; i ++)
		dis[i] = - 1000000000000ll;
	while(not q.empty()) {
		int u = q.front();
		q.pop();
		inq[u] = false;
		// debug("%d: %lld\n", u, dis[u]);
		cnt[u] ++;
		if(cnt[u] > n) {
			// assert(false);
			// FIXME
			debug("FUCK\n");
			puts("-1");
			return 0;
		}
		for(int i = head[u]; i; i = nxt[i])
			if(fuck[to[i]] and dis[u] + val[i] > dis[to[i]]) {
				dis[to[i]] = dis[u] + val[i];
				if(not inq[to[i]]) {
					q.push(to[i]);
					inq[to[i]] = true;
				}
			}
	}
	printf("%lld\n", std::max(dis[n], 0ll));
}

Measured memory_bytes: 384
# coding:utf-8

K, N = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
dist = []
ans = []

for i in range(N):
    if i != N - 1:
        dist.append(A[i+1] - A[i])
    else:
        dist.append(A[0] + (K - A[N-1]))

s = sum(dist)

for i in range(N):
    ans.append(s - dist[i])

print(min(ans))

Measured memory_bytes: 26444
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    a = LI()
    s = sum(a)
    m = II()
    for _ in range(m):
        p,x = LI()
        print(s-a[p-1]+x)

main()


Measured memory_bytes: 5420
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  if((a == b && b != c) || (b == c && a != b) || (a == c && a != b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
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;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
while(1){
int n,m;
cin>>n>>m;
if(n==0)return 0;
V<ll> ma(m,0);
for(int i=0;i<n;i++){
  ll d,v;
  cin>>d>>v;
  chmax(ma[d-1],v);
}
ll sum=0;
for(int i=0;i<m;i++)sum+=ma[i];
cout<<sum<<"\n";
}
}


Measured memory_bytes: 3244
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Main m = new Main(sc);
    m.show(m.solve());
    // m.debug();
  }

  Scanner sc;
  int A = 0;
  int B = 0;
  boolean answer = true;

  // 標準入力用のコンストラクタ
  public Main(Scanner sc) {
    this.sc = sc;
    A = sc.nextInt();
    B = sc.nextInt();
  }

  // 判定処理
  boolean solve() { //交互に入れられるということは、AとBは両方とも8以下
      if (!(A<= 8 && B <= 8)){
        answer = false;
      }
      return answer;
  }

  // 回答の表示
  void show(boolean answer) {
      if (answer){
        System.out.println("Yay!");
      } else {
        System.out.println(":("); 
      }
  }
    
}


Measured memory_bytes: 35700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []a = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		int min = 100000000;
		int id = 0;
		for(int i = 0; i < n; i++) {
			if(min > Math.abs(sum - n * a[i])) {
				min = Math.abs(sum - n * a[i]);
				id = i;
			}
		}
		System.out.println(id);

	}
}

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

using namespace std;

int main(){
  int N,K;
  long int H[1111111];
  int i;
  cin >> N >> K;
  for(i=0;i<=N-1;i++)
    cin >> H[i];
  sort(H,H+N);
  long int ans = 0;
  if(K<N){
    for(i=0;i<=N-K-1;i++)
      ans += H[i];
      }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, q;
    cin >> n >> q;
    vector<pair<ll, PL>> p(n);
    REP(i,n){
        ll s = in(), t = in(), x = in();
        p[i] = make_pair(x, PL(s, t));
    }
    sort(ALL(p));
    set<PL> st;
    REP(i,q){
        ll d = in();
        st.insert(PL(d, i));
    }
    VL ans(q, -1);
    REP(i,n){
        ll x = p[i].first;
        ll s = p[i].second.first - x, t = p[i].second.second - x;
        set<PL> del;
        auto itr = st.lower_bound(PL(s, -1));
        while (itr->first < t && itr != st.end()){
            ans[itr->second] = x;
            del.insert(*itr);
            itr++;
        }
        for (auto tmp : del) st.erase(tmp);
    }
    REP(i,q) printf("%lld\n", ans[i]);
    return 0;
}


Measured memory_bytes: 28928
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
    
     Scanner scan = new Scanner(System.in);
     int[] a = new int[3];
     int temp =0 ;
     for (int i =0; i<3; i++){
         a[i] = scan.nextInt();
     }
     
        
     for (int i= 2; i >0 ;i--){
         for (int j = 0; j<2;j++){
             if (a[j] > a[i]){
                temp = a[j];
        
                 a[j] = a[i];
                 a[i] = temp;
                
             }
         }
     }
        System.out.println(a[0] +" " + a[1] + " " + a[2]);
    }
}

Measured memory_bytes: 26296
#include<stdio.h>
#define MAX_NUM 45

int table[MAX_NUM];

int Fibonatti(int n){
    if(n==1 || n==0)return table[n]=1;
    if(table[n]!=0)return table[n];
    return table[n] = Fibonatti(n-1)+Fibonatti(n-2);
}

int main(){
    int n;
    for(n=0; n<MAX_NUM; n++)table[n]=0;
    scanf("%d",&n);
    printf("%d\n",Fibonatti(n));
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    vi v(26);
    FOR(i,0,s.size()){
        v[s[i] - 'a'] = 1;
    }
    bool t = true;
    FOR(i,0, 26){
        if(v[i] == 0){
            cout << char(i + 'a');
            t = false;
            break;
        }
    }
    if(t){
        cout << "None";
    }
    cout << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int a,b,dai;
  cin >> a >> b;

  if(a <= 8 && b <= 8){
	cout << "Yay!" << endl;
  }
  else{
	cout << ":(" << endl;
  }

	
  return 0;
}


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

int top,s[1000];

void push(int x){
  s[++top] = x;
}

int pop(){
  top--;
  return s[top+1];
}

int main(){
  int a,b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}


Measured memory_bytes: 2108
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
using namespace std;
#define int long long
class DChatInACircle {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;
cin>>n;
        vector<int> a(n);
        for (int i = 0; i <n ; i++) {
            cin>>a[i];
        }
        sort(a.begin(), a.end());
        int sum=0;
        for (int j = 1; j < n; j++) {
            int cnt=j/2;
            sum+=a[n-cnt-1];
        }
        cout<<sum;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    DChatInACircle solver;
    solver.solve(in, out);
}


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

int main() {
  
  int x;
  cin >> x;
  
  int s = 0; //嬉しさポイント
  int n = 0; //500円玉の後のコイン
  
  n += x % 500;        //余り
  
  s += x / 500 * 1000 + n / 5 * 5;
  
  cout << s << endl;
  
}


Measured memory_bytes: 256
n, m = map(int, input().split())
center1 = (m+1) // 2
center2 = center1 + m
for i in range(m):
    if i % 2 == 0:
        a = center1 - i // 2
        b = center1 + i // 2 + 1
    else:
        a = center2 - i // 2
        b = center2 + (i+1) // 2 + 1
    print(f"{a} {b}")


Measured memory_bytes: 9196
import sys
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    gcd_n = reduce(gcd, A)
    max_a = max(A)
    
    if K % gcd_n == 0 and K <= max_a:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 84332