akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = a; i < n; ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

class HopcroftKarp {

    void bfs() {
        const int n = g.size();
        dist.assign(n, -1);
        queue<int> que;
        for (int i = 0; i < n; ++i) {
            if (used[i]) continue;
            que.emplace(i);
            dist[i] = 0;
        }
        
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int& u : g[v]) {
                int w = match[u];
                if (w >= 0 && dist[w] == -1) {
                    dist[w] = dist[v] + 1;
                    que.emplace(w);
                }
            }
        }
    }

    bool dfs(int v) {
        vv[v] = true;
        for (auto& u : g[v]) {
            int w = match[u];
            if (w < 0 || (!vv[w] && dist[w] == dist[v] + 1 && dfs(w))) {
                match[u] = v;
                used[v] = true;
                return true;
            }
        }
        return false;
    }
    
public:
    vector<vector<int>> g;
    vector<int> dist, match;
    vector<bool> used, vv;

    HopcroftKarp(int n, int m) : g(n), match(m, -1), used(n) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
    }

    int bipartite_matching() {
        const int n = g.size();
        int res = 0;
        while (true) {
            bfs();
            vv.assign(n, false);
            int flow = 0;
            for (int i = 0; i < n; ++i) {
                if (!used[i] && dfs(i)) ++flow;
            }
            if (!flow) break;
            res += flow;
        }
        return res;
    }
};

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

    int X, Y, E;
    cin >> X >> Y >> E;
    HopcroftKarp hk(X, Y);
    REP(i, E) {
        int x, y;
        cin >> x >> y;
        hk.add_edge(x, y);
    }
    cout << hk.bipartite_matching() << endl;
}


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

int main() {
  int a;
  int b;
  int c;
  int d;

  cin >> a >> b >> c >> d;

  string s;

  if (a + b > c + d)
    s = "Left";
  else if (a + b == c + d)
    s = "Balanced";
  else
    s = "Right";

  cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main() 
{
 int n,i,x,m; 
 scanf("%d %d",&n,&x); 
 int min = 1001; 
 for (i = 0; i < n; i++)
 { 
   scanf("%d", &m); 
   x -= m;
   min = (m < min ? m : min); 
 }
   printf("%d",n + (x / min));
 return 0;
}

    
    

 

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N; cin >> N;
	vector<string> s(N);
	map<string, int> m;

	REP(i,N){
		string a; cin >> a;
		SORT(a);
		s[i] = a;
		m[a]++;
	}


	ll ans = 0;

	for(auto itr = m.begin(); itr != m.end(); ++itr) {
		ll d = itr->second;
		ans += (d*(d-1))/2;
	}

	cout << ans << endl;

	return 0;

}


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

int main(){
  int N;
  cin >> N;
  
  set<string> S;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    S.insert(s);
  }
  
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 19256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

//  if(s[0] == ss[0]) ans++;
//  else anss = "red";

  cout << a*a*a << endl;

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long MAX_N = 200005;

int main()
{
    // スペース区切りの整数の入力
    long long K,N;
    cin >> K >> N;


    long long a[MAX_N];
    long long b[MAX_N];
    cin >> a[0];
    for (long long i = 1; i < N; i++)
    {
        cin >> a[i];
        b[i-1] = a[i] - a[i-1];
    }
    b[N-1] = K - a[N-1] + a[0];


    long long c=0;

    for (long long i = 0; i < N; ++i) {
        if (c < b[i])
        {
            c = b[i];
        }
    }

    //sort(b,b+MAX_N);

    cout << K - c << endl;


    return 0;
}

Measured memory_bytes: 3328
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
tmp = 999999999
ans = 0
for i in range(N):
  if abs(A - T + H[i]*0.006) < tmp:
    tmp = abs(A - T + H[i]*0.006)
    ans = i+1
  else:
    pass
print(ans)


Measured memory_bytes: 3060
a = [[[0 for room in range(10)] for floor in range(3)] for building in range(4)]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().strip().split())
    a[b - 1][f - 1][r - 1] += v
for b in range(4):
    for f in range(3):
        print(''.join(' {}'.format(a[b][f][r])for r in range(10)))
    if b < 3:
        print("#" * 20)

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

vector<int> sieve_of_eratosthenes(int n) {
  vector<int> primes(n);
  for (int i = 2; i < n; ++i)
    primes[i] = i;
  for (int i = 2; i*i < n; ++i)
    if (primes[i])
      for (int j = i*i; j < n; j+=i)
        primes[j] = 0;
  return primes;
}

void solve(long long N){
  vector<int> primes = sieve_of_eratosthenes(1000);
  vector<int> factors;
  long long a = 1;
  long long ans = 1;
  for ( long long i = 1; i <= N; i++ ) {
    long long z = i;
    for ( long long j = 2; j <=i; j++ ) {
      while ( z > 1 ) {
        if ( z % j == 0 && primes[j] == j ) {
          z /= j; factors.push_back(j);
        } else {
          break;
        }
      }
    }
  }
  sort(factors.begin(), factors.end());
  int memo[1001] = {0};
  for ( long long i = 1; i <= factors.size(); i++ ) {
    memo[factors[i-1]]++;
  }
  for ( int i = 0; i <= 1000; i++ ) {
    ans = (ans * (memo[i]+1)) % 1000000007;
  }
  cout << ans << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        BigDecimal a = sc.nextBigDecimal();
        BigDecimal b = sc.nextBigDecimal();
        sc.close();

        a = a.multiply(b).setScale(0, BigDecimal.ROUND_DOWN);
        System.out.println(a.toPlainString());
    }
}


Measured memory_bytes: 37504
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define lint __int128
#define vi vector<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    string t ; cin >> t ;
    lp(i, 0, t.size() - 1) if(t[i] == '?') t[i] = 'D' ;
    cout << t << endl ;
}


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

using namespace std;

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






	



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main() {

	string S,T;
	cin>>S>>T;
	S=S+S;
	bool flag=false;
	for(int i=0;i<S.size();i++){
		if(S.substr(i+1,T.size())==T){
			flag=true;
			break;
		}
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) a.push_back(a[i] + k);

    int ans = INF;
    
    for (int i = 0, j = n - 1; j < a.size(); i++, j++) {
        ans = min(ans, a[j] - a[i]);
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{
		int sx = nextInt();
		int sy = nextInt();
		int tx = nextInt();
		int ty = nextInt();

		int u=ty-sy;
		int r=tx-sx;
		for(int i=0;i<u;i++){
			System.out.print("U");
		}
		for(int i=0;i<r;i++){
			System.out.print("R");
		}
		for(int i=0;i<u;i++){
			System.out.print("D");
		}
		r++;
		for(int i=0;i<r;i++){
			System.out.print("L");
		}
		u++;
		for(int i=0;i<u;i++){
			System.out.print("U");
		}
		for(int i=0;i<r;i++){
			System.out.print("R");
		}
		System.out.print("D");
		System.out.print("R");
		for(int i=0;i<u;i++){
			System.out.print("D");
		}
		for(int i=0;i<r;i++){
			System.out.print("L");
		}
		System.out.println("U");


	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 24916
#include <iostream>

using namespace std;

class dice {
public:
    int face[6];
    void rotate(char dir) {
        int temp;
        switch (dir) {
        case 'N':
            temp = face[0];
            face[0] = face[1];
            face[1] = face[5];
            face[5] = face[4];
            face[4] = temp;
            break;
        case 'E':
            temp = face[0];
            face[0] = face[3];
            face[3] = face[5];
            face[5] = face[2];
            face[2] = temp;
            break;
        case 'W':
            temp = face[0];
            face[0] = face[2];
            face[2] = face[5];
            face[5] = face[3];
            face[3] = temp;
            break;
        case 'S':
            temp = face[0];
            face[0] = face[4];
            face[4] = face[5];
            face[5] = face[1];
            face[1] = temp;
            break;
        }
    }
};

int main()
{
    ios::sync_with_stdio(false);
    dice d;
    for (int i=0; i<6; i++) {
        cin >> d.face[i];
    }
    char dir;
    while (cin >> dir)d.rotate(dir);
    cout<<d.face[0]<<'\n';
    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    set<string> key;
    for(int i = 1; i < s.size(); ++i) {
      string a = s.substr(0, i);
      string b = s.substr(i, s.size() - i);
      for(int rev = 0; rev < 2; ++rev) {
        for(int a_rev = 0; a_rev < 2; ++a_rev) {
          for(int b_rev = 0; b_rev < 2; ++b_rev) {
            string res;
            if(a_rev) reverse(a.begin(), a.end());
            if(b_rev) reverse(b.begin(), b.end());
            if(rev) res = b + a;
            else res = a + b;
            key.insert(res);
            if(a_rev) reverse(a.begin(), a.end());
            if(b_rev) reverse(b.begin(), b.end());
          }
        }
      }
    }
    cout << key.size() << endl;
  }
  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

using namespace std;

int main(){
	int n, k;	cin >> n >> k;
	long long int a[n];
	for( int i = 0; i < n; i++ ){
		cin >> a[i];
	}

	for( int i = k; i < n; i++ ){
		if( a[i] > a[i-k] )	cout << "Yes" << endl;
		else	cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  Sort(P);
  rep(i,0,N-2)rep(j,i+1,N-1)rep(k,j+1,N)if(P[i]+P[j]-P[k]>0)sum++;
  Out(sum);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int r = scan.nextInt();
		int c = scan.nextInt();
		scan.nextLine();

		int[][] arr = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = scan.nextInt();
				arr[i][c] += arr[i][j];
				arr[r][j] += arr[i][j];
				arr[r][c] += arr[i][j];
			}
			scan.nextLine();
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				System.out.print(arr[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}

		scan.close();
	}
}



Measured memory_bytes: 46620
def d_Unbalanced(S):
    for i in range(0, len(S) - 2):
        cond1 = S[i] == S[i + 1]  # XXと文字が並んでいる
        cond2 = S[i] == S[i + 2]  # XYXと文字が並んでいる
        # cond1かcond2が成り立てば、それを満たす文字列をアンバランスなものとして出せばいい
        # 全部調べても成り立たなければ、アンバランスな文字列はない
        if cond1:
            return '{} {}'.format(i + 1, i + 2)
        elif cond2:
            return '{} {}'.format(i + 1, i + 3)
        else:
            continue
    # 上のfor文では最後の2文字が等しいかチェックできていないので、最後にチェック
    if S[-2] == S[-1]:
        return '{} {}'.format(len(S) - 1, len(S))
    # アンバランスな文字列はなかった
    return '-1 -1'

S = input().strip()
print(d_Unbalanced(S))

Measured memory_bytes: 3188
import math

class KochCurve:
    def koch(self, d, p1, p2): 
        if d == 0:
            return
        th = math.pi * 60.0 / 180.0
        sx = (2.0 * p1[0] + 1.0 * p2[0]) / 3
        sy = (2.0 * p1[1] + 1.0 * p2[1]) / 3
        s = [sx, sy]
        tx = (1.0 * p1[0] + 2.0 * p2[0]) / 3
        ty = (1.0 * p1[1] + 2.0 * p2[1]) / 3
        t = [tx, ty]
        ux = (tx - sx) * math.cos(th) - (ty - sy) * math.sin(th) + sx
        uy = (tx - sx) * math.sin(th) + (ty - sy) * math.cos(th) + sy
        u = [ux, uy]
        
        self.koch(d-1, p1, s)
        print("{} {}".format(sx, sy))
        
        self.koch(d-1, s, u)
        print("{} {}".format(ux, uy))

        self.koch(d-1, u, t)
        print("{} {}".format(tx, ty))
        
        self.koch(d-1, t, p2)

if __name__ == '__main__':
    n = int(input().rstrip())
    p1 = [0, 0]
    p2 = [100, 0]
    print("{} {}".format(p1[0], p1[1]))
    x = KochCurve()
    x.koch(n, p1, p2)
    print("{} {}".format(p2[0], p2[1]))

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    bool y = false;
    while (N > 0) {
        if (N % 10 == 7)
            y = true;
        N /= 10;
    }

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

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<map>

using namespace std;

struct Memo
{

  int count;
  bool flag;

  Memo()
  {
    count = 0;
    flag = false;
  }

};

Memo memo[31][4];

int ProgressNumberOfYears(int step_num, int step_kind)
{

  int kind_count = 0;


  if(step_num == 0) return 1;
  else if(step_num < 0)  return 0;
  else if(memo[step_num][step_kind].flag)  return memo[step_num][step_kind].count;
  for(int i = 1; i < 4; ++i) kind_count = kind_count + ProgressNumberOfYears(step_num - i,i);


  memo[step_num][step_kind].count = kind_count;
  memo[step_num][step_kind].flag = true;

  return kind_count;

}

int main()
{

  int step_num;

  while(cin >> step_num && step_num != 0) cout << ProgressNumberOfYears(step_num,0)/10/365 + 1<< endl;

  return 0;

}

Measured memory_bytes: 1160
from collections import deque
import numpy as np

N, Q = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N-1)]
P = [list(map(int, input().split())) for _ in range(Q)]

link = [[] for _ in range(N)]
for i in range(N-1):
    link[A[i][0]-1].append(A[i][1]-1)
    link[A[i][1]-1].append(A[i][0]-1)


ans = [0 for _ in range(N)]
for i in range(Q):
  ans[P[i][0] - 1] += P[i][1]

dist = [-1 for _ in range(N)]
dist[0] = 0
d = deque([0])
while d:
    now = d.pop()
    for i in range(len(link[now])):
        if dist[link[now][i]] == -1:
            ans[link[now][i]] += ans[now]
            dist[link[now][i]] = 0
            d.append(link[now][i])

for i in range(N):
    if i != N - 1:
        print(ans[i], end=" ")
    else:
        print(ans[i])


Measured memory_bytes: 143656
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long double ll;
struct node {
	ll x, y;
friend bool operator <(node a, node b) {
	return atan2(a.x, a.y) > atan2(b.x, b.y);
}

}r[1234567];


int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r[i].x >> r[i].y;
	}
	sort(r, r + n);
	ll x, y, ans = 0;
	for (int i = 0; i < n; i++) {
		x = r[i].x; y = r[i].y;
		ans = max(ans, r[i].x * r[i].x + r[i].y * r[i].y);
		for (int j = (i + 1) % n; j != i; j = (j+1)%n) {
			x += r[j].x; y += r[j].y;
			ans = max(ans, x * x + y * y);
		}
	
	}
	cout << fixed << setprecision(30) << ((long double)sqrt(ans)) << '\n';
	return 0;
}



Measured memory_bytes: 256
function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines.shift());
  const A = lines.shift().split(' ').map(x => parseInt(x)).sort((l, r)=>l-r);

//  console.log(N);
//  console.log(A);

  var current=A[0];
  var count=1;
  var result=0;
  for(var i=1;i<=A.length;i++){
    if(A[i-1]==A[i]){
      count++;
    }else{
      var diff=count-current;
      if(diff<0){diff+=current;}
      result+=diff
      current=A[i];
      count=1;
    }
  }

  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28332
#include <stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = 0;
    int min = 10001;
    int middle = 0;
    
    if(a > max) max = a;
    if(b > max) max = b;
    if(c > max) max = c;

    if(a < min) min = a;
    if(b < min) min = b;
    if(c < min) min = c;
    
    middle = (a+b+c) - max - min;

    printf("%d %d %d\n", min, middle, max);
}


Measured memory_bytes: 2696
#include <stdio.h>
#define MAX 100000
 
int Partition(int*, int, int);
 
int main(){
  int i, n, x;
  int A[MAX];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
   
  x = Partition(A,0,n-1);
 
  for(i=0;i<n-1;i++){
    if(x == i){
      printf("[%d] ",A[i]);
      continue;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
   
  return 0;
}
 
int Partition(int *A, int p, int r){
  int x, i, j;
  int tmp;
   
  x = A[r];
  i = p - 1;
 
  for(j=p;j<r;j++){
    if(A[j]<= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
   
  return i+1;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
using namespace std;
typedef pair<int, int> pii;
const ll mod = 998244353;
const int sz = 2 * 1e6 + 10, inf = 1e9 + 10;

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


	int n;
	cin >> n;
	ll s = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i%3!=0 && i%5!=0)s+=i;
	}
	cout << s << '\n';

	return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  int an[n];
  int sm=0;
  rep(i,n) {
    cin >> an[i];
    sm += an[i];
  }
  sort(an, an+n);
  reverse(an, an+n);
  if (an[m-1] * 4 * m < sm) cout << "No";
  else cout <<"Yes";
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	int zh(string x);
	int s;
	s1+=s2;
	s=zh(s1);
	if(int(sqrt(s))==sqrt(s))
		cout<<"Yes";
	else
		cout<<"No";
}
int zh(string x){
	int s=0,i;
	for(i=0;i<x.size();i++) s=s*10+(x[i]-'0');
	return s;
}

Measured memory_bytes: 256
N=int(input())
count=0
for i in range(1,10):
     if N/i==1:
         count=count+1
     elif N/i==2:
         count=count+1
     elif N/i==3:
         count=count+1
     elif N/i==4:
         count=count+1
     elif N/i==5:
         count=count+1
     elif N/i==6:
         count=count+1
     elif N/i==7:
         count=count+1
     elif N/i==8:
         count=count+1
     elif N/i==9:
         count=count+1
     else:
         count=count
if count==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9216
//遷移を手で全部書いたりすると、イヤーなことになる。遷移の仕方だけかいて、あとは自動で何とかしてもらおう。→探索！！
//dfsしていれば勝手に辞書順になる。
#include<iostream>
using namespace std;

int y, j;
char s[100];

void dfs( int a, int b, char *s, int dep=0) {
	if (a == y && b == j) {
		for( int i = 0; i < y+j; i++ ) {
			cout << s[i];
		}
		cout << endl;
		return;
	}
	if (min(a, b) <= 3 && max(a, b) >= 5)
		return;
	if (a == 5 && b == 5)
		return;
	if (max(a, b) >= 6)
		return;
	s[dep] = 'A';
	dfs(a+1, b, s, dep+1);
	s[dep] = 'B';
	dfs(a, b+1, s, dep+1);
}

int main() {
	cin >> y >> j;
	dfs(0, 0, s);
	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>

int min(int n, int m)
{
    return n < m ? n : m;
}
int main()
{
    int t1, t2, b1, b2;
    scanf("%d %d %d %d", &t1, &t2, &b1, &b2);
    printf("%d", min(t1, t2) + min(b1, b2));
    return 0;
}

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

int n, w[1010], a[1010], b[10010] = {}, mi=100000;
bool used[1010];

//sorting
int partition(int *A, int p, int r){
  int x = A[r];
  int i = p - 1;
    for(int j = p;j < r;j++){
      if(A[j] <= x){
        i++;
        swap(A[i], A[j]);
      }
    }
    swap(A[i + 1], A[r]);
  return i + 1;
}

void quicksort(int *A, int p, int r){
  if(p < r){
    int q = partition(A, p, r);
    quicksort(A, p, q - 1);
    quicksort(A, q + 1, r);
  }
}

int solve(){
  
  int ans = 0; //answer
  
  quicksort(a, 0, n - 1); //sorting
  for(int i = 0;i < n;i++) b[a[i]] = i; //record a position
  
  for(int i = 0;i < n;i++){
    int cnt = 0, sum = 0, now = i, mimi = 100000;
    
    if(used[i]) continue; //if i is already used, continue
    
    while(true){
      if(used[now]) break; //if now is already used, break
      cnt++; //count up
      used[now] = true; //now is used
      mimi = min(mimi, w[now]); //minimun weight in cyclic group
      sum += w[now]; //add a weight to sum
      now = b[w[now]]; //update now
    }
    
    ans += min(sum + (cnt - 2) * mimi, sum + mimi + (cnt + 1) * mi); //add minimum cost to ans variable
  }
  
  return ans;
}

int main(){

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> w[i];
    a[i] = w[i];
    mi = min(mi, w[i]); //minimum weight
  }

  //output
  cout << solve() << endl;

  return 0;
}




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

public class P
{
    public int h { get; set; }
    public int w { get; set; }
}

public class hello
{
    public static void Main()
    {
        var d = new Dictionary<int, int>();
        var ps = new P[6];
        for (int i = 0; i < 6; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h < w) ps[i] = new P { h = h, w = w };
            else ps[i] = new P { h = w, w = h };
            if (d.ContainsKey(h)) d[h]++;
            else d[h] = 1;
            if (d.ContainsKey(w)) d[w]++;
            else d[w] = 1;
        }
        var ps2 = ps.OrderBy(x => x.h).ThenBy(x => x.w).ToArray();
        Console.WriteLine(check(d, ps2) ? "yes" : "no");
    }
    static bool check(Dictionary<int, int> d, P[] ps)
    {
        for (int i = 0; i < 3; i++)
        {
            var i2 = i * 2;
            if ((ps[i2].h == ps[i2 + 1].h) && (ps[i2].w == ps[i2 + 1].w)) continue;
            else return false;
        }
        if (d.Count() == 1) return true;
        else if (d.Count() == 2)
        {
            var a = new int[2];
            var p = 0;
            foreach (var x in d) a[p++] = x.Value;
            if (a[0] == 4 | a[0] == 8) return true;
            else return false;
        }
        else if (d.Count() == 3)
        {
            foreach (var x in d)
                if (x.Value != 4) return false;
            if (ps[0].h == ps[0].w) return false;
            else return true;
        }
        else return false;
    }
}



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

int main(){
	long int H,W;
	cin >> H >> W;
  	if(H==1 || W==1) cout << 1 << endl;
    else if((H%2)==0) cout << W*(H/2) << endl;
    else cout << W*((H-1)/2)+(W/2+W%2) << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
//#define _CRTDBG_MAP_ALLOC
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 4000 + 15;
const ll MOD = 1e9 + 7;
int C = 700;
const double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd;

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) (_v * _v)
#define vi vector <int>
#define vii vector <pair <int, int> >
#define eb emplace_back


inline void IO() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}

template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

#define int int64_t

int get(int h) {
    if (h == 1) {return 1;}
    return 1 + 2 * get(h / 2);
}

inline void solve() {
    int h;
    cin >> h;
    cout << get(h);
}

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

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

#define INF 100000000001
#define VALUE_MAX 100000

signed main()
{
    int N, W, w, v, ans;
    long long dp[100001] = {};

    cin >> N >> W;

    for(int i=0 ;i<=VALUE_MAX ; i++ ){
        dp[i] = INF;
    }

    dp[0] = 0;
    ans = 0;
    for(int i=0 ;i<N ;i++ ){
        cin >> w >> v;
        
        for(int j=VALUE_MAX-v ;j>=0 ;j-- ){
            if( dp[j] + w <= W){
                dp[j+v] = min(dp[j+v], dp[j] + w);

                ans = max(ans, j+v);
            }
        }
    }

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

Measured memory_bytes: 4380
#!/usr/bin/env pypy3


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)


from functools import reduce


def main():
    N, X = get_ints()
    x = get_ints()
    x = [abs(_ - X) for _ in x]

    print(reduce(gcd, x))


if __name__ == '__main__':
    main()

Measured memory_bytes: 63640
/*
FIND YOUR PURPOSE BECOME UNSTOPPABLE---->>> ?????? 
                    ,.
                  ,_> `.   ,';
              ,-`'      `'   '`'._
            ,,-) ---._   |   .---''`-),.
          ,'      `.  \  ;  /   _,'     `,
      ,--' ____       \   '  ,'    ___  `-,
      _>   /--. `-.              .-'.--\   \__
    '-,  (    `.  `.,`~ \~'-. ,' ,'    )    _\
    _<    \     \ ,'  ') )   `. /     /    <,.
  ,-'   _,  \    ,'    ( /      `.    /        `-,
  `-.,-'     `.,'       `         `.,'  `\    ,-'
  ,'       _  /   ,,,      ,,,     \     `-. `-._
  /-,     ,'  ;   ' _ \    / _ `     ; `.     `(`-\
  /-,        ;    (o)      (o)      ;          `'`,
,~-'  ,-'    \     '        `      /     \      <_
/-. ,'        \                   /       \     ,-'
  '`,     ,'   `-/             \-' `.      `-. <
    /_    /      /   (_     _)   \    \          `,
      `-._;  ,' |  .::.`-.-' :..  |       `-.    _\
        _/       \  `:: ,^. :.:' / `.        \,-'
      '`.   ,-'  /`-..-'-.-`-..-'\            `-.
        >_ /     ;  (\/( ' )\/)  ;     `-.    _<
        ,-'      `.  \`-^^^-'/  ,'        \ _<
        `-,  ,'   `. `"""""' ,'   `-.   <`'
          ')        `._.,,_.'        \ ,-'
            '._        '`'`'   \       <
              >   ,'       ,   `-.   <`'
                `,/          \      ,-`
                `,   ,' |   /     /
                  '; /   ;        (
                  _)|   `       (
                  `')         .-'
                    <_   \   /    
                      \   /\(
                        `;/  `
*/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define INF 100000000
int main(){
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#define SIZE 102

int main(void){
    int x, n, i, p, count[SIZE] = {0}, a, b, ans;
    scanf("%d %d", &x, &n);
    for(i = 0; i < n; i++){
        scanf("%d", &p);
        count[p]++;
    }
    a = x;
    while(count[a] != 0)
        a--;
    b = x;
    while(count[b] != 0)
        b++;
    ans = (x - a <= b - x) ? a : b; 
    printf("%d", ans);
    return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		double x1, y1, x2, y2;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] coor = in.readLine().split(" ");
		x1 = Double.parseDouble(coor[0]);
		y1 = Double.parseDouble(coor[1]);
		x2 = Double.parseDouble(coor[2]);
		y2 = Double.parseDouble(coor[3]);
		System.out.println(Math.sqrt(Math.pow(Math.abs(x2 - x1), 2)
				+ Math.pow(Math.abs(y2 - y1), 2)));
	}
}

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


int main(void){
	int n;
  cin >> n;
  vector<string> list;
  rep(i, n){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    list.push_back(s);
  //  cout << s << endl;
  }
  sort(list.begin(), list.end());
  //rep(i, n) cout << list.at(i) << endl;
  ll ans = 0, count = 1;
  int begin = 0, end = 1;
  
  
  
  while(end<n){
    string left = list.at(begin), right = list.at(end);
    if(left==right){
      count++;
      end++;
    }
    else {
      ans += (count*(count-1))/2; 
      begin=end; 
      end ++;
      count =1;
    }
    //cout << count << endl;
  
  }
  //cout << count << endl;
  ans += (count*(count-1))/2; 
  
  cout << ans;
}


Measured memory_bytes: 7376
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

int n, k;
vector<int > a[3];

int crank(int x) {
	if(!x) return a[0].size() * a[2].size() + 1;
	int ret = 1;
	vector<int > tmp;
	if(x > 0) {
		for(int i = 0; i < 3; i += 2) {
			for(auto j : a[i]) {
				ret += distance(tmp.begin(), lower_bound(tmp.begin(), tmp.end(), (x + j - 1) / j));
				tmp.push_back(j);
			}
			tmp.clear();
		}
		ret += (a[1].size() * (a[1].size() - 1)) / 2 + a[0].size() * a[2].size() + a[1].size() * (a[0].size() + a[2].size());
	}
	else for(auto i : a[0]) ret += a[2].size() - distance(a[2].begin(), upper_bound(a[2].begin(), a[2].end(), -x / i));
	return ret;
}

signed main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if(x > 0) a[0].push_back(x);
        else if(!x) a[1].push_back(x);
        else a[2].push_back(-x);
    }
    for(int i = 0; i < 3; ++i)
        sort(a[i].begin(), a[i].end());
    int l = -1e18, r = 1e18, ans;
    while(l <= r) {
        int mid = (l + r) >> 1;
        int rk = crank(mid);
		if(rk <= k) ans = mid, l = mid + 1;
		else r = mid - 1;
    }
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5232
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
    int S = 0;
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
		S += vec[i];
	}
	int ans = 1000000;
    int sum = 0;
		for (int j = 0; j < N-1; j++) {
      	    sum += vec[j];
            int Sum = 0;
			Sum =S -sum;
			ans = min(abs(sum - Sum), ans);
		}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	ll N, K; cin >> N >> K;	
	ll ans = N%K;
	ans = min(ans, -1*(ans-K));
	
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long money = 100;
		int y = 0;
		while(x > money) {
			money = money + money / 100;
			y++;
		}
		System.out.println(y);
	}
}

Measured memory_bytes: 35672
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x1 = in.nextInt();
        int x2 = in.nextInt();
        int x3 = in.nextInt();
        int x4 = in.nextInt();
        int x5 = in.nextInt();

        int ans = 0;
        if (x1 == 0) {
            ans = 1;
        } else if (x2 == 0) {
            ans = 2;
        } else if (x3 == 0) {
            ans = 3;
        } else if (x4 == 0) {
            ans = 4;
        } else {
            ans = 5;
        }
        System.out.println(ans);
    }
}


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

int main()
{
    int i,j,res,d,m = 0x3f3f3f3f;
    int min[10010];
    char str[13];
    gets(str);
    d=strlen(str);

    for(i=0; i<d-2; i++)
    {
        res=(str[i]-'0')*100+(str[i+1]-'0')*10+(str[i+2]-'0');

        min[i] = abs(753-res);

    }
    for (i=0; i<d-2; i++)
    {
        if(m > min[i])
            m = min[i];
    }

    printf("%d",m);

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner stdin=new Scanner(System.in);
		String s=stdin.next();
		StringBuilder sb=new StringBuilder();
		sb.append(s);

		sb.replace(0, 4, "2018");
		System.out.println(sb);
	}
}


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

int main() {
  int i,j,k,a,b,cnt=0;
  cin>>a>>b;
  for(i=a;i<=b;i++){
    j=i;
      if(j/10000==j%10){
        //j/10;
        k=j/1000;
        j/=10;
       // cout<<k<<" "<<j<<endl;
        if(k%10==j%10){
          cnt++;
        }
      }
    
  }
  
  cout<<cnt<<endl;
  
        
}



Measured memory_bytes: 256
// It’s always great to set new goals, keep trying, keep training, and then achieve those goals.
#include <bits/stdc++.h>
#define ll long long int
#define f(i,n) for(ll i=0;i<n;i++)
#define rf(i,n) for(ll i=n;i>=0;i--)
#define endl '\n'
#define pub push_back
#define vf v[i].first
#define vs v[i].second
#define mp make_pair
#define z 998244353   
using namespace std;
ll powMod(ll x,ll y){ll p=1; while(y){if(y%2){p=(p*x)%z;} y/=2; x=(x*x)%z;} return p;}
ll invMod(ll x){return powMod(x,z-2);}
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}

const int N = (int)2e5 + 100;
set<char> st[N];
ll visited[N];

void solve(){ 
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll dp[n];
    f(i,n)cin>>a[i];

    f(i,n)dp[i]=INT64_MAX;
    
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(ll i=2 ;i<n ;i++){
        for(ll j=1;j<=k && j<=i ; j++)
        dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        // cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
}
int main(){
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ; cout.tie(0) ;

    solve();
    
}

Measured memory_bytes: 11264
import java.util.Scanner;

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

    void solve(Scanner sc) {
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        
        if (b < a) {
            System.out.println(0);
            return;
        }

        if (n == 1 && a != b) {
            System.out.println(0);
            return;
        } else if (n == 1) {
            System.out.println(1);
            return;
        }

        System.out.println((n - 2) * (b - a) + 1);
    }
}

Measured memory_bytes: 25172
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define inf 99999999
int main(){
	int n,a,b,c;
	int cost[64][64];
	while(cin >> n, n) {
		rep(i,64) {
			rep(j,64) {
				cost[i][j] = inf;
			}
		}
		int max = 0;
		rep(i,n) {
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			cost[a][a] = 0;
			cost[b][b] = 0;
			if(max < a) max = a;
			if(max < b) max = b;
		}

		rep(i,max+1) {
			rep(j,max+1) {
				rep(k,max+1) {
					int len = cost[j][i] + cost[i][k];
					if(len < cost[j][k]) {
						cost[j][k] = len;
					}
				}
			}
		}
		int min = inf, rmin = -1;
		rep(i,max+1) {
			int ret = 0;
			rep(j,max+1) {
				ret += cost[i][j];
			}
			if(min > ret) {
				min = ret;
				rmin = i;
			}
		}
		cout << rmin << " " << min << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>
 
int main(void){
    int m,f,r;
    for(;scanf("%d %d %d",&m,&f,&r),m+f+r != -3;puts("")){
        if(m==-1 || f==-1)
            putchar('F');
        else if(m+f >= 80)
            putchar('A');
        else if(m+f >= 65)
            putchar('B');
        else if(m+f >= 50 || r >= 50)
            putchar('C');
        else if(m+f >= 30)
            putchar('D');
        else
            putchar('F');
    }
    return 0;
}

Measured memory_bytes: 588
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if (a == 0 && b == 0)
				break;
			char[][] map = new char[a + 2][b + 2];
			for (int i = 1; i <= a; i++) {
				String line = scanner.next();
				for (int j = 1; j <= b; j++) {
					map[i][j] = line.charAt(j - 1);
				}
			}
			int count = 0;
			for (int i = 1; i <= a; i++) {
				for (int j = 1; j <= b; j++) {
					if (map[i][j] != ' ') {
						count++;
						solve(map[i][j], map, i, j);
					}
				}
			}
			System.out.println(count);
		}
	}

	private static void solve(char c, char[][] map, int y, int x) {
		int[] a = { -1, 0, 0, 1 };
		int[] b = { 0, -1, 1, 0 };
		Deque<int[]> deque = new ArrayDeque<int[]>();
		deque.push(new int[] { y, x });
		while (!deque.isEmpty()) {
			int[] p = deque.pop();
			int yp = p[0];
			int xp = p[1];
			map[yp][xp] = ' ';
			for (int i = 0; i < a.length; i++) {
				int yn = yp + a[i];
				int xn = xp + b[i];
				if (map[yn][xn] == c) {
					boolean flag = true;
					for (int[] t : deque) {
						if (t[0] == yn && t[1] == xn) {
							flag = false;
							break;
						}
					}
					if (flag) {
						deque.push(new int[] { yn, xn });
					}
				}
			}
		}
	}

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n - 1);
  for(int i = 0; i < n - 1; i++) cin >> b.at(i);
  
  a.at(0) = b.at(0);
  a.at(n - 1) = b.at(n - 2);
  int sum = a.at(0) + a.at(n - 1);
  for(int i = 1; i < n - 1; i++){
    a.at(i) = min(b.at(i - 1), b.at(i));
    sum += a.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline


    n = int(input())
    restaurant = [None]*n
    for i in range(n):
        input_list = list(input().split())
        input_list[1] = int(input_list[1])
        input_list.append(i+1)
        restaurant[i] = input_list

    restaurant.sort(key= lambda num: num[1], reverse=True)
    restaurant.sort(key= lambda num: num[0])
    for num in restaurant:
        print(num[2])


Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 45

int F[MAX];

void fib(int n){
  int i;
   F[0]=F[1]=1;
   for(i=2;i<n+1;i++){
     F[i]=F[i-1]+F[i-2];
   }
}

int main(){
  int n;
  scanf("%d",&n);
  fib(n);
  printf("%d\n",F[n]);
  return 0;
}



Measured memory_bytes: 2052
# @author 

import sys

class KStones:
    def solve(self):
        n, k = [int(_) for _ in input().split()]
        a = [int(_) for _ in input().split()]
        dp = [0] * (k + 1) # can we win with i remaining ?
        for i in range(min(a), k + 1):
            dp[i] = int(any(not dp[i - x] for x in a if x <= i))
        
        print("First" if dp[k] else "Second")

solver = KStones()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 44508
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    int N=s.nextInt();
    long D=s.nextLong();
    D=D*D;
    int ans=0;
    long[][] point=new long[N][2];
    for(int i=0;i<N;i++){
      for(int j=0;j<2;j++){
        point[i][j]=s.nextLong();
        point[i][j]=point[i][j]*point[i][j];
      }
      if (point[i][0]+point[i][1]<=D){ans+=1;}
    }
    
    
    System.out.println(ans);
  }  
}

Measured memory_bytes: 67924
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll fact(ll x)
{
    ll f=1;
    for(ll i=1;i<x;i++)
    {
        f=f*i;
    }
    return f;
}
float ncr(ll n,ll k)
{
    return fact(n)/(fact (k) * fact(n-k));
}
ll rep(ll k,ll a)
{
    ll counter=0;
    while(a<k)
    {
        a *=2;
        counter++;
    }
    return counter;
}
int main() 
{
    std::cout << std::fixed;
    std::cout << std::setprecision(15);
    ll n,k;
    cin>>n>>k;
    double ans=0.000000000;
    if(n==1)
    {
        if(k==1)
        {
            ans=1;
            cout<<ans;
            return 0;
        }
        else
        {
            ll factor=rep(k,1);
            double x=pow(2,factor);
            x=x*n;
            //cout<<x<<endl;
            ans += (1/x);
        }
        cout<<ans;
        return 0;
    }
        
    else if(n>=k)
    {
        ans += (1/n)*(n-k+1);
        for(ll i=1;i<=n;i++)
        {
            ll factor=rep(k,i);
            double x=pow(2,factor);
            x=x*n;
            //cout<<x<<endl;
            ans += (1/x);
            //cout<<ans<<endl;
        }
        cout<<ans;
        return 0;
    }
    else
    {
        for(ll i=1;i<=n;i++)
        {
            ll factor=rep(k,i);
            double x=pow(2,factor);
            x=x*n;
            //cout<<x<<endl;
            ans += (1/x);
            //cout<<ans<<endl;
        }
        cout<<ans;
        return 0;
    }
}




    
    
    
    


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

ll n,x,Plev[51];
ll sz[51];

ll sol(ll lev,ll height){
//    cerr << lev << " " << height << el;
    if (lev==0){
        return height;
    }
    if (height>=sz[lev]){
        return Plev[lev];
    }
    if (height<=1){
        return 0;
    }

    ll mid=(sz[lev]+1)/2;

    if (height>=mid){
        return 1+Plev[lev-1]+sol(lev-1,height%mid); 
    }

    return sol(lev-1,height-1);
}

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

    cin >> n >> x;
    sz[0]=1;
    Plev[0]=1;
    for (int i=1;i<=n;i++){
        sz[i]=sz[i-1]+sz[i-1]+3;
        Plev[i]=Plev[i-1]+Plev[i-1]+1;
    }

    ll ans=sol(n,x);
    cout << ans << el;

    return 0;
}

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

def solve():
    n, m = map(int, input().split())
    l, r = 0, 55301301
    for i in range(m):
        a, b = map(int, input().split())
        l = max(a, l)
        r = min(b, r)
    print(max(0, r - l + 1))

if __name__=="__main__":
    solve()


Measured memory_bytes: 3060