akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll INF = 1e18;

using matrix = vector<V>;
struct Matrix
{
    static const int maxn = 105;
    ll A[maxn][maxn];
    int n;

    Matrix(int n_) : n(n_)
    {
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                A[i][j] = 0;
    }

    Matrix operator*(const Matrix &o) const
    {
        Matrix ret(n);
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                for (int k = 0; k < n; ++k)
                {
                    ll c = A[i][k] * o.A[k][j] % mod;
                    ret.A[i][j] = (ret.A[i][j] + c) % mod;
                }
        return ret;
    }

    static Matrix identity(int n)
    {
        Matrix ret(n);
        for (int i = 0; i < n; ++i)
            ret.A[i][i] = 1;
        return ret;
    }

    Matrix operator^(long long k) const
    {
        Matrix ret = identity(n);
        Matrix a = *this;
        while (k)
        {
            if (k & 1)
                ret = ret * a;
            a = a * a;
            k /= 2;
        }
        return ret;
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    Matrix a(n);
    rep(i,n)rep(j,n){
        ll x;
        cin>>x;
        a.A[i][j] = x;
    }
    a = a ^ k;
    ll res=0;
    rep(i,n){
        rep(j,n){
            
            if(a.A[i][j]){
                res+=a.A[i][j];
                res%=mod;
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
  {
  int k,d;
  cin>>k>>d;
  if((k>=1 && k<=100 )&& (d>=0 && d<=4111))
    {
    if(k>=10)
      cout<<d;
    else
      cout<<(d+100*(10-k));
    }
  return 0;
  }

Measured memory_bytes: 256
S = require('fs').readFileSync('/dev/stdin', 'utf8');
N = M = 0;

S.split('').map(char => {
	if ('ACGT'.includes(char)) {
		N ++;
	} else {
		if (N > M) M = N;
		N = 0;
	}
});

console.log(M);

Measured memory_bytes: 21064
#include<algorithm>
#include<iostream>
#include<math.h>

using namespace std;

int main(){
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;
	long long int e, f;
	long long int r;
	e = max(c, d);
	f = min(c,d);

	r = e % f;
	while (r != 0) {
		e = f;
		f = r;
		r = e % f;
	}
	long long int z = c * d / f;
	long long int cnt = 0;
	cnt = (b / c) - (a -1) / c;
	cnt += (b / d) - (a -1) / d;
	cnt -= (b / z) - (a -1) / z;
	cnt = b - a + 1 - cnt;
	cout << cnt << endl;
}

Measured memory_bytes: 256
import 'dart:io';

void main() {
  int k = int.parse(stdin.readLineSync());
  int i;
  i = 1;
  int sum;
  sum = 7;
  int x = 7 % k;
  var s = <int>{};
  if (k % 2 == 0 || k % 5 == 0) {
    print("-1");
    return;
  }
  while (!s.contains(0)) {
    if (x == 0) {
      print(i);
      return;
    }

    s.add(x);
    sum = x * 10 + 7; // 一桁目は割ったもので良い
    if (sum % k == 0) {
      print(i + 1);
      return;
    }
    x = sum % k;
    // print("sum$sum,$i,${s.contains(x)}");
    // print(x);
    i++;
  }

  print('-111');
}

Measured memory_bytes: 44324
pr_a, pr_b, pr_c, num_a, num_b = map(int, input().split())

res = 10**10
for num_half in range(max(num_a, num_b)+1):
    rest_a = (lambda x: x if x >= 0 else 0)(num_a - num_half)
    rest_b = (lambda x: x if x >= 0 else 0)(num_b - num_half)
    price = rest_a*pr_a + rest_b * pr_b + num_half * pr_c*2
    res = min(res, price)

print(res)


Measured memory_bytes: 3060
#include <stdio.h>

int main (){
	
	int i,j,k,l, height[305], width[305];
	
	i=0;
	do {
		scanf ("%d %d", &height[i], &width[i]);
		i++;
	} while (height[i-1] != 0 && width[i-1] != 0);
	
	for (j=0;j<i-1;j++){
		for (l=0;l<height[j];l++){
			for (k=0;k<width[j];k++){
				if ((l+k)%2==0){
					printf ("#");
				}
				else {
					printf (".");
				}
			}
			printf ("\n");
		}
		printf ("\n");
	}

return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
int g[233][233];
int main()
{	int n,cnt; cin>>n; cnt=n*(n-1)/2;
	if(n&1) for(rint i=1;i<=n/2;i++) g[i][n-i]=1,cnt--;
	else for(rint i=1;i<=n/2;i++) g[i][n-i+1]=1,cnt--;
	cout<<cnt<<endl;
	for(rint i=1;i<=n;i++)
	for(rint j=i+1;j<=n;j++) if(!g[i][j]) cout<<i<<" "<<j<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

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

    ll cnt1 = 0;
    FOR(i, 1, N+1) {
        if (i % K == 0) cnt1++;
    }

    ll cnt2 = 0;
    if (K % 2 == 0) {
        FOR(i, 1, N+1) {
            if (i % K == K / 2) cnt2++;
        }
    }

    cout << cnt1*cnt1*cnt1 + cnt2*cnt2*cnt2 << LF;
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> spare(n);
    vector<ll> vs(n);
    map<ll,ll> mp;
    for(i = 0;i < 2019;++i){
        mp[i] = 0;
    }
    for(i = 0;i < n;++i){
        vs.at(i) = s.at(i) -'0';
    }
    spare.at(n-1) = vs.at(n-1);
    ++mp[spare.at(n-1)];
    ++mp[0];
    vector<ll> spare10(n,1);
    spare10.at(n-1) = 1;
    for(i = 1;i < n;++i){
        spare10.at(n-1-i) = spare10.at(n-i)*10%2019;
        spare.at(n-1-i) = (vs.at(n-1-i)*spare10.at(n-1-i) + spare.at(n-i))%2019;
        ++mp[spare.at(n-1-i)];
    }
    ll ans = 0;
    for(auto x:mp){
        ll tmp = x.second;
        ans += tmp*(tmp-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8416
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include <deque>
using namespace std;

int n, m;
int a[210000], dp[210000];
int sum[210000];

map <int, int> ans;

int doit() {
	dp[n - 1] = -a[n];
	int ma = -dp[n - 1] - sum[n - 1];
	int now = n - 1;
	vector <int> ve;
	while (ma < 0 && now > 2) {
		int q = 2, h = now, mid;
		if (-ma <= sum[2])
			break;
		while (q < h - 1) {
			mid = (q + h) / 2;
			if (-ma > sum[mid])
				q = mid;
			else
				h = mid;
		}
		ma = -ma - 2 * sum[q];
		now = q;
		if (ans.count(ma)) {
			for (int i = 0; i < (int) ve.size(); i++)
				ans[ve[i]] = ans[ma];
			return ans[ma];
		}
		ve.push_back(ma);
	}
	for (int i = 0; i < (int) ve.size(); i++)
		ans[ve[i]] = ma + sum[1] + a[1];
	return ma + sum[1] + a[1];
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i < n; i++)
		sum[i] = sum[i - 1] + a[i];
	scanf("%d", &m);
	while (m--) {
		scanf("%d", &a[n]);
		printf("%d\n", doit());
	}
}

Measured memory_bytes: 28860
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int N = nextInt();// PC数
			if (N == 0) {
				break;
			}
			int M = nextInt();// 学生数

			int r = nextInt();// 記録数
			int[] loginNum = new int[M];// 学生iのログインしている台数
			HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
			for (int i = 0; i < M; i++) {
				map.put(i + 1, new ArrayList<Integer>());
			}

			for (int i = 0; i < r; i++) {
				int time = nextInt();
				int nPC = nextInt();
				int m = nextInt();
				int s = nextInt();

				if (s == 0) {
					// ログアウト時
					loginNum[m - 1]--;
					if (loginNum[m - 1] == 0) {
						// 最後のログアウト
						map.get(m).add(time);
					}
				} else {
					// ログイン時
					loginNum[m - 1]++;
					if (loginNum[m - 1] == 1) {
						// 最初のログイン
						map.get(m).add(time);
					}
				}
			}

			int q = nextInt();
			for (int i = 0; i < q; i++) {
				int start = nextInt();
				int stop = nextInt();
				int student = nextInt();
				int use = 0;
				for (int j = 0; j * 2 < map.get(student).size(); j++) {
					int on = map.get(student).get(j * 2);
					int off = map.get(student).get(j * 2 + 1);
					if (off <= start || on >= stop) {
						// 開始時刻より前のことはどうでも良い
						continue;
					}
					if (on <= start) {
						on = start;
					}
					if (off >= stop) {
						off = stop;
					}
					use += off - on;
				}

				System.out.println(use);

			}

		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	static char nextChar() {
		try {
			int b = System.in.read();
			while (b != -1 && (b == ' ' || b == '\r' || b == '\n'))
				;
			if (b == -1)
				return 0;
			return (char) b;
		} catch (IOException e) {
		}
		return 0;
	}

}

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

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

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int price = a[n - 1] / 2;
    for (int i = 0; i < n - 1; i++){
        price += a[i];
    }
    cout << price << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int n;
	
	scanf("%d", &n);
	
	int a[n];
	
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	
	for(int j=n-1; j>=0; j--){
		printf("%d",a[j]);
		if(j != 0)printf(" ");
	}
	
	printf("\n");
	
	return 0;
	
}


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

int main(){
  int n;
  cin >> n;
  
  map<int, int> m;
  int x;
  for(int i=0; i<n; i++){
    cin >> x;
    if(m.count(x))
      m[x]++;
    else
      m[x] = 1;
  }
  
  cin >> x;

  long long ans = 0;
  for(int i=0; i<x; i++){
    int b, c;
    cin >> b >> c;
    
    long long diff;
    if(m.count(c)){
      m[c] += m[b];
      diff = (long long)m[b]*c - (long long)m[b]*b;
    }
    else{
      m[c] = m[b];
      diff = (long long)m[c]*c - (long long)m[b]*b;
    }
    
    m.erase(b);
    
    if(i==0){
      for(auto p : m){
        auto key = p.first;
        auto value = p.second;
        ans += (long long)key * value;  
      }
    }
    else{
      ans += diff;
    }
    
    cout << ans << endl;
  }
}


Measured memory_bytes: 6572
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] x = new int[2][M];
        for(int i = 0; i < M; i++){
            x[0][i] = sc.nextInt();
            x[1][i] = sc.nextInt();
        }

        int[] num = new int[N];
        Arrays.fill(num, 1);
        int[] red = new int[N];
        red[0] = 1;
        for(int i = 0; i < M; i++){
            if(red[x[0][i]-1] == 1){
                if(num[x[0][i]-1] == 1){
                    red[x[0][i]-1] = 0;
                }
                red[x[1][i]-1] = 1;
            }
            num[x[0][i]-1]--;
            num[x[1][i]-1]++;
        }
        int count = 0;
        for(int i = 0; i < N; i++){
            if(red[i] == 1)
                count++;
        }
        System.out.println(count);
    }   
}

Measured memory_bytes: 81528
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef string ST;
 
 
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
 
 
LL modpow(LL a, LL n, LL mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void func() {
  LL N;
  cin >> N;


  LL M = N-1;
  for(LL i=1;i<=sqrt(N);++i){
    if(N%i==0){
      LL j = N/i;
      if(M>(i+j-2)){
        M=(i+j-2);
      }  
    }
  }
  cout << M;
    
}
 

int main()
{
  func();
  return 0;
}
 

Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def sieve(n:Int) = {
    val list = Array.tabulate(n+1) { _ % 2 }
    val primes = new ArrayBuffer[Int]
    list(1) = 0
    list(2) = 2
    primes += 2

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(list(i) == 1) {
        (i*i to n by i*2).foreach { list(_) = 0 }
        primes += primes(primes.length-1)+i
      }
    }
    for(i<-Math.sqrt(n).toInt+1 to n if list(i)==1)
      primes += primes(primes.length-1)+i
    primes.toArray
  }

  def main(args:Array[String]) = {
    val p = sieve(110000)
    var n = 0
    while( { n = readInt; n} != 0 ) println(p(n-1))
  }
}

Measured memory_bytes: 49260
//ABC154C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin >> p.at(i);
	}
	long long int num = 0;
	for(int i=0;i<k;i++){
		num += p.at(i);
	}
	long long int m = num;
	for(int i=1;i<n-k+1;i++){
		num -= p.at(i-1);
		num += p.at(i+k-1);
		m = max(m,num);
	}
	double ans = (m+k)/2.0;
	cout << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const ll MAX = 210000;
const ll MOD = 1000000007;

long long 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) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
const ll ainf = 998244353;
pair<ll, ll> sc[100010];
ll memo[61][2];
ll digi[61];
ll n, k;
ll rec(ll dig, int fix) {

	ll v = 1LL << dig;
	if (dig < 0) return 0;

	ll& res = memo[dig][fix];
	if (~res) return res;
	res = 0;
	if (fix == 1) {
		if ((k & v) > 0) {
			ll v1 = rec(dig - 1, 1);
			v1 += (n - digi[dig]) * v;
			ll v2 = rec(dig - 1, 0);
			v2 += digi[dig] * v;
			res = max(v1, v2);
		}
		else {
			ll v1 = rec(dig - 1, 1);
			v1 += digi[dig] * v;
			res = v1;
		}
	}
	else {
		ll v1 = rec(dig - 1, 0);
		v1 += digi[dig] * v;
		ll v2 = rec(dig - 1, 0);
		v2 += (n - digi[dig]) * v;
		res = max(v1,v2);

	}
	return res;
}

void solv() {

	cin >> n >> k;
	ll a[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	memset(memo, -1, sizeof(memo));
	for (size_t i = 0; i < n; i++)
	{
		ll p = a[i];
		int dig = 0;
		while (p > 0)
		{
			if (p & 1) {
				digi[dig]++;
			}
			dig++;
			p >>= 1;
		}
	}

	cout << rec(60, 1) << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

#define x first
#define y second

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        vector<pair<long long, long long>> p;
        for (int i = 0; i < n; i ++) {
                long long x, y;
                scanf("%lld%lld", &x, &y);
                p.emplace_back(x, y);
        }
        sort(all(p));
        long long ans = INFL;
        for (int i = 0; i < n; i ++) {
                for (int j = i + 1; j < n; j ++) {
                        int left = 0;
                        for (int right = 0; right < n; right ++) {
                                int cnt = 0;
                                bool swapped = false;
                                if (p[i].y < p[j].y) { 
                                        swap(p[i].y, p[j].y);
                                        swapped = true;
                                }
                                for (int k = 0; k < n; k ++) {
                                        if (p[left].x <= p[k].x && p[k].x <= p[right].x && p[j].y <= p[k].y && p[k].y <= p[i].y) {
                                                cnt ++;
                                        }
                                }
                                if (cnt >= k) {
                                        ans = min(ans, (p[right].x - p[left].x) * (p[i].y - p[j].y));
                                        left ++;
                                        right --;
                                }
                                if (swapped) swap(p[i].y, p[j].y);
                        }
                }
        }
        printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

const int MAX_FACT = 200001;
unsigned long long MOD = 1e9 + 7;
unsigned long long fact[MAX_FACT], invFact[MAX_FACT], inv[MAX_FACT];

void init()
{
	fact[0] = 1;
	fact[1] = 1;
	invFact[0] = 1;
	invFact[1] = 1;
	inv[1] = 1;
	for (auto i = 2; i < MAX_FACT; ++i)
	{
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		invFact[i] = invFact[i - 1] * inv[i] % MOD;
	}
}

unsigned long long calcCombination(int n, int k)
{
	if (n < k)
	{
		return 0;
	}
	if ((n < 0) || (k < 0))
	{
		return 0;
	}

	return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}

int main()
{
	unsigned long long N, M, K;
	cin >> N >> M >> K;

	init();

	auto result = 0ull;
	for (auto i = 1; i < N; ++i)
	{
		result = (result + i * (N - i) * M % MOD * M % MOD) % MOD;
	}
	for (auto i = 1; i < M; ++i)
	{
		result = (result + i * (M - i) * N % MOD * N % MOD) % MOD;
	}

	result = (result * calcCombination(N * M - 2, K - 2)) % MOD;
	cout << result << endl;

	return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

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

bool chk[maxn];
vector<int> adj[maxn];
int h[maxn];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, m; cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> h[i];
  for (int i = 0; i < m; ++i){
    int u, v; cin >> u >> v;
    adj[u].push_back(v); adj[v].push_back(u);
  }
  int ans = 0;
  for (int u = 1; u <= n; ++u){
    int d = 0;
    for (auto v : adj[u]){
      d = d + (h[v] >= h[u]);
    }
    if (d == 0) ++ans;
  }
  cout << ans;
}



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

using namespace std;

int main(void) {
  unsigned long long ans = 1;
  int N; cin >> N;

  bool of = false;
  
  for (int i = 0; i < N; i++) {
    unsigned long long A; cin >> A;
    unsigned long long tmp = ans*A;

    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }

    if (!of) {
      if (tmp%A != 0 || tmp/A != ans || tmp > 1000000000000000000) {
        of = true;
      }

      ans = tmp;
    }
  }

  if (of) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

int main() {
	int H,W;
	while(true){
		scanf("%d %d", &H, &W);
		if (H==0){break;}
		for (int i=1; i<H+1; i++) {
			if (i%2==1) {
				for(int j=1;j<W+1;j++){
					if(j%2==1){
						printf("#");
					}else{
						printf(".");
					}
				}
				printf("\n");
			}else{
				for(int j=1;j<W+1;j++){
					if(j%2==1){
						printf(".");
					}else{
						printf("#");
					}
				}
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2684
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N,K = LI()
    V = [LI() for _ in range(N)]
    V.sort(key=lambda x:x[1],reverse=True)
    c = [0] * (N+1)
    s = []
    ans = 0
    cnt = 0
    for t,d in V[:K]:
        ans += d
        if c[t] == 0:
            ans += 1 + 2*cnt
            cnt += 1
        else:
            s.append((t,d))
        c[t] = 1

    tmp = ans
    for t,d in V[K:]:
        if s == []: break
        if c[t] == 0:
            x,y = s.pop()
            tmp += d + cnt * 2 + 1 - y
            c[t] = 1
            cnt += 1
            ans = max(tmp,ans)
    print(ans)





if __name__ == '__main__':
    main()

Measured memory_bytes: 64216
import java.util.Scanner;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        Integer[] a = new Integer[n];
        Stream.of(sc.nextLine().split(" "))
              .map(Integer::parseInt)
              .collect(Collectors.toList())
              .toArray(a);
        int t = 0;
        for (int i = 0; i < a.length; i++) {
            int minj = i;
            for (int j = i; j < a.length; j++) {
                if (a[j] < a[minj]) {
                    minj = j;
                }
            }
            if (minj != i) {
                int tmp = a[i];
                a[i] = a[minj];
                a[minj] = tmp;
                t++;
            }
        }
        System.out.println(Stream.of(a).map(Object::toString)
                           .collect(Collectors.joining(" ")));
        System.out.println(t);
    }
}




Measured memory_bytes: 32688
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const a = s[0];
  const b = s[1];

  const ans = (a + b) % 24;

  console.log(ans);
}

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


Measured memory_bytes: 11468
use std::io::{ stdin, stdout, BufRead, Write };

const SP   : u8 = b' ';
const LF   : u8 = b'\n';
const ZERO : u8 = b'0';

#[inline(always)]
fn uitoa(mut n: usize, buf: &mut Vec<u8>) {
  buf.clear();
  if n == 0 {
    buf.push(ZERO);
    return;
  }

  while n > 0 {
    buf.push((n % 10) as u8 + ZERO);
    n /= 10;
  }

  buf.reverse();
}

#[inline(always)]
fn atoui(s: &[u8]) -> usize {
  let mut n = 0;
  for b in &s[..] { n = n * 10 + (b - ZERO) as usize; }
  n
}

fn main() {
  let stdin = stdin();
  let mut stdin = stdin.lock();

  let mut buf = Vec::with_capacity(500 * 2);
  let len = stdin.read_until(SP, &mut buf).unwrap();
  buf.truncate(len - 1);
  let h = atoui(&buf);

  buf.clear();
  let len = stdin.read_until(LF, &mut buf).unwrap();
  buf.truncate(len - 1);
  let w = atoui(&buf);

  let mut num = Vec::with_capacity(3);
  let mut ans = Vec::new();
  let mut n   = 0;

  let mut odd = 0;
  let mut x   = 0;
  let mut y   = 0;

  for i in 0..h {
    buf.clear();
    stdin.read_until(LF, &mut buf).unwrap();

    if i % 2 == 0 {
      for j in 0..w {
        if odd != 0 {
          uitoa(y + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(x + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(i + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(j + 1, &mut num);
          num.push(LF);
          ans.extend_from_slice(&num);

          n += 1;
        }
        odd ^= buf[j * 2] & 1;
        y = i;
        x = j;
      }
    } else {
      for mut j in 0..w {
        j = w - 1 - j;

        if odd != 0 {
          uitoa(y + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(x + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(i + 1, &mut num);
          num.push(SP);
          ans.extend_from_slice(&num);

          uitoa(j + 1, &mut num);
          num.push(LF);
          ans.extend_from_slice(&num);

          n += 1;
        }
        odd ^= buf[j * 2] & 1;
        y = i;
        x = j;
      }
    }
  }

  let stdout = stdout();
  let mut stdout = stdout.lock();

  uitoa(n, &mut buf);
  buf.push(LF);
  stdout.write(&buf).unwrap();

  stdout.write(&ans).unwrap();
  stdout.flush().unwrap();
}


Measured memory_bytes: 8188
#include <iostream>

using namespace std;

int main()
{
	int t;
	int n;

	int s,a, b,c;

	for(int i = 0; i < 4; i++)
	{
		cin >> n;

	if(n == 1)
	{
		cin >> s;
		cout << s * 6000 << endl;
	}
	else if(n == 2)
	{
		cin >> a;
		cout << a * 4000 << endl;
	}
	else if(n == 3)
	{
		cin >> b;
		cout << b * 3000 << endl;
	}
	else if(n == 4)
	{
		cin >> c;
		cout << c * 2000 << endl;
	}

}


	return 0;
}

Measured memory_bytes: 1160
n = int(input())
#n, m = map(int,input().split())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split())) for i in range(n)]
ls = [input() for i in range(n)]

for i in range(1,len(ls)):
  if ls[i][0] != ls[i-1][-1]:
    print("No")
    quit()
  if ls.count(ls[i]) >= 2:
    print("No")
    quit()
    
print("Yes")

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    ll B = 0;
    ll W = 0;
    REP(i, N){
        if(i%2 == 0){
            if(S[i] == '0'){
                B++;
            }
            else{
                W++;
            }
        }
        else{
            if(S[i] == '0'){
                W++;
            }
            else{
                B++;
            }
        }
    }
    cout << min(B, W) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;


const int N = 100000 + 5;
int n;
int cnt[N];

void solve()
{
    cin >> n;
    int x;
    for(int i = 0; i < n; ++ i) {
        scanf("%d", &x);
        cnt[x] ++;
        cnt[x + 1] ++;
        if (x)
        cnt[x - 1] ++;
    }
    cout << *max_element(cnt, cnt + N) << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::max;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io;

// fn main() {
//     let input = input_number();
//     let n = input[0] as usize;
//     let mut current_n = n;
//     let mut hash_set: HashSet<usize> = HashSet::new();
//
//     for i in 2..(n as f64).sqrt() as usize + 2 {
//         if current_n % i == 0 {
//             current_n /= i;
//             hash_set.insert(i);
//         }
//     }
//     if n > 1 && hash_set.len() == 0 {
//         hash_set.insert(n);
//     }
//     println!("{}", hash_set.len());
// }

fn main() {
    let input = input_number();
    let n = input[0] as usize;
    let mut current_n = n;
    let mut counter = 0usize;

    for i in 2..(n as f64).sqrt() as usize + 2 {
        if current_n % i == 0 {
            current_n /= i;
            counter += 1;

            let mut j = 2;
            while current_n % i.pow(j) == 0 {
                current_n /= i.pow(j);
                counter += 1;
                j += 1;
            }

            while current_n % i == 0 {
                current_n /= i;
            }
        }
    }
    if current_n > 1 {
        counter += 1;
    }
    println!("{}", counter);
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<u64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<u64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (u64, f32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: u64 = iter.next().unwrap().parse().unwrap();
    let n: f32 = iter.next().unwrap().parse().unwrap();
    (c, n)
}


Measured memory_bytes: 2144
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
t=int(input())
INF=10**19
def dfs(k):
    if k==1:return d
    if k==0:return 0
    if k in dic:return dic[k]
    ans=k*d
    ans=min(ans,dfs(k//2)+a+k%2*d,dfs((k+1)//2)+a+-k%2*d,dfs(k//3)+b+k%3*d,dfs((k+2)//3)+b+-k%3*d,dfs(k//5)+c+k%5*d,dfs((k+4)//5)+c+-k%5*d)
    dic[k]=ans
    return ans
for _ in range(t):
    dic={}
    n,a,b,c,d=map(int,input().split())
    print(dfs(n))

Measured memory_bytes: 11020
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow ---question galat mat padhna */
{
    fast;
    ll n;
    cin>>n;
    map<ll,ll>mp;
    vector<ll>x,y;
    vector<ll>point;
    For(i,n)
    {
        ll x1,y1;
        cin>>x1>>y1;
        x.pb(x1);
        y.pb(y1);
    }
    sort(all(x));
    sort(all(y));
    reverse(all(y));
    ll ans=0;
    if(n%2==1)
    {
        ll x1=x[n/2];
        ll y1=y[n/2];
        ll ans=y1-x1+1;
        cout<<ans<<endl;
    }
    else 
    {
        ll x1=x[n/2-1];
        ll y1=y[n/2];
        ll x2=x[n/2];
        ll y2=y[n/2-1];
        
        
            ans=abs((y1-x1+1)*(y2-x2+1))-abs((y1-x1)*(y2-x2));
        
        
        cout<<ans<<endl;
    }
}   

Measured memory_bytes: 6760
line = raw_input()
H, W = [int(s) for s in line.split(' ')]
lines = []
ret = [0] * W
for h in range(0, H):
    line = raw_input()
    A = [0 if s == '.' else 1 for s in line]
    if all([a == 0 for a in A]):
        continue
    lines.append(line)
    ret = [i + j for i, j in zip(ret, A)]
for line in lines:
    print ''.join([c for i, c in zip(range(0, W), line) if ret[i] > 0])


Measured memory_bytes: 2568
#include <cstdio>

const int MAXN = 25;

int n, ans;
int arr[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &arr[i]);
	}
	for (int i = 2; i < n; ++i) {
		if ((arr[i] - arr[i - 1]) * (arr[i] - arr[i + 1]) < 0)
			++ans;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

long long int N, M;

int main(void) {

	cin >> N >> M;

	long long int ans = 0;

	if (N >= M/2) { ans = M/2; }
	else { ans = (N * 2 + M) / 4; }

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
N, A, B, C = [int(_) for _ in input().split()]
H = [int(input()) for _ in range(N)]
INF = 1000 * 1000

def dfs(h, a, b, c):
    if not h:
        return INF if a * b * c == 0 else abs(A - a)+  abs(B - b) + abs(C - c)

    k = h[0]
    return min(dfs(h[1:], a, b, c),
               dfs(h[1:], a + k, b, c) + 10,
               dfs(h[1:], a, b + k, c) + 10,
               dfs(h[1:], a, b, c + k) + 10)

print(dfs(H, 0, 0, 0) - 30)


Measured memory_bytes: 3064
def solve(string):
    n, k, *td = map(int, string.split())
    td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)
    max_variety = len(set([c[0] for c in td]))
    choice = td[:k]
    count = [0] * n
    for _c in choice:
        count[_c[0] - 1] += 1
    variety = set([c[0] for c in choice])
    ans = [len(variety)**2 + sum([c[1] for c in choice])]
    i_remove, i_append = k - 1, k
    while len(variety) < min(max_variety, k):
        while td[i_append][0] in variety:
            i_append += 1
        while count[td[i_remove][0] - 1] == 1:
            i_remove -= 1
        variety.add(td[i_append][0])
        count[td[i_remove][0] - 1] -= 1
        ans.append(ans[-1] - td[i_remove][1] + td[i_append][1] + 2 * len(variety) - 1)
        i_remove -= 1
        i_append += 1
    return str(max(ans))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


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

int main()
{
	int a, b;
	char x;
	while (true) {
		cin >> a >> x >> b;
		if (x == '+') cout << a + b << endl;
		else if (x == '-') cout << a - b << endl;
		else if (x == '/') cout << a / b << endl;
		else if (x == '*') cout << a * b << endl;
		else break;
	}
}


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

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

    map<string, int> S;

    for (int i = 0; i < N; ++i) {
        cin >> s;
        S[s]++;
    }

    cout << S.size() << endl;
}

Measured memory_bytes: 19120
import sys

import numpy as np
def sieve_of_eratosthenes(n=10**6):
  sieve = np.ones(n+1); sieve[:2] = 0
  for i in range(2, int(n**.5)+1):
    if sieve[i]: sieve[i*2::i] = 0
  return sieve, np.flatnonzero(sieve)

# def sieve_of_eratosthenes(n=10**6):
#   sieve = [1] * (n+1); sieve[0] = sieve[1] = 0
#   for i in range(2, int(n**.5)+1):
#     if not sieve[i]: continue
#     for j in range(i*2, n+1, i): sieve[j] = 0
#   prime_nums = [i for i in range(2, n+1) if sieve[i]]
#   return sieve, prime_nums

is_prime, prime_nums = sieve_of_eratosthenes()

def prime_factorize(n):
  res = dict()
  if n < 2: return res
  border = int(n**.5)
  for p in prime_nums:
    if p > border: break
    while n % p == 0: res[p] = res.get(p, 0)+1; n //= p
    if n == 1: return res
  res[n] = 1
  return res

def prime_factorize_fac(n):
  res = dict()
  for i in range(2, n+1):
    for p, c in prime_factorize(i).items(): res[p] = res.get(p, 0)+c
  return res

def main():
    n = int(sys.stdin.readline().rstrip())
    res = prime_factorize(n)
    ans = 0
    for m in res.values():
        i = 1
        while True:
            if (1 + i) * i // 2 > m:
                i -= 1
                break 
            i += 1
        ans += i
    print(ans)

    


if __name__ == '__main__':
    main()

Measured memory_bytes: 35080
import java.util.Scanner;

public class Main {
    static long mod = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong(), a = sc.nextInt(), b = sc.nextInt();
        long ans = pow(2, n) - comb(n, a) - comb(n, b) - 1;
        if(ans < 0) ans += (Math.abs(ans) / mod + 1) * mod;
        System.out.println(ans);
    }
    static long pow(long x, long n) {
        long a = 1;
        do {
            if((n & 1) == 1) a = (a * x) % mod;
            x = (x * x) % mod;
        } while((n >>= 1) > 0);
        return a;
    }
    static long comb(long n, long r) {
        long mol = n, den = r;
        for(int i = 1; i < r; i++) {
            mol = (mol * (n - i)) % mod;
            den = (den * i) % mod;
        }
        return mol * pow(den, mod - 2) % mod;
    }
}

Measured memory_bytes: 23764
from collections import defaultdict

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

x -= 1
y -= 1

storage = defaultdict(int)

for i in range(n - 1):
    for j in range(i + 1, n):
        # print('i,j', i, j)
        # print(j-i, find_distance(x, i) + find_distance(x, j), find_distance(y, i) + find_distance(y, j))
        distance = min(j-i, abs(i - x) + abs(j - y) + 1, abs(i - y) + abs(j - x) + 1)
        # print('res', distance)
        storage[distance] += 1

for i in range(1, n):
    print(storage[i])

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

bool in(ll x1, ll y1, ll x2, ll y2, ll xn, ll yn) {
	return (x1 <= xn && xn <= x2 && y1 <= yn && yn <= y2);
}

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

	VL v(n);
	REP(i, n) { cin >> v[i]; }

	ll sum = 0;
	REPC(x, v) {
		sum += x;
	}

	ll t = 0;
	double min = 1e10;
	REP(i, v.size()) {
		ll dis = abs(v[i] * n - sum);
		if (dis < min) {
			min = dis;
			t = i;
		}
	}
	cout << t << endl;
}

Measured memory_bytes: 256
def bf(edges, start, N):
    INF = float('inf')
    costs = [INF] * N
    costs[start] = 0
    for i in range(N):
        for f, t, c in edges:
            if costs[f] != INF and costs[f] + c < costs[t]:
                costs[t] = costs[f] + c
                if i == N-1 and t == N-1:
                    return 'inf'
    return -costs[N-1]

N, M = map(int, input().split())
edges = []
for _ in range(M):
    f, t, c = map(int, input().split())
    edges.append((f-1, t-1, -c))

print(bf(edges, 0, N))


Measured memory_bytes: 3388
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, M;
ll X[1001], Y[1001], Z[1001], W[1001];

int main() {
    fastio();
    cin >> N >> M;
    ll ans = 0;
    REP(i, N) cin >> X[i] >> Y[i] >> Z[i];
    REP(i, 8) {
        int x = (i >> 2) & 1 ? 1 : -1;
        int y = (i >> 1) & 1 ? 1 : -1;
        int z = (i >> 0) & 1 ? 1 : -1;
        REP(j, N) W[j] = x * X[j] + y * Y[j] + z * Z[j];
        sort(W, W + N);
        ll tmp = 0;
        REP(j, M) tmp += W[j];
        ans = max(ans, abs(tmp));
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll A;
    char B[6];
    for(ll i = 0; i < 6; i++){
        B[i] = 'A';
    }

    cin >> A >> B;

    ll ansI = 0;
    ll ansD = 0;
    ll p = 0;
    ll counter = 0;
    while(counter <= 2){
        if(B[p] != '.' && counter == 0){
            ansI *= 10;
            ansI += A * (B[p] - '0');
        }else if(B[p] != '.' && counter > 0){
            ansD *= 10;
            ansD += A * (B[p] - '0');
            counter++;
        }else{
            counter = 1;
        }
        p++;
    }

    cout << ansI + ansD / 100 << endl;

    return 0;
}


Measured memory_bytes: 3620