akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

using D = double;
const D PI = acos(D(-1)), EPS = 1e-8;

int sgn(D a) { return (abs(a) <= EPS) ? 0 : (a < 0 ? -1 : 1); }
int sgn(D a, D b) { return sgn(a-b); }

struct Pt2 {
    D x, y;
    Pt2() {}
    Pt2(D _x, D _y) : x(_x), y(_y) {}
    Pt2 operator+(const Pt2 &r) const { return Pt2(x+r.x, y+r.y); }
    Pt2 operator-(const Pt2 &r) const { return Pt2(x-r.x, y-r.y); }
    Pt2 operator*(const Pt2 &r) const { return Pt2(x*r.x-y*r.y, x*r.y+y*r.x); }

    Pt2 operator*(const D &r) const { return Pt2(x*r, y*r); }
    bool operator<(const Pt2 &r) const { return 2*sgn(x, r.x)+sgn(y, r.y)<0; }

    D norm() const { return x*x + y*y; }
    D abs() const { return sqrt(norm()); }
    D rabs() const { return max(std::abs(x), std::abs(y)); }
    D arg() const { return atan2(y, x); }
    static Pt2 polar(D le, D th) { return Pt2(le*cos(th), le*sin(th)); }
};
ostream& operator<<(ostream& os, const Pt2 &p) {
    return os << "(" << p.x << ", " << p.y << ")";
}
using P = Pt2;

struct L {
    P s, t;
    L() {}
    L(P _s, P _t) : s(_s), t(_t) {}
    P vec() const { return t-s; }
};

D cross(P a, P b) { return a.x*b.y - a.y*b.x; }

int sgncrs(P a, P b) {
    D cr = cross(a, b);
    if (abs(cr) <= (a.rabs() + b.rabs()) * EPS) return 0;
    return (cr < 0) ? -1 : 1;
}

int crossLL(const L &l, const L &m, P &r) {
    D cr1 = cross(l.vec(), m.vec()), cr2 = cross(l.vec(), l.t - m.s);
    if (sgncrs(l.vec(), m.vec()) == 0) {
        r = l.s;
        if (sgncrs(l.vec(), l.t - m.s)) return 0;
        return -1;
    }
    r = m.s + m.vec() * (cr2 / cr1);
    return 1;
}

using Pol = V<P>;

// pol must be convex
D diameter(const Pol &p) {
    int n = int(p.size());
    int x = 0, y = 0;
    for (int i = 1; i < n; i++) {
        if (p[i] < p[x]) x = i;
        if (p[y] < p[i]) y = i;
    }
    D ans = 0;
    int sx = x, sy = y;
    while (sx != y || sy != x) {
        ans = max(ans, (p[x]-p[y]).abs());
        int nx = (x+1 < n) ? x+1 : 0, ny = (y+1 < n) ? y+1 : 0;
        if (cross(p[nx] - p[x], p[ny] - p[y]) < 0) x = nx;
        else y = ny;
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(20) << fixed;
    int n;
    cin >> n;
    Pol p(n);
    for (int i = 0; i < n; i++) {
        D x, y;
        cin >> x >> y;
        p[i] = P(x, y);
    }
    cout << diameter(p) << endl;
    return 0;
}



Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll x;
           cin>>x;
           if(x==1){
            cout<<1<<endl;
             return 0;
           }
           ll ans=0;
           rep(i,2,x){
             ll c=i;
             while(c*i<=x)c*=i;
             //cout<<c<<endl;
             if(c==i)continue;
             chmax(ans,c);
           }
           cout<<ans<<endl;
}

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

int main()
{
    int n, c;
    map<int,int> m;

    while( cin >> n )
    {
        if( !n )
            break;

        int id = 0, max = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> c;

            if( m[c] == 0 )
                m[c] = 1;
            else
                m[c]++;

            if( m[c] > max )
            {
                max = m[c];
                id = c;
            }
        }
        if( max > n / 2 )
            cout << id << endl;
        else
            cout << "NO COLOR" << endl;
        m.clear();
    }
    return 0;
}


Measured memory_bytes: 4548
F=lambda:map(int,input().split());H,W,D=F();d={};e=[0]*H*W
for i in range(H):
 for j,v in enumerate(F()):d[v-1]=(i,j)
for i in range(D,H*W):e[i]=sum(abs(p-q)for p,q in zip(d[i-D],d[i]))+e[i-D]
for i in range(int(input())):l,r=F();print(e[r-1]-e[l-1])

Measured memory_bytes: 22612
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static double INF=1e19;
	static double eps=1e-9;
	
	static class State implements Comparable<State>{
		int n1, n2;
		double timer;
		State(int n1, int n2, double timer){
			this.n1=n1;
			this.n2=n2;
			this.timer=timer;
		}
		public int compareTo(State s) {
			if(this.timer>s.timer) {
				return 1;
			}
			else {
				return -1;
			}
		}
	}
	
	static double calc(double A, double B, double C) {
		if(A!=0 && B*B-4*A*C>eps) {
			if((-1*B-Math.sqrt(B*B-4*A*C))/(2*A)>eps) {
				return (-1*B-Math.sqrt(B*B-4*A*C))/(2*A);
			}
			else if((-1*B+Math.sqrt(B*B-4*A*C))/(2*A)>eps) {
				return (-1*B+Math.sqrt(B*B-4*A*C))/(2*A);
			}
		}
		if((Math.abs(A)<eps && B!=0) && -1*C/B>eps) {
			return -1*C/B;
		}
		return INF;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				
				double[] time=new double[n];//流れ星消滅の時間
				double[] px=new double[n];
				double[] py=new double[n];
				double[] pz=new double[n];
				double[] vx=new double[n];
				double[] vy=new double[n];
				double[] vz=new double[n];
				double[] r=new double[n];
				double[] vr=new double[n];
				
				for(int i=0; i<n; i++) {
					px[i]=sc.nextDouble();
					py[i]=sc.nextDouble();
					pz[i]=sc.nextDouble();
					vx[i]=sc.nextDouble();
					vy[i]=sc.nextDouble();
					vz[i]=sc.nextDouble();
					r[i]=sc.nextDouble();
					vr[i]=sc.nextDouble();
				}
				PriorityQueue<State> pq=new PriorityQueue<>();
				
				for(int i=0; i<n; i++) {
					if(vr[i]!=0) {
						time[i]=r[i]/vr[i];
					}
					else {
						time[i]=INF;
					}
				}
				
				for(int i=0; i<n; i++) {
					for(int j=i+1; j<n; j++) {
						double A=-Math.pow(vr[i]+vr[j], 2)+Math.pow(vx[i]-vx[j], 2)+Math.pow(vy[i]-vy[j], 2)+Math.pow(vz[i]-vz[j], 2);
						double B=2*((vr[i]+vr[j])*(r[i]+r[j])+(vx[j]-vx[i])*(px[j]-px[i])+(vy[j]-vy[i])*(py[j]-py[i])+(vz[j]-vz[i])*(pz[j]-pz[i]));
						double C=-Math.pow(r[i]+r[j], 2)+Math.pow(px[i]-px[j], 2)+Math.pow(py[i]-py[j], 2)+Math.pow(pz[i]-pz[j], 2);
						
						pq.add(new State(i, j, calc(A, B, C)));
						
					}
				}
				while(! pq.isEmpty()) {
					State state=pq.poll();
					if(time[state.n1]<state.timer || time[state.n2]<state.timer) {
						//消滅できない
						continue;
					}
					time[state.n1]=state.timer;
					time[state.n2]=state.timer;
				}
				for(int i=0; i<n; i++) {
					System.out.printf("%.12f\n", time[i]);
				}
			}
		}
	}
}


Measured memory_bytes: 121132
def main():
    temp=input()
    temp=list(map(int,list(temp.split(" "))))    
    a=int(temp[0])
    b=int(temp[1])
    c=a*b
    count=c-2*a-2*b+4
    if count<0:
        count*=-1
    print(count)


if __name__ == '__main__':
    main()


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

int main() {
  int n; cin >> n;
  int k; cin >> k;
  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }
  ll sum = 0;
  sort(h.begin(), h.end(), greater<int>());
  for (int i = k; i < n; i++) {
    sum += h.at(i);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  cin >> N;
  vector<string> V;
  set<string> S;
  rep(i, N) {
    string s;
    cin >> s;
    V.push_back(s);
    if (S.count(V[i]) != 0) {
      cout << "No" << endl;
      return 0;
    }
    S.insert(s);
  }

  rep(i, N) {
    if (i != 0 && V[i - 1][V[i - 1].size() - 1] != V[i][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

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

    vector<int> k(M);
    vector<vector<int>> s;
    vector<int> p(M);
    int switch_count = 0;
    int light_count = 0;
    int result_count = 0;

    for(int i = 0; i < M; i++) {
        cin >> k[i];
        vector<int> tmp(k[i]); 
        for(int j = 0; j < k[i]; j++) {
            cin >> tmp[j];
        }
        s.push_back(tmp);
    }

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

    for(int biti = 0; biti < (1<<N); biti++) {
        light_count = 0;

        for(int j = 0; j < M; j++) {
            switch_count = 0;

            for(int l : s[j]) {
                if(biti & (1<<(l-1))) {
                    switch_count++;
                }
            }

            if(switch_count % 2 == p[j]) {
                light_count++;
            }
        }

        if(light_count == M) {
            result_count++;
        }
    }

    cout << result_count << endl;
	return 0;
}

Measured memory_bytes: 3636
n,a,b,c=map(int,input().split())
l=[int(input()) for _ in range(n)]

def dfs(i,x,y,z):
  if i==n:
    return abs(x-a)+abs(y-b)+abs(z-c) if x*y*z else 10**9
  r1 = dfs(i+1,x+l[i],y,z)+ (10 if x>0 else 0)
  r2 = dfs(i+1,x,y+l[i],z)+ (10 if y>0 else 0)
  r3 = dfs(i+1,x,y,z+l[i])+ (10 if z>0 else 0)
  r4 = dfs(i+1,x,y,z)
  return min(r1,r2,r3,r4)

print(dfs(0,0,0,0))


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

int n, a, ans;

int main() {
  cin >> n;
  ans = 0;
  rep (i, n) {
    cin >> a;
    ans += a;
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}

int main() {
    
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    auto v = runlength(s);
    int ans = 0;
    rep(i, sz(v)) ans += v[i].S - 1;
    cout << min(n - 1, 2 * k + ans) << '\n';
}


Measured memory_bytes: 1656
import sys
from itertools import groupby

def resolve():
    input = sys.stdin.readline
    N=int(input())
    d= sorted(list(map(int, [input() for _ in range(N)])),reverse=True)
    a=[]
    for key, group in groupby(d):
        a.append(key)  
    print(len(a))
    
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
10
8
8
6"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
15
15
15"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """7
50
30
50
100
50
80
30"""
        output = """4"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 5888
n = int(input())
a = list(map(int, input().split()))
okane = 1000
kabu = 0
for i in range(n-1):
  if a[i] > a[i+1]:
    okane += kabu * a[i]
    kabu = 0
  elif a[i] < a[i+1]:
    kabu += okane // a[i]
    okane = okane % a[i]
r = okane + kabu * a[n-1]
print(r)

Measured memory_bytes: 9188
#include<stdio.h>
#include<string.h>
int main(void){
    int count=0;
    char W[12],end[12]="END_OF_TEXT";
    char T[1003]={'\0'};
    scanf("%s",W);
    while(1){
        scanf("%s",T);
        if(strcmp(T,end)==0){
            break;
        }
        for(int i=0;i<strlen(T);i++){
            if(T[i]>=65 && T[i]<=90){
                T[i]+=32;
            }
        }
        if(strcmp(T,W)==0){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2148
using System;
using System.Collections.Generic;
using System.Linq;

namespace CFBA
{
    static class MainClass
    {

        public static void Main(string[] args)
        {


            int N = int.Parse(Console.ReadLine());


            int ans = 0;


            for (int i = 0; i < 4; i++)
            {
                if (N % 10 == 2)
                {
                    ans++;
                }
                N = N / 10;
            }


            Console.WriteLine(ans);


        }


    }

}






Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define pb push_back
#define fi first
#define se second
#define FF first
#define SS second
#define INF 2e18;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()
typedef long double f80;

int x[105], y[105];

signed main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    fr(i, 1, n) {
        cin >> x[i] >> y[i];
    }
    f80 z = (2 * acos(-1))/1000000;
    ll ans = 0;
    for(int i = 0; i < 1000000; i++) {
        f80 x1 = cos(z * i), y1 = sin(z * i);
        int xx = 0, yy = 0;
        fr(j, 1, n) {
            if(x1 * x[j] + y1 * y[j] >= 0) {
                xx += x[j], yy += y[j];
            }
        }
        ans = max(ans, (ll)xx * xx + (ll)yy * yy);
    }
    cout << setprecision(20) << fixed << sqrtl(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;

int main(void){
    long N;
    cin >> N;
    vector<long> A, B, C;
    for(long j =0; j < N; j++){
        long tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    for(long j =0; j < N; j++){
        long tmp;
        cin >> tmp;
        B.push_back(tmp);
    }
    for(long j =0; j < N; j++){
        long tmp;
        cin >> tmp;
        C.push_back(tmp);
    }
    long sum = 0;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    for(long i =0; i < N; i++){
        long centor = B[i];
        long low =  (long)(lower_bound(A.begin(), A.end(), centor) - A.begin());
        long height = (long)( C.end() - upper_bound(C.begin(), C.end(), centor));
        sum += low*height;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int A, B;
    cin>>A>>B;
    int Amin, Amax, Bmin, Bmax;
    if(A%2==0){
        Amin=25*A/2;
        Amax=25*A/2+12;
    } else{
        Amin=25*(A+1)/2-12;
        Amax=25*(A+1)/2-1;
    }
    Bmin=10*B;
    Bmax=10*B+9;
    if(max(Amin, Bmin)>min(Amax, Bmax)) cout<<-1<<endl;
    else cout<<max(Amin, Bmin)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 49696
cus1 = [1 for i in range(1001)]
cus2 = [1 for i in range(1001)]
sum_ = dict(zip([i+1 for i in range(1000)],[0 for i in range(1000)]))
while(1):
    input_ = input()
    if input_ == "":
        break
    a,b = [int(i) for i in input_.split(",")]
    cus1[a] *= 0
    sum_[a] += 1
while(1):
    try:
        a,b = [int(i) for i in input().split(",")]
        cus2[a] *= 0
        sum_[a] += 1
    except EOFError:
        break
for i in range(1,1001):
    if cus1[i] + cus2[i] == 0:
        print(i,sum_[i])


Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, deque<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long solve() {
    long long N, X, M;
    cin >> N >> X >> M;

    map<long long, int> ma; // かつて来た地点を求める
    deque<long long> rireki, syu;
    long long sum = 0;
    for (int n = 0; n < N; ++n) {
        // かつて来た地点に戻ったら
        if (ma.count(X)) {
            int p = ma[X];
            for (long long i = p; i < n; ++i) syu.push_back(rireki[i]);
            break;
        }
        ma[X] = n;
        rireki.push_back(X);
        sum += X;

        X = (X * X) % M;
    }
    N -= rireki.size();

    // 戻る前に N 項目に到達した場合
    if (N == 0) return sum;

    // 周期の累積和をとる
    deque<long long> ruiseki(syu.size() + 1, 0);
    for (int i = 0; i < syu.size(); ++i) ruiseki[i+1] = ruiseki[i] + syu[i];

    // 周期を q 週して r あまる
    long long q = N / syu.size();
    long long r = N % syu.size();
    sum += ruiseki[syu.size()] * q + ruiseki[r];
    return sum;
}

int main() {
    cout << solve() << endl;
}

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

int  main()
{
	int n; cin >> n;
	vector <int> d(n);
	rep(i, n) cin >> d[i];
	int ans = 0;
	rep(i, n)
	{
		for (int j = i + 1; j < n; j++)
		{
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
	return (0);
}

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

int main(void)
{
    IOS
    int n; cin >> n;
    ll f00 = n / 500;
    n -= 500 * f00;
    ll f = n / 5;
    OUT(f00 * 1000 + f * 5)


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()

using namespace std;

int main(void){
    int a, b, c, x;
    int i,j,k;
    int cnt = 0;
    int sum = 0;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;

    for(i=0;i<=a;i++){
        for(j=0;j<=b;j++){
            for(k=0;k<=c;k++){
                sum = 500*i + 100*j + 50*k;
                if(sum==x) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;


}


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

int main(){
  string s;
  cin >> s;
  int a=0,b=0,n=s.size(),i;
  for(i=0; i<n; i++){
    if(s[i]=='0'){
      a++;
    }else{
      b++;
    }
  }
  cout << min(a,b)*2;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n;
	cin >> n;
	ll p = n;
	map<ll, ll> mp;
	repl(i, 2, (ll)sqrt(n) + 1) {
		while (p % i == 0) {
			p /= i;
			mp[i]++;
		}
	}
	if (p != 1) mp[p]++;
	vector<ll> a(2000000);
	rep(i, 2000000) a[i] = i * (i + 1) / 2;
	ll ans = 0;
	for (auto m : mp) ans += upper_bound(all(a), m.second) - a.begin() - 1;
	;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18780
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 500000000
#define mod 1000000007
#define INF2 1000000000000000000

int d[210][210];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, R;
    cin >> N >> M >> R;
    rep(i, N) rep(j, N) d[i][j] = INF;
    rep(i, N) d[i][i] = 0;
    int r[10];
    rep(i, R) cin >> r[i];
    rep(i, R) r[i]--;
    sort(r, r + R);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ll ans = INF;
    do{
        ll tmp = 0;
        rep(i, R - 1) {
            tmp += d[r[i]][r[i + 1]];
            //cout << r[i] << " " << r[i + 1] << "->" << d[r[i]][r[i + 1]] << endl;
        }
       // cout << tmp << endl;
        ans = min(ans, tmp);
    }while(next_permutation(r, r + R));
    cout << ans << endl;


    return 0;
}


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

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

    int n = s.size();
    bool flag1 = true;
    bool flag2 = true;
    bool flag3 = true;

    for(int i=0;i<((n-1)/2);i++){
        if(s[i] != s[n-i-1]){
            flag1 = false;
            break;
        }
    }

    for(int i=0;i<((n-1)/4);i++){
        if(s[i] != s[(n-1)/2-i-1]){
            flag2 = false;
            break;
        }
    }

    for(int i=(n+3)/2-1;i<3*n/4+1/4;i++){
        if(s[i] != s[n-i-1]){
            flag3 = false;
            break;
        }
    }

    if(flag1&&flag2&&flag3){
        cout <<"Yes"<< endl;
    }else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 256
# ABC164_B.py
a,b,c,d=map(int,input().split())
for i in range(300):

  if i%2==0:
    c-=b
  else:
    a-=d
  if a<=0:
    print("No")
    exit(0)
  elif c<=0:
    print("Yes")
    exit(0)

Measured memory_bytes: 9124
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner io = new Scanner(System.in);
		int N = io.nextInt();
		int A = io.nextInt();
		int B = io.nextInt();
		long C = io.nextLong();
		long D = io.nextLong();
		
		for(int k=0;k<=N-1;k++){
			long max = D*k - C *(N-1-k);
			long min = C*k - D *(N-1-k);
			if(B-A>=min && B-A<=max){
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 23764
// https://atcoder.jp/contests/abc079/tasks/abc079_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int t, s;
string l, r;
int main()
{
  cin >> l;
  REP(i, 8)
  {
    t = l[0] - '0';
    r = l[0];
    REP(j, 3)
    {
      char c = l[j + 1];
      if (i >> j & 1)
      {
        t += c - '0';
        r += '+';
      }
      else
      {
        t -= c - '0';
        r += '-';
      }
      r += c;
    }
    if (t == 7)
      break;
  }
  cout << r << "=7" << '\n';

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    H, W = readi(2)
    G = readi(10, 10)
    for k in range(10):
        for i in range(10):
            for j in range(10):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

    ans = 0
    for a in chain.from_iterable(readi(H, W)):
        if a != -1:
            ans += G[a][1]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3960
import fractions
n,m=map(int,input().split())
s=input()
t=input()
l=n*m//fractions.gcd(n,m)
p=l//n*l//m//fractions.gcd(l//n,l//m)
ss,tt="",""
for i in range(l//p):
  ss+=s[i*p*n//l]
  tt+=t[i*p*m//l]
print(l if ss==tt else -1)

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

using namespace std;

const int MAX_N = 2000;
int n;
int next1[MAX_N];
int prev1[MAX_N];
string a, b;


int main()
{
  cin >> a >> b;
  n = a.length();

  bool same = true;
  int first1 = -1, last1;
  for (int i = 0; i < n; i++) {
    same &= a[i] == b[i];
    if (b[i] == '1') {
      last1 = i;
      if (first1 < 0) first1 = i;
    }
  }

  if (same) {
    cout << 0 << endl;
    return 0;
  }

  if (first1 < 0) {
    cout << -1 << endl;
    return 0;
  }

  int prev = last1;
  for (int i = 0; i < n; i++) {
    prev = b[i] == '1' ? i : prev;
    prev1[i] = prev <= i ? i - prev : n - prev + i;
  }

  int next = first1;
  for (int i = n-1; i >= 0; i--) {
    next = b[i] == '1' ? i : next;
    next1[i] = next >= i ? next - i : next + n - i;
  }

  int result = INT_MAX;
  for (int d = -n; d <= n; d++) {
    //cout << "[" << d << "]" << endl;
    int flip = 0;
    vector<pair<int, int> > xy;
    for (int i = 0; i < n; i++) {
      if (a[i] == b[(i+d+n)%n]) continue;
      flip++;
      if (d >= 0) {
        if (next1[i] <= d) continue;
        xy.push_back(make_pair(prev1[i], next1[(i+d)%n]));
      } else {
        if (prev1[i] <= -d) continue;
        xy.push_back(make_pair(next1[i], prev1[(i+d+n)%n]));
      }
      //cout << i << ": " << xy.back().first << ", " << xy.back().second << endl;
    }

    sort(xy.begin(), xy.end());

    //cout << "flip: " << flip << endl;
    int max_y = 0;
    for (int i = xy.size()-1; i >= 0; i--) {
      result = min(result, 2*(xy[i].first + max_y) + abs(d) + flip);
      max_y = max(max_y, xy[i].second);
    }
    result = min(result, 2*max_y + abs(d) + flip);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
string s;
int main()
{
	cin>>s;
	long long ans=0;
	for (int i=0;i<(1<<(s.size()-1));i++){
		long long num=s[0]-'0';
		for (int j=0;j<s.size()-1;j++){
			if (i&(1<<j)){
				ans+=num;
				num=0;
			}
			num=num*10+s[j+1]-'0';
		}
		ans+=num;
	}
	cout<<ans<<endl;
	return 0;
}

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

int judge(int a[], int n, int c) {
	int max, maxp, semimax;
	max = a[0];
	maxp = 0;
	for (int i = 1; i < 26; i++)
		if (a[i] > max) {
			max = a[i];
			maxp = i;
		}
	
	if (maxp == 0) semimax = a[1];
	else semimax = a[0];
	for (int i = 1; i < 26; i++)
		if (a[i] > semimax && maxp != i)
			semimax = a[i];
	
	if (max - semimax > n - c) return maxp;
	else return 26;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		int count[26] = {0};
		char data[n];
		for (int i = 0; i < n; i++)
			cin >> data[i];
		for (int i = 0; i < n; i++) {
			char t = data[i];
			count[t - 'A']++;
			
			char u = judge(count, n, i + 1);
			if (u != 26) {
				char v = u + 'A';
				cout << v << ' ' << i + 1 << endl;
				break;
			} else {
				if (i == n - 1) {
					cout << "TIE\n";
				}
			}
		}
	}
}

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

int main() {
  vector<int> score;
  int N;
  int ret[2] = {0,0};
  
  cin >> N;
  score = vector<int>(N);
  for (int i=0;i<N;i++) cin >> score.at(i);
  
  sort(score.begin(), score.end());
  reverse(score.begin(), score.end());
  
  for (int i=0;i<N;i++) ret[i%2] += score.at(i);
  
  cout << ret[0] - ret[1] << endl;
}


Measured memory_bytes: 256
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

ll solve(){ 
    ll n; cin>>n;
    set<string> s;
    lp(i,0,n){
        string a; cin>>a;
        s.insert(a);
    }
    cout<<sz(s);
    return 0;
}   

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

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())

const ll inf = 1 << 25;
const ll mod = 1e9 + 7;

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

int main() {
    int N, K;
    cin >> N >> K;
    
    vector<int> l(N, 0);
    rep(i, N) cin >> l[i];
    
    int ans = 0;
    sort(l.rbegin(), l.rend());
    rep(i, K) ans += l[i];
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<cstdlib>
#include<iostream>
#include<bitset>
#include<functional>
using namespace std;
/*********************************************************************************************/
inline int read(){int x=0;bool fg=0;char ch=getchar();while(ch<'0'||'9'<ch)fg|=ch=='-',       //
ch=getchar();while('0'<=ch&&ch<='9')x=x*10+ch-'0',ch=getchar();return fg?-x:x;}               //
inline long long readll(){long long x=0;bool fg=0;char ch=getchar();while(ch<'0'||'9'<ch)     //
fg|=ch=='-',ch=getchar();while('0'<=ch&&ch<='9')x=x*10+ch-'0',ch=getchar();return fg?-x:x;}   //
inline void Out(int x){if(x<0)x=-x,putchar('-');if(x>9)Out(x/10);putchar(x%10+'0');}          //
inline void Outll(long long x){if(x<0)x=-x,putchar('-');if(x>9)Outll(x/10);putchar(x%10+'0');}//
inline double readdb(){double Dec=0.1,num;bool IsN=false,IsD=false;char ch=getchar();         //
while(ch!='-'&&ch!='.'&&(ch<'0'||ch>'9'))ch=getchar();if(ch=='-')IsN=true,num=0;              //
else if(ch=='.')IsD=true,num=0;else num=ch-'0';if(!IsD){while(ch=getchar(),ch>='0'&&ch<='9')  //
num=num*10+ch-'0';}if(ch=='.'){while(ch=getchar(),ch>='0'&&ch<='9')num+=Dec*(ch-'0'),Dec*=0.1;//
}return IsN?-num:num;}                                                                        //
/*********************************************************************************************/
#define out(x) Out(x),putchar('\n')
#define outll(x) Outll(x),putchar('\n')
#define ll long long
#define eps 1e-10
#define E exp(1)
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1)
#define mem0(x) memset(x,0,sizeof(x))
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define ui unsigned int
#define ull unsigned long long
/***************************************/
const int MOD=1e9+7;
const int maxn=5e5+3;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

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

  vector<int> c(n+1);

  c[0] = 3;

  mint ans = 1;

  rep(i, n) {
    int num = a[i];
    if (c[num] == 0) {
      puts("0");
      return 0;
    }
    ans *= c[num];
    c[num]--;
    c[num+1]++;
  }

  cout << ans.x << endl;

  return 0;
}


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

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 400 + 5, kM = 1e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, m, ans = 0, u[kM], v[kM]; bool flag[kN];
std::bitset <kN> S[kN];

int main() { 
	int T = 1; //rd(T);
	while(T--) {
		rd(n, m);
		for(int i = 1; i <= m; ++i) rd(u[i], v[i]);
		for(int i = 1; i <= n; ++i) S[i][i] = 1;
		for(int i = m; i; --i) {
			for(int j = 1; j <= n; ++j) {
				if(S[j][u[i]] && S[j][v[i]]) flag[j] = true;
				else if(S[j][u[i]] || S[j][v[i]]) S[j][u[i]] = S[j][v[i]] = true;
			}
		}
		for(int i = 1; i <= n; ++i)
			for(int j = i + 1; j <= n; ++j)
				if(!flag[i] && !flag[j] && (S[i] & S[j]).none())
					++ans;
		printf("%d\n", ans);
	} return 0;
}


Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  cin>>n;
  vector<int> v;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    v.push_back(x);
  }
  cin>>q;
  vector<int>::iterator it;
  for(int i=0;i<q;i++){
    int a;
    cin>>a;
    it=lower_bound(v.begin(),v.end(),a);
    cout<<(it-v.begin())<<endl;
  }
  return 0;
}



Measured memory_bytes: 3508
import heapq
from collections import deque

WHITE = 0
GRAY = 1
BLACK = 2

n = int(raw_input())
M = [ [] for _ in xrange(n)]
color = [WHITE] * n
d = [float('inf')] * n

for i in xrange(n):
    a = map(int, raw_input().split())
    for j in xrange(a[1]):
        M[a[0]].append((a[2*(j+1)],a[2*(j+1)+1]))

def dijkstra():
    d[0] = 0

    PQ = []
    heapq.heappush(PQ,(0,0))#value, node
    
    color[0] = GRAY

    while len(PQ) > 0:
        f = heapq.heappop(PQ)
        u = f[1]
        color[u] = BLACK

        if d[u] < f[0]:
            continue

        for j in xrange(len(M[u])):
            v = M[u][j][0]
            if color[v] == BLACK:
                continue
            if d[v] > d[u] + M[u][j][1]:
                d[v] = d[u] + M[u][j][1]
                heapq.heappush(PQ, (d[v],v))
                color[v] = GRAY

    for i in xrange(n):
        print "{} {}".format(i, d[i])

    return 0

def main():
    dijkstra()
    return 0

main()

Measured memory_bytes: 66384
#include<stdio.h>

int main()
{
	int a,b,c,t;
	scanf("%d%d%d", &a,&b,&c);
	t=a;
	a=b;
	b=t;
	
	t=a;
	a=c;
	c=t;
	printf("%d %d %d", a,b,c);
}

Measured memory_bytes: 128
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

class Pair {
	private int numA;
	private int numB;

	public Pair(int numA, int numB) {
		this.numA = numA;
		this.numB = numB;
	}

	public int getNumA() {
		return numA;
	}

	public void setNumA(int numA) {
		this.numA = numA;
	}

	public int getNumB() {
		return numB;
	}

	public void setNumB(int numB) {
		this.numB = numB;
	}

	public static Function<Pair, Pair> getResultScore = p -> {
		if (p.numA > p.numB) {
			p.numA += p.numB;
			p.numB = 0;
		}
		if (p.numA < p.numB) {
			p.numB += p.numA;
			p.numA = 0;
		}
		return p;
	};
}

public class Main {
	public static void main(String[] args) {
		solve0500();
	}

	public static void solve0500() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			if (0 == n) {
				break;
			}

			Set<Pair> datasets = new HashSet<Pair>();
			for (int i = 0; i < n; i++) {
				datasets.add(new Pair(sc.nextInt(), sc.nextInt()));
			}
			datasets = datasets.stream().map(Pair.getResultScore).collect(Collectors.toSet());
			System.out.println(datasets.stream().mapToInt(p -> p.getNumA()).sum() + " "
					+ datasets.stream().mapToInt(p -> p.getNumB()).sum());
		}

		sc.close();
	}

}



Measured memory_bytes: 62852
"use strict";
function Main (input) {
    const str = input.slice(0, 10);
    let res = Infinity;
    for(let i=0; i < str.length - 2; i++) {
        const num = parseInt(input.slice(i, i+3), 10);
        if (Math.abs(753 - res) > Math.abs(753 - num)) {
            res = num;
        }
    }
    console.log(Math.abs(753 - res));
}

//標準入力から文字列を受け取ってMain関数を実行
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()){
			int candyCount = stdIn.nextInt();
			while(candyCount > 39){
				candyCount -= 39;
			}
			System.out.println(String.format("3C%1$02d",candyCount));
		}
	}
}

Measured memory_bytes: 11000
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
const ll Maxn=1e5;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
map<pair<int,int>,int>q;
int x[60],y[60];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
    cin>>x[i]>>y[i];
int Max=0;
for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    if(i!=j)
{
    q[make_pair(x[i]-x[j],y[i]-y[j])]++;
  Max=max(Max,q[make_pair(x[i]-x[j],y[i]-y[j])]);
}
cout<<n-Max<<endl;
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline
N,X = [int(i) for i in input().split()]
m = [0] * N
msum = 0
for i in range(N) :
    m[i] = int(input())
for i in range(N) :
    msum+= m[i]
X -= msum
count = N
m.sort()
while X > 0 :
    X -= m[0]
    count+=1
if X == 0 :
    print(count)
else :
    print(count-1)

Measured memory_bytes: 3064
N, X = map(int, input().split())

# List = list([map(int, input().split())] for _ in range(N))
# List = [list(map(int, input().split())) for _ in range(N)]
List = list(map(int, input().split()))
# print(List)

ans = 1
sum_x = 0
for i in range(N):
    if(sum_x + List[i] <= X):
        # print(List[i])
        sum_x += List[i]
        ans += 1
    else:
        break
# print(sum_x)
print(ans)



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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int a=0,b=0,c=0,m=0,n=0,h=0,w=0,count=0,ans=1;
  string s;
  cin>>n;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans=ans%1000000007;
  }
  cout<<ans<<endl;
}
///////////////////////////

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    int x,y,a,b,c;scanf("%d %d %d %d %d",&x,&y,&a,&b,&c);
    int p[200000];for(int i=0;i<a;i++)scanf("%d",&p[i]);
    int q[200000];for(int i=0;i<b;i++)scanf("%d",&q[i]);
    int r[200000];for(int i=0;i<c;i++)scanf("%d",&r[i]);

    qsort(p,a,sizeof(int),asc_cmp);
    qsort(q,b,sizeof(int),asc_cmp);
    qsort(r,c,sizeof(int),asc_cmp);

    for(int i=a-x,j=b-y,k=c-1;k>=0;){
        if(i==a&&j!=b){
            if(q[j]<r[k])q[j++]=r[k--];
            else break;
        }else if(i!=a&&j==b){
            if(p[i]<r[k])p[i++]=r[k--];
            else break;
        }else{
            if(p[i]<q[j]){
                if(p[i]<r[k])p[i++]=r[k--];
                else break;
            }else{
                if(q[j]<r[k])q[j++]=r[k--];
                else break;
            }
        }
        
    }
    ll ans=0;
    for(int i=a-x;i<a;i++){
        //printf("%d ",p[i]);
        ans+=p[i];
    }
    for(int j=b-y;j<b;j++){
        //printf("%d ",q[j]);
        ans+=q[j];
    }
    printf("%lld\n",ans);

}

Measured memory_bytes: 2684
#include <iostream>
using namespace std;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

int main(){
	int m,d;
	int count=0;
	cin>>m>>d;
	if(d<m){
		cout<<m-1<<endl;
	}else{
		cout<<m<<endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            if(op.equals("+")){
                System.out.println(a + b);
            }
            if(op.equals("-")){
                System.out.println(a - b);
            }
            if(op.equals("*")){
                System.out.println(a * b);
            }
            if(op.equals("/")){
                System.out.println(a / b);
            }
            if(op.equals("?")){
                break;
            }
        }
    }
}


Measured memory_bytes: 26112