akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
vector<vector<vector<int>>> v;
int n, m, p;
int dx[] = { 1, 0, 0, 1, 0, 1, -1, 0, 1, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, 1, 1, 0, 1, -1, 0, 1, 1, -1, -1 };
int dz[] = { 0, 0, 1, 0, 1, 1, 0, 1, -1, 1, 1, 1, 1 };

bool search(int x, int y, int z,int i, int t)
{
	REP(j, m-1)
	{
		x += dx[i]; y += dy[i]; z += dz[i];
		if (x < 0 || y < 0 || z < 0 || x >= n || y >= n || z >= v[x][y].size()) return false;
		if (v[x][y][z] != t) return false;
	}

	return true;
}

bool solve(int x)
{
	REP(i, n)
	{
		REP(j, n)
		{
			REP(k, v[i][j].size())
			{
				REP(l, 13)
				{
					if (v[i][j][k]==x && search(i, j, k, l, x)) return true;
				}
			}
		}
	}
	return false;
}

int main()
{
	while (cin >> n >> m >> p, n)
	{
		v.assign(n, vector<vi>(n));
		int x = 0;
		bool f = true;
		REP(i, p)
		{
			int a, b;
			cin >> a >> b;
			a--; b--;
			v[a][b].push_back(x);
			if (f&&solve(x))
			{
				cout << (x == 0 ? "Black " : "White ") << i + 1 << endl;
				f = false;
			}
			x ^= 1;
		}
		if(f) cout << "Draw" << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
import itertools

D,G = map(int,input().split())
ab = []
for _ in range(D):
    p, c = (int(x) for x in input().split())
    ab.append([p,c])

ans = 10000000

pick_num = []

for i in range(D):
    pick_num.append(i)

for i in range(0,D+1):
    for v in itertools.combinations(pick_num, i):      
        tmp_point = 0
        tmp_count = 0
        for j in v:
            tmp_point += ab[j][0]*(j+1)*100+ab[j][1]
            tmp_count += ab[j][0]
        if tmp_point < G:
            nokori = G-tmp_point
            for k in range(D-1, -1,-1):
                if k not in v:
                    if nokori%(100*(k+1)) == 0:
                        if nokori//(100*(k+1)) < ab[k][0]:
                            tmp_count += nokori//(100*(k+1))
                            tmp_point += nokori
                    else:
                        if nokori//(100*(k+1))+1 < ab[k][0]:
                            tmp_count += nokori//(100*(k+1))+1
                            tmp_point += nokori
                    break
        if G <= tmp_point:
            ans = min(ans, tmp_count)
print(ans)

Measured memory_bytes: 70948
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
 
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	long double val=pow(2,n-1);
	sort(a,a+n);
	long double sum=a[0],temp=1;
	for(int i=1;i<n;i++){
		sum+=a[i]*temp;
		temp*=2;
	}
	cout<<sum/val<<endl;
}

Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())

c_count = b//c
d_count = b//d
# 最小公倍数で割る
c_d = b//(c*d//gcd(c, d))

print(b - c_count - d_count + c_d - (a-1 - (a-1)//c - (a-1)//d + (a-1)//(c*d//gcd(c, d))))

Measured memory_bytes: 5048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    reverse(all(s));
    vector<vector<ll>> dp(n+1,vector<ll>(13,0));
    dp[0][0] = 1;
    ll l = 1;
    rep(i,n){
        if (s[i] == '?'){
            rep(j,13){
                rep(k,10){
                    ll t = (l*k)%13;
                    (dp[i+1][(j+t)%13] += dp[i][j])%=MOD;
                }
            }
        }
        else{
            ll t = (l*(s[i]-'0'))%13;
            rep(j,13){
                (dp[i+1][(j+t)%13] += dp[i][j])%=MOD;
            }
        }
        (l *= 10)%=13;
    }
    PRINT(dp[n][5]);
}



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

int main(){
	int i, j, n, cnt;
	char strch, buf[12];
	string str, strtmp;
	while(true){
		cin>>n;
		if(n==0) break;
		cin>>str;
		for(i=0;i<n;i++){
			cnt=1;
			strch=str[0];
			for(j=1;j<=str.size();j++){
				if(j<str.size() && strch == str[j]){
					cnt++;
				}else{
					sprintf(buf, "%d", cnt);
					strtmp+=buf;
					strtmp+=strch;
					strch=str[j];
					cnt=1;
				}
			}
			str=strtmp;
			strtmp.erase();
		}
		cout<<str<<endl;
	}
	return 0;
}

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

cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i] > A[j]:
            cnt += 1

cnt2 = 0
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            cnt2 += 1

ans = (cnt*K + cnt2*(K*(K-1)//2))%(10**9 + 7)
print(ans)

Measured memory_bytes: 9216
#n,W=map(int, input().split())
s=input()
t=input()
ns=len(s)
nt=len(t)
dp=[[0 for j in range(ns+1)] for i in range(nt+1)]
    
for i in range(1,nt+1):
    for j in range(1,ns+1):
        if t[i-1]==s[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

cnt=dp[-1][-1]
ans=[]
ct,cs=nt,ns
while cnt>0:
    while dp[ct][cs]==dp[ct-1][cs] and ct>0:
        ct-=1
        
    while dp[ct][cs]==dp[ct][cs-1] and cs>0:
        cs-=1

    ans.append(t[ct-1])
    cnt-=1
    #print(ct,cs,t[ct-1])
    ct-=1
    cs-=1

print(''.join(ans[::-1]))


Measured memory_bytes: 119644
#include<iostream>
using namespace std;
#include<math.h>

int main()
{
long long int H;
  cin>>H;
  long long int tot=0,i=1;
  
  while(i<=H)
  {
    i=i*2;
  
  }
  tot=i-1;
  cout<<tot<<endl;

}

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

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

Measured memory_bytes: 256
N, M =map(int,input().split())
L = []
for _ in range(N):
    L.append(list(map(int,input().split())))
L.sort()
ans = 0
i = 0
while M > 0:
    if M - L[i][1] > 0:
        ans += L[i][0] * L[i][1]
        M -= L[i][1]
    else:
        ans += (M * L[i][0])
        break
    i += 1
print(ans)

Measured memory_bytes: 27760
#include <iostream>

using namespace std;

int isNum(char);
int power(int, int);

int main(){
        int p = 0, i = 0;    //p: buffer????????????????????????, i:formula????????????????????????
        int count = 0;    //??°????????????????????°
        int tmp;
        int val;
        string formula;
        int buffer[100] = {0};

        getline(cin, formula);
        while(formula[i] != '\0'){
                if((val = isNum(formula[i]))){
                        buffer[p] = (val < 0)? 0:val;    //??????p????????????????????°???????????\
                        p = p + 1;    //?¬?????????????
                        ++count;
                }else{
                        switch (formula[i]) {
                                case ' ':
                                        if(count){    //??´??????buffer?????°??????????????????????????´???,?????£?¶?????????°????????£????????°???????????£
                                                tmp = p - count;
                                                buffer[tmp] *= power(10, --count);
                                                for(; count > 0; count--){
                                                        buffer[tmp] += buffer[p - count] * power(10, count-1);
                                                }
                                                p = tmp + 1;
                                                count = 0;
                                        }
                                        break;
                                case '+':
                                        buffer[p - 2] += buffer[p - 1];
                                        p = p - 1;
                                        break;
                                case '-':
                                        buffer[p - 2] -= buffer[p - 1];
                                        p = p - 1;
                                        break;
                                case '*':
                                        buffer[p - 2] *= buffer[p - 1];
                                        p = p - 1;
                                        break;
                        }
                }
                i++;
        }

        cout<<buffer[0]<<endl;

}

int isNum(char a){
        int judge;
        char numlist[10] = {'0','1','2','3','4','5','6','7','8','9'};

        for(judge = 0; judge < 10; judge++){
                if(a == numlist[judge]) break;
        }

        if(judge == 10){
                judge = 0;
        }else if(judge == 0){
                judge = -1;
        }

        return judge;
}

int power(int x, int n){
        int result = 1;

        for(; n >0; n--){
                result *= x;
        }
        return result;
}

Measured memory_bytes: 1176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	int c;
	vector<int> v,d;
	cin>>a>>b;
	for(int i=0;i<a;i++){
		cin>>c;
		v.push_back(c);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<a-(b-1);i++){
		d.push_back(v[i+(b-1)]-v[i]);
	}
	sort(d.begin(),d.end());
	cout<<d[0]<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int mat[205][205]={};
    vector<int> vs[205]={};
    int n;
    char st;
    scanf("%d",&n);
    scanf("%c",&st);
    REP(i,n){
        REP(j,n){
            scanf("%c",&st);
            mat[i][j]=st-'0';
            if(mat[i][j]==1){
                vs[i].push_back(j);
            }
        }
        scanf("%c",&st);
    }
    int bw[205];
    REP(i,205)bw[i]=-1;
    bw[0]=0;
    queue<int> que;
    que.push(0);
    int flag = 0;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        auto gos = vs[now];
        for(int i:gos){
            if(bw[i]==-1){
                bw[i] = 1-bw[now];
                que.push(i);
            }
            else{
                if(bw[i]+bw[now]!=1){
                    flag=1;
                }
            }
        }
    }
    if(flag==1){
        printf("-1\n");
        return 0;
    }

    // floyd-warshall
    ll dist[205][205];
    REP(i,n)REP(j,n){
        if(i==j)dist[i][j]=0;
        else if(mat[i][j]==1)dist[i][j]=1;
        else dist[i][j]=1145141919;
    }

    REP(k,n)REP(i,n)REP(j,n)if(dist[i][j]>dist[i][k]+dist[k][j])dist[i][j]=dist[i][k]+dist[k][j];
    ll max=-1;
    //REP(i,n)REP(j,n)printf("###%d %d %d\n",i,j,dist[i][j]);
    REP(i,n)REP(j,n)if(max<dist[i][j])max=dist[i][j];
    printf("%lld\n",max+1);
    return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  valarray<int> a(n), b(n);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1) a[y] = 1;
    if (y == n) b[x] = 1;
  }
  cout << ((a * b).sum() > 0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

int64_t N, A, B, C, D;
std::string s;

bool solve() {
  for(int i = A; i < C; i++){
    if(s[i] == '#' && s[i + 1] == '#') return false;
  }
  for(int i = B; i < D; i++){
    if(s[i] == '#' && s[i + 1] == '#') return false;
  }
  if(C < D) return true;
  for(int i = B; i <= D; i++){
    if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') return true;
  }
  return false;
}

int main(int argc, char *argv[]) {
  std::cin >> N >> A >> B >> C >> D >> s;
  A--;
  B--;
  C--;
  D--;
  std::cout << (solve() ? "Yes" : "No") << std::endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int a, b;
  char op;
  while (true) {
    fscanf(stdin, "%d %c %d", &a, &op, &b);
    if (op == '?') { break; }
    int val = -1;
    switch (op) {
      case '+': {
        val = a + b;
        break;
      }
      case '-': {
        val = a - b;
        break;
      }
      case '*': {
        val = a * b;
        break;
      }
      case '/': {
        val = a / b;
        break;
      }
    }
    fprintf(stdout, "%d\n", val);
  }
  return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int n , k;
	
	cin >> n >> k;
	
	int t = n-2;
	
	int mx = t + (t*(t-1))/2; 
	
	if(k > mx) {
		cout << -1;
		return;
	}
	
	vector<pair<int,int>> ans;
	
	ans.pb({1,2});
	
	vector<int> dis2;
	
	dis2.pb(1);
	
	int tot = 0;
	int flg = 0;
	
	for(int i = 3; i <= n; ++i) {
		
		if(flg) {
			ans.pb({2,i});
			for(auto u : dis2) {
				ans.pb({i , u});
			}
			dis2.pb(i);
			continue;
		}
		if(tot + dis2.size() <= k) {
			ans.pb({2 , i});
			tot += dis2.size();
		}
		else {
			ans.pb({2 , i});
			
			int tm = tot + dis2.size() - k;
			
			for(int j = 0; j < tm; ++j) {
				ans.pb({i , dis2[j]});
			}
			
			//cout << i << " " << tm << endl;
			
			tot += dis2.size();
			
			flg = 1;
		}
		
		dis2.pb(i);
	}
	
	cout << ans.size() << endl;
	
	for(auto u : ans) {
		cout << u.F << " " << u.S << endl;
	}
}

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


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; ++i)
  {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j)
    {
      int t;
      cin >> t;
      mp[t]++;
    }
  }
  int cnt = 0;
  for (auto &e : mp)
  {
    if (e.second == n)
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

int main() {
	long long a, b, k;
	std::cin >> a >> b >> k;
	
	if(a>=k){
	    printf("%lld %lld", a-k, b);
	}else if(a < k and (a+b) <= k){
	    std::cout << "0 0" << std::endl;
	}else if(a < k){
	    printf("%lld %lld", 0, b-(k-a));
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	fmt.Println(a*b, 2*(a+b))
}



Measured memory_bytes: 1120
n,m=map(int,input().split())
ans=0
if n==1:
    ans+=300000
if n==2:
    ans+=200000
if n==3:
    ans+=100000
if m==1:
    ans+=300000
if m==2:
    ans+=200000
if m==3:
    ans+=100000
if n==m==1:
    ans+=400000
print(ans)

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

int main() {
	int N;
	long T, A;
	vector<long> tmp(3);
	cin >> N;
	for (size_t i = 0; i < 2; ++i) cin >> tmp.at(i);
	for (int i = 1; i < N; ++i) {
		cin >> T >> A;
		tmp.at(2) = max((tmp.at(0) + T - 1) / T, (tmp.at(1) + A - 1) / A);
		tmp.at(0) = T * tmp.at(2);
		tmp.at(1) = A * tmp.at(2);
	}
	cout << tmp.at(0) + tmp.at(1);
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	static	double EPS=1e-1;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			Point p1=new Point(in.nextDouble(), in.nextDouble()); 
			Point p2=new Point(in.nextDouble(), in.nextDouble()); 
			if(p1.x==0&&p1.y==0&&p2.x==0&&p2.y==0)
				return;
			Point p3=new Point(in.nextDouble(), in.nextDouble()); 
			Point p4=new Point(in.nextDouble(), in.nextDouble()); 
			Point p5=new Point(in.nextDouble(), in.nextDouble()); 
			Point p6=new Point(in.nextDouble(), in.nextDouble());
			boolean judge=true;
			if(!lineCross(p1, p2, p3, p4))
				judge=false;
			if(!lineCross(p3, p4, p5, p6))
				judge=false;
			if(!lineCross(p5, p6, p1, p2))
				judge=false;

			if(judge)
			{
				double a1=slanting(p1, p2);
				double a2=slanting(p3, p4);
				double x1=(a1*p1.x-p1.y-a2*p3.x+p3.y)/(a1-a2);
				if(a1==-1.123)
					x1=p1.x;
				else if(a2==-1.123)
					x1=p3.x;
				double y1=(p2.y-p1.y)/(p2.x-p1.x)*(x1-p1.x)+p1.y;
				if(a1==-1.123)
					y1=(p4.y-p3.y)/(p4.x-p3.x)*(x1-p3.x)+p3.y;

				a1=slanting(p3, p4);
				a2=slanting(p5, p6);
				double x2=(a1*p3.x-p3.y-a2*p5.x+p5.y)/(a1-a2);
				if(a1==-1.123)
					x2=p3.x;
				else if(a2==-1.123)
					x2=p5.x;
				double y2=(p4.y-p3.y)/(p4.x-p3.x)*(x2-p3.x)+p3.y;
				if(a1==-1.123)
					y2=(p5.y-p6.y)/(p5.x-p6.x)*(x2-p5.x)+p5.y;

				a1=slanting(p5, p6);
				a2=slanting(p1, p2);
				double x3=(a1*p5.x-p5.y-a2*p1.x+p1.y)/(a1-a2);
				if(a1==-1.123)
					x3=p5.x;
				else if(a2==-1.123)
					x3=p1.x;
				double y3=(p6.y-p5.y)/(p6.x-p5.x)*(x3-p5.x)+p5.y;
				if(a1==-1.123)
					y3=(p2.y-p1.y)/(p2.x-p1.x)*(x3-p1.x)+p1.y;

				double a=x2-x1;
				double b=y2-y1;
				double c=x3-x1;
				double d=y3-y1;
				double S=Math.abs(a*d-b*c)/2;
				if(S<EPS)
					System.out.println("kyo");
				else if(S<100000)
					System.out.println("syo-kichi");
				else if(S<1000000)
					System.out.println("kichi");
				else if(S<1900000)
					System.out.println("chu-kichi");
				else 
					System.out.println("dai-kichi");			
			}
			else
				System.out.println("kyo");
		}
	}

	static boolean lineCross(Point p1,Point p2,Point p3,Point p4)
	{
		double jc1=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x);
		double jd1=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x);
		double jc2=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x);
		double jd2=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x);
		return jc1*jd1<=0 && jc2*jd2<=0;
	}

	static double slanting(Point p1,Point p2)
	{
		if(Math.abs(p1.x-p2.x)<EPS)
			return -1.123;
		else
			return (p1.y-p2.y)/(p1.x-p2.x);
	}
}
class Point
{
	double x;
	double y;
	Point(double x,double y)
	{
		this.x=x;
		this.y=y;
	}
}

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

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for(int i = l; i <= r; i++){
        if(i % d == 0){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<ll> c(100005);
    for(int i=0;i<n;i++){
        int d;
        cin>>d;
        c[d]++;
        if(i==0&&d!=0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=0;
    if(c[0]==1) ans=1;
    for(int i=1;i<n;i++){
        for(int j=0;j<c[i];j++){
            ans*=c[i-1];
            ans%=998244353;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4056
#include <stdio.h>

int main(void) {
	char str[2][4];

	scanf("%s %s", str[0], str[1]);

	int ok = 1;
	for (int i = 0; i < 3; i++)
		ok &= str[0][i] == str[1][2 - i];

	puts(ok ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 128
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Node {
    int id;
    Node left;
    Node right;
}

class Main {
    static Node root;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            String command = sc.next();
            if (command.charAt(0) == 'i') {
                int id = sc.nextInt();
                insert(id);
            } else if (command.charAt(0) == 'p') {
                System.out.println(inParse(root));
                System.out.println(preParse(root));
            }
        }
    }

    public static void insert(int id) {
        Node insertedNode = new Node();
        insertedNode.id = id;

        if (root == null) {
            root = insertedNode;
            return;
        }

        Node node = root;
        while(true) {
            if (id < node.id) {
                if (node.left == null) {
                    node.left = insertedNode;
                    return;
                }
                node = node.left;
            } else {
                if (node.right == null) {
                    node.right = insertedNode;
                    return;
                }
                node = node.right;
            }
        }
    }

    public static String preParse(Node node) {
        if (node == null) {
            return "";
        }
        return " " + node.id + preParse(node.left) + preParse(node.right);
    }

    public static String inParse(Node node) {
        if (node == null) {
            return "";
        }
        return inParse(node.left) + " " + node.id + inParse(node.right);
    }
}



Measured memory_bytes: 474836
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((c + b - 1) / b <= (a + d - 1) / d)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
 
using namespace std;
 
int main(){
  int N, Y;
  cin >> N >> Y;
  for(int x=0; x<=N; x++){
    for(int y=0; y<=N-x; y++){
      int z = N - x -y;
      int total = 10000*x + 5000*y +1000*z;
      if(total == Y){
        cout << x <<" "<< y<<" " << z <<endl;
        return 0;
      }
    }
  }
  cout << -1<<" " << -1 <<" "<< -1<< endl;
}

Measured memory_bytes: 888
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

fn main() {
    let (n, m): (usize, usize) = (read(), read());
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let (a, b) = (read::<usize>() - 1, read::<usize>() - 1);
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut path: VecDeque<usize> = VecDeque::new();
    path.push_front(0);
    path.push_back(graph[0][0]);
    let mut used: Vec<bool> = vec![false; n];
    used[0] = true;
    used[graph[0][0]] = true;
    loop {
        let mut ok = true;
        let s = *path.front().unwrap();
        let g = *path.back().unwrap();
        for i in &graph[s] {
            if !used[*i] {
                ok = false;
                path.push_front(*i);
                used[*i] = true;
                break;
            }
        }
        if !ok {
            continue;
        }
        for i in &graph[g] {
            if !used[*i] {
                path.push_back(*i);
                used[*i] = true;
                ok = false;
                break;
            }
        }
        if ok {
            break;
        }
    }
    println!("{}", path.len());
    for i in &path {
        if i != path.front().unwrap() {
            print!(" ");
        }
        print!("{}", *i + 1);
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 13052
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int N;
  cin >> N;
  vector<int> A;
  REP(i, N) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  bool flag = false;
  int cur = 0;
  int cnt = 1;
  while (cur != N) {
    if (A[cur] == cnt)
      cnt++;
    else
      cur++;
  }

  if (cnt > 1)
    cout << N - cnt + 1 << endl;
  else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1528
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(n):
  A=list(map(int,input().split()))
  result=0
  for j in range(m):
    result += A[j]*B[j]
  result += c
  if result > 0:
    count+=1
print(count)

Measured memory_bytes: 9136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    std::set<int> as;
    for (int i = 0; i < n; i++)
    {
        std::cin >> a[i];
        as.insert(a[i]);
    }

    std::sort(a.begin(), a.end());

    long long ans = 0;
    for (auto itr = as.begin(); itr != as.end(); itr++)
    {
        
        int num = std::upper_bound(a.begin(), a.end(), *itr) - std::lower_bound(a.begin(), a.end(), *itr);
        if(num%2 != 0) {
            ans += num%2;
        }
    }

    std::cout << ans << "\n";
}


Measured memory_bytes: 8116
#include <stdio.h>

int gcd(int x, int y)
{
    if(x < y)
    {
        int z = x;
        x = y;
        y = z;
    }

    while(y > 0)
    {
        int r = x % y;
        x = y;
        y = r;
    }

    return x;
}

int main(void)
{
    int x, y;
    scanf("%d %d", &x, &y);
    printf("%d\n", gcd(x, y));
    return 0;
}

Measured memory_bytes: 592
n = int(input())
res = n
for i in range(1,n//2+1):
    tmp = 0
    a = str(n-i)
    b = str(i)
    for j in a:
        tmp += int(j)
    for j in b:
        tmp += int(j)
    res = min(res,tmp)
else:
    print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x)

ll gcd(ll a, ll b){
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
int main(){
    ll n, ans; sc(n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) sc(a[i]);
    ans = gcd(a[0], a[1]);
    for (int i = 2; i < n; i++) ans = gcd(ans, a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
// Aizu Vol0 0064: Secret Number
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int main()
{
	int n;
	int ans = 0;

	while (gets(p = buf) != NULL) {
		while (*p) {
			if (isdigit(*p)) {
				n = 0;
				while (isdigit(*p)) n = 10 * n + (*p++ - '0');
				ans += n;
			} else p++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define inf 100000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    int N = scanner.nextInt();
		    int array[] = new int[N];
		    int count = 0;
		    
		    
		    for(int i = 0; i < N ; i++)
		    {
		    	array[i] = scanner.nextInt();
		    }
		    for(int i = 0; i < N - 1; i++) 
		    {
		    	if(array[i] == array[ i + 1 ]) 
		    	{
		    		count = count + 1 ;
		    		i = i + 1;

		    	}
		    	else 
		    	{
		    		//何もしない
		    	}
		    }
		    System.out.println(count);
		    scanner.close();}
		  }

Measured memory_bytes: 23764
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      h: usize,
      w: usize,
      d: usize,
      a: [[Usize1; w]; h],
      q: usize,
      lr: [(Usize1, Usize1); q]
   }
   let mut dir = vec![(0, 0); h * w];
   for i in 0..h {
      for j in 0..w {
         dir[a[i][j]] = (i as i32, j as i32);
      }
   }
   let mut mag = vec![vec![0; (h * w) / d + 1]; d];
   let mag_dif = |(x1, y1): (i32, i32), (x2, y2): (i32, i32)| (x1 - x2).abs() + (y1 - y2).abs();
   for i in 0..d {
      let mut j = 1;
      while i + d * j < h * w {
         mag[i][j] = mag[i][j - 1] + mag_dif(dir[i + d * (j - 1)], dir[i + d * j]);
         j += 1;
      }
   }
   for (l, r) in lr {
      let i = l % d;
      println!("{}", mag[i][r / d] - mag[i][l / d]);
   }
}


Measured memory_bytes: 11448
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

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

const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	vector<int> lst;
	for(int i=0;i<sz(s);++i) {
		if(s[i]=='o') {
			lst.push_back(i);
		}
	}
	vector<int> dp(sz(lst));
	dp[sz(lst)-1]=1;
	for(int i=sz(lst)-2;i>=0;i--) {
		auto it=lower_bound(lst.begin(), lst.end(), lst[i]+c+1);
		if(it!=lst.end()) {
			int ind=it-lst.begin();
			dp[i]=dp[ind]+1;
		}else {
			dp[i]=1;
		}
	}
	
	set<int> ans;
	int mehet=0, van=0;
	for(int i=0;i<sz(lst);++i) {
		int volt=mehet;
		if(mehet==i) mehet++;
		if(dp[mehet]+van<k) {
			ans.insert(lst[i]+1);
		}
		if(volt<=i) {
			mehet=lower_bound(lst.begin(), lst.end(), lst[i]+c+1)-lst.begin();
			van++;
		}
	}
	
	for(auto i:ans) cout<<i<<"\n";
		
	return 0;
}


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

int dfs(int i, string s, string const& g, int cnt) {
    if(i >= s.size()) {
        return cnt;
    }
    if(s[i] == g[i]) {
        return dfs(i+1, s, g, cnt);
    }
    int res = 1e9;
    int t = (g[i] - s[i] + 10) % 10;
    for(int j=i; j<s.size(); ++j) {
        s[j] = '0' + ((s[j] - '0' + t) % 10);
        res = min(res, dfs(i+1, s, g, cnt+1));
    }
    return res;
}

int main() {
    int k;
    while(cin >> k, k) {
        string s, g;
        cin >> s >> g;
        cout << dfs(0, s, g, 0) << endl;
    }
}


Measured memory_bytes: 3168
n,c,k = map(int, input().split())
lis  =[int(input()) for _ in range(n)]
lis  =sorted(lis)

ans = 0
tmp = lis[0]
cnt = 0
for i in range(n):
    if tmp+k >= lis[i] and cnt <= c-1:
        cnt += 1
    else:
        ans += 1
        tmp = lis[i]
        cnt = 1

print(ans + 1)


Measured memory_bytes: 14148
import java.util.Scanner;
// A - Number of Multiples
class Main{
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();

		int X = (R/d - L/d);
		if (L%d==0) {
			X++;
		}
		System.out.println(X);
		return;


	}
}

Measured memory_bytes: 27080
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
inline bool ok(int x, int l, int r) {
    int sum = 0;
    while (x) {
        sum += x%10;
        x /= 10;
    }
    if (sum <= r && sum >= l) return true;
    return false;
}
int main(int argc, char const *argv[])
{
    int n, l, r, sum = 0;
    cin >> n >> l >> r;
    for (register int i = 1; i <= n; i++)
        if (ok(i, l, r)) sum += i;
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 888
#include<iostream>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	long long a,b,c;
	while(cin>>a>>b>>c){
		if(a+b<c){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}
	return 0;
}

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

template<typename T> T gcd(T a, T b) {
    if(!b) return a;
    return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;

const int MAXN = 100005;

int N, M;
int cnt[MAXN];
bool canRed[MAXN];

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

    for (int i = 1; i <= N; i++) {
        cnt[i] = 1;
    }

    canRed[1] = 1;

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;

        cnt[a] -= 1;
        cnt[b] += 1;

        if (canRed[a]) {
            canRed[b] = 1;
        }
        if (cnt[a] == 0) {
            canRed[a] = 0;
        }
    }

    int ans = 0;

    for (int i = 1; i <= N; i++) {
        ans += canRed[i];
    }

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


Measured memory_bytes: 768
#include<iostream>

using namespace std;

const int MAX_N=2*1e5+5;
const long long INF=1e18;
long long a[MAX_N];

//long long abs(long long x){return x>0?x:-x;}

int main(){
	int n;
	cin>>n;
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	long long s=a[0];
	long long ans=INF;
	for(int i=1;i<n;i++){
		ans=min(ans,abs(sum-2*s));
		s+=a[i];
	}
	cout<<ans<<endl;
}


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

int64_t FizzBuzz(int64_t n) {
    int64_t i = 0;
    int64_t sum = 0;
    while (i < n) {
        i++;

        if (i % 3 == 0 || i % 5 == 0) {
            continue;
        } else {
            sum += i;
        }
    }

    return sum;
}

int main() {
    int64_t n;
    cin >> n;
    cout << FizzBuzz(n) << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        if(c>=a&&c<=b)
            printf("Yes\n");
        else
             printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
INF = 10**8
N = gets.to_i
S = gets.chomp
# 先頭がリーダーの時の変更人数→先頭以外の文字列から"E"の個数
pre = S[1, S.size - 1].count("E")
ans = pre
# binding.pry
(S.size - 1).times do |i|
  if S[i] == "W" && S[i+1] == "W"
    pre += 1

  elsif S[i] == "E" && S[i+1] == "E"
    pre -= 1
    ans = pre if ans > pre
  end
end
puts ans

Measured memory_bytes: 2436
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer a[] = new Integer[N];
        for (int i=0; i<N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());

        int Alice = 0;
        int Bob   = 0;
        for (int i=0; i<N; i+=2) {
            Alice += a[i];
        }
        for (int i=1; i<N; i+=2) {
            Bob += a[i];
        }
        System.out.println(Alice - Bob);
    }
}


Measured memory_bytes: 23380
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        mut x: i64,
        mut k: i64,
        d: i64,
    }

    if x >= 0 {
        let simple_move_cnt = x / d;
        if simple_move_cnt >= k {
            println!("{}", x - k * d);
            return;
        }

        x -= simple_move_cnt * d;
        k -= simple_move_cnt;
        if k % 2 == 0 {
            println!("{}", x.abs());
        } else {
            println!("{}", (x - d).abs().min((x + d).abs()));
        }
    } else {
        let simple_move_cnt = -x / d;
        if simple_move_cnt >= k {
            println!("{}", (x + k * d).abs());
            return;
        }

        x += simple_move_cnt * d;
        k -= simple_move_cnt;
        if k % 2 == 0 {
            println!("{}", x.abs());
        } else {
            println!("{}", (x - d).abs().min((x + d).abs()));
        }
    }
}


Measured memory_bytes: 2176
n = int(input())
m = int(input())
a = []
for i in range(n*2):
    a.append(i+1)
for i in range(m):
    k = int(input())
    if k == 0:
        b = []
        for j in range(n):
            b.append(a[j])
            b.append(a[j+n])
        a = b.copy()
    else:
        a = (a[k:] + a[:k]).copy()
for i in range(n*2):
    print(a[i])



Measured memory_bytes: 5624
"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const N = parseInt(arg_str)

if(N == 1){
    console.log(1)
}else if(N % 2 == 1){
    const M = N + 1
    const L = M /2
    console.log(L/N)
}else{
    console.log(0.5)
}


Measured memory_bytes: 22080
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0

for _ in range(N):
    A = list(map(int, input().split()))
    t = 0
    for a, b in zip(A, B):
        t += a * b
    if t + C > 0:
        ans += 1

print(ans)


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

using namespace std;

struct edge {
    int first, second;
    long long int cost;
};

int main() {
    const long long int INF = 1LL<<60;
    int N, M, P;
    cin >> N >> M >> P;

    vector<edge> edges(M);

    for(int idx = 0; idx < M; ++idx) {
        long long int A, B, C;
        cin >> A >> B >> C;

        // 0-based index
        edges[idx].first = A - 1;
        edges[idx].second = B - 1;

        // distribute the cost among the edges
        // instead of considering it at the end
        edges[idx].cost = P - C;
    }

    // Bellman-Ford
    vector<long long int> d(N, INF);
    d[0] = 0;

    for(int i = 0; i < 2*N; ++i) {
        for(int j = 0; j < M; ++j) {
            if(d[edges[j].first] < INF) {
                if(d[edges[j].second] > d[edges[j].first] + edges[j].cost) {
                    if(i < N)
                        d[edges[j].second] =
                            max(-INF, min(INF, d[edges[j].first] + edges[j].cost));
                    else
                        d[edges[j].second] = -INF;
                }
            }
        }
    }

    if(-INF == d[N - 1])
        cout << -1 << endl;
    else
        cout << max(0LL, -d[N - 1]) << endl;

    return 0;
}



Measured memory_bytes: 384
from sys import exit
import math
from fractions import gcd

def lcm(x,y):
    return x*y//gcd(x,y)

N,M=map(int,input().split())
S=input()
T=input()
if S[0] != T[0]:
    print("-1")
    exit()
if N==M:
    if S==T:
        print(N)

    else:
        print(-1)
    exit()
    
if N<M:
    N,M=M,N
    S,T=T,S
    

# N>M S>T
if(N%M==0):
    S2=""
    for i in range(N):
        if i%(N//M)==0 :
            S2+=S[i]
            
    if S2==T:
        print(N)
    else:
        print(-1)
    exit()

else:
    g=gcd(N,M)
    S2=""
    for i in range(N):
        if i%(N//g)==0 :
            S2+=S[i]
    T2=""
    for i in range(M):
        if i%(M//g)==0 :
            T2+=T[i]
    if S2==T2:
        print(lcm(N,M))
    else:
        print(-1)


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

int main()

{
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='a') a++;
        else if(s[i]=='b') b++;
        else c++;
    }
    if(a==1 && b==1 && c==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int k,t;
  cin >> k >> t;
  int a[t];
  for(int i=0;i<t;i++)
    cin >> a[i];
  sort(a,a+t,greater<int>());
  int index = 0;
  for(int i=1;i<t;i++)
    index += a[i];
  if(index>a[0]) cout << 0 << endl;
  else cout << a[0] - index - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
n, x = gets.chomp.split.map(&:to_i)
ary = gets.chomp.split.map(&:to_i)
ary.push x
ary.sort!

ans = 0
(ary.size - 1).times do |i|
  diff = ary[i + 1] - ary[i]
  ans = ans.gcd(diff)
  break if ans == 1
end
puts ans

Measured memory_bytes: 22592
#include <stdio.h>
static long q, h, s, d, n, sum;
int main(void) {
    scanf("%ld%ld%ld%ld%ld", &q, &h, &s, &d, &n);
    if (2 * q < h)
        h = 2 * q;
    if (2 * h < s)
        s = 2 * h;
    if (2 * s < d)
        d = 2 * s;
    sum += n / 2 * d;
    if (n % 2)
        sum += s;
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    char t,k;
    int m,i,d;
    m=0;
    string S;
    cin >> S;
    for(i=0;i<=2;i++){
        d=i+1;
        t=S[i];
        k=S[d];
        if(t==k){
            m=1;
            }
        }
    if(m==1){
        cout << "Bad";
        }
    else{
        cout << "Good";
        }
    return 0;
}

Measured memory_bytes: 256
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

let solve h w c =
  let s = Array.make w 0 in
  let t = Array.make w 0 in
  let r = ref 0 in
  for i = 0 to h - 1 do
    if c.(i).(0) = 0 then r := 1
  done;
  for j = 0 to w - 1 do
    if c.(0).(j) = 0 then begin
      s.(j) <- 1;
      r := 1
    end
  done;
  for i = 1 to h - 1 do
    if c.(i).(0) = 0 then t.(0) <- 1;
    for j = 1 to w - 1 do
      if c.(i).(j) = 1 then t.(j) <- 0
      else begin
        let d = if s.(j) < t.(j-1) then s.(j) else t.(j-1) in
        t.(j) <- 1 + if s.(j-1) < d then s.(j-1) else d;
        if t.(j) > !r then r := t.(j)
      end
    done;
    Array.iteri (fun i e -> s.(i) <- e) t
  done;
  !r * !r

let () =
  match IO.read_ns () with
  | [h; w] ->
    let c = Array.make_matrix h w 0 in
    for i = 0 to h - 1 do
      let rec doit j = function
        | [] -> ()
        | x::xs ->
          c.(i).(j) <- x;
          doit (j + 1) xs in
      IO.read_ns () |> doit 0
    done;
    solve h w c |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 25268
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true) {
			int n = in.nextInt();
			if(n==0) break;
			long result=1;
			int count=0;
			for(int i=n; i>1; i--) {
				result *= i;
				if(result > 1000000000) result %= 1000000000;
				while(result%10 == 0) {
//					System.out.println("result:" + result + " i:" + i + " count:" + count);
					count++;
					result /= 10;
				}
			}
			System.out.println(count);
		}
	}
}

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




int N;
string S;
//-----------------------------------------------------------------
int ans[101010];
bool sol() {
	rep(i, 1, N - 1) {
		char c = S[i];
		if (ans[i] == 1) {
			if (c == 'o')
				c = 'x';
			else
				c = 'o';
		}

		if (c == 'o') 
			ans[i + 1] = ans[i - 1];
		else
			ans[i + 1] = 1 - ans[i - 1];
	}

	rep(i, 0, N) {
		char c = S[i];
		if (ans[i] == 1) {
			if (c == 'o') c = 'x';
			else c = 'o';
		}

		if (c == 'o') if (ans[(i - 1 + N) % N] != ans[(i + 1) % N]) return false;
		if (c != 'o') if (ans[(i - 1 + N) % N] == ans[(i + 1) % N]) return false;
	}
	return true;
}
//-----------------------------------------------------------------
string ss = "SW";
int main() {
	cin >> N >> S;

	rep(i, 0, 2) rep(j, 0, 2) {
		ans[0] = i;
		ans[1] = j;
		if (sol()) {
			rep(i, 0, N) printf("%c", ss[ans[i]]);
			printf("\n");
			return 0;
		}
	}

	printf("-1\n");
}

Measured memory_bytes: 924