akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long n,m;
	cin >> n >> m;
	long long answer = 1;
	long long mod = 1e9 + 7;
	int turn = 1;	// 1 for n, -1 for m;
	if (abs(n-m) > 1) answer = 0;
	else if (n == m)
	{
		while (1)
		{
			if ((turn == 1 && n == 0) || (turn == -1 && m == 0)) break;
			if (turn == 1) {
				answer *= n--;

			}
			else {
				answer *= m--;
			}
			turn *= -1;
			answer = answer % mod;
		}
		answer *= 2;
		answer = answer % mod;
	}
	else
	{
		int first = n, second = m;
		if (m > n) 
		{
			first = m;
			second = n;
		}
		while (1)
		{
			if ((turn == 1 && first == 0) || (turn == -1 && second == 0)) break;
			if (turn == 1) {
				answer *= first--;
			}
			else {
				answer *= second--;
			}
			turn *= -1;
			answer = answer % mod;
		}
	}

	cout << answer;

	return 0;
}

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

using namespace std;

int N;

int main(){
  cin >> N;
  vector<int>d(N);
  for(auto &v: d)
    cin >> v;
  set<string>S;
  for(int i=0;i<N;i++){
    string s = "";
    for(int j=i;j<min(i+5, N);j++){
      s += to_string(d[j]);
      S.insert(s);
    }
  }
  for(int i=0;i<N*N+1;i++){
    if(S.find(to_string(i)) == S.end()){
      cout << i << endl;
      return 0;
    }
  }
      
  return 0;
}

Measured memory_bytes: 3540
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {

	int A,B;
	scanf("%d%d", &A, &B);

	if ((A + B) % 2 == 0) {
		printf("%d", (A + B) / 2);
	}

	else {
		printf("IMPOSSIBLE");
	}



}






Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

string makeString(string s, int l, int r) {
    string t;
    t = s.substr(l, r );
    return t;
}
int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (a + b > 2 * c) {
        if (x < y) {
            if (b > 2 * c) cout << y * 2 * c << endl;
            else cout << x * c * 2 + (y - x) * b << endl;
        }
        else {
            if (a > 2 * c) cout << x * 2 * c << endl;
            else cout << y * c * 2 + (x - y) * a << endl;
        }
    }
    else  cout << x * a + y * b << endl;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

i64 gcd(i64 a, i64 b) {
    if (a < b) swap(a, b);

    i64 t;
    while(b > 0) {
        t = a % b;
        a = b;
        b = t;
    }

    return a;
}

i64 lcm(i64 a, i64 b) {
    return a * (b / gcd(a, b));
}

int main() {
    i64 A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

using pd = pair<double,int>;

int main(){
    int n,m;
    scanf(" %d %d", &n, &m);
    vector<int> a(m),b(m),c(m),d(m);
    rep(i,m) scanf(" %d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    auto check = [&](double x){
        vector<pd> v(m);
        rep(i,m) v[i] = {x*c[i]-d[i], i};

        sort(all(v));

        UF uf(n);
        double tmp = 0;
        rep(i,m){
            int vi = v[i].se;
            int p = a[vi], q = b[vi];
            if(uf.same(p,q)) tmp += v[i].fi;
            else uf.unite(p,q);
        }

        return tmp >= 0;
    };

    double l=0, r=1e11;
    rep(loop,70){
        double mid = (l+r)/2;
        if(check(mid)) r = mid;
        else l = mid;
    }
    printf("%.10f\n", r);
    return 0;
}



Measured memory_bytes: 3480
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
		{
			int a = sc.nextInt(),
				b = sc.nextInt(),
				x = Math.max(a, b),
				y = Math.min(a, b);
			while (y != 0)
			{
				x = x % y;
				int tmp = x;
				x = y;
				y = tmp;
			}
			System.out.printf("%d\n", x);
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	ll a, b, c, k;
	vector<ll>vec;
	cin >> a >> b >> c >> k;
	if (a>=k) {
		cout << k << endl;
	}
	else if (a + b >= k) {
		cout << a << endl;
	}
	else {
		cout << a-1*(k-(a+b)) << endl;
	}

}

Measured memory_bytes: 3636
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
INF = float('inf')


def main():
    N, T = map(int, readline().split())
    ans = INF

    for _ in range(N):
        c, t = map(int, readline().split())
        if t<=T:
            ans = min(ans, c)

    if ans == INF:
        print('TLE')
    else:
        print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	double l;
	cin >> l;
	l = l / 3.0;
	printf("%.10f\n", l * l * l);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, k;
  cin >> a >> b >> k;
  set<int> list;
  rep(i, a, min(b + 1, a + k)) list.insert(i);
  rep(i, max(a, b - k + 1), b + 1) list.insert(i);
  for (auto d : list)
    cout << d << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	LL sum = 0;
	int l = 0;
	int n;
	int N;
	scanf("%d",&N);
	while(N --){
		int x;
		scanf("%d",&x);
		int buf = x - l;
		l = x;
		if(buf > 0) sum += buf;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
typedef long long ll;
using namespace std;
int main(void){
    // Your code here!
    ll N;
    cin>>N;
    static ll h[100000],dp[100000];
    rep(0,i,N)cin>>h[i];
    rep(1,i,N){
        if(i>=2){
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }else{
            dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        }
        //cout<<dp[i]<<endl;
    }
    cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1792
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
    if (a < b && b < c){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }    
            
    }
}


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

int main() {
  string a, b;
  cin >> a >> b;
  if(a.length() == b.length()) {
    for(int i = 0; i < a.length(); i++) {
      if(a[i] != b[i]) {
        printf("%s\n", a[i] > b[i] ? "GREATER" : "LESS");
        return 0;
      }
    }
    printf("EQUAL\n");
  } else
    printf("%s\n", a.length() > b.length() ? "GREATER" : "LESS");
}

Measured memory_bytes: 256
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let inp: Vec<_> = s.trim().split(' ').collect();
    let n: usize = inp[0].parse().unwrap();
    let mut a = vec![0;n];
    
    let s = getline();
    let inp: Vec<_> = s.trim().split(' ').collect();
    for i in 0..n {
        a[i] = inp[i].parse().unwrap();
    }
    a.sort();
    println!("{}",a[n-1]-a[0]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    cin>>a>>b;
    int lena=a.size(),lenb=b.size();
    for(int i=0;i<min(lena,lenb);i++)
        cout<<a[i]<<b[i];
    if(lena>lenb) for(int i=lenb;i<lena;i++) cout<<a[i];
    else for(int i=lena;i<lenb;i++) cout<<b[i];
    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A1011
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section

//
int N;

int expt3(int n)
{
  if(n==0)
    return(1);
  else
    return(3 * expt3(n-1));
}
int calc_carbon(int n)
{
  int i,ret;

  ret=0;
  for(i=0;i<n;i++)
    ret += expt3(i);
  //printf("CC1:%d %d\n",n,ret);
  return(ret);
}
calcc(int n)
{
  int i,ret;



  if(n==1)
    return(1);
  if(n==2)
    return(2);


  if(n % 2)
    {
      ret = 2*calc_carbon((n-1)/2);
    }
  else
    ret=0;
  for(i=0;i<(n-(n % 2))/2;i++)
    ret += 4*calc_carbon(i);
    
  return(ret+n);
}
main()
{
  int ret;



  while(EOF != scanf("%d",&N))
    {
      ret=calcc(N);
      printf("%d\n",ret);
    }
return(0);
}

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

int main(){
    int V, E;
    cin >> V >> E;
    vector<pair<int, int> > edge(E);
    for (int i = 0; i < E; i++) {
        cin >> edge[i].first >> edge[i].second;
    }
    vector<int> ans;
    vector<int> state(V, 0);

    for (int i = 0; i < E; i++) {
        state[edge[i].second]++;
    }

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (state[i] == 0) {
                ans.push_back(i);
                for (int j = 0; j < edge.size(); j++) {
                    if (edge[j].first == i) {
                        state[edge[j].second]--;
                        edge[j] = edge.back();
                        edge.pop_back();
                        j--;
                    }
                }
                state[i]--;
                break;
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3340
#include <iostream>
#include <cmath>
using namespace std;
int count(int n)
{
    int c=0;
    int n1=sqrt(n);
    for(int i=1;i<=n1;i++)
    {
        if(n%i==0)
        {
            c++;
        }
    }
    return c;
}
int main() {
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<n;i++)
    {
        int c=count(n-i);
        if((n-i)!=1)
        {
            c=c*2;
            int c1=sqrt(n-i);
            if(c1*c1==(n-i))
            {
                c--;
            }
        }
        //cout<<"i: "<<i<<"  c:"<<c<<endl;
        ans=ans+c;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();
    	int M=sc.nextInt();


    	int[] A=new int[M];
    	int[] B=new int[M];

    	for(int i=0;i<M;i++) {
    		A[i]=sc.nextInt()-1;
    		B[i]=sc.nextInt()-1;
    	}

    	int ans=0;
    	for(int i=0;i<M;i++) {
    		UnionFind uf=new UnionFind(N);

    		for(int j=0;j<M;j++) {

    			if(i!=j) {
    				uf.unite(A[j], B[j]);
    			}

    		}

    		int counter=0;
    		for(int j=0;j<N;j++) {

    			if(j==uf.par[j]) {
    				counter++;
    			}

    		}

    		if(counter>1) {
    			ans++;
    		}

    	}

    	System.out.println(ans);
    }
}

class UnionFind {

	int[] par;
	int[] rank;

	public UnionFind(int MaxN){
		par=new int[MaxN];
		rank=new int[MaxN];
		init(MaxN);
	}

	//ｎ個の要素で初期化。
	void init(int n) {
		for(int i=0;i<n;i++) {
			par[i]=i;
			rank[i]=0;
		}
	}

	//木の根を求める
	public int root(int x) {

		//根までたどりついたので返させる。
		if(par[x]==x) {
			return x;
		}else {
			//経路圧縮
			return par[x]=root(par[x]);
		}

	}

	//xとyの根を比べて、同じ集合に属するかどうかを返す。
	public boolean same(int x,int y) {
		return root(x)==root(y);
	}

	//xとyの属する集合を併合
	public void unite(int x,int y) {
		x=root(x);
		y=root(y);

		if(x==y) {
			return;
		}

		if(rank[x]<rank[y]) {
			par[x]=y;
		}else {
			par[y]=x;

			if(rank[x]==rank[y]) {
				rank[x]++;
			}
		}
	}

	public void printJudge(int x,int y) {
		if(same(x,y)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	public int getNumOfSet() {
		Set<Integer>set=new TreeSet<Integer>();

		for(int i=0;i<par.length;i++) {
			set.add(par[i]);
		}

		return set.size();
	}
}





Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int n, l;
int main() {
  cin >> n >> l;
  int mn = 1e9;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    if (abs(l + i) < abs(mn)) {
      mn = l + i;
    }
    sum += l + i;
  }
  cout << sum - mn << endl;
}

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

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int[] xA = new int[n];
        int[] yA = new int[m];

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

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

        Arrays.sort(xA);
        Arrays.sort(yA);

        boolean _isfFlag = false;

        for (int z = xA[n-1]+1; z <= yA[0]; z++) {
            if (z > x && z <= y) {
                _isfFlag = true;
                break;
            }
        }

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


Measured memory_bytes: 23124
k = int(input())
if k <= 10:
    print(k)
    exit()


def f(c, l):
    ret = ''
    for i in range(l):
        a = max(0, int(c) - i)
        ret += str(a)
    return ret


k -= 11
s = '11'
while k > 0:
    if s[-2] >= s[-1] and s[-1] < '9':
        s = s[:-1] + str(int(s[-1]) + 1)
        k -= 1
        continue
    c = False
    for j in range(len(s) - 2, 0, -1):
        if s[j] <= s[j+1] and s[j] <= s[j-1] and s[j] < '9':
            s = s[:j] + str(int(s[j])+1) + f(s[j],len(s)-j-1)
            k -= 1
            c = True
            break
    if c:
        continue

    if s[0] < s[1]:
        s = str(int(s[0]) + 1) + f(s[0], len(s) - 1)
        k -= 1
        continue

    s = '1' + '0' * len(s)
    k -= 1

print(s)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int n,x,y,z,d,count;
    while(scanf("%d",&n)!=EOF)
    {
        count=0;
        for(x=0; x<=9; x++)
        {
            for(y=0; y<=9; y++)
            {
                for(z=0; z<=9; z++)
                {
                    for(d=0; d<=9; d++)
                    {
                        if(x+y+z+d==n)count++;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

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

using namespace std;


int calculateSumOfDigits(int x){

    int sum = 0;

    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main() {

    int N, A, B;
    cin >> N >> A >> B;

    int total = 0;


    int digits;
    for (int i = 0; i <= N; ++i) {
        digits = calculateSumOfDigits(i);
        if ( A <= digits && B >= digits){
            total += i;
        }
    }

    cout << total << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
long long p = 1000000007;
long long ans = 1;
long long d = 4294967296;
long long gcd(long long gcd_a, long long gcd_b) {
	if (gcd_a < gcd_b) {
		long long gcd_c;
		gcd_c = gcd_a;
		gcd_a = gcd_b;
		gcd_b = gcd_c;
	}
	if (!gcd_b)return gcd_a;
	return gcd(gcd_b, gcd_a % gcd_b);
}
struct two {
	long long x;
	long long y;
	bool operator<(two f){
		unsigned long long hx[3], hy[3];
		unsigned long long px[2], py[2];
		px[0] = y / d;
		px[1] = y % d;
		py[0] = f.x / d;
		py[1] = f.x % d;
		hx[0] = px[0] * py[0];
		hx[1] = px[0] * py[1] + px[1] * py[0];
		hx[2] = px[1] * py[1];
		hx[1] += hx[2] / d;
		hx[2] %= d;
		hx[0] += hx[1] / d;
		hx[1] %= d;

		px[0] = x / d;
		px[1] = x % d;
		py[0] = f.y/ d;
		py[1] = f.y % d;
		hy[0] = px[0] * py[0];
		hy[1] = px[0] * py[1] + px[1] * py[0];
		hy[2] = px[1] * py[1];
		hy[1] += hy[2] / d;
		hy[2] %= d;
		hy[0] += hy[1] / d;
		hy[1] %= d;
		if (hx[0] < hy[0])return true;
		if (hx[0] > hy[0])return false;
		if (hx[1] < hy[1])return true;
		if (hx[1] > hy[1])return false;
		if (hx[2] < hy[2])return true;
		return false;
	}
	bool operator==(two g){
		if (x == g.x && y == g.y)return true;
		else return false;
	}
};
two ux[200000];
two dx[200000];
two in;
int uux, ddx;
int uxx, dxx, ddxx;
long long n;
long long a, b, c, o;
long long rui[200005];
int main() {
	rui[0] = 1;
	for (int i = 1; i < 200005; i++) {
		rui[i] = rui[i - 1] * 2 % p;
	}
	scanf("%lld", &n);
	for (long long i = 0; i < n; i++) {
		scanf("%lld%lld", &a, &b);
		if (a == 0 && b == 0) {
			o++;
			continue;
		}
		if (a == 0) {
			in.x = 0;
			in.y = 1;
			ux[uux] = in;
			uux++;
			continue;
		}
		if (a < 0) {
			a = -a;
			b = -b;
		}
		if (b > 0) {
			c = gcd(a, b);
			a /= c;
			b /= c;
		}
		else if (b == 0) {
			a = 1;
		}
		else if (b < 0) {
			c = gcd(a, -b);
			a /= c;
			b /= c;
		}
		if (b > 0) {
			in.x = a;
			in.y = b;
			ux[uux] = in;
			uux++;
		}
		else {
			in.x = -b;
			in.y = a;
			dx[ddx] = in;
			ddx++;
		}
	}
	std::sort(ux, ux + uux);
	std::sort(dx, dx + ddx);
	for (int i = 0; i < uux; i++) {
		uxx = 1;
		while (i < uux - 1 && ux[i] == ux[i + 1]) {
			uxx++;
			i++;
		}
		dxx = 0;
		in = ux[i];
		while (ddxx < ddx && dx[ddxx] < in) {
			ans *= 2;
			ans %= p;
			ddxx++;
		}
		while (ddxx < ddx && dx[ddxx] == in) {
			dxx++;
			ddxx++;
		}
		ans *= (rui[uxx] + rui[dxx] - 1);
		ans %= p;
	}
	ans *= rui[ddx - ddxx];
	ans %= p;
	ans += o;
	ans += p - 1;
	ans %= p;
	printf("%lld\n", ans);
}

Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

ll n, a, b;


int main()
{

    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    cin >> n >> a >> b;
    ll temp = n / (a+b);
    ll ans = temp * a;
    n %= (a+b);
    ans += min(a, n);
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
n=int(input())
w=list(map(int,input().split()))
s=[w[0]]
sum=sum(w)
ans=sum
for i in range(1,n):
    temp=s[i-1]+w[i]
    s.append(temp)
    ans=min(ans,abs(sum-2*s[i]))
print(ans)

Measured memory_bytes: 9024
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

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

    const ll indexes[10] = { 1, 1, 0, 2, 0, 0, 1, 0, 1, 0, };
    const char* names[3] = { "hon", "pon", "bon" };

    cout << names[indexes[N%10]] << endl;

    return 0;
}


Measured memory_bytes: 3624
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in()%10;
    cout<<(n==3?"bon":n==0||n==1||n==6||n==8?"pon":"hon")<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};


int main() {
	long long h,n,sum=0;
    cin>>h>>n;
    long long a[100005]={0};
    for(int i=0;i<n;i++){
         cin>>a[i];
         sum+=a[i];
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e5+5;
ll a[3*MAX_N];
int main(){
	int n;
	cin>>n;
	rep(i,3*n)cin>>a[i];
	sort(a,a+3*n);
	reverse(a,a+3*n);
	ll ans=0;
	rep(i,n){
		ans+=a[2*i+1];
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main() {
  long long int a, b, k;
  cin >> a >> b >> k;
  if ( b - a <= k * 2 - 1 ) {
    for ( int i = a; i <= b; i++ ) {
      cout << i << endl;;
    }
    return 0;
  }
  for ( int i = a; i <= a + k - 1; i++ ) {
    cout << i << endl;
  }
  for ( int i = b - k + 1; i <= b; i++ ) {
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

// const int N = ;
int n, m, a, b;

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

	cin >> n >> m;
	cin >> a >> b;

	for(int i = 0; i < b; i ++)
		cout << string(a, '1') << string(m - a, '0') << '\n';
	for(int i = b; i < n; i ++)
		cout << string(a, '0') << string(m - a, '1') << '\n';
}	

	

Measured memory_bytes: 1280
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

struct node {
    int parent = -1;
    vector<int> child;
    int child_num = 0;
    int counter = 0;
};

vector<node> tree;

void step_counter(int i) {
    // cout << i << " " << tree[i].child_num << endl;
    for (int j = 0; j < tree[i].child_num; j++) {
        int child = tree[i].child[j] - 1;
        if (child != tree[i].parent) {
            tree[child].parent = i;
            tree[child].counter += tree[i].counter;
            // cout << child << " " << tree[child].child_num << endl;
            if (tree[child].child_num != 1) step_counter(child);
        }
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;

    vector<pair<int, int>> ab(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    // sort(ab.begin(), ab.end());

    tree.resize(N);
    for (int i = 0; i < Q; i++) {
        int p, tmp;
        cin >> p >> tmp;
        tree[p - 1].counter += tmp;
    }

    for (int i = 0; i < N - 1; i++) {
        tree[ab[i].first - 1].child.push_back(ab[i].second);
        tree[ab[i].second - 1].child.push_back(ab[i].first);
        tree[ab[i].first - 1].child_num++;
        tree[ab[i].second - 1].child_num++;
    }

    step_counter(0);

    for (int i = 0; i < N; i++) {
        cout << tree[i].counter << " ";
    }
    cout << endl;

    return 0;
}


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

int main(){
    int a,b;
     while(scanf("%d %d",&a,&b)){
         if((a==0&&b==0))break;
         else{
             if(a>b){
                cout<<b<<" "<<a<<endl;
             }
             else cout<<a<<" "<<b<<endl;

         }

     }
return 0;
}



Measured memory_bytes: 3144
#include<stdio.h>
int main(void){
	int i,j,A[101],N,v,count;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<N;i++){
		printf("%d",A[i]);
		if(i == N-1){
			printf("\n");
		}
		else{
			printf(" ");
		}
	}
	for(i=0;i<N-1;i++){
		j=i+1;
		count=0;
		while(A[i]>A[j]){
			v=A[j];
			A[j]=A[i];
			A[i]=v;
			i--;
			j--;
			count++;
			if(i == -1){
				break;
			}
		}
		i+=count;
		for(j=0;j<N;j++){
			printf("%d",A[j]);
			if(j == N-1){
				printf("\n");
			}
			else{
				printf(" ");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
  int l[100];
  int n;
 
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
 
  sort(l,l+n);
  int max = l[n-1];
  int sum;
  for(int i=0; i<n-1;i++){
    sum += l[i];
  }
  if(sum > max)
    cout << "Yes";
  else
    cout << "No";
 
      return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans[5];
int main(){ 
	long long a,b,c,x,y,min_xy,max_xy;
	cin>>a>>b>>c>>x>>y;
	min_xy=min(x,y);
	max_xy=max(x,y);
	ans[0]=a*x+b*y;
	
	if(x>y){
		ans[1]=2*y*c+(x-y)*a;	
	} 
	else if(x<y){
		ans[1]=2*x*c+(y-x)*b;
	}
	else ans[1]=1000000000009;
	ans[2]=2*max_xy*c;
	sort(ans,ans+3);
	cout<<ans[0]<<endl;
	return 0;
}

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

using namespace std;

long long n, A, a[55], q[10005][55];

int main(){
    cin >> n >> A;
    for(long long i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = a[i] - A;
    }
    for(long long j = 1; j <= n; j++){
        for(long long i = 0; i <= 6000; i++){
            long long tmp = i - a[j];
            if(tmp >= 0) q[i][j] = q[i][j - 1] + q[tmp][j - 1];
            if(i == a[j] + 2500) q[i][j] += 1;
        }
    }
    cout << q[2500][n];
}


Measured memory_bytes: 4352
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll a,b,c=0,d=0,n=0;
    //VI a(N);
    string s,s1,s2;
    cin >> s; 
    VI alpha(26);
    bool ans = true;
    for(int i=0; i<s.size();i++){
        alpha[s[i]-'a']++;
    }
    for(int i=0; i<26;i++){
        if(alpha[i]%2==0){
            continue;
        }
        else {
            ans = false;
        }
    }
    if(ans)
        cout << "Yes" << endl; 
    else 
        cout << "No" << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a;
  int l;
  int max=0;
  long Q[100000]={0};
  long sum[100000]={0};
  long mul[100000]={0};
  int i,j=0;
  
  scanf("%d",&a);
  for(l=0;l<a;l++){
    scanf("%d", &Q[l]);
    if(max<=Q[l])
      max=Q[l];
  }

  for(i=1;i<=max;i++)
    mul[i]=1;
  
  for(i=2;i<=max;i++){
    for(j=2*i;j<=max;j+=i){
      mul[j]*=i;
      if(mul[j]>2*j)
	mul[j]=2*j;
    }
  }
  
  for(i=2;i<=max;i++){
    sum[i]=sum[i-1];
    if(mul[i]>=2*i)
      sum[i]++;
  }
  
  for(l=0;l<a;l++)
    printf("%d\n",sum[Q[l]]);

  return 0;
}


Measured memory_bytes: 5068
import math
n, m = map(int, input().split())

def comb(n, r):
    if n == 0 or n == 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


a = comb(n, 2)
b = comb(m, 2)
print(a+b)


Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int K; cin>>K;

    for(int i=0;i<min(K,SZ(s));i++)
    {
        if(s[i]!='1'){
            cout<<s[i]<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
}

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

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

//istream& operator>>(istream& is, const mint& a){return is >> a.x;}
//ostream& operator<<(ostream& os, const mint& a){return os << a.x;}

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

mint dp[2005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int s;
	cin >> s;
	dp[0] = 1;
	rep(i,s+1){
		for(int j = i+3; j <= s; ++j){
			dp[j] += dp[i];
		}
	}
	cout << dp[s].x << endl;
	return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	char c = s[k - 1];
	c += 32;
	s[k - 1] = c;
	cout << s << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (S == U)
  {
    cout << A - 1 << " " << B << endl;
  }
  else
  {
    cout << A << " " << B - 1 << endl;
  }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    typedef pair<int, int> pi;
    typedef pair<ll,ll> pl;

    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector<pi> vpi;
    typedef vector<pl> vpl;
    typedef vector<vi> vvi;

    #define FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
            int n;cin>>n;
            string s;cin>>s;

            if(s.length()>n)
            {
                cout<<s.substr(0,n)<<"..."<<nl;
            }
            else cout<<s<<nl;
    }


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

int main() {

    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        cout << B << endl;
    }
    else if (A >= 6) {
        cout << B/2 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if((c+b-1)/b<=(a+d-1)/d) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 3720
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using ll = long long;

using namespace std;


int main() {
	int n;
	ll h;
	cin>>n>>h;
	vector<ll>a(n),b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	ll a_max=a[0];
	ll ans=0;
	for(int i=0;i<n;i++){
		if(b[i]>a_max){
			ans++;
			h-=b[i];
		}else{
			break;
		}
		if(h<=0)break;
	}
	if(h>0){
		if(h%a_max==0)ans+=h/a_max;
		else ans+=h/a_max+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4788
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(readline())
    d = list(map(int, readline().split()))
    m = int(readline())
    t = list(map(int, readline().split()))

    cd = Counter(d)
    ct = Counter(t)

    cd.subtract(ct)

    for key, val in cd.items():
        if val < 0:
            return print("NO")

    print("YES")


if __name__ == '__main__':
    main()


Measured memory_bytes: 169128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};

//--global--//



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

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    string t, s;
    cin >> s >> t;
    cout << t << s << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<queue>

#define rep(i,j) for(int i=0;i<(j);i++)

using namespace std;

typedef pair<int,int> pii;
const int d[2]={-1,1};
int n,l,a[100000],b[100000];

int f(int p,bool right){
    int ne = p+d[right];
    if(ne >=0 && ne < n){
        if(b[ne]>0)return b[ne];
        if(a[p] > a[ne])return l-a[p] + f(ne,right);
    }
    return l-a[p];
}
int main(){
    scanf("%d%d",&n,&l);
    rep(i,n)scanf("%d",a+i);
    int ans=0;
    rep(i,n){
        ans = max(ans,max(f(i,true),f(i,false)));
    }
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2008
fun isNewBiggerThanOld(new: String, old: String) : Boolean {
    if (new.length != old.length) {
        return new.length > old.length
    }
    var i = 0
    while (i < new.length) {
        if (new[i] > old[i]) {
            return true
        } else if (new[i] < old[i]) {
            return false
        }
        i++
    }
    // Other
    return false
}

fun generateNext(str: String, number: Char) : String {
    val buffer = StringBuffer()
    var used = false
    var i = 0
    while (i < str.length) {
        val c = str[i]
        if (used) {
            buffer.append(str.substring(i))
            break
        }

        if (!used && number > c) {
            buffer.append(number)
            buffer.append(c)
            used = true
        } else {
            buffer.append(c)
        }
        i++
    }

    if (!used) {
        buffer.append(number)
    }

    return buffer.toString()
}
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toCharArray()[0] }
    val numToCost = listOf(-1, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val default = ""
    val dp = Array(N + 1, { default })

    (1..N).forEach { i ->
        var max = dp[i]
        A.forEach {
            val num = it
            val cost = numToCost[num - '0']
            if (i - cost >= 0) {
                var new = ""
                if (dp[i - cost] == default) {
                    if (i - cost == 0) {
                        new = num.toString()
                    }
                } else {
                    new = generateNext(dp[i-cost], num)
                }
                if (isNewBiggerThanOld(new, max)) {
                    max = new
                }
            }
        }
        dp[i] = max
    }
    println(dp[N])
}

Measured memory_bytes: 171884
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll x; cin >> x;
    ll y; cin >> y;
    string ret = "No";
    REP(i, x+1){
        if (i*4 + (x-i)*2 == y){
            ret = "Yes";
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3600
n,x,y=map(int,input().split())
a=[0]*n
for i in range(1,n+1):
    for j in range(i,n+1):
        b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i))
        a[b]+=1
print(*a[1:],sep="\n")

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

int main() {
  string s,ans;
  cin >> s;
  for(int i = 0;i < s.size();i++){
    if(s.at(i) != 'B'){
      ans += s.at(i);
    }
    else if(ans.size() > 0){
      ans.pop_back();
    }
  }
  cout << ans << endl;
}

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

int N;

int main(){
  cin >> N;
  int sum = 0;
  int cN = N;
  while(cN>0){
    sum += cN%10;
    cN/=10;
  }
  if(N%sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];


	sort(all(a));
	int b = 0;
	int ans = 0;
	if (n == 1) {
		if (a[0] == 1) dunk(0);
		else dunk(1);
		return 0;
	}

	for (int i = 1; i < n; ++i) {
		if (a[i] == a[i - 1]) {
			b++;
		}
		else {
			b++;
			if (b > a[i - 1]) ans += b - a[i - 1];
			if (b < a[i - 1]) ans += b;
			b = 0;
		}

		if (i == n - 1) {
			if (b == 0) ans++;
			else {
				b++;
				if (b > a[i - 1]) ans += b - a[i - 1];
				if (b < a[i - 1]) ans += b;
			}
		}
	}

	dunk(ans);

	return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
A = list(map(int,input().split()))
total = (1/(4*M)) * sum(A)
if A[M-1] >= total:
    print("Yes")
else:
    for i in range(M,N):
        if A[i] >= total:
            print("Yes")
            exit()
    print("No")

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

int main(){
  int N, cnt = 0;
  string S;
  
  cin >> N >> S;

  for(int i = 0; i < 1000; i++){
    int c[3] = {i / 100, (i / 10) % 10, i % 10};
    int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == ('0'+c[f])) {
              f++;
            }
			if (f == 3) break;
		}
		if (f == 3) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	stack<char> st;
	string X;
	cin >> X;

	for(size_t i = 0; i < X.size(); i++)
	{
		if(st.empty()){
			st.push(X[i]);
		}else if(st.top()=='S'){
			if(X[i]=='T'){
				st.pop();
			}else{
				st.push(X[i]);
			}
		}else{
			st.push(X[i]);
		}
	}

	cout << st.size() << endl;

	return 0;
}

Measured memory_bytes: 720
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define LL long long
#define ULL unsigned long long
#define DD double
using namespace std;
inline int read(){
    int red=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
    while (ch>='0'&&ch<='9') red=(red<<3)+(red<<1)+ch-'0',ch=getchar();
    return red*f;
}
const int maxn=200005;
int n,A[maxn];
bool vis[35];
LL Ans;
int main(){
    n=read();
    for (int i=1;i<=n;i++) A[i]=read();
    int j=1;
    for (int bas=0;bas<=20;bas++) if (A[j]&(1<<bas)) vis[bas]=true;
    for (int i=1;i<=n;i++){
    	for (int bas=0;bas<=20;bas++) if (A[i-1]&(1<<bas)) vis[bas]=false;
		bool flg=true;
		while (flg&&j<n){
			for (int bas=0;bas<=20;bas++) if ((A[j+1]&(1<<bas))&&vis[bas]){flg=false;break;}
			if (flg){
				++j;
				for (int bas=0;bas<=20;bas++) if (A[j]&(1<<bas)) vis[bas]=true;
			}
		}
		Ans=Ans+j-i+1; 
	}
	cout<<Ans;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> v1;

const ll mod = 1000000007;

ll a[1000];
ll b[1000];
ll x,y;
ll ans;

int main(){
  cin >> x >> y;
  a[1] = 300000;
  a[2] = 200000;
  a[3] = 100000;
  ans += a[x];
  ans += a[y];
  if(x == 1 && y == 1){
    ans += 400000;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256