akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}



ll sub(ll k){
  ll res = 0;
  for(ll i = 1; i <= 11; i++)for(ll j = 1; j <= 5; j++){
    ll sum = (7 * i + j - 7) * 9;
    sum += 72;
    if(sum % 11 == k) res++;
  }
  return res;
}

void solve(){
  ll N, K;
  cin >> N >> K;
  N -= 2;
  ll one = sub(K);
  ll ans = 0;
  ans += N / 11 * one;
  for(ll i = N / 11 * 11 + 1; i <= N; i++)for(ll j = 1; j <= 5; j++){
    ll sum = (7 * i + j - 7) * 9;
    sum += 72;
    if(sum % 11 == K) ans++;
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 256
//abc136_a.cpp
//Sun Aug  4 21:00:17 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a,b,c;
	cin >> a >> b >> c;

	cout << max(0,c-(a-b)) << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

char so[30001];

int main(){
	int t,i,j,c,b;
	
	memset(so,0,sizeof(so));

	for(i=2;i*i<=30000;i++){
		for(j=2*i;j<=30000;j+=i){
			so[j]=1;
		}
	}
	while(scanf("%d",&t)){
		if(t==0)break;
		c=0;
		for(i=2;i<=t/3+1;i++){
			if(t%2==0 && c==1)break;
			if(i!=2 && i%2==0)++i;
			if(i!=3 && i%3==0)++i;
			if(i!=5 && i%5==0)++i;
			if(i!=7 && i%7==0)++i;
			for(j=(i>t/2-i-1?i:t/2-i-1);j<=t/2+1;j++){
				if(t<i+j+j)break;
/*				if(j!=2 && j%2==0)continue;
				if(j!=3 && j%3==0)continue;
				if(t-i-j!=2 && (t-i-j)%2==0)continue;
				if(t-i-j!=3 && (t-i-j)%3==0)continue;
*/				if(2*(i+j)<=t)continue;
				if(so[i]==0 && so[j]==0 && so[t-i-j]==0)++c;
			}
		}
//		if(t%100==0){
		printf("%d\n",c);
//		}
	}
	return 0;
}

Measured memory_bytes: 792
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		char a[][] = new char[h][w];
		for (int i = 0 ; i < h ; i++) {
			String s = sc.next();
			for (int j = 0; j < w ; j++)
				a[i][j] = s.charAt(j);
		}
		int num = 0;
		for (int i = 0; i < 1 << h; i++) {
			for (int j = 0; j < 1 << w; j++) {
				int count = 0;
				for (int p = 0; p < h ; p++) {
					for (int q = 0; q < w ; q++) {
                      int p2 = 1 << p;
                      int q2 = 1 << q;
						if((i & p2) == 0 && (j & q2) == 0 && a[p][q] == '#') {
								count++;
							}
					}
					}
				if (count == k)
					num++;
				}
		}
		sc.close();
		System.out.println(num);
	}
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int n, m, q;
int a[50], b[50], c[50], d[50];
ll ans = 0;

void rec(vector<int> x, int mv) {
  if (x.size() == n) {
    ll cnt = 0;
    rep(i, q) {
      if (x[b[i] - 1] - x[a[i] - 1] == c[i]) cnt += d[i];
    }
    ans = max(ans, cnt);
  } else {
    REP(i, mv, m + 1) {
      vector<int> _x = x;
      _x.eb(i);
      rec(_x, i);
    }
  }
}

int main() {
  cin >> n >> m >> q;
  rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }

  rec(vector<int>(), 1);

  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<utility>
#include <string.h>
#include <cmath>
#include <math.h> 


#define For(i,begin,end) for(int i=(begin);i<(end);i++)
#define FORD(i,begin,end) for(int i=(begin);i>(end);i--)
#define FOR(l) for(auto p = l.begin(); p != l.end(); p++)
#define ALL(k) (k).begin(),(k).end()
#define e1 first
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> Vl;


ll dp[100000];
ll n,m;
VI adj[100005];
ll dfs_fun(ll x)
{
	if(dp[x] != -1)
		return dp[x];
	ll ret = 0; //max length keeps getting updated
	For(i,0,adj[x].size())
	{
		ret = max(ret, 1 + dfs_fun(adj[x][i]));
	}
	return dp[x] = ret;
}

int main()
{	
	memset(dp, -1, sizeof dp);
	cin>>n>>m;
	ll u,v;
	For(i,0,m)
	{
		cin>>u>>v;
		adj[u-1].push_back(v-1);
	}

	ll ans = 0;

	For(i,0,n)
		ans = max(ans,dfs_fun(i));

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

Measured memory_bytes: 8576
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,m;
	
	while(cin>>n>>m,n|m)
	{
		vector<pair<int,pair<int,int> > > v;
		int infected[n+1] = {};
		infected[1] = 1;
		
		
		REP(i,m)
		{
			int t,s,d;
			
			cin >> t >> s >> d;
			
			v.PB(MP(t,MP(s,d)));
		}
		
		sort(ALL(v));
		
		REP(i,m)
		{
			if(infected[v[i].SE.FI])
				infected[v[i].SE.SE] = 1;
		}
		
		int ans = 0;

		REP(i,n+1)
		{
			ans += infected[i];
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n,k;
  cin >> n >> k;
  set<int> st;
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      st.insert(a-1);
    }
  }
  int ans = 0;
  rep(i,n){
    if(!st.count(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
N=int(input())
A=list(map(int,input().split()))
C=[0]
for i in range(N):
  C.append(C[i]+A[i])
INF=10**18
DP=[[INF]*N for i in range(N)]
def f(l,r):
  if l==r:
    return 0
  if DP[l][r]!=INF:
    return DP[l][r]
  for i in range(l+1,r+1):
    DP[l][r]=min(DP[l][r],f(l,i-1)+f(i,r)+C[r+1]-C[l])
  return DP[l][r]

print(f(0,N-1))

Measured memory_bytes: 76068
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;
const ll INF=1e12;

int main(){
    ll a,b,q;
    cin >> a >> b >> q;
    vector<ll> s(a),t(b),x(q);
    for(ll i=0;i<a;i++){
        cin >> s[i];
    }
    for(ll i=0;i<b;i++){
        cin >> t[i];
    }
    for(ll i=0;i<q;i++){
        cin >> x[i];
    }
    s.push_back(INF);
    s.push_back(-1*INF);
    t.push_back(INF);
    t.push_back(-1*INF);

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    for(ll i=0;i<q;i++){
        ll sIter=lower_bound(s.begin(),s.end(),x[i])-s.begin(),tIter=lower_bound(t.begin(),t.end(),x[i])-t.begin();
        ll ans=INF;
        for(ll j=-1;j<1;j++){
            for(ll k=-1;k<1;k++){
                ll d=min(abs(x[i]-s[sIter+j]),abs(x[i]-t[tIter+k]))+abs(s[sIter+j]-t[tIter+k]);
                ans=min(d,ans);
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define number_of_digit(n) __builtin_ffs(n);
#define ll long long
#define T int
#define ld long double
inline void print(T n)
{
	if (n == 0)
	{
		putchar('0');
		putchar('\n');
	}
	else if (n == -1)
	{
		putchar('-');
		putchar('1');
		putchar('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar(buf[++i]);
	}
}
int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int ret = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          ret = ret * 10 + cc - '0';
          cc = getc(stdin);
       }
      return ret;
}
ll power(ll num,ll g)
{
	if(g==0)return 1;

	if(g%2==1)return (num*power((num*num)%mod,g/2))%mod;
	return power((num*num)%mod,g/2);
}
int main()
{
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);

  	ll n;
  	cin>>n;
  	ll a[n],b[n];
  	For(i,n)cin>>a[i]>>b[i];
  	pair<int,int> pa[n];
  	For(i,n)
  	{
  		pa[i]=mp(a[i]+b[i],i);
  	}
  	sort(pa,pa+n);
  	For(i,n)
  	{
  		int j=i;
  		while(j+1<n && pa[j].ff==pa[j+1].ff)j++;
  		i=j;
	}
	bool is=false;
  	int i=0,j=n-1;
  	ll ans=0;
  	while(0<=j)
  	{
  		if(is)
  		{
  			ans-=b[pa[j].ss];
  			is=false;
  			j--;
  		}
  		else
  		{
  			ans+=a[pa[j].ss];
  			is=true;
  			j--;
  		}
  	}
  	cout<<ans<<endl;
 	return 0;
}

Measured memory_bytes: 2560
s = input().split()
stack = []
for a in range(len(s)):
    w = s[a]
    if w == "+":
        stack.append(stack.pop(-2)+stack.pop())
    elif w == "-":
        stack.append(stack.pop(-2)-stack.pop())
    elif w == "*":
        stack.append(stack.pop(-2)*stack.pop())
    else:
        stack.append(int(w))
print(stack[0])


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

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


typedef long long ll;
typedef long double ld;
const ll SIZE = 1e6;
ll q;
vector<ll> vec;
vector<pair<ll, ll>> st;
ll pos[SIZE], ans[SIZE], lft[SIZE];

int main() {
    fastInp;

    ll n;
    cin >> n;
    vec.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
        vec[i]--;
        pos[vec[i]] = (i + 1);
        lft[i] = n;
        st.push_back({ vec[i], i });
    }

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

    queue<ll> emp;
    for (int i = 0; i < n * n; i++) {
        if (!pos[i]) {
            emp.push(i);
        }
        else {
            if (emp.size() < pos[i] - 1) {
                cout << "No";
                return 0;
            }
            ans[i] = pos[i];
            lft[pos[i] - 1]--;
            for (int j = 0; j < pos[i] - 1; j++) {
                ll q = emp.front();
                emp.pop();
                ans[q] = pos[i];
                lft[pos[i] - 1]--;
            }
        }
    }

    for (int i = 0; i < n * n; i++) {
        if (ans[i] == 0) {
            for (int k = 0; k < n; k++) {
                if (lft[st[k].second] > 0) {
                    ans[i] = st[k].second + 1;
                    lft[st[k].second]--;
                    k = n;
                }
            }
            continue;
        }
    }

    for (int i = 0; i < n; i++) {
        ll s = 0;
        for (int j = 0; j < vec[i]; j++) {
            s += (ans[j] == (i + 1));
        }
        if (s != i) {
            cout << "No";
            return 0;
        }
    }

    cout << "Yes\n";
    for (int i = 0; i < n * n; i++) cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 10880
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000009
typedef long long ll;
using namespace std;

const ll MAX_n = 105;
const ll MAX_W = 100005;
ll w[MAX_n];
ll v[MAX_n];
ll dp[MAX_n][MAX_W];
int n,W;

int main(){
  cin >> n >> W;
  for(int i=0;i<n;i++) cin >> w[i] >> v[i];

  for(int i=0;i<=W;i++) dp[0][i] = 0;

  for(ll i=0;i<n;i++){
    for(ll j=0;j<=W;j++){
      if(j-w[i]>=0) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }

  cout << dp[n][W] << endl;
  return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 600005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
char s[1005];
int main()
{
    int n,i;
    long long ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        int b=n/i;
        if(n%i)
        {
            ans=ans+b;
        }
        else
        {
            ans=ans+b-1;

        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3820
def main():
  _, *AB = map(int, open(0).read().split())

  AB = iter(AB[::-1])
  increment = 0

  for b, a in zip(AB, AB):
    a += increment
    if a % b:
      increment += b - a % b

  print(increment)
  
if __name__=="__main__":
  main()

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

using namespace std;

void solve()
{
	string s;
	cin >> s;
	bool update = true;
	while(update)
	{
		if(s.size() <= 3)
		{
			break;
		}
		update = false;
		string next = "";
		next += s[0];
		for(int i = 1; i < s.size() - 1; ++i)
		{
			if(i <= s.size() - 3 && s[i] == 'm' && s[i + 1] == 'e' && s[i + 2] == 'w')
			{
				update = true;
				i += 2;
				continue;
			}
			else
			{
				next += s[i];
			}
		}
		next += s[s.size() - 1];
		s = next;
	}
	if(s == "" || s == "mew")
	{
		cout << "Cat" << endl;
	}
	else
	{
		cout << "Rabbit" << endl;
	}
}

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

Measured memory_bytes: 1200
def main():
	N, M = map(int, input().split())
	st = [0]*N
	p = [0]*M
	INF = 10**9+7
	ans = [[INF, N] for _ in range(N)]
	for i in range(N):
		st[i] = list(map(int, input().split()))
	for i in range(M):
		p[i] = list(map(int, input().split()))
	for i in range(N):
		for j in range(M):
			dist = abs(st[i][0]-p[j][0])+abs(st[i][1]-p[j][1])
			if dist < ans[i][0]:
				ans[i][0] = dist
				ans[i][1] = j

	for i in range(N):
		print(ans[i][1]+1)


if __name__ == '__main__':
	main()

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

#define fastio1 ios_base::sync_with_stdio(false)
#define fastio2 cin.tie(NULL)
#define LL long long
using namespace std;

namespace patch
{
    template < typename T > string to_string( const T& n )
    {
        ostringstream stm ;
        stm << n ;
        return stm.str();
    }
}

int main(){
    fastio1; fastio2;
	int h, w; cin >> h >> w;
	int c[10][10];
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			cin >> c[i][j];
		}
	}
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			for (int k = 0; k < 10; k++){
				c[j][k] = min(c[j][k], c[j][i]+c[i][k]);
			}
		}
	}
	
	int total = 0;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			int temp; cin >> temp;
			if (temp != -1 ){
				total += c[temp][1];
			}
		}
	}
	cout << total << endl;
}


Measured memory_bytes: 256
fn main() {
    let input: Vec<i32> = read_vec();
    let (a, b) = (input[0], input[1]);

    if (a + b) % 2 == 1 {
        println!("IMPOSSIBLE");
    } else {
        println!("{}", (a + b) / 2);
    }
}





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

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 main() {
    int n;
    cin >> n;
    vector<ll> v(n+2,0);
    repl(i,1,n+1)cin >> v[i];
    vector<ll> r(n+2,0);
    repl(i,1,n+2){
        r[i] = r[i-1] + abs(v[i-1] - v[i]);
    }
    repl(i,1,n+1){
        cout << r[n+1] + abs(v[i-1] - v[i+1]) - (abs(v[i-1] - v[i]) + abs(v[i] - v[i+1])) << endl;;
    }
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int *buildZ(const string &s){
	int n = s.size();
	int *z = new int[n];
	int l = 0, r = 0;
	
	memset(z, 0, sizeof(int)*n);
	for(int i = 1; i < n; i++){
		if(i <= r) z[i] = min(z[i - l], r - i + 1);
		while(i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;
		if(i + z[i] - 1 > r){
			l = i;
			r = i + z[i] - 1;
		}
	}
	return z;
}

string s, rs;
int *z, *rz, n;

inline bool check(int len){
	for(int l = 1; l * l <= len; l++) if(len % l == 0){
		if(l < len && z[l] >= len - l) return 0;
		if(len / l < len && z[len / l] >= len - len / l) return 0;
	}
	for(int l = 1; l * l <= n - len; l++) if((n - len) % l == 0){
		if(l < n - len && rz[l] >= n - len - l) return 0;
		if((n - len) / l < n - len && rz[(n - len) / l] >= n - len - (n - len) / l) return 0;
	}
	return 1;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> s;
	rs = s; reverse(all(rs));
	z = buildZ(s);
	rz = buildZ(rs);
	n = s.size();
	
	//rep(i, n + 1) dbg(z[i], s, s.substr(i));
	
	if(z[1] == n - 1){
		cout << n << "\n1" << endl;
		return 0;
	}
	if(check(0)){
		cout << "1\n1" << endl;
		return 0;
	}
	int ans = 0;
	for(int i = 1; i < n; i++) if(check(i)) ans++;
	cout << "2\n" << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5404
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int b[N];
int l[N], r[N];
bool vis[N];
vector<pair<int, int>> g[N];
vector<int> ans;
void dfs (int cur) {
  vis[cur] = true;
  for (auto nxt : g[cur]) if (!vis[nxt.first]) {
    dfs (nxt.first);
    if (b[nxt.first]) {
      b[cur] ^= 1;
      b[nxt.first] ^= 1;
      ans.push_back(nxt.second);
    }
  }
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> points(n);
  for (int i = 0; i < n; i++) cin >> points[i].first >> points[i].second;
  sort(points.begin(), points.end());
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    l[i] = lower_bound(points.begin(), points.end(), make_pair(l[i], -1)) - points.begin();
    r[i] = upper_bound(points.begin(), points.end(), make_pair(r[i], 10)) - points.begin();
    if (l[i] == r[i]) continue;
    g[l[i]].emplace_back(r[i], i);
    g[r[i]].emplace_back(l[i], i);
  }
  for (int i = 0; i < n - 1; i++) b[i + 1] = points[i + 1].second ^ points[i].second;
  b[0] = points[0].second;
  b[n] = points[n - 1].second;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs (i);
      if (b[i] == 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < (int) ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans[i] + 1;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 14972
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<pair<ll, ll> >
#define vl vector<ll>
#define vi vector<int>
#define vii vector<pair<int, int> >
const ll mod = 1e9 + 7;
using namespace std;

ll power_mod(ll x, ll y, ll p)
{
	ll ans = 1;
	x = x%p;
	if(x==0)
	return p;

	while(y>0)
	{
		if(y&1)
		{
			ans = (ans*x)%p;
		}
		y = y>>1;
		x = (x*x)%p;
	}
	return ans;
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)
	cout<<"bust\n";
	else
	cout<<"win\n";
	return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  ll sum = 0;
  for(int i = 0; i < n + 1; i++) {
    cin >> a[i];
    sum += a[i];
  }
  vector<ll> tree(n + 5, 0);
  tree[0] = 1;
  for(int i = 0; i < n + 1; i++) {
    tree[i] -= a[i];
    sum -= a[i];
    if((tree[i] <= 0 && i < n - 2) || tree[i] < 0) {
      cout << -1 << endl;
      return 0;
    }
    tree[i + 1] = 2 * tree[i];
    tree[i + 1] = min(tree[i + 1], sum);
  }
  ll ans = 0;
  for(int i = 0; i < n + 1; i++) {
    ans += tree[i] + a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m];
    rep(i,n){
        rep(j,m){
            cin >> a[i][j];
        }
    }
    int b[m];
    rep(i,m) cin >> b[i];
    rep(i,n){
        int x=0;
        rep(j,m) x += a[i][j]*b[j];
        cout << x << endl;
    }
}


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

namespace ALDS1_9_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var pq = new PriorityQueue<int>((x, y) => y - x, 2000000);
            string line;

            while(true)
            {
                line = Console.ReadLine().Trim();
                var vals = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
                if (vals[0] == "extract")
                {
                    Console.WriteLine(pq.Dequeue());
                }
                else if (vals[0] == "insert")
                {
                    pq.Enqueue(int.Parse(vals[1]));
                }
                else
                {
                    break;
                }
            }
        }
    }

    /// <summary>
    /// 優先度付き待ち行列
    /// </summary>
    /// <typeparam name="T"></typeparam>
    class PriorityQueue<T> where T : IComparable<T>
    {
        private readonly List<T> List;
        private readonly Comparison<T> Comparison;
        public int Count { get; private set; }

        public PriorityQueue() : this((x, y) => x.CompareTo(y)) {}
        public PriorityQueue(int capacity) : this((x, y) => x.CompareTo(y), capacity) { }
        public PriorityQueue(Comparison<T> comparison)
        {
            this.List = new List<T>();
            this.Comparison = comparison;
            Count = 0;
        }
        public PriorityQueue(Comparison<T> comparison, int capacity)
        {
            this.List = new List<T>(capacity);
            this.Comparison = comparison;
            Count = 0;
        }

        private int InsertLast(T value)
        {
            if (Count == List.Count)
                List.Add(value);
            else
                List[Count] = value;
            return Count++;
        }
        private void Swap(int a, int b)
        {
            T tmp = List[a];
            List[a] = List[b];
            List[b] = tmp;
        }
        public void Enqueue(T value)
        {
            int c = InsertLast(value);
            while (c > 0)
            {
                int p = (c - 1) / 2;
                if (Comparison(List[c], List[p]) < 0) { Swap(p, c); } else { break; }
                c = p;
            }
        }
        public T Dequeue()
        {
            T value = List[0];
            List[0] = List[Count - 1];
            Count--;
            int p = 0;
            while (true)
            {
                int l = p * 2 + 1; // Left
                int r = p * 2 + 2; // Right
                if (l >= Count) { break; }
                int c = (r >= Count || Comparison(List[l], List[r]) < 0) ? l : r;
                if (Comparison(List[c], List[p]) < 0) { Swap(p, c); } else { break; }
                p = c;
            }
            return value;
        }
    }
}



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

int main(){
  char C = 'a';
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if(s.at(0)!='a'){
    cout << 'a' << endl;
  }
  else{
  for(int i=0;i<s.size();i++){
    if(s.at(i)==C){
      if(i == s.size()-1 && C!='z'){
        C +=1;
        cout << C << endl;
      }
      else if(i == s.size()-1 && C=='z'){
        cout << "None" << endl;
      }
    }
    else{
      C +=1;
      if(C!= s.at(i)){
        cout << C << endl;
        break;
      }
      if(i == s.size()-1 && C!='z'){
        C +=1;
        cout << C << endl;
      }
      else if(i == s.size()-1 && C=='z'){
        cout << "None" << endl;
      }
    }
  }       
}
}


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

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int maxn = 1020;

char buf[maxn][maxn], nbuf[maxn][maxn];
ll K;
int n, m;

int qpow(int x, ll y) {
	int ret = 1;
	while (y) {
		if (y & 1) ret = 1LL * ret * x % mod;
		x = 1LL * x * x % mod;
		y >>= 1;
	}
	return ret;
}

struct matrix {
	int a[3][3];
};

matrix operator*(const matrix &m1, const matrix &m2) {
	matrix ret;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			ret.a[i][j] = 0;
			for (int k = 0; k < 3; k++) {
				ret.a[i][j] = (ret.a[i][j] + 1LL * m1.a[i][k] * m2.a[k][j] % mod) % mod;
			}
		}
	}
	return ret;
}

matrix qpow(matrix x, ll y) {
	matrix ret;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			ret.a[i][j] = (i == j);
		}
	}
	while (y) {
		if (y & 1) ret = ret * x;
		x = x * x;
		y >>= 1;
	}
	return ret;
} 

int main() {
	scanf("%d%d%lld", &n, &m, &K);
	for (int i = 1; i <= n; i++) scanf("%s", buf[i] + 1);
	if (K <= 1) {
		puts("1");
		return 0;
	}
	int H = 0, V = 0;
	for (int i = 1; i <= n; i++) if (buf[i][1] == '#' && buf[i][m] == '#') H = 1;
	for (int j = 1; j <= m; j++) if (buf[1][j] == '#' && buf[n][j] == '#') V = 1;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cnt += (buf[i][j] == '#');
		}
	}
	if (!H && !V) {
		printf("%d\n", qpow(cnt, K-1));
	} else if (H && V) {
		puts("1");
	} else {
		if (V) {
			swap(H, V);
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= m; j++) {
					nbuf[j][i] = buf[i][j];
				}
			}
			for (int i = 1; i <= m+10; i++) {
				for (int j = 1; j <= n+10; j++) {
					buf[i][j] = nbuf[i][j];
				}
			}
			swap(n, m);
		}
		int T1 = 0, T2 = 0, T3 = 0;
		for (int i = 1; i <= n; i++) {
			int ok = 1;
			for (int j = 1; j <= m; j++) {
				if (buf[i][j] != '#') {
					ok = 0;
				}
			}
			for (int j = 1; j <= m; j++) if (buf[i][j] == '#' && buf[i][j+1] != '#') ++ T3;
			if (ok != 0) {
				-- T3, ++ T2;
			} else {
				if (buf[i][1] == '#' && buf[i][m] == '#') {
					T3 -= 2, ++ T1;
				}
			}
		}
		matrix tr;
		tr.a[0][0] = T2+T1, tr.a[0][1] = T1, tr.a[0][2] = 0;
		tr.a[1][0] = 0, tr.a[1][1] = T2, tr.a[1][2] = 0;
		tr.a[2][0] = cnt - T2 + T3, tr.a[2][1] = T3, tr.a[2][2] = cnt;
		matrix to = qpow(tr, K-2);
		int nT1 = (1LL * to.a[0][0] * T1 % mod + 1LL * to.a[0][1] * T2 % mod + 1LL * to.a[0][2] * T3 % mod) % mod;
		int nT2 = (1LL * to.a[1][0] * T1 % mod + 1LL * to.a[1][1] * T2 % mod + 1LL * to.a[1][2] * T3 % mod) % mod;
		int nT3 = (1LL * to.a[2][0] * T1 % mod + 1LL * to.a[2][1] * T2 % mod + 1LL * to.a[2][2] * T3 % mod) % mod;
		printf("%d\n", (int) ((0LL + 2 * nT1 + nT2 + nT3) % mod));
	}
	return 0;
}

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

#define int long long

signed main() {
	int n;
	cin >> n;
	string dat[10] = {".,!? ",
										"abc",
										"def",
										"ghi",
										"jkl",
										"mno",
										"pqrs",
										"tuv",
										"wxyz"};										
	while ( n-- ) {
		string s;
		cin >> s;
		int l = s.size();
		for ( int i = 0; i < l; i++ ) {
			char c = s[i];
			int cnt = 0;
			for ( i = i+1; i < l; i++ ) {
				if ( s[i] != c ) break;
				cnt++;
			}
			i--;
			if ( c == '0' ) continue;
			int num = c-'0'-1;
			cnt %= dat[num].size();
			cout << dat[num][cnt];
		}
		cout << endl;
	}
	return 0;
}



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

struct  DICE {
    int Top;
    int Bottom;
    int Front;
    int Back;
    int Left;
    int Right;
    void roll(char S) {
        if ('N'==S) {
            swap(Back, Top);
            swap(Top, Front);
            swap(Front, Bottom);
        } else if('S'==S) {
            swap(Back, Bottom);
            swap(Bottom, Front);
            swap(Front, Top);
        } else if('W'==S) {
            swap(Right, Bottom);
            swap(Bottom, Left);
            swap(Left, Top);
        } else if('E'==S) {
            swap(Left, Bottom);
            swap(Bottom, Right);
            swap(Right, Top);
        }
        return;
    }
};

int main() {
    DICE D;
    cin >>D.Top >>D.Front >>D.Right >>D.Left >>D.Back >>D.Bottom;
    int N;
    cin >>N;
    for (int i=0; i<N; i++) {
        int TOP, FRONT;
        cin >>TOP >>FRONT;
        while(FRONT!=D.Front) {
            D.roll('E');
            for (int i=0; i<3; i++) {
                if (FRONT==D.Front)
                    break;
                D.roll('S');
            }
        }
        while(TOP!=D.Top)
            D.roll('E');
        cout <<D.Right <<endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include<stdio.h>
int main(){
    int h, w;
    int i,j;
    while(1){
        scanf("%d %d", &h, &w);
        if(h==0 && w==0){
            break;
        }
        for(i=0; i<h; i++){
            for(j=0; j<w; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	char c;
	scanf("%d %c%d",&a,&c,&b);
	if(c=='+')
	{
		printf("%d",a+b);
	} 
	if(c=='-')
	{
		printf("%d",a-b);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String s =sc.next();
    String t[] =s.split("",0);
    for(int i=1;i<4;i++){
      if(t[i].equals(t[i-1])){System.out.println("Bad");System.exit(0);}}
    System.out.println("Good");
  }
}

Measured memory_bytes: 23892
import sys,math,collections,itertools
input = sys.stdin.readline

N,M=list(map(int,input().split()))
mn = M//N
ml = M%N
if ml == 0:
    print(mn)
    exit()
ans = 0
for i in range(mn+1,0,-1):
    if i < ans:
        break
    tmp = math.gcd(i,M-i*(N-1))
    ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 83384
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int n1 = a>b? a : b;
  int n2 = a>b? (a-1 > b? a-1:b) : (a > b-1? a : b-1);
  cout << n1 + n2;
}

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

int main() {
    int N;
    int A;
    cin >> N;
    cin >> A;
    N %= 500;
    if (N>A) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
# A, B, C = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

# 出来るだけ 500, そのあとは出来るだけ 5

a = n / 500
n -= a * 500
b = n / 5

p (a * 1000 + b * 5)

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

long long re[100005],wa[100005];
int main(void){
    long long T,i,j,n,m,l,r,ok,a,b,c,ans,cnt;
    scanf("%lld %lld %lld",&n,&m,&l);
    for(i=0;i<n;i++){
        scanf("%lld",re+i);
    }
    for(i=0;i<m;i++){
        scanf("%lld",wa+i);
    }



    ans = 1e18;

    for(i=0;i<l;i++){
        scanf("%lld %lld %lld",&a,&b,&c);
        cnt = 0;
        cnt = re[a-1]+wa[b-1]-c;
        ans = min(ans,cnt);
    }

    sort(re,re+n);
    sort(wa,wa+m);
    cnt = wa[0]+re[0];
    ans = min(ans,cnt);
    printf("%lld\n",ans);
}


Measured memory_bytes: 1792
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto input = readln.chomp.split.to!(long[]);

    long a = input[0];
    long b = input[1];
    long x = input[2];

    writeln((a <= x && x <= a + b)?"YES":"NO");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long x, y;
	cin >> x >> y;
	x *= -1;
	long long ans = 100000000007;
	if (y >= x) {
		if (ans > y - x + 1) {
			ans = y - x + 1;
		}
	}
	y *= -1;
	if (y >= x) {
		if (ans > y - x + 2) {
			ans = y - x + 2;
		}
	}
	x *= -1;
	if (y >= x) {
		if (ans > y - x + 1) {
			ans = y - x + 1;
		}
	}
	y *= -1;
	if (y >= x) {
		if (ans > y - x) {
			ans = y - x;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
# ABC 121 C
from heapq import heappop, heappush
n, m = [int(el) for el in input().split(' ')]
X =[]
for i in range(n):
    a, b = [int(el) for el in input().split(' ')]
    heappush(X, (a,b))
total = 0
price = 0
for i in range(n):
    a, b = heappop(X)
    if total + b < m:
        price += a*b
        total += b
    else:
        price += a*(m-total)
        print(price)
        break






Measured memory_bytes: 16668
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N,C = map(int,sys.stdin.readline().split())
stc = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
M = 10**5
imos=[[0]*(M+1) for _ in range(C+1)]

for s,t,c in stc:
    imos[c][s] += 1
    if t+1 < M+1:
        imos[c][t+1] -= 1

#print(imos)
s = set()
ret = 0
for i in range(M):
    for c in range(C+1):
        imos[c][i+1] += imos[c][i]
    ret = max(ret,sum(min(1,imos[c][i+1]) for c in range(C+1)))
#print(imos)
print(ret)


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

int main()
{
	long int W, H, x, y;
	double S;

	scanf("%ld", &W);
	scanf("%ld", &H);
	scanf("%ld", &x);
	scanf("%ld", &y);

	S = W * H / 2.0;
	printf("%lf\n", S);

	if (fabs(x - W / 2.0)<0.001&&fabs(y - H / 2.0)<0.001) 
	{
		printf("1");
	}
	else 
	{
		printf("0");
	}
	
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner x=new Scanner(System.in);
    	int n=x.nextInt(),r=0;
    	int a[]=new int[n];
		int b[]= new int[n];
		int c[]=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=x.nextInt();
			b[i]=a[i];
		}
		Arrays.sort(b);
		for(int i=0;i<n;i++)
		{
			c[i]=b[i]-a[i];
			if(c[i]==0)
			{
				r++;
			}
		}
		if(r>=(n-2))
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
		}
	}
}

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

int main(){
    string s;
    cin >> s;
    int ans = 7;
    if (s == "MON"){
        ans = 6;
    }else if (s == "TUE"){
        ans = 5;
    }else if (s == "WED"){
        ans = 4;
    }else if (s == "THU"){
        ans = 3;
    }else if (s == "FRI"){
        ans = 2;
    }else if (s == "SAT"){
        ans = 1;
    }

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		while (m!=0) {
			Card[] cards = new Card[m];
			for (int i = 0; i < m; ++i) {
				int no = sc.nextInt();
				int num = sc.nextInt();
				cards[i] = new Card(no,num);
			}
			int g = sc.nextInt();
			int[] ns = new int[g];
			for (int i = 0; i < g; ++i) {
				ns[i] = sc.nextInt();
			}
			System.out.print(solve(m,cards,g,ns));
			m = sc.nextInt();
		}
	}

	public static String solve(int m, Card[] cards, int g, int[] ns) {

		Arrays.sort(cards,new Comparator<Card>() {
			@Override
			public int compare (Card c1, Card c2) {
				return c1.no() - c2.no();
			}
		});
		
		int n =0;
		for (int nn : ns) {
			n = Math.max(n,nn);
		}
		
		int[][] table = new int[m+1][n+1];
		table[0][0] = 1;

		for (int i = 0; i < m; ++i) {
			int no = cards[i].no();
			int num = cards[i].num();
			for (int j = 0; j <= n; ++j) {
				for (int k=0;k<=num&&0<=(j-k*no);++k) {
					table[i+1][j] += table[i][j-k*no];
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int nn : ns) {
			sb.append(table[m][nn]+"\n");
		}
		return new String(sb);
	}
	

	static class Card {
		private int no;
		private int num;
		public Card(int no, int num) {this.no = no;this.num = num;}
		public int no() {return no;}
		public int num() {return num;}
	}
}

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

template <typename T>
struct BinaryIndexedTree{
// アーベル群に対応するデータ構造
// 1要素更新:O(logN), 区間演算:O(logN)
  vector<T> m_BIT;
  size_t m_sz_pow2;
 
  BinaryIndexedTree(int N)
  : m_BIT(N+1)
#ifdef __GNUC__
  , m_sz_pow2(1 << (31- __builtin_clz(N)))
#endif
  {
#ifndef __GNUC__
    m_sz_pow2= N;
    m_sz_pow2|= (m_sz_pow2 >>  1);
    m_sz_pow2|= (m_sz_pow2 >>  2);
    m_sz_pow2|= (m_sz_pow2 >>  4);
    m_sz_pow2|= (m_sz_pow2 >>  8);
    m_sz_pow2|= (m_sz_pow2 >> 16);
    m_sz_pow2++;
    m_sz_pow2 >>= 1;
#endif
  }
 
  void add(int idx, T diff){ /* 1-indexed */
    for(size_t i=idx; i< m_BIT.size(); i+= i&-i){
      m_BIT.at(i)+= diff;
    }
  }
 
  T cumulative(int right) const{// [1, right)
    T ans= 0;
    for(int i=right-1; i>0; i-= i&-i){
      ans+= m_BIT.at(i);
    }
    return ans;
  }
 
  T range(int left, int right) const{// [left, right)
    return cumulative(right)- cumulative(left);
  }
 
  void set_val(int idx, T val){
    T a_i= range(idx, idx+ 1);
    add(idx, val- a_i);
  }

  size_t lower_bound(T val) const{// a[i]>= 0 のとき
    size_t offset= 0;
    for(size_t s= m_sz_pow2; s>0; s>>=1){
      if(offset+ s < m_BIT.size() && m_BIT.at(offset+ s) < val){
        offset+= s;
        val-= m_BIT.at(offset);
      }
    }
    return offset+ 1;
  }
};

int main(){
  using interval= pair<int, int>;
  int N,Q;
  cin >> N >> Q;

  priority_queue<interval> edges; // [left_e, right_e] 1-indexed
  unordered_map<int, int> pos_color;
  int color;
  for(int i=1; i<=N; i++){
    cin >> color;
    if(pos_color.count(color)){
      edges.push(make_pair(pos_color.at(color), i));
      pos_color.at(color)= i;
    }
    else{
      pos_color[color]= i;
    }
  }

  vector<interval> queries(Q);
  vector<interval> queriesIO(Q);
  int leftQ,rightQ;
  for(int q=0; q<Q; q++){
    cin >> leftQ >> rightQ;
    rightQ++; // [leftQ, rightQ] 1-indexed => [leftQ, rightQ) 1-indexed
    interval segQ= make_pair(leftQ, rightQ);
    queries.at(q)  = segQ;
    queriesIO.at(q)= segQ;
  }
  sort(queries.begin(), queries.end(), greater<interval>());

  map<interval, int> answers;
  BinaryIndexedTree<int> bit(N);
  for(auto query:queries){
    auto [leftQ, rightQ]= query;
    if(answers.count(query)){ continue; }
    else{
      while(!edges.empty()){
        auto [left_e, right_e]= edges.top();
        if(left_e >= leftQ){
          bit.add(right_e, 1);
          edges.pop();
        }
        else{ break; }
      }

      answers[query]= (rightQ- leftQ)- bit.cumulative(rightQ);
    }
  }

  for(auto query:queriesIO){
    cout << answers.at(query) << endl;
  }
}

Measured memory_bytes: 64520
#include <stdio.h>
int main(){
  int S;
  int ans,ans2,ans3;
  int ama,ama2;
  scanf("%d",&S);

  ans=S/60;
  ans2=ans/60;
 

  ama=S%60;
  ama2=ans%60;
 
  printf("%d:%d:%d\n",ans2,ama2,ama);
  return 0;
}

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

const int N = 1e5 + 5;

#define int long long

main(void) {
	int n , k , ans = 0;
	cin >> n >> k;
	for(int b = k + 1;b <= n;++ b) {
		int now = n / b;
		ans += max(n - now * b - k + 1 , 0ll);
		-- now;
		ans += (now + 1) * (b - k);
	}
	if(!k) ans -= n;
	cout << ans;
}

Measured memory_bytes: 256
n,m = gets.chomp.split.map(&:to_i)
ary = []
n.times do
  # ary[0][2]→z1
  ary << gets.chomp.split.map(&:to_i)
end
ans = 0

# +-の組み合わせで8通り試す
plmi=[[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
plmi.each do |i|
  eva = []
  ary.each do |xyz|
    eva << (xyz[0]*((-1)**i[0])+xyz[1]*((-1)**i[1])+xyz[2]*((-1)**i[2]))
  end
  # 降順ソート
  eva.sort! {|a, b| b <=> a }
  tmp_ans = 0
  m.times do |i|
    tmp_ans += eva[i]
  end
  ans = [ans,tmp_ans].max
end

puts ans


Measured memory_bytes: 2040
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

ll f(ll n){
    ll sum = 0;
    for(ll i = 1; i <= n; i *= 2){
        //i桁目の1の個数
        ll now = n / (2 * i) * i + max(ZER, n % (i * 2) - i);
        now %= 2;
        sum += now * i;
        //cout << now << " " << i << endl;
    }
    return sum;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n)cin >> x[i];
    ll res = 0;
    rep(i, n - 1){
        ll d = x[i + 1] - x[i];
        if(d * a < b)res += d * a;
        else res += b;
    }
    cout << res << endl;
}





Measured memory_bytes: 4052