akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
int A[112345], B[112345];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", A + i);
	REP(i, N) scanf("%d", B + i);
	
	vector<int> over, under;
	REP(i, N) {
		if (A[i] > B[i]) over.push_back(A[i] - B[i]);
		if (A[i] < B[i]) under.push_back(B[i] - A[i]);
	}
	
	sort(ALL(over), greater<int>());
	sort(ALL(under), greater<int>());
	
	int pos = 0, ans;
	ll res = 0;
	REP(i, under.size()) {
		while (pos < over.size() && res < under[i]) {
			res += over[pos++];
		}
		
		if (res >= under[i]) {
			res -= under[i];
		}
		else {
			ans = -1;
			break;
		}
		if (i + 1 == under.size()) ans = pos + under.size();
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a,b,c,d;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        d = sc.nextInt();
        int tokillaoki = 0,tokilltaka = 0;

        while (a>0){
            a -= d;
            tokilltaka++;
        }
        while (c>0){
            c -= b;
            tokillaoki++;
        }
        if(tokillaoki<=tokilltaka){
            System.out.println("Yes");

        }else {
            System.out.println("No");
        }


        }


    }





Measured memory_bytes: 35836
module Main where

import Control.Monad
import Control.Applicative
import Data.List

main = do
 n <- (read:: String -> Int) <$> getLine
 x <- map (read:: String -> Int) . words <$> getLine
 forM_ (count n (x ++ [0])) print

count:: Int -> [Int] -> [Int]
count n x = let dist = reverse . fst $ foldl' (\(line, former) x -> ((x - former):line, x)) ([], 0) x
                comp = foldl' (+) 0 $ map abs dist
            in reverse . fst $ foldl' (\(result, d1:d2:rest) x -> ((comp - abs d1 - abs d2 + abs (d1 + d2)):result, d2:rest)) ([], dist) [0..n-1]


Measured memory_bytes: 49532
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,a,b;
    cin>>n>>m;
    vector<ll> arr(n+1,1);
    set<ll> s;
    s.insert(1);
    for(int i=0;i<m;i++){
        cin>>a>>b;
        arr[a]--;
        if(s.find(a)!=s.end())
        s.insert(b);
        if(arr[a]==0 && s.find(a)!=s.end()) s.erase(a);
        arr[b]++;
    }
    cout<<s.size();
    return 0;
}


Measured memory_bytes: 5760
#include<stdio.h>
#include<math.h>
int a[100000];
int main()
{
    int n,i,temp,k,sum,x;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);

         sum=0,x=0;
        for(i=1; i<=n; i++)
        {
            sum=sum+fabs(a[i]-x);
            x=a[i];
        }
          sum=sum+fabs(x-0);
           // printf("%d\n",sum);
    for(k=1; k<=n; k++)
    {
        int sum2=sum;
        int yuanlai=fabs(a[k]-a[k-1])+fabs(a[k+1]-a[k]);
        int xianzai=fabs(a[k+1]-a[k-1]);
        if(yuanlai-xianzai>=0)
        sum2=sum2-(yuanlai-xianzai);
        else
                 sum2=sum2+(yuanlai-xianzai);
        printf("%d\n",sum2);
    }



    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0)

int32_t main() {

	IOS;

	int n, k;
	cin >> n >> k;
	vector<int> v(n);

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

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

	int sum = 0;
	for (int i  = 0; i < k; i++) {
		sum += v[i];
	}

	cout << sum << endl;

	return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

struct UF
{
    vi r, p;
    UF(int n) : r(n, 0), p(n, 0)
    {
        iota(p.begin(), p.end(), 0);
    }

    int f(int x)
    {
        return (p[x] == x ? x : p[x] = f(p[x]));
    }

    void u(int i, int j)
    {
        int x = f(i), y = f(j);
        if (x == y)
            return;

        if (r[x] >= r[y])
        {
            p[y] = x;
            if (r[x] == r[y])
                r[x]++;
        }
        else
            p[x] = y;
    }

    bool s(int i, int j)
    {
        return f(i) == f(j);
    }
};

int mx[100001];
int my[100001];
int x[100001];
int y[100001];
vi v[100001];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    UF uf(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        int x, y;
        cin >> x >> y;
        ::x[i] = x;
        ::y[i] = y;
        if (mx[x])
            uf.u(i, mx[x]);
        if (my[y])
            uf.u(i, my[y]);
        mx[x] = i;
        my[y] = i;
    }
    for (int i = 1; i <= n; ++i)
        v[uf.f(i)].push_back(i);

    ll sol = 0;
    for (vi& w : v)
    {
        set<int> sx, sy;
        for (int k : w)
        {
            sx.insert(x[k]);
            sy.insert(y[k]);
        }
        sol += 1ll * sx.size() * sy.size();
    }
    cout << sol - n;
}


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

int main(){
    int N,M,Q;cin>>N>>M>>Q;
    vector<int> L(M+1),R(M+1);
    vector<vector<int> > X(N+1,vector<int>(N+1)),C(N+1,vector<int>(N+1)); 
    
    for(int i=1;i<=M;i++){
        cin>>L.at(i)>>R.at(i);
        X.at(L.at(i)).at(R.at(i))++;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            C.at(i).at(j)=C.at(i).at(j-1)+X.at(i).at(j);
        }
    }

    int p,q,count;
    for(int i=0;i<Q;i++){
        cin>>p>>q;
        count=0;

        for(int j=p;j<=q;j++){
            count+=C.at(j).at(q)-C.at(j).at(p-1);
        }

        cout<<count<<endl;
    }

    return 0;
}

Measured memory_bytes: 4480
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] map = new int[N][N];
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            for (int k = 0; k < a; k++) {
                int p = sc.nextInt() - 1;
                int bool = (sc.nextInt() == 1) ? 1 : -1;
                map[i][p] = bool;
            }
        }
        // for (int i = 0; i < N; i++) {
        //     System.out.println(Arrays.toString(map[i]));
        // }
        int ans = 0;
        for (int mask = 0; mask < (1 << N); mask++) {
            // System.out.println(Integer.toBinaryString(mask));
            int trs = Integer.bitCount(mask);
            int[] ck = new int[N];
            for (int i = 0; i < N; i++) {
                // System.out.println(Integer.toBinaryString(1 << i));
                ck[i] = (mask & (1 << i)) != 0 ? 1 : -1;
            }
            //System.out.println(Arrays.toString(ck));
            int i;
            turn: for (i = 0; i < N; i++) {
                if (ck[i] == -1)
                    continue;
                for (int k = 0; k < N; k++) {
                    //System.out.println(map[i][k] + "  " + ck[k]);
                    if (map[i][k] != 0) {
                        if (ck[k] != map[i][k])
                            break turn;
                    }
                }
            }
            if (i == N)
                ans = Math.max(ans, trs);
        }

        System.out.println(ans);
    }
}

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

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

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

	int k = 0;
	for (int i = 0; i < n; ++i) {
		int x = a[i];
		bool ok = m[x] < 2 && (x == 1 || m[1] == 0);
		for (int i = 2; i * i <= x; ++i) {
			if (x % i == 0) {
				if (m[i] > 0 || m[x / i] > 0) {
					ok = false;
					break;
				}
			}
		}

		if (ok) {
			++k;
		}
	}

	cout << k;
	
	return 0;
}
	

Measured memory_bytes: 7940
#include<stdio.h>

int N,W;
long long w[110],v[110];
long long dp[110][100010];

long long max(long long x,long long y){
	if(x>y)return x;
	return y;
}

int main(){
	scanf("%d%d",&N,&W);
	for(int i=0;i<N;i++)scanf("%lld%lld",&w[i],&v[i]);
	
	for(int i=0;i<=W;i++)dp[0][i]=0;
	
	for(int i=0;i<N;i++)for(int j=0;j<=W;j++){
		if(j>=w[i])dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
		else dp[i+1][j]=dp[i][j];
	}
	printf("%lld\n",dp[N][W]);
	return 0;
}

Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	ll n,m; cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
	    ll p; cin>>p;
	    n -= p;
	}
	if(n>=0) cout<<n;
	else cout<<-1;
	
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef long long ll;
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ld long double
#define ss second
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384626
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

const int mod = 1'000'000'007;

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
vector<vll> mat;
vector<vll> mul(vector<vector<ll>> mat1 = mat, vector<vector<ll>> mat2 = mat)
{
	ll n = mat1.size();
	vector<vll> nmat(n, vll(n)) ;
	rep(i, 0, n)
	{
		rep(j, 0, n)
		{
			ll sum = 0;
			rep(ii, 0, n)
			{
				sum += (mat1[i][ii]%mod * mat2[ii][j]%mod)%mod;
				sum %= mod;
			}
			nmat[i][j] = sum;
		}
	}
	return nmat;
}
	
int main()
{
		fastio;
		ll ttt = 1;
		//cin >> t;
		rep(tt,1,ttt+1)
		{
			ll n, k;
			cin >> n >> k;
			vector<vll> edge(n, vll(n));
			rep(i, 0, n)
			{
				rep(j, 0, n)
				{
					cin >> edge[i][j];
				}
			}
			vector<vll> dp(n, vll(n));
			rep(i, 0, n) dp[i][i] = 1;
			mat.resize(n, vll(n));
			mat = edge;
			while(k)
			{
				if(k & 1)
				{
					dp = mul(dp, mat);
				}
				mat = mul();
				k >>= 1;
			}
			ll ans = 0;
			rep(i, 0, n)
			{
				rep(j, 0, n)
				{
					ans += dp[i][j];
					ans %=mod;
				}
			}
			cout << ans << endl;
		}
		return 0;
	}
			
			


Measured memory_bytes: 3784
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cassert>
using namespace std;

using Line = vector< pair<int, int> >;

Line rotate(Line l) {
  int dx = l[1].first - l[0].first;
  int dy = l[1].second - l[0].second;

  if(dx == 0 and dy > 0) return l;
  else if(dx == 0 and dy < 0) {
    for(auto &e : l) e = make_pair(-e.first, -e.second);
  }
  else if(dx > 0 and dy == 0) {
    for(auto &e : l) e = make_pair(-e.second, e.first);
  }
  else if(dx < 0 and dy == 0) {
    for(auto &e : l) e = make_pair(e.second, -e.first);
  }
  else assert(false);
  return l;
}

bool is_valid(Line u, Line v) {
  u = rotate(u);
  v = rotate(v);
  
  if(u.size() != v.size()) return false;
  int N = u.size();
  
  int du = u[1].first - u[0].first + u[1].second - u[0].second;
  int dv = v[1].first - v[0].first + v[1].second - v[0].second;
  for(int i=2; i<N; i++) {
    int dxu = u[i].first - u[i-1].first;
    int dyu = u[i].second - u[i-1].second;
    int dxv = v[i].first - v[i-1].first;
    int dyv = v[i].second - v[i-1].second;

    int gu = 0;
    if(dxu > 0) gu += 1;
    if(dxu < 0) gu += 2;
    gu *= 3;
    if(dyu > 0) gu += 1;
    if(dyu < 0) gu += 2;

    int gv = 0;
    if(dxv > 0) gv += 1;
    if(dxv < 0) gv += 2;
    gv *= 3;
    if(dyv > 0) gv += 1;
    if(dyv < 0) gv += 2;

    if(gu != gv) return false;
    int eu = dxu + dyu;
    int ev = dxv + dyv;
    if(du * ev != dv * eu) return false;
  }
  return true;
}

bool compare(Line u, Line v) {
  for(int i=0; i<2; i++) {
    for(int j=0; j<2; j++) {
      if(is_valid(u, v)) return true;
      reverse(v.begin(), v.end());
    }
    reverse(u.begin(), u.end());
  }
  return false;
}

int solve_testcase() {
  int N; cin >> N;
  if(N == 0) return 1;
  N++;

  vector<int> ans;
  vector<Line> lines;
  for(int i=0; i<N; i++) {
    int M; cin >> M;
    Line L;
    for(int j=0; j<M; j++) {
      int x, y; cin >> x >> y;
      L.emplace_back(x, y);
    }
    lines.emplace_back(L);
  }

  for(int i=1; i<N; i++) {
    Line u = lines[0], v = lines[i];
    if(compare(u, v)) ans.emplace_back(i);
  }

  for(auto e : ans) cout << e << endl;
  cout << "+++++" << endl;
  return 0;
}

int main() {
  while(!solve_testcase());
  return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
int main() {
	string s, t; cin >> s >> t;
	vector<string>before(t.size() + 1);
	for (int i = 1; i <= s.size(); i++) {
		vector<string>after(t.size() + 1);
		for (int j = 1; j <= t.size(); j++) {
			if (s[i - 1] == t[j - 1]) {
				string a = before[j - 1] + s[i - 1]; 
				after[j] = a;
			}
			else {
				if (before[j].size() > after[j - 1].size())after[j] = before[j];
				else after[j] = after[j - 1];
			}
		}
		before = after;
	}
	cout << before[t.size()] << endl;
	return 0;
}

Measured memory_bytes: 16796
#include <iostream>
#include <cmath>
#include <vector>


using namespace std;


typedef struct
{
  long long x;
  long long y;
} Coordinate;


long long manhattan_distance(const Coordinate m, const Coordinate n)
{
  return abs(m.x-n.x)+abs(m.y-n.y);
}


int main()
{
  int n, m, idx;
  vector<Coordinate> s, c;
  Coordinate t;
  long long min;
  

  cin >> n >> m;
  for (int i=0; i<n; i++){
    cin >> t.x >> t.y;
    s.push_back(t);
  }

  for (int i=0; i<m; i++){
    cin >> t.x >> t.y;
    c.push_back(t);
  }

  for (int i=0; i<s.size(); i++){
    min=3000000000000000000;
    idx = 51;
    for (int j=0; j<c.size(); j++){
      if (min > manhattan_distance(s[i], c[j])){
	min = manhattan_distance(s[i], c[j]);
	idx = j;
      }
    }
    cout << idx+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

int n, d[10001]={0};
void test() {
    cin >> n;
    for (int x=1; x<=100; ++x) {
        for (int y=1; y<=100; ++y) {
            for (int z=1; z<=100; ++z) {
                int f=x*x+y*y+z*z+x*y+y*z+z*x;
                if (f<=10000) ++d[f];
            }
        }
    }
    for (int i=1; i<=n; ++i) cout << d[i] << endl;
}

int main() {
    IOS;

    // int t; cin>>t;
    // while (t--) {
    //     test();
    // }

    // int t; cin>>t;
    // for (int i=1; i<=t; ++i) {
    //     cout<<"Case #"<<i<<": ";
    //     test();
    // }

    test();
    return 0;
}

Measured memory_bytes: 3640
n = gets.to_i
a = (n.to_f)/1.08
b = ((n+0.99).to_f)/1.08
if a-(a.to_i) == 0
  puts a.to_i
elsif b-(b.to_i) == 0
  puts b.to_i
elsif (a.to_i)+1 <= b
  puts (a.to_i)+1
else
  puts ":("
end

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

int main()
{
	char S[128];
	scanf("%s", S);
	int n = strlen(S);
	int res = 0;
	for(int i=0; i<n/2; i++){
		if(S[i] != S[n-1-i]){
			res++;
		}
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++) {
    if (i == 5 || i == 13) cout << " ";
    else cout << s[i];
  }
  cout << endl;
  return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	LL d,n;
	cin >> d >> n;
	cout << LL(pow(100,d))*(n == 100 ? 101 : n) << endl;
	return 0;
}


Measured memory_bytes: 384
W, H, N = map(int, input().split())
Xmax, Xmin, Ymax, Ymin = W, 0, H, 0

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > Xmin:
        Xmin = x
    elif a == 2 and x < Xmax:
        Xmax = x
    elif a == 3 and y > Ymin:
        Ymin = y
    elif a == 4 and y < Ymax:
        Ymax = y

if Xmax - Xmin > 0 and Ymax - Ymin > 0:
    print((Xmax-Xmin) * (Ymax - Ymin))
else:
    print(0)

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        final double pi = 3.141592653;
        int r = Integer.parseInt(br.readLine());
        pw.println(2 * pi * r);

        pw.close();
    }
}

Measured memory_bytes: 33276
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
int main(void){
    ll N,L,T;
    cin >> N >> L >> T;
    vector<ll> X(N);
    vector<bool> W(N);//０なら時計回り,１なら反時計回り
    for(int i = 0; i < N; i++){
        cin >> X.at(i);
        int a;
        cin >> a;
        a--;
        W.at(i) = a;
    }
    
    vector<ll> afterX(N);
    for(int i = 0; i < N; i++){
        if(W.at(i)){//反時計回り
            afterX.at(i) = (((X.at(i) - T) % L) + L) % L;
        }else{
            afterX.at(i) = (X.at(i) + T) % L;
        }
    }
    
    ll through = 0;
    for(int i = 0; i < N; i++){
        if(W.at(0) != W.at(i)){
            
            ll sa;
            if(!W.at(0)){//時計回り
                sa =  X.at(i) - X.at(0);
            }
            else{//反時計回り
                sa =  X.at(0) + (L - X.at(i));
            }
            
            if(T * 2 >= sa){
                through += 1 + (2 * T - sa) / L;
            }
        }
    }
    
    ll position = 0;
    
    
    if(W.at(0)){//反時計回り
        position -= through;
    }else{//時計回り
        position += through;
        
    }
    
    position = ((position % N) + N) % N;
    //Pがposition番目に出力されたい
    
    ll P = afterX.at(0);
    
    
    sort(afterX.begin(), afterX.end());
    
    bool l = 0;
    ll I1,I2;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(afterX.at(i) == P){
            cnt++;
            if(cnt == 1){
                I1 = i;
            }
            else if(cnt == 2){
                I2 = i;
                l = 1;
            }
        }
    }
    //I1はPの場所
    
    if(l){
        if( (W.at(0) + through) % 2 == 1){
            I1++;
            
        }
        else{
            if(through%2==0)I1++;
            
            
            
            
            
            
            
        }
    }
    
    
    for(int i = 0; i < N; i++){
        cout << afterX.at((((I1 - position + i) % N) + N) % N) << endl;
    }
    
}


Measured memory_bytes: 2816
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long min = 10000000000000l;
    for(int i = 1; i < Math.sqrt(A)+1; i++){
      if(A%i == 0){
        long B = i + A/i;
        if(B < min){
          min = B;
        }
      }
    }
    System.out.println(min-2);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n,0);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h.rbegin(), h.rend());
    long long ans = 0;
    for(int i = k; i < n ;i++){
        ans += h[i];
    }
    printf("%lu\n", ans);
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
const int N =2e5+1;
ll a[N];
ll f[N];
ll n,k;
ll check(ll maxallowed)
{
	ll need = 0;
	for(ll i = 0; i<n ; i++)
	{
		if(a[i]*f[i]<=maxallowed)
			continue;
		else
		{
			need = need + a[i]-((maxallowed)/f[i]);
		}
	}
	if(need <=k)
		return 1;
	else
		return 0;

}
int	main()
{
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);
   cin>>n>>k;
   ll x;
   for(ll i=0; i<n ; i++)
   		{
   			cin>>a[i];
   		
   		}
   	//cout<<"hey";
   for(ll i =0; i<n ; i++)
   		{
   			cin>>f[i];
   			
   		}
   	//cout<<"hu";
   sort(a,a+n,greater<ll>());
   sort(f,f+n);  	
   ll r = 1e12, l  = 0;
   // for(ll i = 0; i<n ; i++)
  	// 	if(a[i]*f[i]>r)
   // 			r = a[i]*f[i];
   
   	while(r-l>0)
   	{
   		ll mid = (l+r)/2;
   		if(check(mid))
   			r = mid;
   		else
   			l = mid+1;
   	}
   	// for(int i = max(r-5,(ll)0) ; i<=r+5 ; i++)
   	// 	if(check(i))
   	// 	{
   	// 		r = i;
   	// 		break;
   	// 	}

 	cout<<r<<endl;  	


	return 0;
}

Measured memory_bytes: 3456
#include<iostream>

using namespace std;

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

	int n;
	cin >> n;
	int a[n]; int b[n]; int c[n-1];
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n-1; i++) cin >> c[i];
		
	int ans = b[a[0]-1];

	for(int i=1; i<n; i++){
		ans += b[a[i]-1];
		if(a[i]==a[i-1]+1){
			ans += c[a[i]-2];
		}
	}
	cout << ans;
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
//		Scanner sc = new Scanner(System.in);
//		sc.useDelimiter(",|\\r\\n");
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		paper = new int[2+10+2][2+10+2];
//		while (sc.hasNext()) {
//			dropInk(sc.nextInt()+2, sc.nextInt()+2, sc.nextInt());
//		}
		String data;
		while ( (data = br.readLine()) != null) {
			String[] xys = data.split(",");
			dropInk(Integer.parseInt(xys[0])+2,
					Integer.parseInt(xys[1])+2,
					Integer.parseInt(xys[2])   );
		}
		//  0, 1, : dammy
		//  2, 3, ... , 10, 11, : use
		//  12, 13, : dammy
		int max = 0, count = 0;
		for (int i=2; i <= 11; i++) {
			for (int j=2; j <= 11; j++) {
				if (paper[i][j] == 0) {
					count++;
				} else if (paper[i][j] > max) {
					max = paper[i][j];
				}
			}
		}
		System.out.println(count);
		System.out.println(max);
	}

	public static int[][] paper;

	public static void dropInk(int x, int y, int s) {
		if (s==1) {
			paper[x][y]++;
			paper[x-1][y]++;
			paper[x][y-1]++;
			paper[x+1][y]++;
			paper[x][y+1]++;
			return;
		}

		if (s==2) {
			dropInk(x, y, 1);
			paper[x-1][y-1]++;
			paper[x+1][y-1]++;
			paper[x-1][y+1]++;
			paper[x+1][y+1]++;
			return;
		}

		if (s==3) {
			dropInk(x, y, 2);
			paper[x-2][y]++;
			paper[x][y-2]++;
			paper[x+2][y]++;
			paper[x][y+2]++;
			return;
		}
	}

}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
signed main(void){
    int n; cin>>n;
    vector <int> p(n), q(n); 
    vector <int> dif1, dif2;
    rep(i,n) {cin>>p[i]; q[i]=p[i];}
    sort(p.begin(),p.end());
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(p[i]!= q[i]) {cnt++; dif1.push_back(p[i]); dif2.push_back(q[i]);}
    }
    
    sort(dif1.begin(),dif1.end());
    sort(dif2.begin(),dif2.end());
    
    if(cnt<=2&& dif1==dif2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define popc64 __builtin_popcountll
#define ctz64 __builtin_ctzll

typedef unsigned long long u64;
const int N = 54;

int n, que[N];
int p1[N], p2[N];
u64 G1[N], G2[N], tG[N], iG[N];
u64 tag, mask;

inline void down(int &x, const int y) {x > y ? x = y : 0;}

void dfs(int x, int *p, u64 *G) {
	int y; u64 S;
	for (S = G[x]; S; S &= S - 1) if ((y = ctz64(S)) != p[x]) p[y] = x, dfs(y, p, G);
}

void common_dfs(int x, int px = -1) {
	int y; u64 S, G = G1[x] & G2[x]; tag &= ~(1llu << x);
	for (S = G; S; S &= S - 1) if ((y = ctz64(S)) != px) common_dfs(y, x);
}

int solve(int root) {
	int i, v, h, t = 0; u64 S;
	p1[root] = p2[root] = -1, tag = mask;
	dfs(root, p1, G1), dfs(root, p2, G2), common_dfs(root);
	memset(tG, 0, sizeof tG), memset(iG, 0, sizeof iG);
	for (S = tag; S; S &= S - 1) {
		v = ctz64(S);
		if (~p1[v] && tag >> p1[v] & 1) tG[v] |= 1llu << p1[v], iG[ p1[v] ] |= 1llu << v;
		if (~p2[v] && tag >> p2[v] & 1) iG[v] |= 1llu << p2[v], tG[ p2[v] ] |= 1llu << v;
	}
	for (i = 0; i < n; ++i) if (!iG[i]) que[t++] = i;
	for (h = 0; h < t; ++h)
		for (S = tG[v = que[h]]; S; S &= S - 1)
			if (!(iG[i = ctz64(S)] &= ~(1llu << v))) que[t++] = i;
	return t == n ? popc64(tag) : INT_MAX;
}

void work() {
	int i, u, v, ans = INT_MAX;
	scanf("%d", &n), mask = ~(-1llu << n);
	memset(G1, 0, sizeof G1), memset(G2, 0, sizeof G2);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), G1[--u] |= 1llu << --v, G1[v] |= 1llu << u;
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), G2[--u] |= 1llu << --v, G2[v] |= 1llu << u;
	if (!memcmp(G1, G2, n << 3)) {putchar(48), putchar(10); return;}
	for (u = 0; u < n; ++u)
		if (!((G1[u] - 1) & G1[u])) {
			v = ctz64(G1[u]), G1[u] = 0, G1[v] &= ~(1llu << u);
			for (i = 0; i < n; ++i) if (i != u && i != v)
				G1[u] = 1llu << i, G1[i] |= 1llu << u,
				down(ans, solve(u)), G1[i] &= ~(1llu << u);
			G1[u] = 1llu << v, G1[v] |= 1llu << u;
		}
	printf("%d\n", ans == INT_MAX ? -1 : ans + 1);
}

int main() {
	int T;
	for (scanf("%d", &T); T; --T) work();
	return 0;
}

Measured memory_bytes: 256
# 点数計算
def scoring(last_, c, s, t, d, score):
    # score += s[d][t[d]-1]
    score = s[d][t]
    k = 8
    
    for i in range(len(c)):
        # score -= c[i] * (d+1 - last_[d][i])
        # score -= c[i] * (d + 1 - last_[i])
        score -= k * c[i] * (d - last_[i]) + c[i] * (k * (k+1)) / 2
    return score


# input
score = -float("inf")
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(i) for i in input().split()])
# t = []
# for i in range(D):
#     t.append(int(input()))
last = [[0 for i in range(len(c))] for j in range(D+1)] # last[d][i]

ans = []
for d in range(D):
    # last[d][t[d]-1] = d+1
    last_dummy = last[d][:]
    score = 0
    t_d = 0
    for t in range(len(c)):
        last_dummy2 = last_dummy[:]
        last_dummy2[t] = d+1
        if score < scoring(last_dummy2, c, s, t, d, score):
            score = scoring(last_dummy2, c, s, t, d, score)

            t_d = t

    ans.append(t_d)
    last[d][t_d] = d+1


    # last更新
    for i in range(len(c)):
        last[d+1][i] = last[d][i]


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





Measured memory_bytes: 9664
while True:
    n, r = list(map(lambda x: int(x), input().split(" ")))
    if n == 0 and r == 0:
        break
    cards = [i for i in range(1,n+1)]
    cards = cards[::-1]

    for i in range(r):
        p, c = list(map(lambda x: int(x), input().split(" ")))
        p -= 1
        cards = cards[p:p+c] + cards[0:p] + cards[p+c:]
    
    print(cards[0])


Measured memory_bytes: 5628
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

ll dp[101][8] = { 0 };

int main() {
	dp[0][0] = 1;
	cin >> H >> W >> K;
	ll _count[10] = { 0 };
	ll path_count = 0;
	for (int i = 0; i < pow(2, W-1); i++) {
		int index = 1;
		int curr = i;
		bool pref = false, curf = false, cont = false;
		while (curr != 0) {
			if (curr % 2 == 1) curf = true;
			else curf = false;
			if (pref && curf) cont = true;
			curr /= 2;
			pref = curf;
		}
		if (cont) continue;
		curr = i;
		while (curr != 0) {
			_count[index] += (curr % 2);
			curr /= 2;
			index++;
		}
		path_count++;
	}

	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if(x != 0) dp[y + 1][x - 1] = (dp[y + 1][x - 1] + (dp[y][x] * _count[x])%MOD)%MOD;
			dp[y + 1][x] = (dp[y + 1][x] + (dp[y][x] * (path_count - _count[x] - _count[x + 1]))%MOD)%MOD;
			if(x != W - 1) dp[y + 1][x + 1] = (dp[y + 1][x + 1] + (dp[y][x] * _count[x + 1])%MOD)%MOD;
		}
	}
	cout << dp[H][K-1];
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

using vi=std::vector<int>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,C;
  cin>>n>>C;
  vi s(n);
  vi t(n);
  vi c(n);
  const int M = 1000000;
  rep(i,n) cin>>s[i]>>t[i]>>c[i];
  vi acc(M);
  repeat(cc,1,C+1) {
    vi temp(M);
    rep(i,n) {
      if(cc==c[i]) {
        temp[s[i]*2-1]+=1;
        temp[2*t[i]]-=1;
      }
    }
    repeat(i,1,M) {
      temp[i]+=temp[i-1];
    }
    rep(i,M) {
      if(temp[i]>0)acc[i]++;
    }
  }
  cout << *max_element(acc.begin(),acc.end()) << endl;
  return 0;
}


Measured memory_bytes: 9276
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = unsafe { _read_value!(_scanned, $t) };
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub unsafe fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            str::from_utf8_unchecked(target).parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        s: String,
    }
    let y = s[0..4].parse::<u32>().unwrap();
    let m = s[5..7].parse::<u32>().unwrap();
    let d = s[8..10].parse::<u32>().unwrap();
    let d = 10000 * y + 100 * m + d;
    if d <= 20190430 {
        println!("Heisei");
    } else {
        println!("TBD");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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;
}

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 / gcd(a, b) * b;
}

//----------------------------------------------------------------

int main()
{
    ll n;
    cin >> n;
    ll t;
    cin >> t;
    ll sum = t;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> t;
        sum = lcm(sum, t);
    }
    cout << sum << endl;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll b, n, m, x, cb = 0, ci = 0;
  ll a[100] = {0};
  cin >> n >> m >> x;
  rep(i, m) {
    cin >> b;
    a[b] = 1;
    }
  FOR(i, x, n) {
    if (a[i]) cb++;
  }
  for(int i = x; i > 0; i--) {
    if (a[i]) ci++;
  }
  if (cb < ci) {
    cout << cb << endl;
  } else {
    cout << ci << endl;
  }
}

Measured memory_bytes: 256
N_gyou, M_retu = map(int, input().split())

if (N_gyou == 2 or M_retu == 2):
    ans = 0
elif (N_gyou == 1 and M_retu == 1):
    ans = 1
elif (N_gyou == 1):
    ans = M_retu - 2
elif (M_retu == 1):
    ans = N_gyou - 2
else:
    ans = (N_gyou - 2) * (M_retu - 2)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(int i=x;i<n;i++)
int N, W, A[102][2];
ll ans = 0;
vector<vector<ll>>dp(102, vector<ll>(100002, INT_MAX));
bool val[100005];
int main()
{
    cin >> N >> W;
    val[0]=1;
    loop(i, 1, N+1)
    {
        cin >> A[i][0] >> A[i][1];
        dp[i][A[i][1]] = A[i][0];
    }
    loop(i, 1, N + 1)
    {
        loop(j, 0, 100002)
        {
            if (val[100001-j])
            {
                dp[i][100001 - j] = min(dp[i - 1][100001 - j], dp[i][100001 - j]);
                //cout << i << "," << 100001 - j + A[i][1] << ":" << dp[i][100001 - j + A[i][1]] << " ";
                dp[i][100001 - j + A[i][1]] = min(dp[i - 1][100001 - j + A[i][1]],min(dp[i][100001 - j + A[i][1]], dp[i - 1][100001 - j] + A[i][0]));
                val[100001 - j + A[i][1]] = 1;
                //cout << i << "," << 100001 - j + A[i][1] << ":" << dp[i][100001 - j + A[i][1]] << " ";
                if (dp[i][100001 - j + A[i][1]] <= W) ans = max(ans, 100001 - (ll)j + (ll)A[i][1]);
            }
        }
    }
    cout << ans;
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vector<string> ss(n);
    rep(i,n) cin >> ss[i];

    int a=0,b=0,ab=0,ans=0;
    rep(i,n){
        string s = ss[i];
        rep(j,s.size()-1){
            if(s[j] == 'A' && s[j+1] == 'B') ans++;
        }
        if(s[s.size()-1] == 'A' && s[0] == 'B'){
            ab++;
        }else if(s[s.size()-1] == 'A'){
            a++;
        }else if(s[0] == 'B'){
            b++;
        }
    }

    if(a == b){
        if(a == 0){
            ans += max(0, ab - 1);
        }else{
            ans += a + ab;
        }
    }else{
        ans += min(a, b) + ab;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int digit(int);

int main(){
	int a,b;
	vector<pair<int,int> > out;
	while (cin>>a>>b){
		pair<int,int> p=make_pair(a,b);
		out.push_back(p);
	}
	for (int i=0;i<out.size();i++){
		cout<<digit(out[i].first+out[i].second)<<endl;
	}
	return 0;
}

int digit(int x){
	//x????????°?????????
	int i;
	for (i=0;x>0;i++){
		x/=10;
	}
	return i;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll f(ll a, ll b) {
    if (a > b) swap(a, b);
    if (b % a == 0) {
        // cout << "(" << a << "," << b << "): " << (2 * (b / a) - 1) * a << endl;
        return (2 * (b / a) - 1) * a;
    }
    // cout << "(" << a << "," << b << "): " << 2 * (b / a) * a << " + f(" << b % a << "," << a << ")" << endl;
    return 2 * (b / a) * a + f(b % a, a);
}

int main() {
    ll N, X; cin >> N >> X;
    cout << N + f(X, N - X) << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = 3.141592653589793;

int n;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> n,n) {
        int  s[105]={};
        rep(i,n) cin >> s[i];
        sort(s,s+n);
        int ans=0;
        rep2(i,1,n-1) ans+=s[i];
        cout << ans/(n-2) << endl;
    }
    return 0;
}

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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI=3.141592653589793;


void solve(){
	ll a,v,b,w,t;
	cin >> a >> v >> b >> w >> t;
	v-=w;
	b-=a;
	if(v<=0){
	   	cout << "NO";
		return;
	}
	v=abs(v);
	b=abs(b);
	if(v*t>=b) cout << "YES";
	else cout << "NO";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


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

int N, M;
const int MAX = 1.0e5 + 100;
priority_queue<int> A;

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push(a);
    }
  
    for (int i = 0; i < M; i++) {
        int f = A.top();
        A.pop();
        f /= 2;
        A.push(f);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int f = A.top();
        A.pop();
        ans += f;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N>>K;
}
//=============================
void func(){}
//=============================
void solve()
{
    // a%b>=K
    int ans = 0;
    if (K == 0){
        ans = N*N;
    }
    else {
        rep(i,K+1,N){
            ans += (i-K)*(N/i);
            if (N%i>=K) {
                ans += (N%i) - K + 1;
            }
        }
    }
    cout<<ans<<endl;


}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	for (int k = 0; k < n; k++){
		char l[10];
		cin >> l;
		int r[8];
		for (int i = 0; i < 8; i++){
			r[i] = l[i] - '0';
		}
		sort(r, r + 8);
		cout << r[7] * 9999999 + r[6] * 999990 + r[5] * 99900 + r[4] * 9000 - r[3] * 9000 - r[2] * 99900 - r[1] * 999990 - r[0] * 9999999;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
using System;

public class p0002{
	p0002(){
		string str;
		string[] s;
		decimal[] a = new decimal[2];
		
		while((str = Console.ReadLine()) != null){
			s = str.Split(' ');
			for(int i = 0; i < 2; ++i)
				a[i] = decimal.Parse(s[i]);
			Console.WriteLine("{0}", ((a[0]+a[1]).ToString()).Length);
		}
	}
	
	public static int Main(string[] args){
		new p0002();
		return 0;
	}
}

Measured memory_bytes: 5756