akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)

int main(){
    int n, r;
    while(cin >>n >>r && n){
        vector<int> v;
        for(int i = n; i >= 1; --i) v.push_back(i);

        REP(i, r){
            int p, c;
            cin >>p >>c;
            vector<int> nv;
            FOR(j, p - 1, p + c - 1) nv.push_back(v[j]);
            FOR(j, 0, p - 1) nv.push_back(v[j]);
            FOR(j, p + c - 1, n) nv.push_back(v[j]);
            v = nv;
        }
        cout <<v[0] <<endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <math.h>

int main(void)
{
    double x1, y1;
    double x2, y2;
    double dx, dy;

    scanf("%lf %lf", &x1, &y1);
    scanf("%lf %lf", &x2, &y2);
    dx = x2 - x1;
    dy = y2 - y1;

    printf("%f\n", sqrt(dx * dx + dy * dy));

    return (0);
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int A,B, C;cin>>A>>B>>C;

    int ans = A +B-C;
    if(ans>=0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}


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

using namespace std;

int main() {
	vector <int> cases;

	int x = 0;
	while (true) {
		cin >> x;
		if (x != 0) {
			cases.push_back(x);
		} else {
			break;
		}
	}
	for (int i = 1; i <= cases.size(); i++) {
		cout << "Case " << i << ": " << cases[i-1] << endl;
	}
}


Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100)
#define INF (1000000000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, ws[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ws[i]);
  }

  // solve
  int ans = INF;
  for (int t = 1; t < N; t++) {
    int s1 = 0, s2 = 0;
    for (int i = 0; i < t; i++) {
      s1 += ws[i];
    }
    for (int i = t; i < N; i++) {
      s2 += ws[i];
    }
    ans = min(ans, abs(s1 - s2));
  }
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	if(K<=A)
	cout<<K*1;
	if(K>A and K<=A+B)
	cout<<A*1+(K-A)*0;
	if(K>A+B and K<=A+B+C)
	cout<<A*1+B*0-(K-A-B)*1;
	return 0;
}

Measured memory_bytes: 3636
S = list(input())
l = len(S)
mod = 10**9+7

A = []
a = 1
for i in range(l):
    A.append(a)
    a = (10*a) % 13

A.reverse()

dp = [[0]*13 for i in range(l)]

for i in range(l):
    for j in range(13):
        if i == 0:
            if S[i] != '?':
                dp[i][(int(S[i])*A[i]) % 13] = 1
            else:
                for k in range(10):
                    dp[i][(k*A[i]) % 13] = 1
        else:
            if S[i] != '?':
                dp[i][j] = dp[i-1][(j-int(S[i])*A[i]) % 13]
            else:
                for k in range(10):
                    dp[i][j] += dp[i-1][(j-k*A[i]) % 13]
                    dp[i][j] = (dp[i][j]) % mod
print(dp[l-1][5])

Measured memory_bytes: 66440
import java.util.Scanner;

class Main {

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();

        if ((100 * a + 10 * b + c) % 4 == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
//ll a[maxn];

//check T
void solve()
{
	//cin >> n; rep(i, 0, n) cin >> a[i];
  string s;
  cin >> s;
  n = s.size();
  vector<int> a(n+5, 0);
  rep(i, 0, n) a[i+1] = s[i]-'0';
  a[n+1] = 0;
  vector<int> dp[2];
  dp[0].resize(n+5); dp[1].resize(n+5);

  dp[0][0] = dp[1][0] = 0;
  int id = 1;
  int lastn9 = 0;
  int cnt = 0;
  //a[0] = 10;
  rep(i, 1, n+1)
  {
    //0 => use prev
    dp[0][i] = dp[1][lastn9] + 1 + 10-a[i];
    if(a[lastn9] != 0) dp[0][i] = min(dp[0][i], dp[0][lastn9] + 10-a[i] -1);
    //1 => id
    dp[1][i] = min(dp[0][i-1] + a[i], dp[1][i-1] + a[i]);
    if(a[i]!=9) lastn9 = i;
  }
  cout << min(dp[1][n], dp[0][n]) << endl;

  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 13084
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

double Mcos(double k){return cos(k*atan(1.0)*4/180);}

void monmo(){
    
}

int main() {
    string s,t;
    int max=0;
    cin>>s>>t;
    for(int i=0;i<s.length()-t.length()+1;i++){
        int count=0;
        for(int j=0;j<t.length();j++){
            if(s[i+j]==t[j])count++;
        }
        if(max<count)max=count;
    }
    cout<<t.length()-max;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int n,m,q; 
vector<pair<P, P>> abcd;
int ans;

void calcscore(vector<int> t){
    int score = 0;
    for(auto p : abcd){
        int a = p.first.first;
        int b = p.first.second;
        int c = p.second.first;
        int d = p.second.second;
        if(t[b-1]-t[a-1] == c) score+=d;
    }
    chmax(ans, score);
}

void dfs(vector<int> t){
    if(t.size() == n){
        calcscore(t);
        return;
    }
    t.push_back(t.back());
    while(t.back() <= m){
        dfs(t);
        t.back()++;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>q;
    rep(i,q){
        int a,b,c,d; cin>>a>>b>>c>>d;
        abcd.push_back(make_pair(make_pair(a,b), make_pair(c,d)));
    }

    // 長さNの順列を全列挙する
    vector<int> tmp;
    tmp.push_back(1);
    dfs(tmp);
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void){
    long a, b, c, k;
    long ans = 0;

    scanf("%ld%ld%ld%ld", &a, &b, &c, &k);
    if(a > k){
        ans = k;
        k = 0;
    }else{
        ans = a;
        k -= a;
    }
    if(k > 0){
        if(b > k){
            k = 0;
        }else{
            k -= b;
        }
    }
    if(k > 0) ans -= k;
    printf("%ld", ans);
    return 0;
}


Measured memory_bytes: 1732
N, M, X, Y = map(int, input().split())

x = list(map(int, input().split()))
y = list(map(int, input().split()))

for z in range(X, Y+1):
    if X < z <= Y and max(x) < z and min(y) >= z:
        print('No War')
        break
else:
    print('War')

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

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

  vector<string> s(n);
  vector<int> t(n);
  for (int i = 0; i < n; i++) cin >> s.at(i) >> t.at(i);

  string x;
  cin >> x;

  int memo;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == x) {
      memo = i;
      break;
    }
  }

  if (memo == n - 1) cout << 0 << endl;
  else {
    int sum = 0;
    for (int i = memo + 1; i < n; i++) {
      sum += t.at(i);
    }
    cout << sum << endl;
  }
}

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

int com[1000001];
vector<int> primes;
void sieve() {
    for (ll i = 2; i*i <= 1000000; ++i) {
        if (!com[i]) {
            for (ll j = i*i; j <= 1000000; j+=i) {
                com[j] = 1;
            }
        }
    }
    for (int i = 2; i <= 1000000; ++i) {
        if (!com[i]) {
            primes.emplace_back(i);
        }
    }
}
int main() {
    int x;
    scanf("%d", &x);
    sieve();
    printf("%d\n", *lower_bound(primes.begin(), primes.end(), x));
    return 0;
}




Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[7],k;
    for(int i=1;i<=5;i++){
        cin>>a[i];
    }
    cin>>k;
    if(a[5]-a[1]<=k){
        cout<<"Yay!";
    }
    else{
        cout<<":(";
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int n = S.size();
  int ans = 1;
  for(int i = 1; i < n; i++) {
    if(S[i] == S[i-1]) continue;
    else ans++;
  }
  cout << ans << endl;

  return 0;
}


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

int dp[100001][3];

int main() {
    int N;
    cin >> N;
    vector<int> a(N),b(N),c(N);
    // vector< vector<int> > dp(N);
    
    rep(i,N){
        cin >> a[i] >> b[i] >> c[i];    
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    rep(i,N-1){
        dp[i+1][0] = a[i+1] + max(dp[i][1], dp[i][2]);
        dp[i+1][1] = b[i+1] + max(dp[i][0], dp[i][2]);
        dp[i+1][2] = c[i+1] + max(dp[i][1], dp[i][0]);  
    }
    
    cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;
    
    return 0;
}

Measured memory_bytes: 5532
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U[52];
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	vector<int> c(3);
	//char p;


	

	

	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	//vector<bool> flag(N);
	
	cin >> N;
	/*rep(i, 0, M) {
		cin >> ch[i].first >> ch[i].second;
	}*/
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;



	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	if(N == 111)
	cout << 999 << endl;
	else if (N == 119)
		cout << 991 << endl;
	else if(N == 191)
		cout << 919 << endl;
	else if(N == 911)
		cout << 199 << endl;
	else if(N == 991)
		cout << 119 << endl;
	else if(N == 919)
		cout << 191 << endl;
	else if(N == 199)
		cout << 911 << endl;
	else if(N == 999)
		cout << 111 << endl;
	

	return 0;

}

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

	return b;
}



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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, a, b;
    cin >> n >> a >> b;

    // 処理
    cout << min(n * a, b) << endl;

    // 出力

    return 0;
}


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

bool is_war(const vector<int>& x, const vector<int>& y) {
    for (int Z = -100; Z <= 100; ++Z) {
        bool is_ok = true;
        for (int i = 0; i < x.size(); ++i) {
            if (x[i] >= Z) is_ok = false;
        }
        for (int i = 0; i < y.size(); ++i) {
            if (y[i] < Z) is_ok = false;
        }
        if (is_ok) return false;
    }
    return true;
}
int main() {
    int N, M; cin >> N >> M;
    vector<int> x(N + 1), y(M + 1);
    cin >> x[0] >> y[0];
    for (int i = 0; i < N; i++) {
        cin >> x[i + 1];
    }
    for (int i = 0; i < M; i++) {
        cin >> y[i + 1];
    }

    if (is_war(x, y))
        cout << "War" << endl;
    else
        cout << "No War" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static String[] input;
	public static int ptr = 0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		doIt();

	}
	
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.nextLine();
			input = s.split(" ");
			ptr = input.length - 1;
			System.out.println(getNext());
		}
	}
	
	public static double getNext(){
		double ret = 0, left = 0, right = 0;
		String s = input[ptr--];
		if(s.equals("+")){
			right = getNext();
			left = getNext();
			ret = left + right;
		}
		else if(s.equals("-")){
			right = getNext();
			left = getNext();
			ret = left - right;
		}
		else if(s.equals("*")){
			right = getNext();
			left = getNext();
			ret = left * right;
		}
		else if(s.equals("/")){
			right = getNext();
			left = getNext();
			ret = left / right;
		}
		else{
			//数字のはず
			ret = Double.parseDouble(s);
		}
		return ret;
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

// 119_a
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        try {
            Date d = sdf.parse(s);

            if (d.compareTo(sdf.parse("2019/04/30")) <= 0) {
                System.out.println("Heisei");
            } else {
                System.out.println("TBD");
            }
        } catch (ParseException e) {
            System.out.println(e.getStackTrace());
            System.exit(1);
        }

        sc.close();
    }
}

Measured memory_bytes: 21968
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    int MAX = 0, ans = 1;
    rep(i, 1, n + 1){
        int tmp = i, cnt = 0;
        while(tmp % 2 == 0){
            tmp /= 2;
            cnt++;
        }
        if(cnt > MAX){
            MAX = cnt;
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#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 gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  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() {
  int n,count=0;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(),v.end());
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(v[i]<v[j]+v[k] && v[j]<v[i]+v[k] && v[k]<v[j]+v[i]) count++;
      }
    }
  }
  cout<<count<<endl;
  
  
}
///////////////////////////

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    set<int> dic;
    int N; cin >> N;
    while (N--) {
        int a; cin >> a;
        dic.emplace(a);
    }
    int M; cin >> M;
    while (M--) {
        int b; cin >> b;
        if (dic.count(b)) cout << b << ln;
    }
}


Measured memory_bytes: 12480
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}

//小数点9桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n,t=0,ans=LLONG_MAX;
    cin>>n;
    vector<ll>a(n);
    vector<ll>s(n+1,0);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        t+=a[i];
        s[i+1]=t;
    }
    for(ll i=1;i<n;i++){
        ans=min(abs((s[n]-s[i])-s[i]),ans);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
 
    

    


    
    
}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ABC_113
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hwk = ReadInts();
            int h = hwk[0];
            int w = hwk[1];
            int k = hwk[2] - 1;
            long mask = 1000000000 + 7;
            var rowPats = new long[6] { 2, 3, 5, 8, 13, 21 };
            var dp = new long[h + 1, w];
            dp[0, 0] = 1;
            for (int i = 1; i <= h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    //まうえ
                    dp[i, j] = dp[i - 1, j];
                    dp[i, j] %= mask;
                    if (j >= 2)
                    {
                        dp[i,j]*= rowPats[j - 2];
                        dp[i, j] %= mask;
                    }
                    if (j + 3 <= w)
                    {
                        dp[i, j] *= rowPats[w - j - 3];
                        dp[i, j] %= mask;
                    }
                    dp[i, j] %= mask;

                    if (j < w - 1)//右
                    {
                        long right = dp[i - 1, j + 1];

                        if (j + 1 >= 3)
                        {
                            right *= rowPats[j - 2];
                            right %= mask;
                        }
                        if (j + 4 <= w)
                        {
                            right *= rowPats[w - j - 4];
                            right %= mask;
                        }
                        dp[i, j] += right;
                        dp[i, j] %= mask;
                    }
                    if (0 < j)//left
                    {
                        long left = dp[i - 1, j - 1];
                        if (j - 3 >= 0)
                        {
                            left *= rowPats[j - 3];
                            left %= mask;
                        }
                        if (j + 3 <= w)
                        {
                            left *= rowPats[w - j - 3];
                            left %= mask;
                        }
                        dp[i, j] += left;
                        dp[i, j] %= mask;
                    }
                    //Console.Write(dp[i, j] + " ");
                }
                //Console.WriteLine();
            }
            Console.WriteLine(dp[h, k]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include <iostream>

int main(){
  int N,A[100001],B[100000],i;
  long sum1=0;
  long sum2=0;
  scanf("%d",&N);
  for(i=0;i<=N;i++){
  	scanf("%d",&A[i]);
    sum1=sum1+A[i];
  }
  for(i=0;i<=N-1;i++){
  	scanf("%d",&B[i]);
    if(A[i]<B[i]){
      if(A[i]+A[i+1]<=B[i]){
      	A[i]=0;
        A[i+1]=0;
      }
      else{
    	A[i+1]=A[i+1]-(B[i]-A[i]);
      	A[i]=0;
      }
    }
    else{
    	A[i]=A[i]-B[i];
    }
    sum2=sum2+A[i];
  }
  sum2=sum2+A[N];
  printf("%ld",sum1-sum2);
}

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

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

int main(){
  vector<int> A;
  A.resize(3);
  for (int i = 0; i < A.size(); i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  if (A[0] + A[1] == A[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if (a == b || b == c || c == a) {
      if (a != b || a != c || b != c) {
		System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21972
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

graph = [[] for _ in range(n)]
for _ in range(m):
    l,r,d = li()
    l -= 1
    r -= 1
    graph[l].append((d,r))
    graph[r].append((-d,l))
    
searched = [False]*n
dist = [float("inf") for _ in range(n)]

exist = True
for i in range(n):
    if not searched[i]:
        dist[i] = 0
        searched[i] = True
        stack = [(0,i)]
        
        while stack:
            cost, cur = stack.pop()
            for nex_cost, nex_node in graph[cur]:
                if searched[nex_node]:
                    if cost + nex_cost != dist[nex_node]:
                        exist = False
                        
                else:
                    stack.append((cost+nex_cost, nex_node))
                    dist[nex_node] = cost + nex_cost
                    searched[nex_node] = True
                    
if exist:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 74480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()

int main() {
	int N; cin >> N;
	vector<ll> left(N);
	vector<ll> right(N);
	vector<ll> A(N);
	for (int i = 0;i < N;i++)
		cin >> A[i];
	for (int i = 0;i < N;i++) {
		left[i] = A[i];
		if (i)
			left[i] += left[i - 1];
	}
	for (int i = 0;i < N;i++) {
		right[i] = A[N - 1 - i];
		if (i)
			right[i] += right[i - 1];
	}
	ll x, y;
	ll cp1,cp3;
	vector<vector<ll>> T(4);
	for (int i = 1;i < N - 2;i++) {
		x = left[i];
		//cout << x << endl;
		auto it1 = upper_bound(all(left), x / 2);
		auto it2 = it1;
		if (it1 != left.begin()) {
			it1--;
		}
		y = right[N - 2 - i];
		//cout << y << endl;
		auto it3 = upper_bound(all(right), y / 2);
		auto it4 = it3;
		if (it3 != right.begin()) {
			it3--;
		}
		if (abs(x - *it1 - *it1) > abs(x - *it2 - *it2)) {
			T[0].push_back(*it2);
			T[1].push_back(x - *it2);
		}
		else {
			T[0].push_back(*it1);
			T[1].push_back(x - *it1);
		}
		if (abs(y - *it3 - *it3) > abs(y - *it4 - *it4)) {
			T[3].push_back(*it4);
			T[2].push_back(y - *it4);
		}
		else {
			T[3].push_back(*it3);
			T[2].push_back(y - *it3);
		}
	}
	ll ans = -1, cp;
	for (int i = 0;i < T[0].size();i++) {
		cp = 0;
		cp += max({ T[0][i],T[1][i],T[2][i],T[3][i] });
		cp -= min({ T[0][i],T[1][i],T[2][i],T[3][i] });
		//cout << cp << endl;
		if (ans + 1) {
			ans = min(ans, cp);
		}
		else {
			ans = cp;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11332
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int main()
{
	int n;
	char s[10000];
	cin>>n;
	cin>>s;
	int len=strlen(s);
	for(int i=0;i<len;i++)
	{
		cout<<a[(s[i]-'A'+n)%26];
	}
	cout<<endl;
	return 0;
}

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

#define rep(i, n) for (size_t i = 0; i < (size_t)n; ++i)

using namespace std;

bool is_kaibun(const string &s) {
  auto n = s.length();
  rep(i, n / 2) {
    if (s[i] != s[n - 1 - i]) {
      return false;
    }
  }

  return true;
}

int main() {
  string s;
  cin >> s;
  auto n = s.length();
  auto sublen = (n - 1) / 2;
  auto result = is_kaibun(s) && is_kaibun(s.substr(0, sublen)) &&
                is_kaibun(s.substr((n + 1) / 2, sublen));

  printf("%s\n", (result ? "Yes" : "No"));
  /* code */
  return 0;
}


Measured memory_bytes: 256
class Heap
    attr_reader :size
    def initialize
        @heap = []
        @size = 0
    end

    def push(x)
        i = @size
        @size += 1
        while i > 0 do
            p = (i - 1) / 2
            break if @heap[p] <= x
            @heap[i] = @heap[p]
            i = p
        end
        @heap[i] = x
        self
    end

    def pop
        return nil if @size == 0
        ret = @heap[0]
        @size -= 1
        x = @heap[@size]
        i = 0
        while i * 2 + 1 < @size do
            a = i * 2 + 1
            b = a + 1
            if b < @size && @heap[b] < @heap[a]
                a = b
            end
            break if @heap[a] >= x
            @heap[i] = @heap[a]
            i = a
        end
        @heap[i] = x
        @heap.pop
        return ret
    end
end

N = gets.to_i
as = gets.split.map(&:to_i)

frontmax = []
heap = Heap.new
sum = 0
(0...(2*N)).each do |i|
    heap.push(as[i])
    sum += as[i]
    if heap.size > N
        min = heap.pop
        sum -= min
    end
    frontmax[i] = sum
end

as.map!{|a| -a}
as.reverse!
backmin = []
heap = Heap.new
sum = 0
(0...(2*N)).each do |i|
    heap.push(as[i])
    sum += as[i]
    if heap.size > N
        min = heap.pop
        sum -= min
    end
    backmin[3*N-1-i] = -sum
end

score = -Float::INFINITY
((N-1)...(2*N)).each do |i|
    s = frontmax[i] - backmin[i+1]
    score = s if s > score
end

p score

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

#define rep(i, n) \
for(int i = 0; i <n; i++)
#define REP(i, a, b) \
for(int i = int(a); i <= int(b); i++)
#define TRvi(c, it) \
for(vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for(vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for(msi::iterator it = (c).begin(); it != (c).end(); it++)

#define INF 2000000000

#define MEMSET_INF 127
#define MEMSET_HALF_INF 63

void solve(){
    int n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
    }else{
        cout<<(n/1000+1)*1000-n<<endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

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

int main(){
    ll a, b, x; cin >> a >> b >> x;

    ll c;
    if(a > 0){
        c = b / x - (a - 1) / x;
    }else{
        c = b / x + 1;
    }
    cout << c << endl;
    return 0;
}


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


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

    cin >> N;

    if(N%2 == 0)cout << N << endl;
    else cout << N*2 << endl;
    
}

    


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1*10**7
dp = [[0]*(W+1) for _ in range(N)]
dp[0][S[0][0]] = S[0][1]

for i in range(1, N):
    w, v = S[i]
    for j in range(w):
        dp[i][j] = dp[i-1][j]
    dp[i][w] = max(dp[i-1][w], S[i][1])
    for j in range(w+1, W+1):
        if dp[i-1][j] == 0 and dp[i-1][j-w] == 0:
            pass
        elif dp[i-1][j] == 0:
            dp[i][j] = dp[i-1][j-w]+v
        elif dp[i-1][j-w] == 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)

print(max(dp[N-1]))

Measured memory_bytes: 120044
#pragma region header
#include <bits/stdc++.h>
#define int long long
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++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int a,b,c;cin >> a >> b >> c;
    int k;cin >> k;
    rep(i, k) {
        if(b<=a) b*=2;
        else c*=2;
    }
    if(a<b&&b<c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import qualified Control.Arrow         as Arrow
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Char             as Char
import qualified Data.Vector           as V
import qualified Data.Vector.Unboxed   as VU

type Parser a = BSC8.ByteString -> Maybe (a, BSC8.ByteString)
parseInt :: Parser Int
parseInt = fmap (Arrow.second BSC8.tail) . BSC8.readInt
parse1 :: IO Int
parse1 = readLn
parse4 :: IO (Int, Int, Int, Int)
parse4 = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3)) . VU.unfoldrN 4 parseInt <$> BSC8.getLine
parseNM :: Int -> Int -> IO (V.Vector (VU.Vector Int))
parseNM n m = V.replicateM n $ VU.unfoldrN m parseInt <$> BSC8.getLine

main :: IO ()
main = do
  t    <- parse1
  nmab <- parseNM t 4
  putStr . unlines . map show . V.toList $ V.map sumOfFloorLinear nmab

sumOfFloorLinear :: VU.Vector Int -> Int
sumOfFloorLinear nmab = iter n m a b 0
  where
    n = nmab VU.! 0
    m = nmab VU.! 1
    a = nmab VU.! 2
    b = nmab VU.! 3
    iter :: Int -> Int -> Int -> Int -> Int -> Int
    iter p q r s ret
      | r >= q && s >= q = if y1 == 0 then ret1' else ret1'' + iter y1 a1 q ((a1 - x1 `mod` a1) `mod` a1) 0
      | r >= q && s <  q = if y2 == 0 then ret2' else ret2'' + iter y2 a2 q ((a2 - x2 `mod` a2) `mod` a2) 0
      | r <  q && s >= q = if y3 == 0 then ret3' else ret3'' + iter y3 a3 q ((a3 - x3 `mod` a3) `mod` a3) 0
      | otherwise        = if y4 == 0 then ret4' else ret4'' + iter y4 a4 q ((a4 - x4 `mod` a4) `mod` a4) 0
      where
        ret1  = ret + (p - 1) * p * (r `div` q)
        a1    = r `mod` q
        ret1' = ret1 + p * (s `div` q)
        b1    = s `mod` q
        y1    = (a1 * p + b1) `div` q
        x1    = y1 * q - b1
        ret1'' = ret1' + (p - (x1 + a1 - 1) `div` a1) * y1
        
        ret2' = ret + (p - 1) * p * (r `div` q) `div` 2
        a2    = r `mod` q
        b2    = s
        y2    = (a2 * p + b2) `div` q
        x2    = y2 * q - b2
        ret2'' = ret2' + (p - (x2 + a2 - 1) `div` a2) * y2

        ret3' = ret + p * (s `div` q)
        a3    = r
        b3    = s `div` q
        y3    = (a3 * p + b3) `div` q
        x3    = y3 * q - b3
        ret3'' = ret3' + (p - (x3 + a3 - 1) `div` a3) * y3
        
        ret4' = ret
        a4    = r
        b4    = s
        y4    = (a4 * p + b4) `div` q
        x4    = y4 * q - b4
        ret4'' = ret4' + (p - (x4 + a4 - 1) `div` a4) * y4


Measured memory_bytes: 24840
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
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, vector<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; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
template<typename T>
long long pow(T n, T x, T MOD=(T)(1e9)+7){
    long long res = 1LL;
    while(x){
        if(x%2==1) res = (res*n) % MOD;
        x = x>>1;
        n= (n*n) % MOD;
    }
    return res%MOD;
}

template<typename T>
long long factorial(T n, T MOD=(T)(1e9)+7) {
    ll res = 1;
    for(ll i=1; i<=n;i++){
        res = (res*i)%MOD;
    }
    return res%MOD;
}
ll N;
vector<vector<long double>> dist;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
     cin >> N;
    vector<long double> X(N);
    vector<long double> Y(N);
    REP(i, N){
        cin>>X[i]>>Y[i];
    }
    dist.resize(N+1, vector<long double>(N+1, 0));
    REP(i, N){
        REP(j, N){
            if(i==j) dist[i][j] = 0;
            else{
                dist[i][j] = sqrtl((X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]) );
            }
        }
    }
    long double res = 0;
    for(ll i=0; i<N; i++){
        for(ll j=i; j<N; j++){
            res += dist[i][j]*(2*(N-1)*factorial(N-2));
        }
    }
    cout << fixed << setprecision(10) << res/factorial(N) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int n; cin >> n;
  cout << 800*n-200*(n/15);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 998244353
using Graph=vector<vector<int>>;

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  X--;
  Y--;
  Graph G(N);
  for(int i=0;i<N-1;i++){
    G.at(i).push_back(i+1);
    G.at(i+1).push_back(i);
  }
  G.at(X).push_back(Y);
  G.at(Y).push_back(X);
  vector<int> count(N,0);
  for(int i=0;i<N;i++){
    vector<int> dist(N,1000000000);
    dist.at(i)=0;
    queue<int> q;
    q.push(i);
    while(!q.empty()){
      int v=q.front();
      for(auto nv:G.at(v)){
        if(dist.at(nv)!=1000000000){
          continue;
        }
        dist.at(nv)=dist.at(v)+1;
        q.push(nv);
      }
      q.pop();
    }
    for(int i=0;i<N;i++){
      count.at(dist.at(i))++;
    }
  }
  for(int i=1;i<N;i++){
    cout<<count.at(i)/2<<endl;
  }
}


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

int gcd(int x, int y)
{
    if (y > x)
    {
        swap(x, y);
    }

    while (true)
    {
        int z = x % y;
        if (z == 0)
        {
            return y;
        }
        x = y;
        y = z;
    }
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N), G(K+1,0);
  for(int i = 0; i < N; ++i) cin >> A[i];
  G[0] = 0;
  for(int i = 0; i <= K; ++i){
    for(int j = 0; j < N; ++j){
      if(A[j] > i) break;
      if(G[i-A[j]]) continue;
      G[i] = 1;
      break;
    }
  }
  if(G[K]) cout << "First" << endl;
  else cout << "Second" << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iomanip>
using namespace std;

int main(){
    int x,y,n,m;

    cin >> n >> m >> x >> y;

    int xx[n];
    int yy[m];

    for(int i=0; i<n; i++){
        cin >> xx[i];
    }
    for(int i=0; i<m; i++){
        cin >> yy[i];
    }

    int xflag=0;
    int yflag=0;
    int z = 200;

    for(int i=x+1; i<=y; i++){
        for(int j=0; j<n; j++){
            if(xx[j] >= i){
                xflag=1;
            }
        }
        for(int j=0; j<m; j++){
            if(yy[j] < i){
                xflag=1;
            }
        }
        if(xflag==0 && yflag==0){
            z = i;
        }
        xflag = 0;
        yflag = 0;
        

    }

    if(z != 200){
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
}

Measured memory_bytes: 3664
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if N * A < B:
        print(N * A)
    else:
        print(B)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
H, W = map(int, input().split())
S = ['.'+input()+'.' if i > 0 and i < H + 1 else '.' * (W+2) for i in range(H+2)]
for i in range(1, H+1):
    s = ''
    for j in range(1, W+1):
        if S[i][j] == '#': s += '#'
        else: s += str((S[i-1][j-1]+S[i-1][j]+S[i-1][j+1]+S[i][j-1]+S[i][j+1]+S[i+1][j-1]+S[i+1][j]+S[i+1][j+1]).count('#'))
    print(s)


Measured memory_bytes: 68608
lst=list(map(int,input().split()))
lst[1]/=1000
i=0
for a in range(lst[0]+1):
    if i !=0:
        break
    for b in range(lst[0]+1):
     	if lst[0]-a-b>=0:
            if 10*a+5*b+(lst[0]-a-b)==lst[1]:
                print(a,b,lst[0]-a-b)
                i=1
                break
        
if i==0:
    print(-1,-1,-1)



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

int main()
{
    int n;

    cin >> n;

    if(n>= 400 && n<=599)
    {
        cout << "8";
    }

    else if(n>= 600 && n<=799)
    {
        cout << "7";
    }

    else if(n>= 800 && n<=999)
    {
        cout << "6";
    }

    else if(n>= 1000 && n<=1199)
    {
        cout << "5";
    }

    else if(n>= 1200 && n<=1399)
    {
        cout << "4";
    }

    else if(n>= 1400 && n<=1599)
    {
        cout << "3";
    }

    else if(n>= 1600 && n<=1799)
    {
        cout << "2";
    }

    else if(n>= 1800 && n<=1999)
    {
        cout << "1";
    }

    return 0;
}


Measured memory_bytes: 3620