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

int main() {
    int n,m,a,b;
    cin >> n >> m;
    vector<int> x(n);

    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        x.at(a-1)++;
        x.at(b-1)++;
    }
    for (int i = 0; i < n; i++)
    {
        cout << x.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

void spin_w(int x[]){
  int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  } 

  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}

void spin_s(int x[]){
int sai1[6],i;

  for(i=0;i<6;i++){
    sai1[i]=x[i];
  } 
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
  sai1[5]=x[1];

  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }

}


int main(){
 
  int i,a=0,j,sai1[6];
  char dic[101];
  for(i=0;i<6;i++){
    scanf("%d",&sai1[i]);
  }
  scanf("%s",dic);
  
  for(i=0;i<=100;i++){
    if(dic[i]=='\0')break;
    
    if(dic[i]=='W'){
      spin_w(sai1);
    }else if(dic[i]=='E'){
      for(j=0;j<3;j++){
	spin_w(sai1);
      }
    }else if(dic[i]=='S'){
      spin_s(sai1);

    }else if(dic[i]=='N'){
      for(j=0;j<3;j++){
	spin_s(sai1);
      }
    }
  }
  printf("%d\n",sai1[0]);
  return 0;
}

Measured memory_bytes: 596
u, s, e, w, n, d = input().split()
t = input()
for i in t:
    if i == 'N':
        u, s, n, d = s, d, u, n
    elif i == 'E':
        u, e, w, d = w, u, d, e
    elif i == 'S':
        u, s, n, d = n, u, d, s
    elif i == 'W':
        u, e, w, d = e, d, u, w
print(u)

Measured memory_bytes: 7432
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n, t;
    cin >> n >> t;

    vector<int> imos(t + 1);
    rep(i, n){
        int l, r;
        cin >> l >> r;
        ++imos[l];
        --imos[r];
    }

    reps(i, t){
        imos[i] += imos[i - 1];
    }

    int ans = 0;
    rep(i, t + 1){
        chmax(ans, imos[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3352
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(ALL(a), greater<int>());
  ll ans = a[0];
  FOR(i, 2, n) ans += a[i / 2];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)

int tot = 100500;
int n,dp[100500][3],arr[100500][3];


int ans(int ind,int cur)
{
   if(ind==n+1)return 0;
   if(dp[ind][cur]!=-1)return dp[ind][cur];

   dp[ind][cur]=-MOD*MOD;

   forn(j,0,2)
   {
       if(j==cur)continue;
       dp[ind][cur]=max(dp[ind][cur],arr[ind][j]+ans(ind+1,j));
   }
   return dp[ind][cur];


}



signed main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    st(dp,-1);

    forn(i,1,n)
        forn(j,0,2) 
            cin>>arr[i][j];
    
    cout<<max(ans(1,0),max(ans(1,1),ans(1,2)));


    

     
     




     return 0;

}

//       g++ -g c2.cpp ; ./a.exe

Measured memory_bytes: 12800
#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 s, w;
    cin >> s >> w;
    if (w >= s)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string str;
int main()
{
	cin>>str;
	if(str=="SUN") puts("7");
	if(str=="MON") puts("6");
	if(str=="TUE") puts("5");
	if(str=="WED") puts("4");
	if(str=="THU") puts("3");
	if(str=="FRI") puts("2");
	if(str=="SAT") puts("1");
	return 0;
}

Measured memory_bytes: 256
m = int(input())
a = list(map(int, input().split()))
s = sorted([c for c in a if c <= 0], key=lambda c: -c)
p = sorted([c for c in a if c > 0])
c = p.pop(0) if len(s) == 0 else s.pop(0)
ans = []
if len(p) > 0:
    for v in p[1:]:
        ans.append((c, v))
        c = c - v
    ans.append((p[0], c))
    c = p[0] - c
for v in s:
    ans.append((c, v))
    c = c - v
print(c)
for a, b in ans:
    print(a, b)


Measured memory_bytes: 69464
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;

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

	double r;
	double s, l;
	cin >> r;
	s = r * r * M_PI;
	l = r * 2 * M_PI;
	cout << fixed;
	cout << setprecision(6) << s << " " << l << "\n";

	return 0;
}


Measured memory_bytes: 3272
#include<stdio.h>
int main()
{
    int i,j,a[4][4],b[4][4],c[5][5],fh=0;
    for(i=1;i<4;i++)
        for(j=1;j<4;j++)
        scanf("%d",&c[i][j]);
    for(i=1;i<4;i++)
    {
        a[i][1]=c[i][1]-c[i][2];
        a[i][2]=c[i][1]-c[i][3];
        a[i][3]=c[i][2]-c[i][3];
        b[i][1]=c[1][i]-c[2][i];
        b[i][2]=c[1][i]-c[3][i];
        b[i][3]=c[2][i]-c[3][i];
    }
    for(i=1;i<4;i++)
    {
        if(a[1][i]!=a[2][i]||a[1][i]!=a[3][i]||b[1][i]!=b[2][i]||b[1][i]!=b[3][i])
        fh=1;
    }
    if(fh)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
cnt = 0
a.sort.chunk_while do |x,y|
  x==y
end.each do |ar|
  c=ar[0]
  if ar.size > c
    cnt+=ar.size-c
  elsif ar.size == c
  else
    cnt+=ar.size
  end
end
puts cnt


Measured memory_bytes: 12152
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = getInputString(sc);
 
        // programming
        int[] l = toIntegerList(s);
        int sum = 0;
        for (int v : l) {
            sum += v;
        }
        output(String.valueOf(sum));
	}

	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String s) {
        int[] ret = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            ret[i] = Integer.parseInt(String.valueOf(s.charAt(i)));
        }
        return ret;
    }
}

Measured memory_bytes: 22996
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N-1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N-1, 0)
void chmax(ll &a, ll b) { if (a < b) a = b; }
void chmin(ll &a, ll b) { if (a > b) a = b; }

const ll MOD = 1000000007;
const ll INF = 1LL << 60;

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

//C

//B

//A
int main() {
	ll M1;
	scanf("%lld", &M1);
	ll D1;
	scanf("%lld", &D1);
	ll M2;
	scanf("%lld", &M2);
	ll D2;
	scanf("%lld", &D2);

	ll result = 0;

	if (M1 != M2) {
		result = 1;
	}

	printf("%lld\n", result);
}


Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

//smaller names
#define int long long
#define double long double
#define Int signed
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define mii map<int, int>
#define unordered_map gp_hash_table

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

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(),v.end()

const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acosl(-1);

//order_of_key(k) - number of elements e such that func(e, k) returns true, where func is less or less_equal
//find_by_order(k) - kth element in the set counting from 0

typedef tree <
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update
> 
ordered_set;

typedef tree <
    int,
    null_type,
    less_equal<int>,
    rb_tree_tag,
    tree_order_statistics_node_update
>
ordered_multiset;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxa = 1e6 + 5;
const int logmax = 25;

//fast exponentiation

template <typename T>
T power (T a, int n = 1, T id = 1) {
    T ans = id;
    while(n) {
        if(n & 1) ans *= a;
        a *= a;
        n >>= 1;
    }
    return ans;
}

//custom hash

struct custom_hash {
    // http://xorshift.di.unimi.it/splitmix64.c
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int sumdigs (int n) {
    int ans = 0;
    while (n) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}


void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vi a(n);
    vi b(m);
    vi prea(n+1), preb(m+1);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    rep(i, n) prea[i+1] = prea[i] + a[i];
    rep(i, m) preb[i+1] = preb[i] + b[i];
    int fin = 0;
    rep(i, n+1) {
        int tar = k - prea[i];
        if(tar < 0) continue;
        int ans = 0;
        int left = 0, right = m;
        while(left <= right) {
            int mid = (left + right)/2;
            if(preb[mid] <= tar) {
                ans = mid;
                left = mid + 1;
            }
            else right = mid - 1;
        }
        fin = max(ans + i, fin);
    }
    cout << fin << endl;
}

signed main(){
    fastio;
    cout << setprecision(6) << fixed;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 9484
S = []

for x in input().split():
    if x == "+":
        S[-2] = S[-2] + S[-1]
        S.pop(-1)
    elif x == "-":
        S[-2] = S[-2] - S[-1]
        S.pop(-1)
    elif x == "*":
        S[-2] = S[-2] * S[-1]
        S.pop(-1)
    else:
        S.append(int(x))

print(*S)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    int n, a;
    cin >> n >> a;
    cout << (n % 500 <= a ? "Yes" : "No") << endl;
}


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

int main() {
	int n; cin >> n;
	long long ans = 0;
	if (n % 10 != 0) {
		string s = to_string(n);		
		for (int i = 0; i < s.size(); i++) {
			ans += (s[i] - '0');
		}
	}
	else {
		ans = 10;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

int main() {
	int w, h;
	while(cin >> w >> h, w) {
		vs field(h);
		pii s;
		vector<pii> dirty;
		REP(i, h) {
			cin >> field[i];
			REP(j, w) {
				if(field[i][j] == 'o') {
					s = make_pair(i, j);
				}
				if(field[i][j] == '*') {
					dirty.push_back(make_pair(i, j));
				}
			}
		}

		int dnum = dirty.size();
		vvi ddist(dnum, vi(dnum, INF));
		queue<pii> Q;
		REP(i, dnum) {
			Q.push(dirty[i]);
			vvi visited(h, vi(w));
			visited[dirty[i].first][dirty[i].second] = 1;
			while(!Q.empty()) {
				pii p = Q.front();
				Q.pop();

				REP(d, 4) {
					int ny = p.first + dy[d];
					int nx = p.second + dx[d];
					
					if(nx<0 || w<=nx || ny<0 || h<=ny || visited[ny][nx] || field[ny][nx] == 'x') {
						continue;
					}
					if(field[ny][nx] == '*') {
						FOR(j, i, dnum-1) {
							if(dirty[j].first == ny && dirty[j].second == nx) {
								ddist[i][j] = ddist[j][i] = visited[p.first][p.second];
							}
						}
					}
					visited[ny][nx] = visited[p.first][p.second] + 1;
					Q.push(make_pair(ny, nx));
				}
			}
		}	
		
		vi cdist(dnum, INF);
		Q.push(s);
		vvi visited(h, vi(w));
		visited[s.first][s.second] = 1;
		while(!Q.empty()) {
			pii p = Q.front();
			Q.pop();

			REP(d, 4) {
				int ny = p.first + dy[d];
				int nx = p.second + dx[d];

				if(nx<0 || w<=nx || ny<0 || h<=ny || visited[ny][nx] || field[ny][nx] == 'x') {
					continue;
				}
				if(field[ny][nx] == '*') {
					REP(j, dnum) {
						if(dirty[j].first == ny && dirty[j].second == nx) {
							cdist[j] = visited[p.first][p.second];
						}
					}
				}
				visited[ny][nx] = visited[p.first][p.second] + 1;
				Q.push(make_pair(ny, nx));
			}
		}

		vvi dp(1<<dnum, vi(dnum, INF));
		REP(i, 1<<dnum) {
			REP(j, dnum) {
				if(i == 0) {
					dp[1<<j][j] = cdist[j];
				} else {
					REP(k, dnum) {
						dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j]+ddist[j][k]);
					}
				}
			}
		}

		int ans = INF;
		REP(i, dnum) {
			ans = min(ans, dp[(1<<dnum)-1][i]);
		}

		cout << (ans == INF ? -1 : ans) << endl;
	}

	return 0;
}

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

vector<int> w2h[200001];

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        w2h[y].push_back(x);
    }

    int ans = H, loss = 0;
    for(int w=1; w<=W; w++){
        sort(w2h[w].begin(), w2h[w].end());
        for(int h : w2h[w]){
            if(h-loss == w) loss++;
            if(h-loss > w) ans = min(ans, h-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8704
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        for(int i=0;i<3;i++){
            char c = S.charAt(i);
            System.out.print(c);
        }
    }
}

Measured memory_bytes: 35596
#include <cstdio>
#include <math.h>

int main(void){
    while(true){
        int m, n;
        scanf("%d %d", &m, &n);
        if(m == 0) break;
        int MAX = 7368791;
        bool flag[MAX+1];
        for(int i=0;i<MAX;i++){
            flag[i] = false;
        }
        for(int i=m;i<=MAX;i++){
            if(flag[i]){
            }else{
                if(n==0){
                    printf("%d\n", i);
                    break;
                }
                n--;
                for(int j=i;j<=MAX;j+=i){
                    flag[j] = true;
                }
            }
        }

    }
}



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

int main(){
  int N,ac,wa,tle,re;
  ac=0;
  wa=0;
  tle=0;
  re=0;
  cin>>N;
  vector<string> score(N);
  for(int i=0;i<N;i++){
  	cin>>score.at(i);
    
  	if(score.at(i)=="AC")
     ac++;
    else if(score.at(i)=="WA")
      wa++;
    else if(score.at(i)=="TLE")
      tle++;
    else
      re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
}

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

string s = "CODEFESTIVAL2016";
string g;

int main() {
    cin >> g;
    int ans = 0;
    for (int i = 0; i < 16; ++i)
        ans += g[i] != s[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
n = int(input())						# 5

a=int(n**(1/2))

j=0
for i in range(a,0,-1):
	if n/i==int(n/i):
		j=int(n/i)
		#p(i,j)
		break

print(i-1+j-1)
	


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
	int A1, A2, A3;
	cin >> A1 >> A2 >> A3;
	int min =A1 ,max = A2;
	if (A1 >= A2) {//2<1
		if (A1 <= A3) {//2<1<3
			min = A2;
			max = A3;
		}
		else if (A2 >= A3) {//3<2<1
			max = A1;
			min = A3;
		}
		else {//2<3<1
			max = A1;
			min = A2;
		}
	}
	else {//1<2
		if (A2 <= A3) {//1<2<3
			min = A1;
			max = A3;
		}
		else if (A1 <= A3) {//1<3<2
			min = A1;
			max = A2;
		}
		else {
			min = A3;
			max = A2;
		}
	}
	cout << max- min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 ll INF = 1LL <<60;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始


int main(){
  int n;
  cin>>n;
  ll h[n];
  for(int i = 0; i < n; i++) cin>>h[i];
  vector<ll> dp(n,INF);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  
  for(int i = 2; i < n; i++){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
  }

  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanLine() []int {
	var s []int
	scanner.Scan()
	for _, v := range strings.Split(scanner.Text(), " ") {
		i, _ := strconv.Atoi(v)
		s = append(s, i)
	}
	return s
}
func main() {
	var n int
	fmt.Scan(&n)
	p := scanLine()

	var SameWithIndex int
	for i, v := range p {
		if i+1 == v {
			SameWithIndex++
		}
	}
	if n-SameWithIndex <= 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
sx, sy, tx, ty = map(int, input().split())
s = ""

s += "U"*(ty-sy)
s += "R"*(tx-sx)
s += "D"*(ty-sy)
s += "L"*(tx-sx)
s += "L"
s += "U"*(ty-sy+1)
s += "R"*(tx-sx+1)
s += "D"
s += "R"
s += "D"*(ty-sy+1)
s += "L"*(tx-sx+1)
s += "U"
print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> s(N); rep(i,N) std::cin >> s[i];

  int sum = std::accumulate( all(s), 0LL );
  if ( sum % 10 != 0 ) std::cout << sum << std::endl;
  else {
    std::sort( all(s) );
    rep(i,N) if ( s[i] % 10 != 0 ) { sum -= s[i]; break; }
    if ( sum % 10 == 0 ) std::cout << 0 << std::endl;
    else std::cout << sum << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
dp=[10**5]*(n+1)
dp[0]=0
for i in range(n+1):
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=6
    pow=1
    while pow<=n:
        dp[i]=min(dp[i],dp[i-pow]+1)
        pow*=9
print(dp[n])


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,M,i,j;
	cin>>N>>M;
	vector<int> Pass(N+1,0);
	int L,R;
	int ans=0;
	int MaxL=0;
	int MinR=N;
	for (i=0;i<M;i++){
		cin>>L>>R;
		if (MaxL<L){
			MaxL=L;
		}
		if (MinR>R){
			MinR=R;
		}
	}
	if (MinR>=MaxL){
		cout<<MinR-MaxL+1<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var h, w int
	for {
		fmt.Scanln(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if (i+j)%2 == 0 {
					fmt.Printf("#")
				} else {
					fmt.Printf(".")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1092
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}

const int mod = 1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n;
bool chk(int x, int y) {return x>=1&&x<=n&&y>=1&&y<=n;}
int a[511*511];
int dis[511][511];
bool f[511][511];
int eval(int x, int y)
{
	int mn = 1e9;
	for (int d=0; d<4; d++)
	{
		int nx = x+dx[d], ny = y+dy[d];
		mn = min(mn, dis[nx][ny]);
	}
	mn += f[x][y];
	return mn;
}
void upd(int x, int y)
{
	dis[x][y]--;
	for (int d=0; d<4; d++)
	{
		int nx = x+dx[d], ny = y+dy[d];
		if (chk(nx, ny)&&eval(nx, ny)<dis[nx][ny])
		{
			upd(nx, ny);
		}
	}
}
int main()
{
	geti(n);
	for (int i=1; i<=n*n; i++) geti(a[i]);
	int ans = 0;
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=n; j++)
		{
			dis[i][j] = min(min(i-1, n-i),min(j-1, n-j))+1;
			f[i][j] = true;
		}
	}
	for (int i=1; i<=n*n; i++)
	{
		int x = (a[i]-1)/n+1, y = (a[i]-1)%n+1;
		f[x][y] = false;
		upd(x, y);
		ans += dis[x][y];
		/*
		for (int tx=1; tx<=n; tx++)
		{
			for (int ty=1; ty<=n; ty++)
			{
				cerr<<dis[tx][ty]<<" ";			
			}
			cerr<<endl;
		}cerr<<endl;
		*/
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20948
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(ABC[2] + " " + ABC[0] + " " + ABC[1]);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
using namespace std;

const int MAX = 10000;
string s;
int x, y;
bitset<2 * MAX + 3> dpX, dpY;

int main() {
	int i, j;
	
	cin >> s >> x >> y;
	
	vector<int> splits;
	int len = 0;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == 'T') {
			splits.push_back(len);
			len = 0;
		}
		else {
			len++;
		}
	}
	splits.push_back(len);
	
	x -= splits[0];	//最初はx正方向にしかいけない
	
	if (x < -(int)s.length()) {
		cout << "No" << endl;
		return 0;
	}
	
	vector<int> xs;
	vector<int> ys;
	for (i = 1; i < splits.size(); i++) {
		if (i % 2 == 0) xs.push_back(splits[i]);
		else ys.push_back(splits[i]);
	}
	
	//x, y方向で独立に部分和問題を解く
	int trans = MAX;
	bitset<2 * MAX + 3> tmp1, tmp2;
	
	dpX[trans] = 1;
	for (i = 0; i < xs.size(); i++) {
		tmp1 = dpX >> xs[i];
		tmp2 = dpX << xs[i];
		dpX = tmp1 | tmp2;
	}
	
	dpY[trans] = 1;
	for (i = 0; i < ys.size(); i++) {
		tmp1 = dpY >> ys[i];
		tmp2 = dpY << ys[i];
		dpY = tmp1 | tmp2;
	}
	
	if (dpX[x + trans] == 1 && dpY[y + trans] == 1) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long lli;
lli n;
lli dp[65][3];
lli d[65];

int main(int argc, char const *argv[]) {
    cin >> n;
    for(lli i = 63;i >= 0;i--,n /= 2){
        d[i] = n % 2;
    }
    dp[0][0] = 1;
    for(lli i = 0;i < 64;i++){
        if(d[i]){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = (dp[i][0]+dp[i][1] )% MOD;
            dp[i+1][2] = (dp[i][1]+dp[i][1]+dp[i][2]+dp[i][2]+dp[i][2] )% MOD;
        }else{
            dp[i+1][0] = (dp[i][0]+dp[i][1]) % MOD;
            dp[i+1][1] = dp[i][1];
            dp[i+1][2] = (dp[i][1]+dp[i][2]+dp[i][2]+dp[i][2]) % MOD;
        }
    }
    cout << (dp[64][0] + dp[64][1] + dp[64][2]) % MOD << endl;
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n; cin >> n;
    vector<ll> right(n+1), left(n+1);
    vector<ll> alis(n);
    REP(i, 0, n){
        cin >> alis[i];
    }
    left[0] = alis[0];
    REP(i, 0, n-1){
        left[i+1] = gcd(left[i], alis[i+1]);
    }
    right[n-1] = alis[n-1];
    for(int i = n-1; i >= 1; i--){
        right[i-1] = gcd(right[i], alis[i-1]);
    }
    ll ans = max(right[1], left[n-2]);
    REP(i, 0, n-2){
        ll mid = gcd(left[i], right[i+2]);
        ans = max(ans, mid);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
/* https://www.hamayanhamayan.com/entry/2019/01/09/004223 */
/* メモ化再帰は区間DP？ */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

int main()
{
    int N, M;
    cin >> N >> M;
    ll a[N][3];
    ll ans = -INF_LL;
    REP(i, N) REP(j, 3) {
        cin >> a[i][j];
    }

    REP(i, 8) {
        vector<ll> vec;
        REP(k, N) {
            ll one = 0;
            REP(j, 3) {
                if(i / (1 << j) % 2 == 1) {
                    one += a[k][j];
                } else {
                    one -= a[k][j];
                }
            }
            vec.push_back(one);
        }
        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());
        ll tmp = 0;
        REP(k, M) tmp += vec[k];
        ans = max(ans, tmp);
        
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
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/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve() {
  int a,b,c;
  cin>>a>>b>>c;
  out(min(b/a,c));
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    set<ll> ins;
    rreps(i, 1, n + 1) {
        ll tmp = 0;
        ll cv = 2 * i;
        while(cv <= n) {
            if (ins.count(cv) > 0) tmp++;
            cv += i;
        }
        if ((tmp % 2) != a[i - 1]) {
            ins.insert(i);
        }
    }
    printf("%lld\n", sz(ins));
    for(auto x : ins) printf("%lld\n", x);
    return 0;
}


Measured memory_bytes: 8576
x,k,d = map(int, input().split())
lists = []
x = abs(x)
 
step = int(x/d) 
 
if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = min(abs(x % d - d), abs(x % d + d))
 
print(answer)

Measured memory_bytes: 9196
def swap(a ,b):
    x = 0
    x = a
    a = b
    b = x
    return a,b


str_number_list = input().split()
X = str_number_list[0]  #A
Y = str_number_list[1]  #B
Z = str_number_list[2]  #C

# swap(A,B)
X , Y = swap(X,Y)
#swap(A,C)
X,Z = swap(X,Z)
print("%s %s %s" % (X,Y,Z))






Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	string s,t; cin>>s>>t;
	rep(i,0,n){
		cout<<s[i]<<t[i];
	}
	
	return 0;
}

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

// Start
template<int SZ> struct UF{
	int p[SZ+1],sz[SZ+1];
	UF(){I(SZ);}
	void I(int n){for(int i=0;i<=n;i++)	sz[p[i]=i]=1;}
	int F(int x){return x==p[x]?x:p[x]=F(p[x]);}
	bool U(int x,int y){
		x=F(x),y=F(y);
		if(x==y)	return false;
		if(sz[x]<sz[y])	swap(x,y);
		return p[y]=x,sz[x]+=sz[y],true;
	}
};
// End

const int maxn = 1e5;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	UF<maxn> D;
	int n,m;
	cin>>n>>m;
	for(int i=1,x,y,z;i<=m;i++){
		cin>>x>>y>>z;
		D.U(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(D.F(i)==i)
			ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main() {
	int n, i;
	long long a[1000]{ 0 }, b[1000]{ 0 }, aa[1000]{ 0 }, bb[1000]{ 0 }, c, d;

	cin >> n;

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

	aa[0] = a[0];
	bb[0] = b[0];

	for (i = 1; i < n; i++) {
		c = aa[i - 1] / a[i];
		d = bb[i - 1] / b[i];
		if (c < d) c = d;
		aa[i] = a[i] * c;
		bb[i] = b[i] * c;
		while (-1) {
			if (aa[i] < aa[i - 1] || bb[i] < bb[i - 1]) {
				aa[i] += a[i];
				bb[i] += b[i];
			}
			else break;
		}
	}

	cout << aa[n - 1] + bb[n - 1] << endl;

	return 0;

}



Measured memory_bytes: 256
//2017-5-25 21:25
//2017-5-25 22:13
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long LL;
const int MaxN = 3e5;

int a[MaxN + 5];
priority_queue<LL>R;
priority_queue<LL, vector<LL >, greater<LL > > L;

LL Lsum[MaxN + 5], Rsum[MaxN + 5];
LL Ltot, Rtot;
int n;

void init(){
		for(int i = 1; i <= n; i++){
			L.push(a[i]);
			Ltot += a[i];
		}
		Lsum[n] = Ltot;
		for(int i = n + 1; i <= 2 * n; i++){
			LL head = L.top();
			L.pop();
			if(a[i] > head) {Ltot += a[i] - head; head = a[i];}
			L.push(head);
			Lsum[i] = Ltot;
		}

		for(int i = 3 * n; i > 2 * n; i--){
			R.push(a[i]);
			Rtot += a[i];
		}
		Rsum[2 * n + 1] = Rtot;
		for(int i = 2 * n; i >= n; i--){
			LL head = R.top();
			R.pop();
			if(a[i] < head) {Rtot -= head - a[i]; head = a[i];}
			R.push(head);
			Rsum[i] = Rtot;
		}
}


int main(){
	while(~scanf("%d", &n)){
		for(int i = 1; i <= 3 * n; i++) scanf("%d", &a[i]);
		init();
		LL ans = -(1LL << 60);
		for(int i = n; i <= 2 * n; i++) ans = max(ans, Lsum[i] - Rsum[i + 1]);
		printf("%lld\n", ans);
	}
	return 0;
}
			
		
		
	




Measured memory_bytes: 5876
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>//accumulateを使うためにインクルード

using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()) cout << "GREATER" << endl;
    else if(a.size() < b.size()) cout << "LESS" << endl;
    else {
        if(a == b) cout << "EQUAL" << endl;
        else if(max(a, b) ==a) cout << "GREATER" << endl;
        else if(max(a, b) ==b) cout << "LESS" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		int sum = 0;

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				int x = gcd(i + 1, j + 1);
				for(int k = 0; k < n; k++) {
					sum += gcd(x, k + 1);
				}
			}
		}

		System.out.println(sum);

		sc.close();
	}

	public static int gcd(int x, int y) {
        int biggerNum = Math.max(x, y);
        int smallerNum = Math.min(x, y);

        // 大きい方から小さい方を割った余を求める
        int surplus = biggerNum % smallerNum;

        // 割り切れていれば、それを返す
        if (surplus == 0) {
            return smallerNum;
        }
        // 割り切れなければ再帰的に自信を呼び出す
        surplus = gcd(smallerNum, surplus);

        return surplus;
	}

}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int k;

int main()
{
    _FastIO;
    string s;
    cin >> s;
    int n = s.size();
    int  sum = 0;
    for(int i = 0; i < n; i++){
        if(int(s[i]) < 97)
            sum++;
    }
    string ans = "AC";
    if(sum == 2 && s[0] == 'A'){
        ans = "AC";
    }
    else
        ans = "WA";
    sum = 0;
    for(int i = 2; i < n - 1; i++){
        if(s[i] == 'C')
            sum++;
    }
    if(sum && ans == "AC")
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a%3==0||b%3==0||(a+b)%3==0){
		printf("Possible\n");
	}
	else printf("Impossible\n");
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(dfs(n, new Integer[n + 1]));
    }

    private static int dfs(int target, Integer[] dp) {
        if (target <= 5) {
            return target;
        }
        if (dp[target] != null) {
            return dp[target];
        }
        int maxNine = 9, maxSix = 6;
        while (maxNine <= target) {
            maxNine *= 9;
        }
        while (maxSix <= target) {
            maxSix *= 6;
        }
//        System.out.println(maxNine/9 + " " + maxSix/6 + " " + target);
        return Math.min(1 + dfs(target - maxNine / 9, dp), 1 + dfs(target - maxSix / 6, dp));
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

int main(void){
	int n;
	int i;
	int money = 100000;

	scanf("%d", &n);
	for(i=0; i<n; i++){
		money = money + money * 0.05;
		if(money % 1000 != 0){
			money = money - (money % 1000) + 1000;
		}
	}

	printf("%d\n", money);

	return 0;
}

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

using namespace std;

int popcount(int x)
{
	if (x == 0) {
		return 0;
	}
	return (x & 1) + popcount(x >> 1);
}

bool ok(int N, const vector<vector<int>> &x, const vector<vector<int>> &y, int m)
{
	for (int i = 0; i < N; ++i) {
		if (m & (1 << i)) {
			for (int j = 0; j < x[i].size(); ++j) {
				if (y[i][j] == 1 && (m & (1 << x[i][j])) == 0) {
					return false;
				}
				if (y[i][j] == 0 && (m & (1 << x[i][j])) != 0) {
					return false;
				}
			}
		}
	}
	return true;
}

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> x(N), y(N);
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		x[i].resize(A);
		y[i].resize(A);
		for (int j = 0; j < A; ++j) {
			cin >> x[i][j] >> y[i][j];
			--x[i][j];
		}
	}

	int ans = 0;

	for (int m = 0; m < (1 << N); ++m) {
		if (ok(N, x, y, m)) {
			ans = max(ans, popcount(m));
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
A,B = input().split()

AandB = int(A+B)

ans = "No"
for i in range(int(AandB**0.5)+1+1):
    if i**2 == AandB:
        ans = "Yes"

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;




int main(){
    ll n,m;
    cin>>n>>m;
    ll mm=m;
    ll os[3];
    os[0]=mm/10000;
    mm=mm%10000;
    os[1]=mm/5000;
    mm=mm%5000;
    os[2]=mm/1000;
   // cout<<os[0]<<os[1]<<os[2]<<endl;
    for(int i=os[0];i>=0;i--){
        //iは一万円の数
        ll i0=os[0]-i;//i0は移動させた
        for(int j=os[1]+2*i0;j>=0;j--){
            ll i1=os[1]+2*i0-j;
            ll i3=os[2]+5*i1;
            ll ans=i+j+i3;
            if(ans==n){
                cout<<i<<" "<<j<<" "<<i3<<endl;return 0;
            }
            
        }
        
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <array>

int main() {
  int n;
  int counter = 0;
  std::cin >> n;
  while (n != 1) {
    n = n / 2;
    counter++;
  }
  int r = 1;
  for (int i; i < counter; i++) {
    r = r * 2;
  }
  std::cout << r << std::endl;
  return 0;
}

Measured memory_bytes: 256