akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

typedef string::const_iterator State;
map<string, int> m;

int expr(State&);
bool f;

int number(State& p){
	int res = 0;
	while(isdigit(*p)){
		res *= 10;
		res += *p - '0';
		p++;
	}
	return res;
}

int factor(State& p){
	assert(*p == '(');
	p++;
	int res = expr(p);
	p++;
	return res;
}

int alp(State& p){
	string s;
	s += *p;
	p++;
	if(islower(*p)){
		s+=*p;
		p++;
	}
	if(m.count(s)) return m[s];
	f = true;
	return -1;
}

int expr(State& p){
	if(f) return 0;

	int res = 0;
	while(true){
		if(f) return 0;
		if(*p == '('){
			int tmp = factor(p);
			res += tmp * number(p);
		}else if(isdigit(*p)){
			int tmp;

			p--;
			if(islower(*p)){
				p--;
			}
			tmp = alp(p);

			int num = number(p);
			res += (num - 1) * tmp;
		}else if(isupper(*p) or islower(*p)){
			res += alp(p);
		}else{
			break;
		}
	}
	return res;
}

int main(){
	string s;
	while(cin >> s){
		if(s == "END_OF_FIRST_PART") break;
		int t;
		cin >> t;
		m[s] = t;
	}

	while(cin >> s, s[0] != '0'){
		s+='@';
		State tmp = s.begin();
		f = false;
		int ans = expr(tmp);

		if(f) cout << "UNKNOWN" << endl;
		else cout << ans << endl;
	}
}



Measured memory_bytes: 3196
A, B, C, X, Y = map(int, input().split())

plan1 = A * X + B * Y
if X > Y:
    plan2 = 2 * C * X
    plan3 = 2 * C * Y + A * (X - Y)
else:
    plan2 = 2 * C * Y
    plan3 = 2 * C * X + B * (Y - X)

print(min(plan1, plan2, plan3))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,l;
	cin>>n>>l;
	
	int ans=0;
	if(l>=0){
		for(int i=1;i<n;++i){
			ans+=i+l;
		}
		cout<<ans<<endl;
		return 0;
	}else{
		if(n-1>=-l){
			REP(i,n){
				ans+=i+l;
			}
			cout<<ans<<endl;
			return 0;
		}else{
		for(int i=0;i<n-1;++i){
			ans+=i+l;
		}
		cout<<ans<<endl;
		return 0;			
		}
	}
}

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


using namespace std;


int main()
{
	int n, x;
	vector<int> *box;

	cin >> n;
	box = new vector<int>(n);
	vector<int>::iterator box_itr = box->begin();

	for(int i = 0; i < n; i++)
		cin >> box_itr[i];

	for(int i = n - 1; i >= 0; i--){
		cout << box_itr[i];

		if(i)
			cout << " ";
	}
	cout << endl;

	return 0;
}


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

int main() {
  double w, h;
  int x ,y;
  cin >> w >> h >> x >> y;
  cout << (w*h)/2.0 << " ";
  if(x*2 == (int)w && y*2 == (int)h) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


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

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<int> S(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> S[i];
	}
	vector<int> NonTenMultiple;
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		ans += S[i];
		if (S[i] % 10 != 0)
		{
			NonTenMultiple.push_back(S[i]);
		}
	}
	if (ans % 10 != 0)
	{
		cout << ans << endl;
	}
	else if (NonTenMultiple.size() == 0)
	{
		cout << 0 << endl;
	}
	else
	{
		sort(NonTenMultiple.begin(), NonTenMultiple.end());
		ans -= NonTenMultiple[0];
		cout << ans << endl;
	}
}

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

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

int main() {
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k && 3 * x <= s; x++) {
        for (int y = x; y <= k; y++) {
            for (int z = y; z <= k; z++) {
                if (x + y + z == s) {
                    if (x == y && y == z) count += 1;
                    else if (x == y && y != z) count += 3;
                    else if (y == z && z != x) count += 3;
                    else if (z == x && x != y) count += 3;
                    else count += 6;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3660
from operator import mul
from functools import reduce
def cmb(n,r):
    r=min(n-r,r)
    if r==0:
        return 1
    over=reduce(mul,range(n,n-r,-1))
    under=reduce(mul,range(1,r+1))
    return over//under

N,M=map(int,input().split())
ans=0
if N>=2:
    ans+=cmb(N,2)
if M>=2:
    ans+=cmb(M,2)
print(ans)

Measured memory_bytes: 38256
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
using namespace std;
const int mod=1e9+7;
int ans,s;
int dig(int n)
{
	int ile=0;
	while (n)n/=10,ile++;
	return ile;
}

int fastpow(int a,int b)
{
	int wynik=1;
	while (b)
	{
		if (b&1)wynik=(wynik*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return wynik;
}

int get(int x)
{
	return (fastpow(10,s/x)-fastpow(10,s/x-1)-x+1+mod*3)%mod;
}
int32_t main()
{
  BOOST;
  cin>>s;
  int sum=0;
  int wskaz=1;
  for (int i=1;i<10000000;i++)
  {
  	while (sum<s)sum+=dig(wskaz),wskaz++;
  	if (sum==s)ans++;
  	sum-=dig(i);
  }
  ans+=s/8;
  for (int i=1;i<=s/8;i++)
  	if (s%i==0)
  	{
  		ans=(ans+get(i))%mod;
  		ans--;
  		if (ans<0)ans+=mod;
  	}
  cout<<ans;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N, K;
	string S;
	cin >> N >> S >> K;
	for(int i = 0; i < S.size(); i ++){
		if(S[i] != S[K - 1])S[i] = '*';
	}
	cout << S << endl;

//"Hiroakimm0415"
	return 0;
}

Measured memory_bytes: 256
H, W, M = map(int, input().split())

HL, WL = [0]*H, [0]*W
B = []

for _ in range(M):
  h, w = map(lambda x:int(x)-1, input().split())
  B.append((h, w))
  HL[h] += 1
  WL[w] += 1

HM, WM = max(HL), max(WL)
K = HL.count(HM) * WL.count(WM)

cnt = 0
for h, w in B:
  if HL[h] == HM and WL[w] == WM:
    cnt += 1

if K > cnt:
  print(HM+WM)
else:
  print(HM+WM-1)


Measured memory_bytes: 110032
n, a, b = map(int, input().split())

mod = 1000000007
ruiseki1 = 1
for i in range(a):
    ruiseki1 = (ruiseki1*(n-i)*pow(i+1, mod-2, mod)) %mod

ruiseki2 = 1
for i in range(b):
    ruiseki2 = (ruiseki2*(n-i)*pow(i+1, mod-2, mod)) %mod
    
print((pow(2,n,mod) - ruiseki1 -ruiseki2-1)%mod)

Measured memory_bytes: 40556
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val D = sc.nextInt
    val N = sc.nextInt

    val n = D match {
      case 0 => 1
      case 1 => 100
      case 2 => 10000
    }
    if (N == 100) {
      (n * (N + 1)).toString
    } else {
      (n * N).toString
    }
  }
}


Measured memory_bytes: 27332
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        
        while (true){
      int n=scan.nextInt();
      int p =scan.nextInt();
     
      if((n|p)==0)break;
      boolean flag=true;
      int init =p;
      int [] Mayor_stone = new int[n];
      for(int i=0;i<n;i++)Mayor_stone[i]=0;
      while(flag){
      for(int i=0;i<n;i++){
    	  if(p!=0){
    		  p--;
    		  Mayor_stone[i]++;
    		  if(p==0&&Mayor_stone[i]==init){
    			  flag=false;
    			  System.out.println(i);
    			  break;
    		  }
    	  }
    	  else {
    		  p=Mayor_stone[i];
    		  Mayor_stone[i]=0;
    	  }
    	  
      }
      }

    			  
      }
        }
      

}

Measured memory_bytes: 12000
#include<iostream>

int main(){
  int n;
  std::cin >> n;
  int diff = 0, l, r;
  for(int i = 0; i < n; i++)
  {
    std::cin >> l >> r;
    diff += (r - l);
  }
  std::cout << diff + n << std::endl;
  return 0;
}


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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    int num=n%10;
    string ans;
    if(num==3){ans="bon";}
    else if(num==0||num==1||num==6||num==8)ans="pon";
    else ans="hon";
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}
vector<vector<int>> T;
vector<vector<char>> S;
void rec(int a, int b, int c, int d) {
    //[a, b)行
    //[c, d)列を保持する
    pair<int, int> cur;
    pair<int, int> next;
    bool flag = false;
    bool two = false;
    for(int i = a; i < b; i++) {
        for(int j = c; j < d; j++) {
            if(S[i][j] == '#' and !flag) {
                flag = true;
                cur = make_pair(i, j);
            } else if(S[i][j] == '#') {
                next = make_pair(i, j);
                two = true;
                break;
            }
        }
    }
    if(!two) {
        for(int i = a; i < b; i++) {
            for(int j = c; j < d; j++) {
                T[i][j] = T[cur.first][cur.second];
            }
        }
        return;
    }
    //分割する
    if(cur.first != next.first) {
        //行で分割できる
        //[a, b)を分割する
        rec(a, next.first, c, d);
        rec(next.first, b, c, d);
    } else {
        //列で分割する
        int maxi = max(cur.second, next.second);
        rec(a, b, c, maxi);
        rec(a, b, maxi, d);
    }
}
int main() {
    int H, W, K;
    cin >> H >> W >> K;
    S.resize(H);
    T.resize(H);
    REP(i, H) {
        S[i].resize(W);
        T[i].resize(W);
        REP(j, W) { T[i][j] = 0; }
    }
    int cnt = 1;
    REP(i, H) {
        REP(j, W) {
            cin >> S[i][j];
            if(S[i][j] == '#') {
                T[i][j] = cnt;
                cnt++;
            }
        }
    }
    rec(0, H, 0, W);
    REP(i, H) {
        REP(j, W) { cout << T[i][j] << " "; }
        cout << endl;
    }
}

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

int main() {
  int N , count;
  cin >> N;
  count = 1;
  vector<int> vec(N);
  
  for (int i=0; i < N ; i++){ //配列を代入。
    cin >> vec.at(i);
  }
  
  //テスト:配列の出力
  //for (int i=0; i<N ; i++){
    //cout << vec.at(i) << ' ';
  //}
  
  for (int i = vec.at(0) ; i != 2 ; i = vec.at(i-1)){
    count ++;
    if (count > N+1){
      count = -1;
      break;
    }
  }
  cout << count << endl;

}


Measured memory_bytes: 640
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)

plus=[]
minus=[]
minus_sum=0
plus_sum=0

for i in 0..n-1
    v=a[i]-b[i]
    if v>0
        plus<<v
        plus_sum+=v
    elsif v<0
        minus<<v
        minus_sum+=v.abs
    end
end

if plus_sum<minus_sum
    p -1
    exit
end

plus.sort!
plus=plus.reverse
count=minus.length

while minus_sum>0
    
    minus_sum-=plus.shift
    count+=1
    
end
p count

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	map<int, int> m;
	rep(i, 0, n) { int t; read(t); m[t]++; }
	
	int ans = 0;
	for (auto p : m) {
		if (p.second >= p.first) ans += p.second - p.first;
		else ans += p.second;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4736
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	char input[100001];
	int n;
	string str;
	int i;
	char prev = 'L';
	bool flag = true;
	int start = -1;
	int sum[2] = { 0, };
	int tot[100001] = { 0, };

	scanf("%s", input);

	str = input;

	n = str.size();

	for (i = 0; i < n; i++)
	{
		if (str[i] != prev)
		{
			if (flag)
			{
				if (start != -1)
				{
					tot[start] += sum[!((i - start) % 2)];
					tot[start - 1] += sum[((i - start) % 2)];
				}
			}

			else
			{
				tot[i] += sum[((i - start) % 2)];
				tot[i - 1] += sum[!((i - start) % 2)];
			}

			flag = !flag;

			start = i;

			sum[0] = 1;
			sum[1] = 0;
		}

		else
		{
			sum[(i - start) % 2]++;
		}

		prev = str[i];
	}

	tot[start] += sum[!((i - start) % 2)];
	tot[start - 1] += sum[((i - start) % 2)];

	for (i = 0; i < n; i++)
	{
		printf("%d ", tot[i]);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 1024
//ALDS1_5_A:Exhaustive Search
#include <bits/stdc++.h>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int n;
int A[20];

bool dp[20][40001];
bool dp_already[20][40001];

//now番目以降の要素を足し合わせてsumを作ることができたらtrueを返す
bool solve(int now, int sum){
    if(sum == 0) return true;
    if(sum < 0) return false;
    if(now == n) return false;
    if(dp_already[now][sum]) return dp[now][sum];

    dp_already[now][sum] = true;
    return dp[now][sum] = (solve(now+1, sum - A[now]) | solve(now+1, sum));
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    for(int i=0; i<n; i++)
        for(int j=0; j<=40000; j++)
            dp_already[i][j] = false;
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int m;
        cin >> m;
        if(solve(0,m)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

struct S
{
    public long I;
    public long Last;
    public S(long i, long last)
    {
        this.I = i;
        this.Last = last;
    }
}

class Program
{
    private int N, K;
    private int[] A;
    private int Cnt = 0;
    private StringBuilder Sb = new StringBuilder();
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.IntArray();
    }

    public void Solve()
    {
        Scan();
        var ar = new int[200001];
        for (int i = 0; i < N; i++)
        {
            ar[A[i]]++;
        }
        Array.Sort(ar, (a, b) => -a.CompareTo(b));
        int c = 0;
        for (int i = 0; i < K; i++)
        {
            c += ar[i];
        }
        Console.WriteLine(N - c);
    }

    static void Main(string[] args)
    {
        new Program().Solve();
    }
}

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

const int maxn = 2e3+2;

int a[maxn];
int t;
int dis[maxn][maxn];
int main()
{
	ios::sync_with_stdio(0);
	int n,x,y; cin>>n>>x>>y;
	memset(a,0,sizeof a);
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			dis[i][j] = j-i;
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			dis[i][j] = min(dis[i][j],abs(x-i)+abs(j-y)+1) ;
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			++a[dis[i][j]];

		}
	}
	for(int i=1;i<=n-1;++i) cout<<a[i]<<"\n"; 
}

Measured memory_bytes: 15360
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        int count = bubbleSort(A, N);
        for(int i = 0; i < N; i++){
            System.out.print(A[i]);
            if(i != N - 1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }

    public static int bubbleSort(int[] A, int N){
        boolean flag = true;
        int count = 0;
        while(flag){
            flag = false;
            for(int i = N - 1; i > 0; i--){
                if(A[i] < A[i - 1]){
                    int temp = A[i];
                    A[i] = A[i - 1];
                    A[i - 1] = temp;
                    count++;
                    flag = true;
                }
            }
        }
        return count;
    }
}


Measured memory_bytes: 26272
from collections import defaultdict as dd

N = int(input())
cost = [int(x) for x in input().split()]
for i in range(2):
    cost.append(0)
INF = 10**9
dp = dd(lambda:INF)
dp[0] = 0

for i in range(N-1):
    for j in range(1,3):
        dp[i+j] = min(dp[i]+abs(cost[i+j]-cost[i]),dp[i+j])

print(dp[N-1])

Measured memory_bytes: 23648
#include<bits/stdc++.h>
typedef long long int LL;
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
LL dp[2000001];
LL mod=1e9+7;
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
 void solve(LL k){
 LL n; 
 cin>>n; 
 if(n>=30){
   cout<<"Yes"<<endl; 
   return;
 }
cout<<"No"<<endl; 
 }
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
// LL t;
//cin>>t;
 LL k=1;
//while(k<=t){
   solve(k);
//  k++;
 // }
   return 0;
   }

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int tmp[26];
	for (int i = 0; i < 26; i++) tmp[i] = 1;
	for (int i = 0; i < n; i++) {
		tmp[s.at(i) - 'a']++;
	}
	int ans = 1;
	for (int i = 0; i < 26; i++) {
		if (tmp[i] != 0) {
			ans = (ans * (ll)tmp[i]) % MOD;
		}
	}
	cout << (ans + MOD - 1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 512
func x  = foldl (\x y->[x!!0+y!!0,x!!1+y!!1]) [0,0] ((map (\y->if y!!0>y!!1 then [y!!0+y!!1,0] else if y!!0==y!!1 then [y!!0,y!!1] else [0,y!!0+y!!1]) x))

func' (x:xs) | x/=[0] = (func (fst y)) : (func' (snd y)) 
			 | x==[0] = []
			 	where y = splitAt (x!!0) xs

main = do
	getContents>>=mapM_ putStrLn.map(unwords.(map show)).func'.map(map(read::String->Int).words).lines

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

int main(){
    int N; cin >> N;
    vector<int> D;
    for (int i = 0; i < N; i++)
    {
        int d; cin >> d;
        D.push_back(d);
    }
    long ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            ans += D[i] * D[j];
        }
        
    }
    cout << ans << endl;
    
}

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

using namespace std;



int main() {
  //
  int N, W;
  cin >> N >> W;
  vector<long long> w(N+1), v(N+1);

  for (int i = 1; i <= N; ++i) {
    cin >> w[i] >> v[i];
  }

  //
  vector<vector<long long>> table(N+1, vector<long long>(W+1, 0));
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= W; ++j) {
      if(j >= w[i])
        table[i][j] = max(table[i-1][j], table[i-1][j-w[i]] + v[i]);
      else
        table[i][j] = table[i-1][j];
    }
  }

//  for (int i = 0; i <= N; ++i) {
//    for (int j = 0; j <= W; ++j) {
//      cout << table[i][j] <<  " ";
//    }
//    cout << endl;
//  }

  cout << table[N][W] <<  endl;

  return 0;
}




Measured memory_bytes: 80256
/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}





fn main() {
    let input : Vec<i32> = read_split();
    let a = input[0] + input[1];
    let b = input[0] - input[1];
    let c = input[0] * input[1];
    let answer;
    if a > b && a > c {
        answer = a;
    } else if b > c {
        answer = b;
    } else {
        answer = c;
    }
    println!("{}", answer);
}



Measured memory_bytes: 4352
N, W = map(int, input().split())
vs = [[] for _ in range(4)]
w1, v1 = map(int, input().split())
vs[0].append(v1)
for i in range(N - 1):
    w, v = map(int, input().split())
    vs[w - w1].append(v)
#print(vs)
s = [[0] for _ in range(4)]
for i in range(4):
    vs[i].sort()
    for j in range(len(vs[i])):
        s[i].append(s[i][-1] + vs[i][-j-1])
#print(vs)
ans = 0
for i in range(N + 1):
    if i > len(vs[0]):
        break
    if i * w1 > W:
        break
    si = s[0][i]
    for j in range(N + 1 - i):
        if j > len(vs[1]):
            break
        if i * w1 + j * (w1 + 1) > W:
            break
        sj = si
        sj += s[1][j]
        for k in range(N + 1 - i - j):
            if k > len(vs[2]):
                break
            if i * w1 + j * (w1 + 1) + k * (w1 + 2) > W:
                break
            sk = sj
            sk += s[2][k]
            for l in range(N + 1 - i - j - k):
                if l > len(vs[3]):
                    break
                if i * w1 + j * (w1 + 1) + k * (w1 + 2) + l * (w1 + 3) > W:
                    break
                sl = sk
                sl += s[3][l]
                ans = max(ans, sl)
print(ans)

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

int main() {
    ll n;
    cin >> n;
    vector<long double> v(n);
    rep(i,n) cin >> v[i];
    vector<vector<ll>> vec(19,vector<ll>(19));
    for(long double d:v){
        d+=0.0000000001;
        ll x=d*1e9+0.1;
        ll b2=0,b5=0;
        while(x%2==0){
            b2++;
            x/=2;
        }
        while(x%5==0){
            b5++;
            x/=5;
        }
        b2=min(b2,18LL);
        b5=min(b5,18LL);
        vec[b2][b5]++;
    }
    ll ans=0;
    vector<vector<ll>> vec2(19,vector<ll>(19));
    rep(i,19)rep(j,19){
        rep(k,19)rep(l,19){
            if(k<i||l<j) continue;
            else vec2[i][j]+=vec[k][l];
        }
    }
    rep(i,19)rep(j,19){
        ll x=vec[i][j];
        ll y=vec2[18-i][18-j];
        ans+=x*y;
    }
    rep(i,10)rep(j,10){
        ans-=vec[9+i][9+j];
    }
    ans/=2;
    cout << ans << endl;

}


Measured memory_bytes: 6316
// https://atcoder.jp/contests/abc118/tasks/abc118_c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

//ユークリッドの互除法
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n, buf, ans = 1000000001;
    scanf("%d", &n);
    int hp[n];

    // 初期化
    for (int i = 0; i < n; i++) {
        scanf("%d", &buf);
        hp[i] = buf;
    }

    // コンビネーションで剰余を取る
    ans = gcd(hp[0], hp[1]);
    for (int i = 2; i < n - 1; i++) {
        ans = gcd(ans, hp[i]);
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l[] = new int [n];
    int total = 0;

    for(int i=0 ; i<n ; i++){
      l[i] = sc.nextInt();
    }

    Arrays.sort(l);

    for(int i=0 ; i<n-2 ; i++){
      for(int j=i+1 ; j<n-1 ; j++){
        int high = n;
        int low =  0;
        int middle = 0;
        while((high-low)>1){
          middle = (high+low)/2;
          if(l[middle]<l[i]+l[j]){
            low = middle;
          }else{
            high = middle;
          }
        }
        total = total + (high-j-1);
      }
    }
    System.out.println(total);
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  int ac=0, wa=0, tle=0, re=0;
  rep(i,n){
    if(s[i] == "AC") ac++;
    if(s[i] == "WA") wa++;
    if(s[i] == "TLE") tle++;
    if(s[i] == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

string S;
const int MAX_S = 20;

int dp[MAX_S][2];

int main()
{
  cin >> S;
  int ans = 0;

  int tmp = 0;

  for(int s = 0; s < S.length(); s++) {
    if(S[s] > '0') {
      int tmp2 = tmp + S[s] - '1';
      for(int i = s+1; i < S.length(); i++) {
	tmp2 += 9;
      }
      ans = max(ans, tmp2);
    }
    
    tmp += S[s] - '0';
  }

  ans = max(ans, tmp);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int, input().split())

if b<c or d<a:
	ans=0
elif a<=c and b<=d:
	ans=b-c 
elif a<=c and d<b:
	ans=d-c 
elif c<a and d<=b:
	ans=d-a 
elif c<a and b<d:
	ans=b-a 

print(ans)


Measured memory_bytes: 3060
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def func(x):
    global cnt
    cnt += 1
    if x % 2:
        if f[3*x+1]: 
            print(cnt)
            quit()
        else:
            f[3*x+1] = 1
            func(3*x+1)
    else:
        if f[x//2]:
            print(cnt)
            quit()
        else:
            f[x//2] = 1
            func(x//2)


s = I()
f = defaultdict(int)
f[s] = 1
cnt = 1
func(s)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll n,a,b;
inline ll power(ll x,ll y)
{
    ll ans=1;
    while(y)
    {
        if(y&1) ans=ans*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return ans;
}
inline ll C(ll n,ll m)
{
    ll ans1=1,ans2=1;
    for(ll i=n-m+1;i<=n;++i) ans1=ans1*i%mod;
    for(ll i=1;i<=m;++i) ans2=ans2*i%mod;
    return ans1*power(ans2,mod-2)%mod;
}
int main()
{
    cin>>n>>a>>b;
    cout<<((power(2,n)-1-C(n,a)-C(n,b)+mod)%mod+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 256
def fn(k):
    return pow(2, k + 2) - 3

def pn(n, x):
    rec = 0
    if n == 0:
        if x >= 1:
            return 1
        return 0

    sum_f = fn(n - 1)
    if x <= sum_f + 1:
        rec += pn(n - 1, x - 1)

    elif x == sum_f + 2:
        rec += pow(2, n)

    else:
        rec += pow(2, n) + pn(n - 1, x - (sum_f + 2))

    return rec

n, x = map(int,input().split())
rec = pn(n, x)
print(rec)


Measured memory_bytes: 38724
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y)
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
ll recur(int n)
{
    if(n<2)
        return 1;
    return n*recur(n-2);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,cnt=0,zero=1;
    cin>>n;
    ull ten=2;
    while(n>=ten)
    {
        ten*=5ll;
        cnt+=n/ten;
    }
    if(n%2 || n<10)
        cnt=0;
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main() {
  int d,n; cin >> d >> n;
  if(d==0){
    if(n<=99) cout << n << endl;
    else cout << 101 << endl;
  }else if(d==1){
    if(n<=99) cout << n*100 << endl;
    else cout << 10100 << endl;
  }else{
    if(n<=99) cout << n*10000 << endl;
    else cout << 1010000 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    lint ans= 1;
    vector<lint> a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    REP(i,n){
        if(a[i] == 0){
            ans = 0;
        }
        else{
            if(ans <= LINF / a[i]){
                ans *= a[i];
            }else{
                println(-1);
                return 0;
            }
        }

    }
    println(ans);
    return 0;
}

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

#define MAX 100001
#define SENTINEL 1000000000

typedef struct{  
  int value;
  char c;
}Record;

void marge (Record A[],int left ,int mid,int right){
  int n1,n2,i,j,k;
  Record L[MAX/2+1],R[MAX/2+1];
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0; i<n1; i++) L[i]= A[left+i];
  for(i=0; i<n2; i++) R[i]= A[mid+i];

  L[n1].value = SENTINEL;
  R[n2].value = SENTINEL;
  i = j = 0;
  
  for(k=left; k < right; k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void margeSort(Record A[],int left,int right){
  int mid;
  if (left+1 < right){
    mid = (left + right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
}

int partition(Record B[],int p,int r){
  int x,i,j;
  Record temp;
  x = B[r].value;
  i=p-1;
  for(j=p; j<r; j++){
    if(B[j].value <= x){
      i++;
      temp = B[i];
      B[i] = B[j];
      B[j] = temp;
    }
  }
  temp = B[i+1];
  B[i+1] = B[r];
  B[r] = temp;
  
  return i+1;
}

void quickSort(Record B[],int p, int right){
  int k;
  if(p < right){
    k=partition(B,p,right);
    quickSort(B,p,k-1);
    quickSort(B,k+1,right);
  }
}


int main(){
  int i,j,n,l,stable;
  Record A[MAX],B[MAX];
  char s[100];


  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s %d",s,&l);
    A[i].c = B[i].c =s[0];
    A[i].value = B[i].value =l;
  }
  margeSort(A,0,n);
  quickSort(B,0,n-1);

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

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



Measured memory_bytes: 4104
import numpy
N, D = map(int,input().split())
point = []

for i in range(N):
    a = input().split()
    a = [int(i) for i in a]
    point.append(a)
ans = 0

for p1 in range(0,len(point)-1):
    for p2 in range(p1+1, len(point)):
        if numpy.linalg.norm(numpy.array(point[p2]) - numpy.array(point[p1])).is_integer():
            ans += 1
    
print(ans)

Measured memory_bytes: 12448
import java.util.*;
public class Main{
    public static void main(String[]args){
	Scanner sc = new Scanner(System.in);
	int ans=0;
	
	int N=sc.nextInt();
	int M=sc.nextInt();
	int K=sc.nextInt();

	int A[]= new int[N];
	int B[]= new int[M];
	long a[]= new long[N+1];
	long b[]= new long[M+1];
	a[0]=0;
	b[0]=0;

	int best[]= new int[N+1];
	
	for(int i=0; i<N; i++){
	    A[i]= sc.nextInt();
	    a[i+1]=a[i]+A[i];
	}
	for(int i=0; i<M; i++){
	    B[i]=sc.nextInt();
	    b[i+1]=b[i]+B[i];
	}

	int j=M;
	for(int i =0; i<N+1; i++){
	    if(a[i]>K){
		break;
	    }
	   long dif=K-a[i];
	    while(dif<b[j]){
		j=j-1;
	    }
	    ans=Math.max(ans,i+j);
	}
	System.out.println(ans);
	
    }
}



Measured memory_bytes: 65736
import itertools
n=int(input())
P=tuple((map(int,input().split())))
Q=tuple((map(int,input().split())))
L=[]

for i in range(n):
    L.append(i+1)
    
M=list(itertools.permutations(L))


print(abs(M.index(P)-M.index(Q)))


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

const int SIZE=100;
using F=bitset<SIZE>;

auto comp=[](const F& lhs,const F& rhs){
    return lhs.count()<rhs.count();
};

int dfs(int pos,vector<vector<F>> &bigSq,F state,unordered_map<F,int>& dp){
    if(pos==bigSq.size()){
        return 0;
    }
    if(!state[pos]){
        auto ret=dfs(pos+1,bigSq,state,dp);
        return ret;
    }
    
    vector<F> toS;
    for(int i=0;i<bigSq[pos].size();i++){
        toS.push_back(state & (~bigSq[pos][i]));
    }
    int res=1e6;
    sort(toS.begin(),toS.end(),comp);
    for(int i=0;i<toS.size();i++){
        bool isok=true;
        for(int j=0;j<i;j++){
            isok&=!((toS[i]&toS[j])==toS[j]);
        }
        if(isok){
            res=min(res,dfs(pos+1,bigSq,toS[i],dp)+1);
        }
    }
    return res;
}

int main(){
    int w,h;
    while(cin>>w>>h,w){
        vector<vector<int>> f(h,vector<int>(w,0));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>f[i][j];
            }
        }
        
        F state=0;
        vector<vector<F>> bigSq(h*w);
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(!f[i][j]) continue;
                state.set(i*w+j);
                int s=0;
                for(int k=1;k<=10;k++){
                    bool isok=true;
                    for(int ii=0;ii<k;ii++){
                        for(int jj=0;jj<k;jj++){
                            isok&=(i+ii<h && j+jj<w && f[i+ii][j+jj]);
                        }
                    }
                    if(!isok) break;
                    s++;
                }
                F sq=0;
                for(int ii=0;ii<s;ii++){
                    for(int jj=0;jj<s;jj++){
                        sq.set((ii+i)*w+j+jj);
                    }
                }
                for(int ii=0;ii<s;ii++){
                    for(int jj=0;jj<s;jj++){
                        bigSq[(i+ii)*w+j+jj].push_back(sq);
                    }
                }
                sort(bigSq[i*w+j].begin(),bigSq[i*w+j].end(),comp);
            }
        }

        for(int i=0;i<h*w;i++){
            vector<F> newBigSq;
            for(int j=0;j<bigSq[i].size();j++){
                bool isok=true;
                for(int k=j+1;k<bigSq[i].size();k++){
                    isok&=((bigSq[i][j] & bigSq[i][k])!=bigSq[i][j]);
                }
                if(isok) newBigSq.push_back(bigSq[i][j]);
            }
            bigSq[i]=newBigSq;
        }
        
        unordered_map<F,int> dp;

        int res=dfs(0,bigSq,state,dp);
        cout<<res<<endl;
    }

    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int l,r,d,cnt=0;
  cin>>l>>r>>d;
  for(int i=l;i<=r;i++)
  {
    if(i%d==0)
    {
      cnt++;
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);


ll gcd(ll a,ll b) {
    if (a<b) swap(a,b);
    while (b>0) {
        ll tmp=b;
        b=a%b;
        a=tmp;
    }
    return a;
}


int main() {
    ios_base::sync_with_stdio(false); 

    int t;
    cin >> t;
    rep(i,t) {
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        bool flag=1;
        if (a<b || d<b) flag=0;
        else if (c<b) {
            a=a%b;
            ll s=d%b;
            ll g=gcd(b,s);
            if (b-g+(a%g)>c) flag=0;
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3520
import java.util.Scanner;

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

        int i1 = scanner.nextInt();
        int i2 = scanner.nextInt();
        int i3 = scanner.nextInt();

        // b a c -> c a b
        System.out.printf("%d %d %d", i3, i1 ,i2);

        scanner.close();
    }
}

Measured memory_bytes: 21844
#include <string.h>
#include <iostream>
using namespace std;

int dp[33][33][33][33][2];

int get_sum(int sum_table[33][33], int sy, int sx, int ey, int ex) {
	return sum_table[ey][ex]-sum_table[ey][sx]-sum_table[sy][ex]+sum_table[sy][sx];
}

int a = 24;
int b = 0;
int c = 32;
int d = 1;

void calc(int table[33][33], int sum_table[33][33], int *group, int *yojo, int dec, int sh, int sw, int eh, int ew) {
	if(dp[sh][sw][eh][ew][0]>=0) {
		*group = dp[sh][sw][eh][ew][0];
		*yojo = dp[sh][sw][eh][ew][1];
		return;
	}
	*group = 1;
	*yojo = dec-get_sum(sum_table,sh,sw,eh,ew);
	//if(sh==a&&sw==b&&eh==c&&ew==d) cout << "all" << " : " << *group << "," << *yojo << endl;
	if(*yojo>0) {
		*group = 0;
		dp[sh][sw][eh][ew][0] = *group;
		dp[sh][sw][eh][ew][1] = *yojo;
		return;
	}
	for(int h = sh+1; h < eh; h++) {
		int _g1,_y1,_g2,_y2;
		calc(table,sum_table,&_g1,&_y1,dec,sh,sw,h,ew);
		calc(table,sum_table,&_g2,&_y2,dec,h,sw,eh,ew);
		//if(sh==a&&sw==b&&eh==c&&ew==d) cout << "h=" << h << " : " << _g1 << "," << _y1 << "," << _g2 << "," << _y2 << endl;
		if(_g1*_g2==0) continue;
		if(*group<=_g1+_g2) {
			if(*group<_g1+_g2) *yojo = max(_y1,_y2);
			else *yojo = min(*yojo,max(_y1,_y2));
			*group = _g1+_g2;
		}
	}
	for(int w = sw+1; w < ew; w++) {
		int _g1,_y1,_g2,_y2;
		calc(table,sum_table,&_g1,&_y1,dec,sh,sw,eh,w);
		calc(table,sum_table,&_g2,&_y2,dec,sh,w,eh,ew);
		//if(sh==a&&sw==b&&eh==c&&ew==d) cout << "w=" << w << " : " << _g1 << "," << _y1 << "," << _g2 << "," << _y2 << endl;
		if(_g1*_g2==0) continue;
		if(*group<=_g1+_g2) {
			if(*group<_g1+_g2) *yojo = max(_y1,_y2);
			else *yojo = min(*yojo,max(_y1,_y2));
			*group = _g1+_g2;
		}
	}
	//if(sh==a&&sw==b&&eh==c&&ew==d) cout << "bst" << " : " << *group << "," << *yojo << endl;
	dp[sh][sw][eh][ew][0] = *group;
	dp[sh][sw][eh][ew][1] = *yojo;
	//cout << sh << " " << sw << " " << eh << " " << ew << " : " << *group << " " << *yojo << endl;
}

int main() {
	while(true) {
		int h,w,s;
		cin >> h >> w >> s;
		if(h==0) break;
		int table[33][33];
		int sum_table[33][33] = {};
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				cin >> table[i][j];
				sum_table[i+1][j+1] = table[i][j]+sum_table[i+1][j]+sum_table[i][j+1]-sum_table[i][j];
			}
		}
		//cout << sum_table[h][w] << endl;
		memset(dp, -1, 33*33*33*33*2*sizeof(int));
		int dec = get_sum(sum_table,0,0,h,w)-s;
		int group,yojo;
		calc(table,sum_table,&group,&yojo,dec,0,0,h,w);
		cout << group << " " << (-yojo) << endl;
	}
}



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

int main()
{
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n)
  {
    int x, y;
    cin >> x >> y;
    p[i] = make_pair(x, y);
  }
  vector<int> a(n);
  rep(i, n) a[i] = i;
  sort(a.begin(), a.end());
  double sum = 0.0;
  int cnt = 0;
  do
  {
    rep(i, n - 1)
    {
      double x = p[a[i]].first - p[a[i + 1]].first;
      double y = p[a[i]].second - p[a[i + 1]].second;
      sum += sqrt(x * x + y * y);
    }
    cnt++;
  } while (next_permutation(a.begin(), a.end()));
  double ave = sum / cnt;
  cout << fixed << setprecision(10);
  cout << ave << endl;
  return 0;
}

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

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1), B(N);
    for(int i = 0; i < N + 1; i++ ) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];

    ll ans = 0;

    for(int i = 0; i < N; i++){
        if(B[i] > A[i]){
            ans += A[i];
            B[i] -= A[i];
            if(A[i+1] < B[i]) ans += A[i+1], A[i+1] = 0;
            else ans += B[i], A[i+1] -= B[i];
        }
        else{
            ans += B[i];
            A[i] -= B[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  int sum = 0;
  int ans = 2147483647;
  int i = 0;
  while(i <= x || i <= y){
    sum = i*2*c + max(0,x-i)*a + max(0,y-i)*b;
    ans = min (ans,sum);
    i++;
  }
  cout << ans << endl;
  

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int N,H,A,i;

 scanf("%d%d",&H,&N);
 for(i=0;i<N;i++){
  scanf("%d",&A);
  H=H-A;
 }

 if(H<=0)
  printf("Yes");
 else
  printf("No");

 return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stack>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

//????????????????????????u?????????v
int next(int u){
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;
        if(M[u][v])
            return v;
    }
    return -1;
}

//??¨????????°?????±?????????????´¢
void dfs_visit(int r){
    for(int i=0;i<n;i++)
        nt[i]=0;

    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;

    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

void dfs(){
    //????§????
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;

    //??\????????????u?????????????????±?????????????´¢
    for(int u=0;u<n;u++)
        if(color[u]==WHITE)
            dfs_visit(u);

    for(int i=0;i<n;i++)
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
}

int main(){
    int u,k,v;

    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;

    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }

    dfs();
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

template<class T>bool chmax(T &a, const T &b) { if( a < b ) { a = b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))
//#define int long long int //dont forget to change int to signed

int main() {
	int N;
	scanf("%d", &N);
	if (N <= 999) {
		printf("ABC\n");
	} else {
		printf("ABD\n");
	}
	return 0;
}



Measured memory_bytes: 256