akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N,S;
	int[] a;
	public void solve() {
		N = nextInt();
		S = nextInt();

		a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = nextInt();
		}

		int left = 0;
		int right = 0;
		int sum = 0;
		int ans = Integer.MAX_VALUE;
		while(left < N){
			while(right < N && sum < S){
				sum += a[right];
				right++;
			}

			if(sum >= S){
				ans = Math.min(ans,right - left);
			}

			sum -= a[left];
			left++;
		}
		out.println(ans == Integer.MAX_VALUE ? 0 : ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 41132
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) {
    int n, d = 0, c = 0, ans = 0;

    if(scanf("%d", &n) == 1);

    while(d <= 100) {
        c = 0;
        while(c <= 100) {
            if((c * 4) + (d * 7) == n)
            ans++;
            c++;
        }
        d++;
    }
    if (ans > 0) {
        printf("Yes");
    } else {
        printf("No");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    int blue = (N / (A + B)) * A;
    if (N % (A + B) != 0) {
        blue += min(A, N % (A + B));
    }
    cout << blue << endl;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
g=int(input())
h=int(input())
i=int(input())
j=int(input())
k=int(input())
l=int(input())
m=int(input())
n=int(input())
o=int(input())
p=int(input())
q=int(input())
r=int(input())
s=int(input())
t=int(input())

x=[a, b, c, d, e, f, g, h, i, j]
y=[k, l, m, n, o, p, q, r, s, t]

z=sorted(x, reverse=True)
w=sorted(y, reverse=True)

wa=sorted(z[:3])
ke=sorted(w[:3])

print(sum(wa), sum(ke))


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
using namespace std;
int h,w;
int map[100][100];
int qtx[800000],qty[800000],qkx[800000],qky[800000];
int ql[800000];
int tail,head;
int ans;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool vis[60][60][60][60];
bool bend;
void BFS(int tx,int ty,int kx,int ky,int len){
	if(len==100)return;
	if(tx==kx&&ty==ky){
		ans=len;
		bend=true;
		return;
	}
	for(int i=0;i<4;i++){
		bool mt=false,mk=false;
		if(tx+dx[i]>=0&&tx+dx[i]<w&&ty+dy[i]>=0&&ty+dy[i]<h){
			if(map[ty+dy[i]][tx+dx[i]]==0){
				mt=true;
			}
		}
		if(kx-dx[i]>=0&&kx-dx[i]<w&&ky-dy[i]>=0&&ky-dy[i]<h){
			if(map[ky-dy[i]][kx-dx[i]]==0){
				mk=true;
			}
		}
		qtx[tail]=tx+mt*dx[i],qty[tail]=ty+mt*dy[i];
		qkx[tail]=kx-mk*dx[i],qky[tail]=ky-mk*dy[i];
		ql[tail]=len+1;
		tail++;
	}
}
int main(){
	while(true){
	cin>>w>>h;
	if(w==0&&h==0)break;
	for(int i=0;i<60;i++){
		for(int j=0;j<60;j++){
			for(int k=0;k<60;k++){
				for(int r=0;r<60;r++){
					vis[i][j][k][r]=false;
				}
			}
		}
	}
	int tx,ty,kx,ky;
	cin>>tx>>ty>>kx>>ky;
	tx--,ty--,kx--,ky--;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>map[i][j];
		}
	}
	ans=869121;
	qtx[0]=tx,qty[0]=ty,qkx[0]=kx,qky[0]=ky;
	ql[0]=0;
	tail=1,head=0;
	bend=false;
	while(true){
		if(tail==head)break;
		if(!vis[qtx[head]][qty[head]][qkx[head]][qky[head]]){
		vis[qtx[head]][qty[head]][qkx[head]][qky[head]]=true;
		BFS(qtx[head],qty[head],qkx[head],qky[head],ql[head]);
		}
		if(bend)break;
		head++;
	}
	if(ans==869121)cout<<"NA"<<endl;
	else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 29112
using System;

namespace ABC124_A
{
    class Program
    {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            int ans = 0;
            if ((a - 1) > b) ans = a + a - 1;
            else if ((b - 1) > a) ans = b + b - 1;
            else ans = a + b;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>

int main(){
    char a[10];
    int i;

    scanf("%s",a);
    if(a[5]=='0'){
    if(a[6]<='4'){
    printf("Heisei\n");
    }
    else{
    printf("TBD\n");
    }

    }
    else{
    printf("TBD\n");
    }













return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (s == u)
        --a;
    else if (t == u)
        --b;
    cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long N,K;
  cin>>N>>K;
  long long sum=0;
  for(long long i=K+1; i<=N; i++){
    long long t=N/i;
    long long s=N%i;
   sum+=t*(i-K);
    if(s>=K && K!=0) sum+=s-K+1;
    if(s>=K && K==0) sum+=s-K;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)
	cout<<"Left";
	else if(a+b==c+d)
	cout<<"Balanced";
	else
	cout<<"Right"; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int G[9],n,a,c;
int main(){
	cin>>n;for(int i=0;i<n;i++){cin>>a;G[min(8,a/400)]++;}
	for(int i=0;i<8;i++){if(G[i]>=1)c++;}
	if(c>=1)cout<<c<<endl<<c+G[8]<<endl;
	else cout<<1<<endl<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
c, a = [], []
for _ in range(n):
    line = list(map(int, input().split()))
    c.append(line[0])
    a.append(line[1:])

ans = []
for i in range(2 ** n):
    tmp1 = [0] * n
    tmp2 = [0] * m
    cost = 0
    for j in range(n):
        if i >> j & 1:
            tmp1[j] = 1
    for j in range(len(tmp1)):
        if tmp1[j] == 1:
            cost += c[j]
            tmp2 = [p+q for p, q in zip(tmp2, a[j])]
    for j in tmp2:
        if j < x:
            break
    else:
        ans.append(cost)

if ans == []:
    print('-1')
else:
    print(min(ans))

Measured memory_bytes: 9248
#include <iostream>

int main(){
    int N;
    std::cin >> N;
    
    int count=1;
    int max_count=1;
    int buf;
    for(int i=0;i<N;i++){
        std::cin >> buf;
        if(buf==1){
            count++;
        }else{
            count=1;
        }
        if(max_count<count){
            max_count=count;
        }
    }
    
    std::cout << max_count << std::endl;
    
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll x = 0, y = 0;
    ll ans[h][w];
    rep(i, n) {
        rep(j, a[i]) {
            ans[x][y] = i + 1;
            y++;
            if (y == w) {
                x++;
                y = 0;
            }
        }
    }

    rep(i, h) {
        if (i % 2 == 0) {
            rep(j, w) { cout << ans[i][j] << " "; }
        } else {
            repb(j, w) { cout << ans[i][j] << " "; }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n,d,A,X[200001],H[200001];
    cin>>n>>d>>A;
    rep(i,n) cin>>X[i]>>H[i];
    vector<P> B;
    rep(i,n) B.push_back(P(X[i],H[i]));
    sort(B.begin(),B.end());
    rep(i,n) X[i]=B[i].first,H[i]=B[i].second;
    ll ans[200001],k=0,a=0;
    rep(i,n){
        if(X[i]<2*d) ans[i]=max(0,int(ceil(double(H[i])/A)-k)),k+=ans[i];
        else{
            for(int j=a;j<n&&X[j]<X[i]-2*d;j++) k-=ans[j],a++;
            ans[i]=max(0,int(ceil(double(H[i])/A)-k)),k+=ans[i];
        }
    }
    ll ANS=0;
    rep(i,n) ANS+=ans[i];
    cout<<ANS;
}


Measured memory_bytes: 5236
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<cstddef>
#include<string>
#include<array>
#include<vector>

using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

#include <utility>

template <class T> T gcd(T m, T n) {
	while (m %= n)
		::std::swap(m, n);
	return n;
}

#include <cassert>
#include <cstddef>
#include <utility>

template <template <class> class Container> class union_find {
protected:
	class node_type;

public:
	using container_type = Container<node_type>;
	using size_type = typename container_type::size_type;

protected:
	class node_type {
	public:
		typename union_find::size_type parent, size;
	};
	container_type c;

public:
	union_find() : c() {}
	explicit union_find(const size_type size) : c(size, { 0, 1 }) {
		for (size_type i = 0; i < size; ++i)
			c[i].parent = i;
	}

	bool empty() const { return c.empty(); }
	size_type size() const { return c.size(); }

	size_type find(size_type x) {
		assert(x < size());
		while (c[x].parent != x)
			x = c[x].parent = c[c[x].parent].parent;
		return x;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return c[find(x)].size;
	}

	::std::pair<size_type, size_type> unite(size_type x, size_type y) {
		assert(x < size());
		assert(y < size());
		x = find(x);
		y = find(y);
		if (x != y) {
			if (c[x].size < c[y].size)
				::std::swap(x, y);
			c[x].size += c[y].size;
			c[y].parent = x;
		}
		return { x, y };
	}
};

template<class T>
using vec_alias = std::vector<T>;


int main() {
	usize n, m;
	std::cin >> n >> m;
	struct edge {
		usize a, b;
	};
	std::vector<edge> edges(m);
	for (auto &e : edges) {
		std::cin >> e.a >> e.b;
		--e.a;
		--e.b;
	}

	union_find<vec_alias> uf(n);
	std::vector<u64> ans(m);
	ans.back() = static_cast<u64>(n)*(n - 1) / 2;
	for (usize i = m;--i;) {
		ans[i - 1] = ans[i];
		const auto &e = edges[i];
		if (!uf.same(e.a, e.b)) {
			ans[i - 1] -= static_cast<u64>(uf.size(e.a))*uf.size(e.b);
			uf.unite(e.a, e.b);
		}
	}
	for (const auto &e : ans) {
		std::cout << e << std::endl;
	}
	return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <map>
using namespace std;
long long dp[2010][2010],mod = 1000000007;
int s[2010],t[2010];
map<int,long long> mp;
int main(){
	int i,j,n,m;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> s[i];
	}
	for(i=0;i<m;i++){
		cin >> t[i];
	}
	for(i=0;i<=n;i++){
		dp[i][0] = 1;
	}
	for(i=0;i<=m;i++){
		dp[0][i] = 1;
	}
	for(i=0;i<n;i++){
		mp.clear();
		for(j=0;j<m;j++){
			(mp[t[j]] += dp[i][j]) %= mod;
			dp[i+1][j+1] = (dp[i][j+1] + mp[s[i]])%mod;
		}
	}
	cout << dp[n][m] << endl;
}
	

Measured memory_bytes: 31744
# https://abc100.contest.atcoder.jp/tasks/abc100_b
# B - Ringos Favorite Numbers

# B_Ringos_Favorite_Numbers.py

D, N = map(int, input().strip().split(" "))

if D == 0:
    #n = N
    #order_100 = -1
    #while n >= 1:
    #    n = n / 100
    #    order_100 += 1

    #if order_100 == 0:
    if N <= 99:
        print(N)
    else:
        print(101)

elif D == 1:
    if N <= 99:
        print(N*100)
    else:
        print(10100)
elif D == 2:
    if N <= 99:
        print(N*10000)
    else:
        print(1010000)



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#define abs(p) (p > 0 ? p : -(p))
using namespace std;

typedef long long ll;
ll n, m;
int main()
{
	cin >> n >> m;
    cout << abs(n - 2) * abs(m - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  REP(i, s.size())
  {
    if (i % 2 && (s[i] == 'R')) {cout << "No" << endl; return 0;}
    if (i % 2 == 0 && (s[i] == 'L')) {cout << "No" << endl; return 0;}
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B;
    cin >> A >> B;

    if(A >= 10){
        cout << B << endl;
    }else{
        cout << B + 100 * (10 - A) << endl;
    }
    

    // if(true){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
#define rep(i,N) for(int i=0;i<(int)N;++i)
//cout << fixed << setprecision(20) << *** << endl;
typedef long long ll;
using namespace std;
int main()
{
	vector<int> vec(3,0);
	unsigned long long X,Y,ANS=0;
	cin>>X>>Y;
	for(int i=1;;i++){
		if(X>Y)break;
		//cout<<X<<endl;
		X=X*2;
		ANS++;
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<map> 
#include<list>
#include<string>
#include<cstring>
#include<set>
#include<vector>
#define ll long long
#define memset(a,n) memset(a,n,sizeof(a))
#define mp make_pair 
#define pb push_back
using namespace std;
const int maxn = 1e6 + 100;


int n,a[maxn],b[maxn];

int main()
{
	scanf("%d",&n);
	for(int i = 0 ; i < n;i++){
		scanf("%d",&a[i]);
		b[i] = a[i];
	}
	sort(b,b+n);
	for(int i = 0 ;i < n;i++){
		if(a[i] == b[n - 1]){
			printf("%d\n",b[n-2]);
		}else{
			printf("%d\n",b[n-1]);
		}
	}
}


Measured memory_bytes: 6528
def solve(l):
	have = 0
	for m, w in l:
		have += w
		if m < have:
			return "No"
	return "Yes"
while True:
	n = input()
	if n == 0: break
	l = [tuple(reversed(map(int, raw_input().split()))) for i in xrange(n)]
	l.sort()
	print solve(l)

Measured memory_bytes: 4252
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main(){
  long long N, M;
  cin >> N >> M;
  //vector<long long> B(M+1,0);
  map<long long,int> B;
  set<long long> S;
  for(int i = 0; i < N; ++i){
    long long l, r;
    cin >> l >> r;
    S.insert(l);
    S.insert(r);
    S.insert(r+1);
    ++B[l];
    --B[r+1];
  }
  long long prev = -1;
  long long ma = -1, l = M, r = 0;
  for(auto e : S){
    B[e] += B[prev];
    prev = e;
    if(B[e] > ma){
      ma = B[e];
      l = e;
      r = e;
    }else if(B[e] == ma){
      l = min(l,e);
      r = max(r,e);
    }
  }
  long long ans = M*ma;
  if(ma%2){
    ans -= M - r;
  }else{
    ans -= l;
  }
  cout << ans << endl;
}



Measured memory_bytes: 68688
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  REP(i, N) cin >> S[i];

  map<string, int> mp;
  REP(i, N) { mp[S[i]]++; }

  priority_queue<P> que;
  for (auto m : mp) {
    que.push({m.second, m.first});
  }

  priority_queue<string, vector<string>, greater<string>> q;
  int ma = que.top().first;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    q.push(p.second);
    if (ma != que.top().first) break;
  }

  while (!q.empty()) {
    string s = q.top();
    q.pop();
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 32876
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A, B, M = lr()
    a = lr()
    b = lr()
    ans = 10**6
    for i in range(M):
        x, y, c = lr()
        ans = min(ans, a[x-1]+b[y-1]-c)
    ans = min(ans, sorted(a)[0]+sorted(b)[0])
    print(ans)
resolve()

Measured memory_bytes: 18736
#include <iostream>

using namespace std;

int main()
{
   int A, B, C, D;
   cin >> A;
   cin >> B;
   cin >> C;
   cin >> D;
   if(A+B>C+D)
   {
       cout << "Left";

   }
   if(A+B == C+D)
   {
       cout << "Balanced";
   }
   if(A+B<C+D)
   {
       cout << "Right";
   }
    return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

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

	vector<int> p(n);
	vector<int> copy(n);

	rep(i, n){
		cin >> p[i];
		copy[i] = p[i];
	}
	
	sort(copy.begin(), copy.end());

	int flag = 0;
	int buf;
	rep(i ,n){
		if(copy[i] != p[i]){
			flag++;
		}
		if(flag > 2){ 
			cout << "NO" << endl;
			break;
		}
	}
	

	if(flag <= 2){
		cout << "YES" << endl;
	}

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x, count, d = 0;
  
  cin >> n >> x;
  vector<int> leng(n, 0);
  for(int i = 0; i < n; i++){
    cin >> leng.at(i);
    d += leng.at(i);
    if(d > x) {
      count = i;
      break;
    }
    else if (i == n - 1){
      count = i + 1;
    }
  }
  cout << count + 1 << endl;
  
}


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

int main(void){
  int n, m, k;
  cin >> n >> m >> k;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
      if(m * i + n * j - 2 * i * j == k){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())

# Lv.1
#def f(t):
#    return 1 if t < 2 else t * f(t-2)
#print(f(n))

# Lv.2
# def g(p):
#     d = {2:0, 5:0}
#     for i in range(p, 1, -2):
#         t = i
#         while(t % 2 == 0):
#             t //= 2
#             d[2] += 1
#         while(t % 5 == 0):
#             t //= 5
#             d[5] += 1
#     return min(d[2], d[5])
# print(g(n))

# Lv.3
# 1,3,5,7,... 末尾は奇数
# 2,4,6,8,... Lv.2 の print(min(d[2], d[5])) は 5の方が常にmin
# 100 の時 10 で割れるのが10, 50で割れるのが2つ
# 250 の時 10 で割れるのが25, 50で割れるのが5つ, 250 で割れるのが1つ 1000個位出してみたら ? 整数分割の + - 交互のあれでは無いっぽい
k = 10
ans = 0
while k <= n:
    ans += n // k
    k = k * 5
print(ans if n % 2 == 0 else 0)

Measured memory_bytes: 61844
#include <bits/stdc++.h>
using namespace std;
 
int main () {
    int N, M;
    cin >> N >> M;
    int list[N];
    for(int i = 0; i<N; i++) {
        cin >> list[i];
    }
 
    int all_vote = 0;
    for(int i = 0; i<N;i++) {
        all_vote += list[i];
    }
 
    bool check = true;
    double border = (double) all_vote / (4 * M);
    sort(list, list + N, greater<int>());
    for(int i = 0; i<M; i++) {
        if(list[i] < border) check = false;
    }
    if(check)  cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[10000]={0};
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	long long num=0;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[k]<(a[i]+a[j]))
				num++;
				else
				break;
			}
		}
	}
	printf("%d\n",num);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x(x%mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    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) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    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 operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

//powMod
ll powMod(ll k, ll n, ll mod) {
    ll x = 1;
    while (n > 0) {
        if (n & 1) {
            x = x * k % mod;
        }
        k = k * k % mod;
        n >>= 1;
    }
    return x;
}

// comb (一つのみ) O(r)
ll comb(ll n, ll r, ll mod) {
    ll ret = 1;
    while (true) {
        if (r == 0) break;
        ll N = n % mod;
        ll R = r % mod;
        if (N < R) return 0;
        for (int i = 0; i < R; i++)
        {
            ret = ret * (N - i) % mod;
        }
        ll imul = 1;
        for (int i = 0; i < R; i++)
        {
            imul = imul * (i + 1) % mod;
        }
        ret = ret * powMod(imul, mod - 2, mod) % mod;
        n /= mod; r /= mod;
    }
    return ret;
}

int main() {
    constexpr int MOD = 1e9 + 7;
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    vector<mint<MOD>> t(n + 1);
    t[k - 1] = 1;
    for (int i = k; i <= n; i++) {
        t[i] = t[i - 1] * (i) / (i - k + 1);
    }
    mint<MOD> ans = 0;
    for (int i = 0; i < n; i++) {
        if (i <= n - k + 1) {
            ans -= t[n - 1 - i] * mint<MOD>(MOD + a[i]);
        }
        if (i >= k - 1) {
            ans += t[i] * mint<MOD>(MOD + a[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#ABC-141-C
N, K, Q = map(int, input().split())
point_list = [K] * N
seikai_list = [0] * N

for _ in range(Q):
    Ai = int(input())
    seikai_list[Ai-1] += 1
    
for i in range(N):
    final_point = point_list[i] - Q + seikai_list[i]
    if final_point > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 5448
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  bitset<4'000'010> dp;
  int s = 0;
  dp[0] = 1;
  REP(i,n){
    dp = dp | (dp<<a[i]);
    s += a[i];
  }
  int half = (s+1)/2;
  int ans;
  for(int i = 0; i <= 4'000'000; i++){
    if(dp[i] && (i >= half)){
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a==c){
		cout << 0 << "\n";
	}else{
		cout << 1 << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 102;

vector<int> ind[N];

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (int i = 0; i < n; i++) {
		ind[a[i]].push_back(a[i]);
	}
	int mx = *max_element(a.begin(), a.end());
	vector<int> d(mx + 1);
	vector<int> to(mx + 1);
	for (int i = 0; i <= mx; i++) {
		d[i] = max(i, mx - i);
	}
	for (int i = 0; i <= mx; i++) {
		if (ind[d[i]].empty()) {
			cout << "Impossible\n";
			return 0;
		}
		to[i] = ind[d[i]].back();
		ind[d[i]].pop_back();
	}
	for (int i = 0; i <= mx; i++) {
		d[i]++;
	} 
	for (int i = 0; i <= mx; i++) {
		ind[d[i]].clear();
	}
	for (int i = 0; i < N; i++) {
		if (!ind[i].empty()) {
			cout << "Impossible\n";
			return 0;
		}
	}
	cout << "Possible\n";
}

Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    max_num = 10**5
    n = int(input())
    a_list = list(map(int, input().split()))
    q = int(input())
    
    query = [map(int, input().split()) for _ in range(q)]
    num = [0 for _ in range(max_num+1)]
    for i in a_list:
        num[i] += 1

    ans = sum(a_list)

    for b,c in query:
        n = num[b]
        num[b] = 0
        num[c] += n
        ans += (c-b)*n
        print(ans)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 58356
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    string S, T; cin >> S >> T;
    ll n = S.size();
    bool k = true;
    for(int i=0; i<n; i++){
        if(S[i] != T[i]){
            k = false;
        }
    }
    if(k){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

const int maxn=1e9+10;

int main()
{
	int r,d,x2000,i=10;
	cin>>r>>d>>x2000;
	x2000=r*x2000-d;
	while (i--)
	{
		cout<<x2000<<endl;
		x2000=r*x2000-d;
	}
	return 0;
}


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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int a,b;cin>>a>>b;
  if (1<=a && a<=9 && 1<=b && b<=9){
    cout << a*b << endl;
  }
  else{
    cout << -1 << endl;
  }
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 768
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        var A = sc.ArrayInt(N);
        int gcd = A[0];
        for (int i = 1; i < N; i++) {
            gcd = Gcd(gcd, A[i]);
        }

        WriteLine(gcd);
    }

    public int Gcd(int a, int b) {
        if (a < b)
            return Gcd(b, a);
        while (b != 0) {
            var tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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


Measured memory_bytes: 20064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sum := 0.0
	for i := 0; i < 5; i++ {
		sc.Scan()
		s, _ := strconv.Atoi(sc.Text())
		sum += math.Max(float64(s), float64(40))
	}
	fmt.Println(int(sum / 5))

}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

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

  map<char, int> m1;
  string s;
  cin >> s;
  REP(j,s.size())m1[s[j]]++;

  REP(i,n-1){
    cin >> s;

    map<char, int> m2;
    REP(j,s.size()){
      m2[s[j]]++;
    }
    for(auto iter = m1.begin(); iter != m1.end(); iter++){
      iter->second = min(iter->second, m2[iter->first]);
    }

  }
  for(auto iter = m1.begin(); iter != m1.end(); iter++){
    REP(i,iter->second)cout << iter->first;
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAXN = 300005;
const int MAXM = 100005;

enum { START, POINT, FINISH };

int N, M;
int fid[MAXN];
int f[MAXN];
int tot;

int sol[MAXM];

void update(int i, int v) {
  tot += v;
  for (i += 2; i < MAXN; i += i & -i)
    f[i] += v;
}

int query(int i) {
  int ret = 0;
  for (i += 2; i; i -= i & -i)
    ret += f[i];
  return ret;
}

struct Event {
  int x, type, id;
  Event(int x, int type, int id) :
    x(x), type(type), id(id) {}
};

bool operator<(const Event &a, const Event &b) {
  if (a.x != b.x) return a.x < b.x;
  return a.type < b.type;
}

void handle(pair<pair<int,int>,int> evt) {
  if (evt.first.second == START)
    update(fid[evt.second], +1);
  else
    update(fid[evt.second], -1);
}

int main(void) 
{
  scanf("%d%d", &N, &M);

  vector<pair<int,int>> ls;
  vector<Event> events;

  REP(i, N) {
    int l, r;
    scanf("%d%d", &l, &r);
    ls.push_back({l, i});
    events.push_back(Event(l, START, i));
    events.push_back(Event(r, FINISH, i));
  }

  sort(ls.begin(), ls.end());
  REP(i, N) fid[ls[i].second] = i;

  FOR(d, 1, M + 1)
    for (int i = 0; i <= M; i += d)
      events.push_back(Event(i, POINT, d));

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

  for (Event &e : events) {
    if (e.type == START) 
      update(fid[e.id], +1);

    else if (e.type == FINISH)
      update(fid[e.id], -1);

    else {
      int px = lower_bound(ls.begin(), ls.end(), make_pair(e.x - e.id + 1, -10000)) - ls.begin();
      sol[e.id] += tot - query(px - 1);
    }
  }

  FOR(d, 1, M + 1)
    printf("%d\n", sol[d]);

  return 0;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> p(n);
rep(i, n){
  cin >> p[i];
}
ans=n;
map<ll,ll> m;
rep(i,n){
  if(m.find(p[i])!=m.end()){
    m[p[i]+1]=m[p[i]]+1;
    m.erase(p[i]);
  }
  else m[p[i]+1]++;
}
for (auto i = m.begin(); i != m.end(); ++i) {
  ans=min(ans,n-i->second);
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 14336
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <cmath>
# include <functional>
# include <utility>

# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	int n = 0, k = 0,  ans = 0,a=0,flag=0;
    int counter=0,x=0;
	cin >> a;
	vector <int> nums(a,0);
	rep(i, a) {
		cin >> nums[i];
	}
	sort(nums.begin(), nums.end());
	for (int i = 2; i <= a - 1;i++) {
		for (int j = i - 1; j >= 1; j--) {
			int needed = nums[i] - nums[j];//nums[k]>needed
			x = std::upper_bound(nums.begin(), nums.end(), needed)-nums.begin();
			counter += max(0,j - x);
		}
	}
	cout << counter << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    Int N,K;cin >> N >> K;
    cout << (N%K-(K-N%K)>0?K-N%K:N%K) << endl;
}

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

using namespace std;

int main()
{
	int n, r, p, c, cd[55];
	while(cin >>n >>r, n!=0 || r!=0){
		iota(cd,cd+55,1);
		while(r--){
			cin >> p>>c;
			rotate(cd+(n-p-c+1),cd+(n-p+1),cd+n);
			//rep(i,n) printf("%d ",cd[i]); puts("");
		}
		cout << cd[n-1] <<endl;
	}

}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll= long long;
int main(){
  int n,m;
  cin>>n>>m;
  vector<double> a(n);
  double sum =0;
  rep(i,n) {
    cin>>a[i];
    sum +=a[i];
  }
  sort(a.begin(),a.end(),greater<double>());
  if ( a[m-1]>=sum/(4*m)) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#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, m;
    cin >> n >> m;
    if (n == m) cout << "a == b" << endl;
    else if (n < m) cout << "a < b" << endl;
    else cout << "a > b" << endl;
    return 0;
}


Measured memory_bytes: 3048
fun main(args: Array<String>) {
    arc081d()
}

fun arc081d() {
    val n = readLine()!!.toInt()
    val s1 = readLine()!!
    val s2 = readLine()!!

    val times = mutableListOf<Int>()
    var left = 0
    while (left in s1.indices) {
        if (left + 1 in s1.indices && s1[left] == s1[left + 1]) {
            times.add(2)
            left++
        } else {
            times.add(1)
        }
        left++
    }

    var answer = Mint(3)

    times.forEachIndexed { index, i ->
        answer *= if (index == 0) {
            if (i == 1) 1L else 2L
        } else if (times[index - 1] == 1) {
            2L
        } else {
            if (i == 1) 1L else 3L
        }
    }

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private class Mint(value: Long = 0L) {
    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * other)
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2, MOD))
    operator fun div(other: Mint) = this.div(other.value)
    override fun toString(): String = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object Mod {
        private fun modPow(n: Long, p: Long, m: Long): Long {
            var x = n
            var y = p
            var result = 1L
            x %= m
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % m
                y = y shr 1
                x = (x * x) % m
            }
            return result
        }
    }
}


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

const int N = 20, M = (1 << 16) + 5,
  P = 1e9 + 7;

inline long long fpow(long long x, int y) {
  long long ret = 1;
  for ( ; y; y >>= 1, x = x * x % P)
    if (y & 1) ret = ret * x % P;
  return ret;
}

int n, m, A[N];
long long fac[M], inv[M];
long long f[N][M], ans;

inline long long binom(int x, int y) {
  if (x < y) return 0;
  return fac[x] * inv[y] % P * inv[x - y] % P;
}

int main() {
  std::cin >> n >> m;
  for (int i = 1; i <= m; ++i)
    std::cin >> A[i];
  fac[0] = 1;
  for (int i = 1; i <= 1 << n; ++i)
    fac[i] = fac[i - 1] * i % P;
  inv[1 << n] = fpow(fac[1 << n], P - 2);
  for (int i = 1 << n; i; --i)
    inv[i - 1] = inv[i] * i % P;
  std::reverse(A + 1, A + m + 1);
  f[0][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int s = 0; s < 1 << n; ++s) {
      f[i + 1][s] = (f[i + 1][s] + f[i][s]) % P;
      for (int j = 0; j < n; ++j) {
        if (s & (1 << j))
          continue;
        int t = s | (1 << j), w = (1 << n) - A[i + 1] - s;
        f[i + 1][t] = (f[i + 1][t] + f[i][s] * binom(w, (1 << j) - 1) % P * fac[1 << j]) % P;
      }
    }
  }
  for (int s = 0; s < 1 << n; ++s) {
    long long w = f[m][s] * fac[(1 << n) - s - 1];
    int cnt = 0;
    for (int j = 0; j < n; ++j)
      cnt += (s >> j) & 1;
    if (cnt & 1)
      ans = (ans + P - w) % P;
    else
      ans = (ans + w) % P;
  }
  ans = (1 << n) * ans % P;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 11008
line = input().split()
N = int(line[0])
nB = int(line[1])
nR = int(line[2])

if nB == 0:
  print(0)
  quit()

nball = nB + nR
nGroup = N // nball
nAdditional = N % nball

if nAdditional > nB:
  nAdditional = nB

nBlueTotal = nB * nGroup + nAdditional
print(nBlueTotal)


Measured memory_bytes: 3060
def euclid(a,b):
    if b ==0:
        return a
    else:
        return euclid(b, a%b)


K = int(input())
SUM = 0
for a in range(K):
    a += 1
    for b in range(K):
        b += 1
        for c in range(K):
            c += 1
            NUMS = [a,b,c]
            SUM += euclid(euclid(a,b),c)
            #print("{}, {}".format(NUMS,SUM))
print("{}".format(SUM))


Measured memory_bytes: 80400
//submitted by Himj
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
  //cin>>t;
    while(t--){
      string a,b;
      cin>>a>>b;
      int n=a.size(),m=b.size(),i,j;
      int dp[n+1][m+1];
      ms(dp,0);
      fr(i,1,n+1)
      {
        fr(j,1,m+1)
        {
          if(a[i-1]==b[j-1])
            dp[i][j]=1+dp[i-1][j-1];
          else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
      }
      i=n,j=m;
      string ans;
      while(i>0 and j>0)
      {
        if(a[i-1]==b[j-1])
        {
          i--;
          j--;
          ans+=a[i];
        }
        else if(dp[i-1][j]>dp[i][j-1])
          i--;
        else j--;
      }
      reverse(ans.begin(),ans.end());
      cout<<ans;
      
       
    }
  return 0;
  }



Measured memory_bytes: 35456
import math

A, B, H, M = map(int, input().split())
r = (H * 30 + M * 0.5) - (M * 6)
if r > 180:
    r = 360 - r
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(r))
print(math.sqrt(ans))


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

int main(){
    int a[3],res,min=-100;
    for(int i = 0; i < 3; i++)
    {
        cin >> a[i];
    }
    
    sort(a,a+3);
    res = a[0]+a[1];
    cout << res;
    
}   


Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Prelude hiding (readLn)
import Data.Ord

main :: IO ()
main = readLn >>= flip replicateM readLn >>= print . solve . sortOn Down

solve :: [Int] -> Int
solve (x : xs) = x `div` 2 + sum xs

readLn :: IO Int
readLn = head <$> readLine

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>

using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int>p;
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        p.push_back(temp);
    }

    int ans=0;
    for (int i = 0; i < n - 2; i++) {
        if (p[i] < p[i + 2]) {
            if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
                ans++;
            }
        }
        else
        {
            if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
                ans++;
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256