akhauriyash/Code-Regression huggingface dataset:
n=input()
for i in range(2**4):
    res=0
    b=[]
    #print("--------------")
    for j in range(4):
        if (i>>j)&1:
            b.append("+")
            res+=int(n[j])
        else:
            b.append("-")
            res-=int(n[j])
    if res==7:
        # c=str(bin(i))[2:].zfill(4)
        # b=[]
        # if c[-3]=="1":
        #     b.append("+")
        # else:
        #     b.append("-")
        # if c[-2]=="1":
        #     b.append("+")
        # else:
        #     b.append("-")
        # if c[-1]=="1":
        #     b.append("+")
        # else:
        #     b.append("-")
        print(n[0]+b[1]+n[1]+b[2]+n[2]+b[3]+n[3]+"=7")
        #print(res,i,c)
        exit()
            

Measured memory_bytes: 38256
//
// Created by yuu on 2019-07-27.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;



int main(void){

    int N;
    cin>>N;
    int p_1[55];
    int p_2[55];

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

    sort(p_1, p_1+N);

    int count = 0;

    for (int i = 0; i < N; ++i) {
        if(p_1[i] != p_2[i]){
            count++;
        }
    }


    if(count<=2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }



    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
      	int tarPri = sc.nextInt();
      	int num1y = sc.nextInt();
      	
      	if(tarPri %500 <= num1y) {
			System.out.println("Yes");          
        } else {
        	System.out.println("No");  
        }
	}
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

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

int main(){
    int N;
    cin >> N;
    vector<ll> t(N);
    for (int i = 0; i < N; i++){
        cin >> t[i];
    }

    ll ans = t[0];
    for (int i = 1; i < N; i++){
        ans = lcm(ans,t[i]);
    }
    cout << ans << endl;



    return 0;
}


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

int main() {
int n,q;
cin >> n >> q;
string s;
cin >> s;
s+='x';
int l[n],r[n];
for(int i=0;i<q;i++){
    cin >> l[i] >> r[i];
}
int sum[n+1];
sum[0]=0;
for(int i=0;i<n;i++){
    if(s[i]=='A'&&s[i+1]=='C'){sum[i+1]=sum[i]+1;}
    else sum[i+1]=sum[i];
    }
for(int i=0;i<q;i++){
    cout << sum[r[i]-1]-sum[l[i]-1] << endl;
}
}


Measured memory_bytes: 2176
import java.text.ParseException;
import java.util.Scanner;

public class Main {

	public static void main(String[] arges) throws ParseException {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String line2 = sc.nextLine();

		String[] k = line.split(" ");
		String[] k2 = line2.split(" ");
		Daice daice1 = new Daice(Integer.parseInt(k[0]),
				Integer.parseInt(k[1]), Integer.parseInt(k[2]),
				Integer.parseInt(k[3]), Integer.parseInt(k[4]),
				Integer.parseInt(k[5]));
		Daice daice2 = new Daice(Integer.parseInt(k2[0]),
				Integer.parseInt(k2[1]), Integer.parseInt(k2[2]),
				Integer.parseInt(k2[3]), Integer.parseInt(k2[4]),
				Integer.parseInt(k2[5]));
		for (int i = 0; i < 4; i++) {
			daice2.south();
			if (daice1.f1 == daice2.f1) {
				break;
			}
			if (i == 3) {
				daice2.west();
			}
		}
		for (int i = 0; i < 4; i++) {
			if (daice1.f1 == daice2.f1) {
				break;
			}daice2.south();
			
		}
		if (daice1.f1 != daice2.f1) {
			System.out.println("No");
		} else {
			for (int i = 0; i < 4; i++) {
				daice2.kaiten();
				if (daice1.f2 == daice2.f2) {
					break;
				}
			}
			if (daice1.f1 == daice2.f1 && daice1.f2 == daice2.f2
					&& daice1.f3 == daice2.f3 && daice1.f4 == daice2.f4
					&& daice1.f5 == daice2.f5 && daice1.f6 == daice2.f6) {
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
	}

	public static class Daice {
		int f1;
		int f2;
		int f3;
		int f4;
		int f5;
		int f6;

		public Daice(int f1, int f2, int f3, int f4, int f5, int f6) {
			super();
			this.f1 = f1;
			this.f2 = f2;
			this.f3 = f3;
			this.f4 = f4;
			this.f5 = f5;
			this.f6 = f6;
		}

		public void south() {
			int[] fs = new int[] { f1, f2, f3, f4, f5, f6 };
			f6 = fs[1];
			f2 = fs[0];
			f1 = fs[4];
			f5 = fs[5];

		}

		public void west() {
			int[] fs = new int[] { f1, f2, f3, f4, f5, f6 };
			f6 = fs[3];
			f3 = fs[5];
			f1 = fs[2];
			f4 = fs[0];

		}

		public void kaiten() {
			int[] fs = new int[] { f1, f2, f3, f4, f5, f6 };
			f2 = fs[3];
			f3 = fs[1];
			f4 = fs[4];
			f5 = fs[2];
		}

	}
}

Measured memory_bytes: 26184
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int dp[401][401];
int INF = (int)1 << 60;
vector<int> A;
vector<int> sm;
int sum(int l, int r) {
	return sm[r + 1] - sm[l];
}
int solve(int l, int r) {
	if (dp[l][r] == -1) {
		dp[l][r] = INF;
		for (int i = l; i < r; i++) {
			dp[l][r] = min(dp[l][r], sum(l, r) + solve(l, i) + solve(i + 1, r));
		}

	}
	return dp[l][r];
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	A.resize(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sm.resize(N + 1,0);

	for (int i = 0; i < N; i++) {
		sm[i + 1] = sm[i] + A[i];
	}
	for (int i = 0; i <= 400; i++) {
		for (int j = 0; j <= 400; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < N; i++) {
		dp[i][i] = 0;
	}
	cout << solve(0, N - 1) << endl;
}

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

class UnionFind {
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) std::swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
private:
	std::vector<int> data;
};

int n, m;
int p[100005];
int main()
{
	std::cin >> n >> m;
	UnionFind uf(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> p[i];
		--p[i];
	}
	for (int i = 0; i < m; ++i) {
		int x, y;
		std::cin >> x >> y;
		--x, --y;
		uf.unionSet(x, y);
	}

	int ans = 0;
	for (int i = 0; i < n; ++i)
		if (uf.findSet(i, p[i]))
			++ans;

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


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
#define INF (1ll<<60)
typedef pair<li, li> PI;

li w[111];
li v[111];

li dp[111][100100];

int main(void)
{
	li n, ww;
	cin >> n >> ww;
	rep(i, n) {
		cin >> w[i] >> v[i];
	}
	rep(i, 100)rep(j, 100100)dp[i][j] = INF;
	dp[0][0] = 0;

	rep(i, n) {
		for (li j = 100100; j >= 0; j--) {
			dp[i + 1][j] = dp[i][j];
			if (j >= v[i]) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
			}
		}
	}

	for (li j = 100100; j >= 0; j--) {
		if (dp[n][j] <= ww) {
			cout << j << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 80128
def main():
    N = int(input())
    D = [list(map(int,input().split())) for i in range(N)]
    cnt = 0
    for i in range(N):
        if D[i][0] == D[i][1]:
            cnt += 1
            if cnt == 3:
                return 'Yes'
        else:
            cnt = 0
    return 'No'

print(main())


Measured memory_bytes: 9172
#include <stdio.h>
 
int main(void){
int sum=0;
double mean=0;
int x,y;
int i=0;
while(scanf("%d,%d",&x,&y)!=EOF){
sum+=x*y;
mean+=y;
i++;
}
printf("%d\n%d\n",sum,(int)(mean/(double)(i)+0.5));
return 0;
}

Measured memory_bytes: 2680
N = int(input())
A = [int(x) for x in input().split()]
in_cnt = 0
de_cnt = 0
now = -1
for ind,a in enumerate(A[:-1]):
    if(A[ind+1]>a):
        if(now==-1):
            in_cnt+=1
            now = 1
        elif(now==0):
            now = -1
    elif(A[ind+1]<a):
        if(now==-1):
            de_cnt+=1
            now = 0
        elif(now==1):
            now = -1
print(in_cnt+de_cnt+(1 if now==-1 else 0))


Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
void quick_sort( int h[], int right, int left );

void swap( int *a, int *b ){
    int temp = 0;
    temp = *a;
    *a = *b;
    *b = temp;
    }

int main(void){
    // 変数宣言
    int n, k;
    int *h;
    h = (int *)malloc( sizeof(int) * n );
    int i;
    int result = 0;
    unsigned long total = 0;

    // 入力処理
    scanf( "%d\n", &n );
    scanf( "%d\n", &k );
    for( i = 0 ; i < n ; i++ ){
        scanf( "%d", &h[ i ] );
    }

    // 演算処理
    if( n > k ){
        // モンスターの体力をソートする
        quick_sort( h, ( n - 1 ), 0 );

        // モンスター数 - kの回数
        n = n - k ;

        // モンスターHPの総和
        for( i = 0; i < n ; i++){
            total += h[i];
        }

    }else{
        total = 0;
    }
    // 出力
    printf("%lu", total );

    return 0;
}

void quick_sort( int h[], int right, int left ){
    // 変数宣言
    int i;
    int pivot;
    int Right = right, Left = left;

    // 中央値を決める
    pivot = h[( right + left ) / 2 ];

    while( 1 ){
        // 中央値を右から比較
        while( pivot < h[ Right ] ){
            Right--;
        }

        // 中央値を左から比較
        while( h[ Left ] < pivot ){
            Left++;
        }

        // カーソルが重なったらループを抜ける
        if( Right <= Left ){
            break;
        }

        // 入れ替え処理
        swap( &h[Right], &h[Left] );
        Right--;
        Left++;
    }
    // ソートを続けるか
    if( left < ( Left - 1 ) ){
        quick_sort( h, Left - 1, left );
    }

    if( ( Right + 1 < right ) ){
        quick_sort( h, right, Right + 1 );
    }

}

Measured memory_bytes: 2944
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		int c = parseInt(sc.next());
		int d = parseInt(sc.next());
		sc.close();
		int ab=a+b;
		int cd=c+d;
		out.println(ab>cd?"Left":(ab==cd?"Balanced":"Right"));
	}
}


Measured memory_bytes: 21844
using System;


namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            string[] Input = Console.ReadLine().Split(' ');

            int A = int.Parse(Input[0]);
            int B = int.Parse(Input[1]);
            int C = int.Parse(Input[2]);

            int Max = B / A;
            if(Max >= C) {
                Console.WriteLine(C);
            }
            else {
                Console.WriteLine(Max);
            }
        }
    }
}

Measured memory_bytes: 13140
/*****Be Name Khoda*****/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define Size(x) ((int)x.size())
#define All(x) x.begin() , x.end()

using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e3 + 10;

int a[N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n , k;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a , a + n);
	reverse(a , a + n);
	int ans = 0;
	for(int i = 0; i < k; i++)
		ans += a[i];
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

/**
 * main
 */
int main () {
  int N; cin >> N;
  int M; cin >> M;

  cout << (N * (N - 1) / 2 + M * (M - 1) / 2) << endl;
}


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

int n,m,a,d;
string bar[33];

bool simuration(){
	int state[10];
	rep(i,10) state[i]=i;
	rep(i,d)rep(j,n-1) if(bar[d-1-i][j]=='1') swap(state[j],state[j+1]);
	return state[m]==a;
}

int main(void){
	while(cin >> n,n){
		cin >> m >> a >> d;
		m--,a--;
		rep(i,d) cin >> bar[i];
		if(simuration()){
			cout << 0 << endl;
			continue;
		}else{
			bool ans=false;
			rep(i,d)rep(j,n-1){
				if(bar[i][j]=='1') continue;
				if(0<=j-1&&bar[i][j-1]=='1') continue;
				if(j+2<n&&bar[i][j+1]=='1') continue;
				bar[i][j]='1';
				if(simuration()){
					cout << (i+1) << " " << (j+1) << endl;
					ans=true;
				}
				bar[i][j]='0';
				if(ans) i=d,j=n-1;
			}
			if(!ans) cout << 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    // 整数の入力
    int N = sc.nextInt();
    // 出力
    System.out.println(
        IntStream.rangeClosed(1, N)
            .asLongStream()
            .filter(n -> (n % 3 != 0) && (n % 5 != 0))
            .sum());
  }
}


Measured memory_bytes: 36296
#include<stdio.h>
#include<string.h>
int main(){
	int n,cnt=0,m[26][101]={0},i,j,u,hn,ln,c=1,a,k,o;
	char h[26],l[101];
	scanf("%d",&n);
	scanf("%s",h);
	hn=strlen(h);
	for(u=0;u<n;u++){
		memset(m,0,sizeof(m));
		scanf("%s",l);
		ln=strlen(l);
		for(i=0;i<hn;i++){
			for(j=0;j<ln;j++){
				if(h[i]==l[j]){
					m[i][j]=1;
				}
			}
		}
		o=0;
		for(i=0;i<ln;i++){
			if(m[0][i]==1){
				for(j=1;j<ln;j++){
					c=1;
					for(k=i+j;k<ln;k+=j){
						if(m[c][k]==0||k>=ln){
							break;
						}
						c++;
						if(c==hn){
							break;
						}
					}
					if(c==hn){
						cnt++;
						o=1;
						break;
					}
				}
				if(o==1){
					break;
				}
			}
			if(o==1){
				break;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

using namespace std;
typedef long long ll;


bool triangle(int a, int b, int c)
{
    if (a==b || b==c || c==a) return false;
    if (a+b > c && b+c > a && c+a > b) return true;

    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);

    int cnt = 0;

    int n;
    cin >> n;
    ll l[n];

    for (int i = 0; i < n; i++)
        cin >> l[i];
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (triangle(l[i],l[j],l[k]))
                    cnt++;
            }
        }
    }

    cout << cnt;


    return 0;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int x = stdIn.nextInt();
		int y = stdIn.nextInt();

		int max = x + y;

		if(x - y > max)
		{
			max = x - y;
		}
		if(x * y > max)
		{
			max = x * y;
		}

		System.out.println(max);

	}

}


Measured memory_bytes: 35600
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
 
int main()
{
    double x1,x2;
    double y1,y2;
    double distance;
     
    cin >> x1 >> y1 >> x2 >> y2;
     
    distance=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
     
    cout << fixed << setprecision(4) << distance << endl;
     
    return 0;
}

Measured memory_bytes: 3264
#include<stdio.h>
int main()
{
    long int i, m=0;
    char s[100005];
    scanf("%s", &s);
    for(i=0; i<strlen(s); i++)
    {
       if(s[i]==s[i+1])
       {
           m++;
           if(s[i+1]=='0')
           {
               s[i+1]='1';
           }
           else
           {
               s[i+1]='0';
           }
       }
    }
    printf("%ld", m);
    return 0;
}

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

#define MOD 1000000007

using namespace std;

long long int fact[100001] = {0};

void factorial(){
    fact[1] = 1;
    for(int i=2;i<=100000;++i)
        fact[i] = (i * fact[i-1]) % MOD;
}

int main(){
    int n, m;
    cin >> n >> m;
    if(abs(n-m) > 1)cout << "0" << endl;
    else{
        factorial();
        long long int ans = 0;
        if(n != m){
            ans = (fact[n] * fact[m]) % MOD;
        }else{
            long long int x = (fact[n] * 2) % MOD;
            ans = (fact[m] * x) % MOD;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, M;
    cin >> N >> M;

    cout << N*(N-1)/2 + M*(M-1)/2 << endl;

    
    return 0;
}

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



int main()
{
	double r ,s ,l;
	cin >> r;
	l = 3.141592653589 * 2.0 * r;
	s = 3.141592653589 * r * r;
	cout << fixed << setprecision(6) << s << " " << fixed << setprecision(6) << l;
} 


Measured memory_bytes: 3264
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var D = one[1];
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = nextIntArray();
	}
	var output = 0;
	for(var i = 0; i < N - 1; i++){
		for(var j = i + 1; j < N; j++){
			var sum = 0;
			for(var k = 0; k < D; k++){
				sum += Math.pow(list[i][k] - list[j][k], 2);
			}
			sum = Math.sqrt(sum);
			if(sum % 1 == 0){
				output++;
			}
		}
	}
	myout(output);
}


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

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


int main() {
  int n;cin>>n;
  int sum=0;
  int temp;
  int ans=0;
  vector<int> a(n,0);
  rep(i,n){
    cin>>temp;
    a[i]=temp;
    sum+=temp;
  }
  int mean = floor(float (sum)/n+0.5);
  rep(i,n){
    ans+=(a[i]-mean)*(a[i]-mean);
  }
  cout<<ans<<endl;
}


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

struct UnionFind
{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return sizes[find(x)];
  }
};

int main(){
    int n,m;cin>>n>>m;
    UnionFind u(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        u.unite(x,y);
    }
    set<int>ans;
    rep(i,n){
        ans.insert(u.find(i));
    }
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 5760
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a*b<c*d){
        cout << c*d << endl;
    }else{
        cout << a*b << endl;
    }
    
    return 0;
}

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

int main()
{
	int N;
	std::string S;
	std::cin >> N >> S;
	std::vector<int> white(N + 1), black(N + 1);
	for (int i{}; i < N; i++)
	{
		if (S[i] == '.') white[i + 1]++;
		else black[i + 1]++;
		white[i + 1] += white[i];
		black[i + 1] += black[i];
	}
	int min{1 << 30};
	for (int i{}; i <= N; i++)
		min = std::min(min, black[i] + white[N] - white[i]);
	
	printf("%d\n", min);

	return 0;
}

Measured memory_bytes: 2180
#include<stdio.h>

int gcd(int,int);
void swap(int *,int *);

int main(){
  int x,y;

  scanf("%d %d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;
}
int gcd(int x,int y){
  int r;

  if(x<y) swap(&x,&y);

  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  return x;
}
void swap(int *x,int *y){
  int *temp;

  temp=x;
  x=y;
  y=temp;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	cout << (a+b)*c/2;
}

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

    using namespace std;
    int main()
    {
        // 整数の入力
        int N;
        cin >> N;
        vector<int> dishVector(N);
        for(int i = 0; i < N; i++){
            cin >> dishVector.at(i);
        }
        vector<int> pointVector(N);
        for(int i = 0; i < N; i++){
            cin >> pointVector.at(i);
        }

        vector<int> exPointVector(N - 1);
        for(int i = 0; i < N - 1; i++){
            cin >> exPointVector.at(i);
        }

        int totalPoint = 0;
        int prevDishIndex = -2;
        for(int i = 0; i < N; i++){
            int currentDishIndex = dishVector.at(i) - 1;
            totalPoint += pointVector.at(currentDishIndex);
            if(currentDishIndex - prevDishIndex == 1){
                totalPoint += exPointVector.at(prevDishIndex);
            }
            prevDishIndex = currentDishIndex;
        }
        cout << totalPoint;
        return 0;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int N,M,P;
map<string,vector<int> > unit;
map<vector<int>,string> revUnit;
map<string,string> var;
bool isErr;

// ツつサツづェツつシツづェツづ個ベツクツトツδ仰づ個療環づーツ陛板つキ
vector<int> dfs(string s){
    if(var.find(s)!=var.end())return unit[var[s]];
    if(s.size()>=3&&s[0]=='('&&s[s.size()-1]==')'){
        int cnt=1;
        bool ok=true;
        for(int i=1;i<s.size()-1;i++){
            if(s[i]=='(')cnt++;
            else if(s[i]==')')cnt--;
            if(cnt==0)ok=false;
        }
        if(ok)return dfs(s.substr(1,s.size()-2));
    }
    int cnt=0;
    // ツ環古環づ個外ツづ個可可算ツ子ツづーツ個ゥツづつつッツづゥ
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='(')cnt--;
        else if(s[i]==')')cnt++;
        else if(cnt==0){
            if(s[i]=='-'||s[i]=='+'){
                vector<int> v1=dfs(s.substr(0,i));
                vector<int> v2=dfs(s.substr(i+1));
                if(v1.size()==0||v2.size()==0)return vector<int>();
                if(v1!=v2){
                    isErr=true;
                    return vector<int>();
                }
                return v1;
            }
        }
    }
    cnt=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='(')cnt--;
        else if(s[i]==')')cnt++;
        else if(cnt==0){
            if(s[i]=='*'||s[i]=='/'){
                vector<int> v1=dfs(s.substr(0,i));
                vector<int> v2=dfs(s.substr(i+1));
                if(v1.size()==0||v2.size()==0)return vector<int>();
                for(int j=0;j<v2.size();j++){
                    if(s[i]=='*')v1[j]+=v2[j];
                    else v1[j]-=v2[j];
                }
                return v1;
            }
        }
    }
    return vector<int>();
}

void solve(){
    while(cin>>N>>M>>P&&(N|M|P)){
        unit.clear();var.clear();
        revUnit.clear();
        isErr=false;
        for(int i=0;i<M;i++){
            string s;
            cin>>s;
            vector<int> v;
            for(int j=0;j<N;j++){
                int t;
                cin>>t;
                v.push_back(t);
            }
            revUnit[v]=s;
            unit[s]=v;
        }
        string fo;
        cin>>fo;
        for(int i=0;i<P;i++){
            string v,d;
            cin>>v>>d;
            var[v]=d;
        }
        vector<int> res=dfs(fo);
        if(isErr)cout<<"error"<<endl;
        else{
            map<vector<int>,string>::iterator it=revUnit.find(res);
            if(it==revUnit.end())cout<<"undefined"<<endl;
            else cout<<it->second<<endl;
        }
    }
}
int main(){

    solve();

    return 0;
}

Measured memory_bytes: 956
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def change(s, s0=""):
    t = list(s0+s)
    ret = 0
    for i in range(1, len(t)):
        if t[i] == t[i-1]:
            t[i] = '*'
            ret += 1
    return "".join(t[len(s0):]), ret

def main():
    s = input()
    k = ri()
    memo = dict()
    memo2 = []
    bef = ""
    if k < 100:
        _, c = change(s*k, "")
        print(c)
        return
    rep = 0
    for i in range(k):
        ns, c = change(s, bef)
        # print(bef, s, ns, c)
        if ns in memo:
            # print("OK", ns, memo[ns])
            rep = i-memo[ns][1]
            break
        memo[ns] = (c, i)
        memo2.append((c, ns))
        bef = ns
    ans = 0
    for m in memo2:
        ans += m[0]
    assert(len(memo2) < 3)
    rem = k-len(memo2)
    if rep == 1:
        ans += rem*memo2[-rep][0]
    elif rep == 2:
        ans += (rem//2)*sum(m[0] for m in memo2)
        if rem % 2 == 1:
            ans += memo2[0][0]
    print(ans)
    # print(rep, memo, memo2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

string MakeSeq(int N){
  string res = "";
  for(int i=0;i<N;i++){
    int random_variable = std::rand() % 2; // 0 or 1
    res.push_back('0' + random_variable);
  }
  return res;
}

bool isClear(const vector<vector<int> >& cards,const string& bits,int N){
  for(int card_pos=0;card_pos < cards.size(); card_pos++){
    int sum = 0;
    for(int i=0;i<cards[card_pos].size();i++){
      if(bits[cards[card_pos][i]] == '1'){
	sum++;
      }
    }
    if(sum < N/8 || sum > 3*N/8) return false;
  }
  return true;
}

int main(){
  int N,K;
  srand(time(0)); // use current time as seed for random generator

  while(~scanf("%d %d",&N,&K)){
    vector<vector<int> > cards;
    for(int card_pos =0; card_pos < K; card_pos++){
      vector<int> card;
      for(int i = 0; i < N/2; i++){
	int seq_pos;
	scanf("%d",&seq_pos);
	card.push_back(seq_pos-1);
      }
      cards.push_back(card);
    }
    
    for(;;){
      string seq = MakeSeq(N);
      if(isClear(cards,seq,N)){
	printf("%s\n",seq.c_str());
	break;
      }
    }
  }
}

Measured memory_bytes: 2060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <random>
#include <chrono>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

int main() {

	int N, M;
	scanf("%d%d", &N, &M);

	if (M % 2 == 1) {
		printf("-1\n");
		return 0;
	}

	int u, v;
	map<pair<int, int>, int> dir;
	vector<vector<int>> edge(N);
	vector<int> out(N);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &u, &v);
		u--, v--;
		edge[u].emplace_back(v);
		edge[v].emplace_back(u);
		if (v < u) swap(u, v);
		dir[{u, v}] = 1; // intial direction is u->v when u < v
		out[u] ^= 1;
	}

	stack<int> que;
	vector<int> used(N);
	int idx = 1;
	que.emplace(0);
	while (!que.empty()) {
		
		int now = que.top();
		que.pop();

		int fliping = out[now];
		DMP(now);
		DMP(fliping);
		
		if (!used[now]) used[now] = idx++;

		bool all_used = true;
		for (const auto &e : edge[now]) {
			if (!used[e]) {
				dir[minmax(now, e)] ^= fliping;
				out[now] ^= fliping;
				out[e] ^= fliping;
				que.emplace(e);
				all_used = false;
				break;
			}
		}

		if (all_used) {
			int max = 0, next = -1;
			for (const auto &e : edge[now]) {
				if (used[e] < used[now]) {
					if (max < used[e]) {
						max = used[e];
						next = e;
					}
				}
			}

			if (next==-1) break;
			dir[minmax(now, next)] ^= fliping;
			out[now] ^= fliping;
			out[next] ^= fliping;
			que.emplace(next);

		}
		
	}


	for (int i = 0; i < N; i++) {
		DMP(out[i]);
	}
	for (int i = 0; i < N; i++){
		DMP(used[i]);
	}

	for (auto &e : dir) {
		if (e.second == 1) printf("%d %d\n", e.first.first + 1, e.first.second + 1);
		else printf("%d %d\n", e.first.second + 1, e.first.first + 1);
	}

	return 0;
}


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

using namespace std;

#define int long long
#define tie() ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0);

int32_t main()
{
    tie();

    int t = 1;
    //cin >> t;
    while(t--)
    {
        int a[3][3];

        int vis[120];
        memset(vis , 0 , sizeof vis);

        for(int i = 0 ; i < 3 ; i++)
            for(int j = 0 ; j < 3 ; j++)
                cin >> a[i][j];

        int m , x;
        cin >> m;

        while(m--)
        {
            cin >> x;
            vis[x] = true;
        }

        bool cond = false;
        for(int i = 0 ; i < 3 ; i++)
        {
            bool poss = true;
            for(int j = 0 ; j < 3 ; j++)
            {
                poss &= vis[a[i][j]];
            }
            if(poss)
                cond = true;
        }


        for(int i = 0 ; i < 3 ; i++)
        {
            bool poss = true;
            for(int j = 0 ; j < 3 ; j++)
                poss &= vis[a[j][i]];
            if(poss)
                cond = true;
        }

        int i = 0;
        bool poss = true;
        while(i < 3)
        {
            poss &= vis[a[i][i]];
            i++;
        }
        if(poss)
                cond = true;

        i = 0;
        poss = true;
        while(i < 3)
        {
            poss &= vis[a[i][2 - i]];
            i++;
        }


        if(poss)
                cond = true;


        if(cond)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    if(s == "SUN"){
        ans = 7;
    }else if(s == "MON"){
        ans = 6;
    }else if(s == "TUE"){
        ans = 5;
    }else if(s == "WED"){
        ans = 4;
    }else if(s == "THU"){
        ans = 3;
    }else if(s == "FRI"){
        ans = 2;
    }else if(s == "SAT"){
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
A,B=map(int, raw_input().split())
ans=0
if A<B:
    ans+=B
    B-=1
else:
    ans+=A
    A-=1
if A<B:
    ans+=B
    B-=1
else:
    ans+=A
    A-=1

print(ans)        

Measured memory_bytes: 2568
#include<stdio.h>
int main(){
  int x,y,c;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)break;
    if(x>y){
      c=x;
      x=y;
      y=c;
    }
    printf("%d %d\n",x,y);
  }
  return 0;
}



Measured memory_bytes: 2032
s = input()[:-1]
ans = -1

while len(s)>1:
  if len(s)%2 == 0:
    s_1 = s[:len(s)//2]
    s_2 = s[len(s)//2:]
    if s_1 == s_2:
      ans = len(s)
      break
      
  s = s[:-1]

print(ans)

Measured memory_bytes: 3060
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int N, M;
    cin >> N >> M;
    int K[N], A[30][30];
    set<int> food[N];
    rep(i, N) {
        cin >> K[i];
        rep(k, K[i]) cin >> A[i][k];
    }

    for (int i = 0; i < N; i++) {
        for (int k = 0; k < K[i]; k++) {
            food[i].insert(A[i][k]);
        }
    }
    int ans = 0;
    loop(k, 1, M + 1) {
        bool flag = true;
        rep(i, N) {
            if (food[i].count(k) == 0) {
                flag = false;
                break;
            }
        }
        if (flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**6)

W = None
H = None
MMAP = None
D = [(0,1),(0,-1),(1,0),(-1,0)]

def main():
    global W,H,MMAP,D
    while True:
        W,H = map(int,input().split())
        if not W and not H:
            return
        MMAP = [[] for _ in range(H)] # tiles[y][x]
        sx,sy = 0,0
        for y in range(H):
            row = list(input())
            if "@" in row:
                sy = y
                sx = row.index("@")
            MMAP[y] = row
        # gprint(tiles)
        print(calc(sx,sy))

def calc(x,y):
    global W,H,MMAP,D

    if not (x >= 0 and x < W and y >= 0 and y < H):
        return 0
    
    if MMAP[y][x] == "v" or MMAP[y][x] == "#":
        return 0

    # gprint(MMAP)
    # input()

    ssum = 1
    MMAP[y][x] = "v"

    for dx,dy in D:
        nx = x+dx
        ny = y+dy
        ssum += calc(x+dx,y+dy)

    return ssum

def gprint(tiles):
    for r in tiles:
        print(str("|".join(r)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5780
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define COUT cout<<fixed<<setprecision(12)
#define fast ios:: sync_with_stdio(false),cin.tie(0);

void solve()
{
	ll d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)
	cout<<"Yes";
	else
	cout<<"No";
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;

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

const int INF = 100000000;



int main()
{
	int h,w;
	cin >> h >> w ;
	vector<string> M(h);
	rep(i,h)cin >> M[i];

	int ans=0;
	vector<vector<int>> d(h , vector<int>(w,INF));
		queue<P> Q;
	rep(i,h)
		rep(j,w)
		if(M[i][j]=='#')
		{
			Q.push(make_pair(i,j));
			d[i][j]=0;
		}

	
		
		
		while(!Q.empty())
		{
			P now = Q.front();
			//cout<<now.first<<now.second<<endl;
			Q.pop();
			for(int i = 0;i<4;i++)
			{
				
				int nx = now.first+dx[i];
				int ny = now.second+dy[i];
				//cout<<d[nx][ny]<<endl;
				P N = make_pair(nx,ny);
				if(0<=nx&&nx<h&&0<=ny&&ny<w&&M[nx][ny]!='X'&&d[nx][ny]==INF)
				{
					
					Q.push(N);
					d[nx][ny]=d[now.first][now.second]+1;
					ans=max(ans,d[nx][ny]);
				}
			}
		}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 13456
#include <stdio.h>

main(){
	int x=0,y=0;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y){
			printf("%d %d\n",y,x);
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;



ll euqrid(ll a, ll b){
    
    while (a%b != 0) {
        ll c = a%b;
        a = b;
        b = c;
    }
    return b;
    
}


bool is_prime(ll n){
    
    for (ll i = 2; i*i <= n; i++) {
        if (n%i == 0) {
            return false;
        }
    }
    
    return true;
    
}



int main()
{
    ll A,B;
    cin >> A >> B;
    
    ll C = euqrid(A,B);
    
    ll ans = 0;
    ll aa = 1;
    ll cc;
    
    
    for (ll i = 1; i*i <= C; i++) {
        if (C%i == 0) {
            cc = euqrid(i, aa);
            if (cc == 1) {
                if(is_prime(i)){
                    aa = i;
                    ans += 1;
                    
                    //
                    //cout << i << endl;
                }
                
            }
            
            if (i != C/i) {
                cc = euqrid(C/i, aa);
                if (cc == 1) {
                    if(is_prime(C/i)){
                        aa = C/i;
                        ans += 1;
                        
                        //
                        //cout << C/i << endl;
                    }
                    
                }
            }
            
        }
    }
    
    cout << ans << endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100005;
  
int N;
int a[MAXN];

void load() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", a + i);
}

int solve() {
  for (int c = 0; ; c ^= 1) {
    int odd = 0;
    for (int i = 0; i < N; i++)
      odd += a[i] % 2;
    if ((N - odd) % 2)
      return c;
    if (odd != 1)
      return c ^ 1;
    for (int i = 0; i < N; i++)
      if (a[i] == 1)
        return c ^ 1;
    int g = 0;
    for (int i = 0; i < N; i++) {
      if (a[i] % 2)
        a[i]--;
      g = __gcd(g, a[i]);
    }
    for (int i = 0; i < N; i++)
      a[i] /= g;
  }
}

int main() {
  load();
  puts(solve() ? "Second" : "First");
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b){
		printf("a < b\n");
	}
	else if (a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 2584
"""Range Minimum Query (RMQ)"""
# 丁寧に実装する


# 配列のidx番目の要素の値をxに変更する, 1点更新
def update(idx, x):
    idx += size-1  # 配列のidx番目の要素に対応するseg木のノードのindex
    seg[idx] = x  # 対象のノードの値を更新する
    # 親のノードの値も更新する
    while idx > 0:
        idx = (idx-1)//2  # ノードidxの親のindex, いつか0になる
        seg[idx] = min(seg[2*idx+1], seg[2*idx+2])  # 左右の子を見てminを計算する
    # 根ノードであるノード0まで修正したのでreturnする
    return


# この関数は半開区間[a, b)に対するクエリについて最小値を答えるもの
def query(a, b, k, l, r):  # 半開区間[a, b)に対するクエリについて、ノードk(担当している半開区間[l, r))が答える
    # 最初は根に質問を飛ばしている
    if r <= a or b <= l:  # ノードkの担当区間は[l, r)であり、この条件を満たすときは求めたい区間[a, b)と範囲が全く被っていない
        return INF  # 区間が被らない場合は単位元(minの単位元はINF)
    if a <= l and r <= b:
        return seg[k]  # ノードkの担当範囲が求めたい区間[a, b)に完全に含まれる場合はそのノードも持っている値をそのまま返す
    else:
        # 一部だけ範囲が被るような場合は左右の子に委託する
        c1 = query(a, b, 2*k+1, l, (l+r)//2)  # 左の子に値を聞く
        c2 = query(a, b, 2*k+2, (l+r)//2, r)  # 右の子に値を聞く
        return min(c1, c2)  # 左右の子のminを取る


N, Q = map(int, input().split())  # 配列のサイズ(管理したい要素の数), クエリの個数
size = 1  # seg木の葉の個数
while N > size:
    size *= 2  # seg木の葉の個数を計算する, N以上の最小の2冪数, 末端に来る葉の数が2の冪数でないと、seg木の構造がおかしくなる

# 単位元
# INF = float('inf')
INF = 2**31-1  # 今回の問題設定
# seg木を単位元で初期化する
seg = [INF]*(2*size-1)

for _ in range(Q):
    com, x, y = map(int, input().split())
    if com == 0:
        update(x, y)
    else:
        print(query(x, y+1, 0, 0, size))  # ノード0(担当している半開区間[0, size))にクエリを投げる
        # y+1としているのは、半開区間とかの関係



Measured memory_bytes: 8692
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
 
class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
 
        StringBuilder sb = new StringBuilder("");
 
        for (int i = 0; i < q; i++) {
            char[] X = br.readLine().toCharArray();
            char[] Y = br.readLine().toCharArray();
            sb.append(LCS(X, Y));
            sb.append('\n');
        }
 
        System.out.print(sb);
    }
 
    private static int LCS(char[] X, char[] Y) {
        int m = X.length;
        int n = Y.length;
        int i, j;
        int[][] len = new int[m+1][n+1];
 
        for (i = 0; i < m; i++) {
            len[i][0] = 0;
        }
        for (j = 0; j < n; j++) {
            len[0][j] = 0;
        }
 
        for (i = 1; i <= m; i++) {
            for (j = 1; j <= n; j++) {
                if (X[i-1] == Y[j-1]) {
                    len[i][j] = len[i-1][j-1] + 1;
                } else {
                    len[i][j] = Math.max(len[i][j-1], len[i-1][j]);
                }
            }
        }
 
        return len[m][n];
    }
}



Measured memory_bytes: 63364
program semi_common_multiple
  implicit none
  integer :: n, i, c, c1 = 0
  integer(16) :: m, a(100000) = 0_16, l = 1_16, k
  read(*,*) n, m
  read(*,*) a(1:n)
  a(1:n) = a(1:n)/2_16
  k = a(1)
  do while (mod(k,2_16) == 0_16)
    k = k/2_16
    c1 = c1+1
  end do
  k = a(1)/k
  do i = 1, n
    c = 0
    do while (mod(a(i),2_16) == 0_16)
      a(i) = a(i)/2_16
      c = c+1
    end do
    if (c /= c1) then
      write(*,'(i0)') 0
      stop
    end if
    l = lcm(l,a(i))
    if (l > m/k) then
      write(*,'(i0)') 0
      stop
    end if
  end do
  write(*,'(i0)') (m/k/l+1_16)/2_16
contains
  integer(16) function lcm(a,b)
    integer(16), intent(in) :: a, b
    lcm = a/gcd(a,b)*b
  end
  integer(16) function gcd(a,b)
    integer(16), intent(in) :: a, b
    integer(16) :: x, y
    x = max(a,b)
    y = min(a,b)
    do while (y > 0_16)
      gcd = y
      y = mod(x,y)
      x = gcd
    end do
  end
end program semi_common_multiple

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
int main(){
  int N, Q;
  cin >> N >> Q;
  fenwick_tree<long long> a(N);
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    a.add(i, x);
  }
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int p, x;
      cin >> p >> x;
      a.add(p, x);
    }
    if (t == 1){
      int l, r;
      cin >> l >> r;
      cout << a.sum(l, r) << endl;
    }
  }
}

Measured memory_bytes: 8228
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

struct Vertex {
    vector<lint> edge;
    bool visited;
    lint dist;
};


int main() {
    lint n, m, k;
    cin >> n >> m >> k;

    UnionFind fr(n), bl(n);
    vector<lint> cfr(n, 0), cbl(n, 0);
    for(lint i=0; i<m; i++) {
        lint a, b;
        cin >> a >> b;
        a--, b--;

        fr.unite(a, b);
        cfr[a]++;
        cfr[b]++;
    }

    for(lint i=0; i<k; i++) {
        lint a, b;
        cin >> a >> b;
        a--, b--;

        bl.unite(a, b);
        if(fr.find(a) == fr.find(b)) {
            cbl[a]++;
            cbl[b]++;
        }
    }

    for(lint i=0; i<n; i++) {
        cout << fr.size(i) - cfr[i] - cbl[i] - 1 << " ";
    }
    cout << endl;
}

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

int main(void){
  int a,b,c,X=0,Y=0;
  
  c=scanf("%d %d",&a,&b);
  if(c!=2){
    printf("正しく入力してください。\n");
    exit(1);
  }
  
  for(int i=0;i<b;i++){
    X=X+a*pow(10,i);
  }
  
  for(int i=0;i<a;i++){
    Y=Y+b*pow(10,i);
  }
  
   if(a>=b){
     printf("%d\n",Y);
   }
  else{
    printf("%d\n",X);
  }
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char a[50];
int b[50];
int main(){
	scanf("%s",a+1);
	for(int i=1;i<=4;++i)b[a[i]-'A']++;
	int w=0;
	for(int i=0;i<26;++i)if(b[i]==2)++w;
	if(w==2)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 384
def is_kaibun(s):
    s_rev = s[::-1]
    if s == s_rev:
        return True
    else:
        return False

s = input()
if is_kaibun(s):
    half_len = int((len(s) - 1) / 2)
    half_s = s[:half_len]
    if is_kaibun(half_s):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int x[1000], y [1000];
int main() {
	
	int n;
	cin>>n;
	int a = 0, b = 0;
	for(int i = 0; i < n; i++)
	{
		cin>>x[i];
	}
	for(int i = 0; i < n; i++)
	{
		cin>>y[i];
	}
	for(int i = 0; i < n; i++)
	{
		if(x[i] >= y[i])
		{
			a+=x[i];
			b+=y[i];
		}
	}
	cout<<(a-b);
	return 0;
}

Measured memory_bytes: 3596