akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
const int INF = 999999999;
int main(){
	int m, n, a, b, p, q, k, r;
	while(cin >> n >> m, (m||n)) {
		int c[110][110], t[110][110];
		rep(i,110) {
			rep(j,110) {
				c[i][j] = INF;
				t[i][j] = INF;
			}
		}
		rep(i,n) {
			cin >> a >> b >> p >> q;
			a--, b--;
			c[a][b] = c[b][a] = p;
			t[a][b] = t[b][a] = q;
		}
		rep(i,m) {
			rep(j,m) {
				rep(k,m) {
					c[j][k] = min(c[j][k], c[j][i]+c[i][k]);
					t[j][k] = min(t[j][k], t[j][i]+t[i][k]);
				}
			}
		}
		cin >> k;
		rep(i,k) {
			cin >> p >> q >> r;
			p--,q--;
			if(r==0) {
				cout << c[p][q] << endl;
			} else {
				cout << t[p][q] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1252
import * as fs from 'fs';

namespace AtCoder.abc163 {

    export class Program {

        constructor(private readonly args: string[]) {
        }

        /**
         * in
         5
         1 1 2 2
         * out
         2
         2
         0
         0
         0
         */
        main(this: Program): void {
            const n: number = parseInt(this.args[0], 0);
            const a: number[] = this.args[1].split(' ').map(Number);
            const ans: any = {};


            a.forEach(x => {
                if (isNaN(ans[x])) {
                    ans[x] = 0;
                }
                ans[x] = 1 + ans[x];
            });

            let result: string = '';

            for (let i = 1; i <= n; i++) {

                if (!ans[i]) {
                    console.log(0);
                } else {
                    console.log(ans[i]);
                }
            }


        }
    }
}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg: AtCoder.abc163.Program = new AtCoder.abc163.Program(args);
prg.main();


Measured memory_bytes: 63556
import math

def main():
    n, d = map(int, input().split())

    x = [0 for i in range(n)]
    y = [0 for i in range(n)]
    for i in range(n):
        x[i], y[i] = map(int, input().split())

    count = 0
    for i in range(n):
        ansd = math.sqrt(x[i] ** 2 + y[i] ** 2)
        if (ansd <= d):
            count += 1
            
    print(count)

main()
        


Measured memory_bytes: 24788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,sum=0,temp,tsum;
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;++i){
        temp=i;
        tsum=0;
        while(temp){
            tsum+=temp%10;
            temp/=10;
        }
        if(tsum>=a&&tsum<=b) sum+=i;
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	char s[a+b+3];
	int n=a+b+1;
	scanf("%s", s);
	int ctrnum=0, ctrh=0;
	for(int i=0; i<n; i++){
		if(s[i]>='0'&&s[i]<='9'){
			ctrnum++;
		}
		if(s[i]=='-'){
			ctrh++;
		}
	}

	if(ctrnum>=2 && s[a]=='-' && ctrh==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	vector<P> vec;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		vec.push_back(P(a, b));
	}
	sort(vec.begin(), vec.end());
	ll sum = 0;
	for(int i = 0; i < n; i++)
	{
		sum += vec[i].second;
		if(sum >= k)
		{
			cout << vec[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main(){
	char shurui[]={'o','x'},inpStr[10],math[3][3];
	int shuruiCount;
	bool flag;
	while(scanf("%s",inpStr)!=EOF){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				math[i][j]=inpStr[3*i+j];
			}
		}
		flag=false;
		
		for(int i=0;i<3 && !flag;i++){
			for(int j=0;j<3 && !flag;j++){
				for(int k=0;k<2;k++){   //テァツィツョテゥツ。ツ榲ゥツ?クテヲツ環?


					if(shurui[k]==math[i][j]){
						shuruiCount=1;
						
						if(j==0){
							for(int u=1;u<3;u++){ //テヲツィツェテァツァツサテ・ツ仰?
								if(math[i][u]!=shurui[k]){
									shuruiCount=1;
									break;
								}
								shuruiCount++;
							}
						}
						if(i==0 && shuruiCount==1){
							for(int u=1;u<3;u++){ //テァツクツヲテァツァツサテ・ツ仰?
								if(math[u][j]!=shurui[k]){
									shuruiCount=1;
									break;
								}
								shuruiCount++;
							}
						}
						if(i==0 && j==0 && shuruiCount==1){
							for(int u=1;u<3;u++){ //テヲツ鳴愿」ツつ?・ツ渉ウテ、ツクツ凝ァツァツサテ・ツ仰?
								if(math[i+u][j+u]!=shurui[k]){
									shuruiCount=1;
									break;
								}
								shuruiCount++;
							}
						}
						if(i==0 && j==2 && shuruiCount==1){
							for(int u=1;u<3;u++){ //テヲツ鳴愿」ツつ?・ツキツヲテ、ツクツ凝ァツァツサテ・ツ仰?
								if(math[i+u][j-u]!=shurui[k]){
									shuruiCount=1;
									break;
								}
								shuruiCount++;
							}
						}
						if(shuruiCount==3){
							cout<<shurui[k]<<endl;
							flag=true;
							break;
						}
					}
				}
			}
		}
		if(!flag){
			cout<<"d"<<endl;
		}
	}
}

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

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

    LL ans=0;
    while(a[0]%2==0){
        ans++;
        a[0]/=2;
    }
    for(LL i=1; i<n; i++){
        LL tmp_ans=0;
        while(a[i]%2==0){
            tmp_ans++;
            a[i]/=2;
        }
        ans=min(ans, tmp_ans);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <list>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef priority_queue<P, vector<P>, greater<P> > minPQ;
struct edge {int to,cost;};
//const int SIZE = 1<<18;

int main() {
	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c=='+') cout << a+b << endl;
	else cout << a-b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    while(1){
        int n;
        cin>>n;
        if(n==0){
            break;
        }
        vector<int>s(n);
        double m=0.00000000;
        for(int i=0;i<n;i++){
            cin>>s[i];
            m+=s[i];
        }
        m/=n;
        double a=0.00000000;
        for(int i=0;i<n;i++){
            a+=pow(s[i]-m,2);
        }
        a/=n;
        cout<<fixed << setprecision(8)<<sqrt(a)<<endl;
    }
}



Measured memory_bytes: 3280
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
#define rep_one(i, n) for(int i=1; i<n; i++)
using namespace std;
typedef long long ll;


int main(){
    int a;cin >> a;
    cout << a + a*a+ a*a*a << endl;
}

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

vector<int> dist(1010);

int cntodd, cnteven;
bool valid;

void dfs(int cv, vector<vector<int>> &G){
    for(auto nv:G[cv]){
        if(dist[nv] != -1){
            if(dist[cv] % 2 == dist[nv] % 2){
                valid = false;
                return ;
            }
        }
        else{
            dist[nv] = dist[cv] + 1;
            if(dist[nv] % 2) cntodd++;
            else cnteven++;
            dfs(nv, G);
        }
    }
}

int main(){
    while(1){
        valid = true;
        cntodd = cnteven = 0;
        for(int i=0; i<1010; i++) dist[i] = -1;
        int n, m; cin>>n>>m;
        if(n == 0) return 0;

        vector<vector<int>> G(n);
        for(int i=0; i<m; i++){
            int s, t; cin>>s>>t;
            s--, t--;
            G[s].emplace_back(t);
            G[t].emplace_back(s);
        }

        dist[0] = 0;
        cnteven++;

        dfs(0, G);

        if(!valid){
            cout << 0 << endl;
        }
        else{
            set<int> ans;
            if(cntodd % 2 == 0){
                ans.emplace(cntodd / 2);
            }

            if(cnteven % 2 == 0){
                ans.emplace(cnteven / 2);
            }

            cout << ans.size() << endl;
            for(auto i:ans){
                cout << i << endl;
            }
        }
    }
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  string stmp; cin >> stmp;
  int S[N]; rep(i,N) S[i] = stmp[i] - '0';
  int result = 0;
  rep(i,10) rep(j,10) rep(k,10) {
    int num[3] = {i,j,k};
    int pos = 0;
    rep(x,N) {
      if (num[pos]==S[x]) pos++;
      if (pos==3) { result++; break; }
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int collect[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    int nums[15]={0};
    int n;
    
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
	int temp=i;
	for(int j=0;j<15;j++){
	    if(collect[j]>temp)
		break;
	    while(temp%collect[j]==0){
		temp/=collect[j];
		nums[j]++;
	    }
	}
    }
    int a=0,b=0,c=0,d=0,e=0;
    for(int i=0;i<15;i++){
	if(nums[i]>=4){
	    a++;
	}
	if(nums[i]>=2)
	    b++;
	if(nums[i]>=14)
	    c++;
	if(nums[i]>=24)
	    d++;
	if(nums[i]>=74)
	    e++;
    }
    if(a<2||b<3)
	printf("0\n");
    else
	printf("%d\n",a*(a-1)/2*(b-2)+c*(a-1)+d*(b-1)+e);
    return 0;
}

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

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
		FastScanner sc=new FastScanner();
			int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
			if(c>=a&&c<=b) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


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

typedef long long ll;

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

    vector<int> h(N);
    for(int i=0;i<N;i++){
        cin>>h.at(i);
    }
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    int cnt=0;

    for(int i=0;i<N;i++){
        if(h.at(i)>=K){
            cnt++;
        }
        else{
            break;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N;
    cin>>N;
    vector<int> ve(N);
    rep(i, 0, N-1) {
        int a;
        cin >> a;
        a--;
        ve[a]++;
    }
    rep(i, 0, N) { cout << ve[i] << endl; }
}


Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////


int main() {
	string s; cin >> s;
	bool ok = true;
	if (s.size() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.size(); ++i) {
		if (i % 2 == 0) {
			if (s[i] != 'h')ok = false;
		}
		else {
			if (s[i] != 'i')ok = false;
		}
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int min(int x,int y){return x>y?y:x;}
int max(int x,int y){return x>y?x:y;}
int main(void){
    char S[114514];
    scanf("%s",S);
    int ans=1;
    char maemoji=S[0];
    int count=1;
    for(int i=1;i<strlen(S);i++){
        if(S[i]!=maemoji){
            maemoji=S[i];
            ans=max(ans,min(i,strlen(S)-i+count));
            count=1;
        }
        else count++;
        if(i==strlen(S)-1)ans=max(ans,min(i+1,strlen(S)-(i+1)+count));
    }
    printf("%d",ans);
    return 0;
    
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	//~ cout.tie(0);
	int n; ll m;
	cin >> n >> m;
	vll a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;
	}

	ll g = a[0];
	for (int i = 1; i < n; i++) {
		g = g * a[i] / __gcd(g, a[i]);
		if (g > m) {
			puts("0");
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		ll x = g / a[i];
		if (x % 2 == 0) {
			puts("0");
			return 0;
		}
	}

	//cerr << "smallest: " << g << endl;
	ll ans = 1 + (m - g) / (2 * g);
	cout << ans << endl;
}


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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		n = 1000 - n;
		int ans = 0, i;
		int w[6] = { 500,100,50,10,5,1 };
		for (i = 0; i <= 5; i++) {
			ans = ans + n / w[i];
			n = n - n / w[i] * w[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n,a,b;
	long long x=1,y=1;
	long long mid;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		mid=max(x/a,y/b);
		while(mid*a<x || mid*b<y)
			mid++;
		x=mid*a;
		y=mid*b;	
	}
	cout<<x+y<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N;
    vector<int> vec;

    cin >> N;
    vec.resize(N);
    rep(i,N) cin >> vec[i];

    int ans[N] = {0}, counter = 0;
    for(int i = N - 1; i >= 0; i--){
        int a = 0;
        for(int j = i; j < N; j += i + 1){
            a += ans[j];
        }
        if(a % 2 != vec[i]){
            ans[i] = 1;
            counter++;
        }
    }
    
    cout << counter << endl;
    rep(i,N) if(ans[i]) cout << i + 1<< " ";
}

Measured memory_bytes: 2432
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int N = (int) 1e5 + 10;

int A[N],B[N],C[N];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i++){
		cin >> A[i];
	}
	for(int i = 0 ; i < n ; i++){
		cin >> B[i];
	}
	for(int i = 0 ; i < n ; i++){
		cin >> C[i];
	}
	sort(A , A + n);
	sort(B , B + n);
	sort(C , C + n);
	long long sum = 0;
	for(int i = 0 ; i < n ; i++){
		int index1 = lower_bound(A , A + n , B[i]) - A;
		int index2 = upper_bound(C , C + n , B[i]) - C;
		sum += (1LL * (index1) * (n - index2));
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<double> > x(N, vector<double>(D));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> x[i][j];
        }
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        double tmp = 0;
        for (int j = i+1; j < N; j++) {
            tmp = 0;
            for (int k = 0; k < D; k++) {
                tmp += pow((x[i][k] - x[j][k]), 2);
            }
            tmp = sqrt(tmp);
            if (tmp == round(tmp)) res++;
        }
    }

    cout << res << endl;


}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cksharma
 */

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

struct Happiness {
    int a;
    int b;
    int index;
};

class CDifferentStrokes {
public:
    void solve(istream& cin, ostream& cout) {
        ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
        cout.setf(ios::fixed); cout.precision(20);

        int n; cin >> n;
        vector<Happiness> A;
        vector<Happiness> B;
        for (int i = 0; i < n; ++i) {
            int a, b; cin >> a >> b;
            A.push_back({a, b, i});
            B.push_back({a, b, i});
        }

        sort(A.begin(), A.end(), [](const Happiness& lhs, const Happiness& rhs) {
            int diff1 = lhs.a - rhs.b;
            int diff2 = rhs.a - lhs.b;
            if ( diff1 > diff2 ) return true;
            return false;
        });

        sort(B.begin(), B.end(), [](const Happiness& lhs, const Happiness& rhs) {
            int diff1 = lhs.b - rhs.a;
            int diff2 = rhs.b - lhs.a;
            if ( diff1 > diff2 ) return true;
            return false;
        });

        set<int> visited; int aIndex = 0, bIndex = 0;
        long long ans = 0LL;
        while (aIndex < n && bIndex < n) {
            while (aIndex < n) {
                Happiness& h = A[aIndex];
                if (visited.find(h.index) != visited.end()) { aIndex++; continue; }
                ans += A[aIndex].a;
                aIndex++;
                visited.insert(h.index);
                break;
            }
            while (bIndex < n) {
                Happiness& h = B[bIndex];
                if (visited.find(h.index) != visited.end()) { bIndex++; continue; }
                ans -= B[bIndex].b;
                bIndex++;
                visited.insert(h.index);
                break;
            }
        }
        cout << ans << endl;
    }
};


int main() {
    CDifferentStrokes solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 7340
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

  int sum = 0;
  vector<int> S(N);
  for(int i = 0;i < N;i++) {
      cin >> S.at(i);
      sum += S.at(i);
  }

   if(sum % 10 != 0) {
       cout << sum << endl;
   }else {
       sort(S.begin(),S.end());
       for(int i = 0;i < N;i++) {
           if(S.at(i) % 10 != 0) {
               sum -= S.at(i);
               cout << sum << endl;
               return 0;
           }
       }
       cout << 0 << endl;
   }

}


Measured memory_bytes: 256
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=5000+10,M=200+10;

int n,m,a[N],b[N][M];
int sta[M][N],top[M];
ll d[N];

void add(int l,int r,int x) {
	if (l>r) return;
	d[l]+=x,d[r+1]-=x;
}

int main() {
	n=read(),m=read();
	for (int i=2;i<=n;++i) a[i]=read();
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) b[i][j]=read();
	ll ans=0;
	for (int i=1;i<=n;++i) {	
		for (int j=1;j<=m;++j) {
			add(i,i,b[i][j]);
			while (top[j]&&b[sta[j][top[j]]][j]<=b[i][j]) {
				add(sta[j][top[j]-1]+1,sta[j][top[j]],b[i][j]-b[sta[j][top[j]]][j]);
				--top[j];
			}
			sta[j][++top[j]]=i;
		}
		add(1,i-1,-a[i]); ll now=0;
		for (int j=1;j<=i;++j) now+=d[j],ans=max(ans,now);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int N;
    long long x;
    cin >> N >> x;
    vector<long long> a(N);
    vector<long long> b(N);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }

    long long res = accumulate(a.begin(), a.end(), 0LL);
    for(int k=1; k<N; ++k) {
        long long tmp = k * x;
        for(int i=0; i<N; ++i) {
            b[i] = min(b[i], a[(i - k + N) % N]); 
            tmp += b[i];
        }
        res = min(res, tmp);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


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

    db a;
    cin >> a;
    cout << a * a << endl;

    return 0;
}


Measured memory_bytes: 3808
N = int(input())
A = list(map(int, input().split()))
default = True
for i in range(N-1):
    if A[i] < A[i+1]:
        default = False
        break
if default:
    print(1000)
    exit()
updown = [(0, A[0])]
for i in range(N-1):
    if A[i] < A[i+1]:
        updown.append((1, A[i+1]))
    elif A[i] > A[i+1]:
        updown.append((-1, A[i+1]))
stock = 0
money = 1000
for i in range(len(updown)-1):
    if updown[i][0] == 0 and updown[i+1][0] == 1:
        buy = money // updown[i][1]
        stock += buy
        money -= buy * updown[i][1]
    if updown[i][0] == 0 and updown[i+1][0] == -1:
        pass
    if updown[i][0] == -1 and updown[i+1][0] == 1:
        buy = money // updown[i][1]
        stock += buy
        money -= buy * updown[i][1]
    if updown[i][0] == -1 and updown[i+1][0] == -1:
        pass
    if updown[i][0] == 1 and updown[i+1][0] == 1:
        pass
    if updown[i][0] == 1 and updown[i+1][0] == -1:
        money += stock * updown[i][1]
        stock = 0
if stock:
    money += stock * updown[-1][1]
    stock = 0
print(money)


Measured memory_bytes: 9320
# https://beta.atcoder.jp/contests/agc029/submissions/3804087
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = Counter(a)

ans = 0
for t in a:
    if b[t] == 0: continue
    s = (1 << t.bit_length()) - t
    if t == s:
        ans += b[t] // 2
        b[t] %= 2
    else:
        u = min(b[s], b[t])
        ans += u
        b[s] -= u
        b[t] -= u

print(ans)


Measured memory_bytes: 56124
#include<stdio.h>
int main()
{
    int N,a,b;
    scanf("%d",&N);
    a=N/10;
    b=N%10;
    if(a==9&&b!=9)
        printf("Yes");
        else if(b==9)
    {printf("Yes\n");
    }
       else if(a!=9&&b!=9)
        {printf("No\n");}
        return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

odds = sum([a % 2 for a in A])
evens = sum([(a+1) % 2 for a in A])

if len(A) == 1:
    print('YES')
    exit()
if odds % 2 == 0:
    print('YES')
    exit()
print('NO')

Measured memory_bytes: 14112
# coding: utf-8

# 標準入力<str>
S = input()
N = len(S)
n = int((N - 1) / 2)
n2 = int((N - 1) / 2)
S2 = S[0:n2]
n3 = int((N+3)/2)
S3 = S[n3 -1:]

isNo1OK = True
isNo2OK = True
isNo3OK = True

for i in range(n):
  if S[i] != S[(i + 1) * -1]:
    isNo1OK = False

for j in range(len(S2)):
  if S2[j] != S2[(j + 1) * -1]:
    isNo2OK = False

for k in range(len(S3)):
  if S3[k] != S3[(k + 1) * -1]:
    isNo2OK = False

if isNo1OK and isNo2OK and isNo3OK:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _154_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var st = Console.ReadLine()
                .Split()
                .ToArray();
            var ab = Console.ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();
            var u = Console.ReadLine();

            if (u == st[0])
                Console.WriteLine($"{ab[0] - 1} {ab[1]}");
            if (u == st[1])
                Console.WriteLine($"{ab[0]} {ab[1] - 1}");
                
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
int main()
{
    double l;
    cin>>l;
    cout<<fixed<<setprecision(8)<<(l/3)*(l/3)*(l/3);
}

void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

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

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

	ll N, N2;
	cin >> N;
	N2 = N;
	ll sum = 0;
	while(N){
		sum += N%10;
		N/=10;
	}
	cout << (N2%sum ? "No" : "Yes") << endl;
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer Search(int key){
  /* your code */
  NodePointer v;
  v = nil->next;
  while(v->key != key && v != nil){
    v = v->next;
  }
  return v;
  
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void print(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t == nil){
    return;
  }
  


  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void First(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void Last(){deleteNode(nil->prev);}
  /* your code */






void delete(int key){deleteNode(Search(key));
  /* your code */
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next=nil->next;
  nil->next->prev=x;


  nil->next=x;
  x->prev=nil;
  

  
  /* 

   your code 


  */

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){


    /*printf("hoge\n");*/

    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) First();
	else if ( com[6] == 'L' ) Last();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  print();
  return 0;
}




Measured memory_bytes: 32952
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  map<int, int> mp;
  cin >> N;
  int ansF = 0;
  for(int i=0; i<N; i++){
    int tmp;
    cin >> tmp;
    tmp = tmp/400;
    if(tmp >= 8) {
      ansF++;
      continue;
    }
    mp[tmp]++;
  }
  int ans = 0;
  ans += mp.size();
  if(ans == 0) {
    ans = 1;
    ansF--;
  }
  cout << ans << " " << ans + ansF << endl;
  return 0;
}

Measured memory_bytes: 256
# 初期入力
N,K = (int(x) for x in input().split(" "))
A = list(map(int, input().split()))

# １からnまでの和 S_n = n*(n+1)/2　さいころの期待値は　S_n /n
kitaiti = [ (i+1)/2 for i in A ]

#　N個のサイコロの期待値の累積和 S
S = [0] * (N +1)
#S[0] = kitaiti[0]
#S =[0]
# S[0] = 0
for i in range(1,N +1):
    S[i] = S[i-1] + kitaiti[i-1]

# 隣接するK個の期待値の和 S_K
S_K = []
for i,v in enumerate(S[:(-1)*K ]):
    S_K.append( S[i + K ] - S[i] )
"""
print(kitaiti)
print(S)
print(S_K)
"""
print(max(S_K))

Measured memory_bytes: 29764
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]


n = int(input())
ju = [False for i in range(1001)]
ju[1] = True
for i in range(2,32):
  now = i**2
  while(now <= 1000):
    ju[now] = True
    now *= i
for i in range(n,0,-1):
  if(ju[i]):
    print(i)
    break

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a,b;
   cin >> a >> b;
   cout << (int)ceil((b-1.0)/(a-1.0)) << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
 
		String s = scan.next();
 
		if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
				
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
 
	}
}

Measured memory_bytes: 22868
/*
ID: jerrywcy
LINK:
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;
const ll mod=1e9+7;

ll n,k;
ll a[4010];
ll sum1,sum2,ans;

ll read(){
    ll f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    n=read();k=read();
    for (int i=1;i<=n;i++)a[i+n]=a[i]=read();
    for (int i=2;i<=n;i++){
        for (int j=1;j<i;j++){
            if (a[i]<a[j])sum1++;
        }
    }
    for (int i=n+1;i<=2*n;i++){
        for (int j=1;j<=n;j++){
            if (a[i]<a[j])sum2++;
        }
    }
//    cout<<sum1<<' '<<sum2<<' '<<(k*(k-1)/2)%mod<<endl;
    ans=((sum1*k)%mod+((k*(k-1)/2)%mod)*sum2%mod)%mod;
    printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include"stdio.h"
#include"cstdio"
#include"algorithm"
#include"string.h"
using namespace std;
typedef long long ll; 
int main()
{
	ll n;
	while(scanf("%d",&n)!=EOF)
	{
		ll ret=(n+1)*n/2;
		printf("%lld\n",ret);
	}
} 

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

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

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

  int n, m; cin >> n >> m;
  int a, b;
  bool G[10][10] = {};
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    G[a][b] = true;
    G[b][a] = true;
  }

  vector<int> v(n-1);
  rep(i, n-1) v[i] = i+1;
  sort(all(v));

  // 順列全列挙
  int ans = 0;
  do {
    int now = 0;
    rep(i, v.size()) {
      if(!G[now][v[i]]) break;
      now = v[i];
      if(i == v.size()-1) ans++;
    }
  } while(next_permutation(all(v)));

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))

s = []
for _ in range(D):
    s.append(list(map(int, input().split())))

# last(d, i)を計算するためのメモ
# new_dp = [[0] * 26 for _ in range(D)]
dp = [0] * 26


def dec(d, dp):
    # d日の終わりに起こる満足度の減少計算の関数
    s = 0
    for j in range(26):
        s += c[j] * (d - dp[j])

    return s


# d日目に開催するコンテストを決める
v = 0
for d in range(D):
    a = 0
    b = 0
    for i in range(26):
        old = dp[i]
        dp[i] = (d + 1)
        if (a <= s[d][i] - dec(d + 1, dp)):
            a = max(s[d][i] - dec(d + 1, dp), a)
            b = i
        dp[i] = old
    v += a
    dp[b] = d + 1
    print(b + 1)


Measured memory_bytes: 9336
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int H,W; cin >> H >> W;
    vector<vector<int>> HW(H);
    repp(i,0,H) {
        vector<int> w(W);
        repp(j,0,W) cin >> w[j];
        HW[i] = w;
    }
 
    vector<vector<int>> op;
    repp(i,0,H) {
        repp(j,0,W) {
            int J = i % 2 == 0 ? j : W-j-1; 
            int nextJ =i % 2 == 0 ? J + 1 : J -1;  
            if (HW[i][J] % 2 == 0) continue;
            
            vector<int> v;
            if (j < W - 1) {
                --HW[i][J];
                ++HW[i][nextJ];
                v.push_back(i+1);
                v.push_back(J+1);
                v.push_back(i+1);
                v.push_back(nextJ+1);
            } else if (i < H - 1) {
                --HW[i][J];
                ++HW[i+1][J];
                v.push_back(i+1);
                v.push_back(J+1);
                v.push_back(i+2);
                v.push_back(J+1);
            } else continue;
            op.push_back(v);
        }
    }
    cout << op.size() << endl;
    repp(i,0,op.size()) {
        repp(j,0,4) {
            if (j > 0) cout << " ";
            cout << op[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 10032
n = int(input())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
clst = list(map(int, input().split()))
alst.sort()
blst.sort()
clst.sort()

b_s = [0 for _ in range(n)]
a_pos = 0
alst.append(10 ** 10)
for i in range(n):
    while blst[i] > alst[a_pos]:
        a_pos += 1
    b_s[i] = a_pos + b_s[i - 1]
b_pos = 0
blst.append(10 ** 10)
ans = 0
for i in range(n):
    while clst[i] > blst[b_pos]:
        b_pos += 1
    if b_pos == 0:
        continue
    ans += b_s[b_pos - 1]
print(ans)

Measured memory_bytes: 29544
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

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

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

	d = d * 2 + 1;
	//cout << d << endl;
	cout << (n + (d - 1)) / d;
}


Measured memory_bytes: 256
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

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

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n, t, a;
    cin >> n >> t >> a;

    vec<int> hs(n);
    for (auto &e : hs)
        cin >> e;

    int ans{};
    double diff{100000000};

    for (int i = 0; i < n; ++i)
    {
        auto mean = t - hs[i] * 0.006;
        auto d = abs(mean - a);
        if (d < diff)
        {
            ans = i + 1;
            diff = d;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import factorial

n, m = map(int, readline().split())
mod = 10 ** 9 + 7
ans = factorial(n) * factorial(m)
if abs(n - m) > 1:
    ans = 0
elif n == m:
    ans *= 2
print(ans % mod)


Measured memory_bytes: 5172
#include<algorithm>
#include<iostream>
using namespace std;
long long gcd(long long a,long long b){
  int i;
  if(a<b)
    swap(a,b);
  for(i=1;a%(b/i);)
    for(i++;b%i;i++);  
  return b/i;
}
long long lcm(long long a,long long b){
  return a*b/gcd(a,b);
}
int main(){
  int i;
  int a[3],m[3],p;
  long long n[3];
  for(;;){
    for(i=0;i<3;i++)
      cin>>a[i]>>m[i];
    if(a[0]+a[1]+a[2]+m[0]+m[1]+m[2]==0)
      break;
    for(i=0;i<3;i++){
      p=a[i]%m[i];
      for(n[i]=1;p!=1;n[i]++)
	p=p*a[i]%m[i];
    }
    cout<<lcm(lcm(n[0],n[1]),n[2])<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
words = list(input())

def is_even_word(s):
  s_len = len(s)
  if s_len % 2 != 0:
    return False
  h = int(s_len/2)
  return s[:h] == s[h:]

l = len(words) - 1
for s in words:
  word = words[:l]
  if is_even_word(word):
    print(l)
    exit(0)
  l -= 1

print(0)
  
    

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

signed main(){
  lint N, W; cin >> N >> W;
  lint w, v; cin >> w >> v;
  vector<vector<lint> > data(4, vector<lint> ());
  data[0].push_back(v);
  for(int i = 1; i < N; i++){
    lint w1, v1; cin >> w1 >> v1;
    data[w1 - w].push_back(v1);
  }
  for(int i = 0; i < 4; i++) sort(data[i].begin(), data[i].end(), greater<lint>());
  vector<lint> sum1(data[0].size()+1, 0), sum2(data[1].size()+1, 0), sum3(data[2].size()+1, 0), sum4(data[3].size()+1, 0);
  for(int i = 0; i < data[0].size(); i++) sum1[i + 1] += sum1[i] + data[0][i];
  for(int i = 0; i < data[1].size(); i++) sum2[i + 1] += sum2[i] + data[1][i];
  for(int i = 0; i < data[2].size(); i++) sum3[i + 1] += sum3[i] + data[2][i];
  for(int i = 0; i < data[3].size(); i++) sum4[i + 1] += sum4[i] + data[3][i];
  
  lint ans = 0;
  for(lint c1 = 0; c1 < sum1.size(); c1++){
    for(lint c2 = 0; c2 < sum2.size(); c2++){
      for(lint c3 = 0; c3 < sum3.size(); c3++){
        for(lint c4 = 0; c4 < sum4.size(); c4++){
          lint sum = w * c1 + (w + 1) * c2 + (w + 2) * c3 + (w + 3) * c4;
          if(sum > W) continue;
          lint ans1 = sum1[c1] + sum2[c2] + sum3[c3] + sum4[c4];
          ans = max(ans, ans1);
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
//package hoge; のようなパッケージ宣言は提出前に除く
//インポート文など
public class Main { //クラス名はMain
    public static void main(String[] args) {
        //コード
        Scanner sc = new Scanner(System.in);
        int n = 0;
        int a = 0;
        int b = 0;
        while (sc.hasNextInt()){
            n = Integer.parseInt(sc.next());
            a = Integer.parseInt(sc.next());
            b = Integer.parseInt(sc.next());
        }
        int resultA = 0;
        if (a < b) resultA = a;
        if (a >= b) resultA = b;
        int resultB = 0;
        if (a+b <= n) resultB = 0;
        if (a+b > n) resultB = a+b - n;
        System.out.println(resultA + " " + resultB);
    }
}

Measured memory_bytes: 20948
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long p = 1;
    for (int i = 1; i <= N; i++) {
      p = (p * i) % 1000000007;
    }
    System.out.println(p);
  }
}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        s[i] += n;
        if(s[i] > 'Z') s[i] -= 26;
    }
    cout << s << endl;
    
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const int date[] = {31,29,31,30,31,30,31,31,30,31,30,31};
const char week[7][10] = {"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};

int main(void){
	int m, d, res, i;
	while(1){
		scanf("%d%d",&m,&d);
		if(m == 0 && d == 0){
			break;
		}
		res = 0;
		for(i = 0;i < m - 1;i++){
			res += date[i];
		}
		res += d;
		printf("%s\n",week[res % 7]);
	}
	return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()


int main()
{
	int N;
	string A, B, C;
	cin >> N >> A >> B >> C;
	int ans = 0;
	REP(i, N){
		if ((A[i] != B[i]) && (B[i] != C[i]) && (C[i] != A[i])) {
			ans += 2;
		} else if ((A[i] == B[i]) && (B[i] == C[i])) {
			ans += 0;
		} else {
			ans++;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
import math

def main():
  A,B,H,M = list(map(int, input().split()))

  angle_per_hour = 360 / 12
  angle_per_minute = 360 / 60

  angle_hour_hand = math.radians(H * angle_per_hour + M * (angle_per_hour / 60))
  angle_minute_hand = math.radians(M * angle_per_minute)

  hour_x = A * math.cos(angle_hour_hand)
  hour_y = A * math.sin(angle_hour_hand)
  minute_x = B * math.cos(angle_minute_hand)
  minute_y = B * math.sin(angle_minute_hand)

  dx = hour_x - minute_x
  dy = hour_y - minute_y

  print(math.sqrt(dx ** 2 + dy ** 2))


if __name__ == "__main__":
  main()

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

public class Main {
    private static final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) {
        String str = readLineStandardInput();
        char[] S = str.toCharArray();
        int plus = 0;
        for(char s: S){
            if(s == '+'){
                plus += 1;
            }
        }
        int minus = 4 - plus;
        int res = plus - minus;
        System.out.println(res);
    }

    private static String readLineStandardInput() {
        String str;
        try {
            str = input.readLine();
        } catch(IOException e){
            str = null;
            System.out.println(e);
        }
        return str;
    }
}

Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<int> g[100010];
ll dp[100010][2];
bool used[100010];

ll dfs(int now,int col){
  if(dp[now][col]>=0) return dp[now][col];
  used[now]=true;

  ll cnt=1;
  for(int i=0;i<g[now].size();i++){
    int u=g[now][i];
    if(used[u]) continue;

    if(col){
      ll tmp=dfs(u,0);
      tmp=(tmp+dfs(u,1))%MOD;
      cnt=(cnt*tmp)%MOD;
    }else{
      cnt=(cnt*dfs(u,1))%MOD;
    }
  }

  used[now]=false;
  return dp[now][col]=cnt;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  for(int i=0;i<=n;i++) for(int j=0;j<=1;j++) dp[i][j]=-1;

  ll ans=dfs(1,0);
  for(int i=0;i<=n;i++) used[i]=false;
  ans=(ans+dfs(1,1))%MOD;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 14336
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int h[]=new int[n];
	for(int i=0;i<n;i++)
	h[i]=s.nextInt();
	int dp[]=new int[n];
	dp[0]=0;
	dp[1]=Math.abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
	dp[i]=Math.min(Math.abs(h[i-1]-h[i])+dp[i-1],Math.abs(h[i-2]-h[i])+dp[i-2]);
	}
	//for(int i=0;i<n;i++)
	//System.out.print(dp[i]+" ");
	System.out.println(dp[n-1]);
	}
}
	 

Measured memory_bytes: 49356
open Batteries
let n, k = Scanf.sscanf (read_line()) "%d %d" (fun n k ->n, k)
let rec how_many n target =
  if n >= target then 0 else 1 + how_many (n*2) target
 
let rec n_loop i =
  if i > n then 0. else(
    ((1. /. 2.) ** (float_of_int @@ how_many i k)) *. (1. /. (float_of_int n)) +. (n_loop @@ i + 1))
 
let () = Printf.printf "%.10f\n" @@ n_loop 1

Measured memory_bytes: 5760
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    int a[13];
    a[1] = a[3] = a[5] = a[7] = a[8] = a[10] = a[12] = 1;
    a[4] = a[6] = a[9] = a[11] = 2;
    a[2] = 3;
    if(a[x] == a[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256