akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    B=list(map(int,readline().split()))

    res=0
    for i in range(N):
        if A[i]>=B[i]:
            res+=B[i]
        elif A[i]<B[i]:
            res+=A[i]
            p=B[i]-A[i]
            res+=min(p,A[i+1])
            A[i+1]=max(A[i+1]-p,0)
    print(res)
if __name__=="__main__":
    main()

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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           1e9
#define   rush()        int T;scanf("%d",&T);while(T--)

typedef   pair<int,int> P;

bool f,vis[M];
vector<P> E[M];
int dis[M],n,m;


void dfs(int u,int pre)
{
    if(!f) return;
     int sz=E[u].size();
     pair<int,int>tmp;
     for(int i=0;i<sz;++i)
     {
        tmp=E[u][i];
        if(vis[tmp.first])
        {
            if(dis[u]+tmp.second!=dis[tmp.first])
            {
                f=0;return;
            }
        }
        else
        {
            vis[tmp.first]=1;
            dis[tmp.first]=dis[u]+tmp.second;
            dfs(tmp.first,u);
        }
     }
}

int main() {
	scanf("%d %d",&n,&m);
	
	for(int i=1;i<=m;i++) {
		int l,r,d;
		scanf("%d %d %d",&l,&r,&d);
		E[r].push_back(make_pair(l,d));
		E[l].push_back(make_pair(r,-d));
	}
	
	f=1;
	
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			vis[i]=1;
			dfs(i,-1);
		}
	}
	
	puts(f?"Yes":"No");
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}


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

int main() {
    //
    string str;
    cin >> str;

    int chk = 0;

    int yy = stoi(str.substr(0, 2));
    int mm = stoi(str.substr(2));
    if ((yy >= 0 && yy <= 99) && (mm >= 1 && mm <= 12)) chk += 1;
    if ((mm >= 0 && mm <= 99) && (yy >= 1 && yy <= 12)) chk += 2;

    if (chk == 0) cout << "NA";
    else if(chk == 1) cout << "YYMM";
    else if(chk == 2) cout << "MMYY";
    else if(chk == 3) cout << "AMBIGUOUS";
    //
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, C;
    cin >> N >> C;
    vector<pair<ll, ll>> v;
    for(int i = 0; i < N; i++) {
        ll x, d;
        cin >> x >> d;
        v.push_back({x, d});
    }
    vector<ll> clock(N), unclock(N);
    ll sum = 0;
    clock[0] = max(0LL, (sum += v[0].second) - v[0].first);
    for(int i = 1; i < N; i++) clock[i] = max(clock[i - 1], (sum += v[i].second) - v[i].first);
    sum = 0;
    unclock[N - 1] = max(0LL, (sum += v[N - 1].second) - (C - v[N - 1].first));
    for(int i = N - 2; i >= 0; i--) unclock[i] = max(unclock[i + 1], (sum += v[i].second) - (C - v[i].first));

    ll ans = 0;
    for(int i = 0; i < N; i++) {
        ll tmp = clock[i];
        if(i < N - 1)
            if(unclock[i + 1] - v[i].first > 0) tmp += unclock[i + 1] - v[i].first;
        ans = max(ans, tmp);
    }

    for(int i = N - 1; i >= 0; i--) {
        ll tmp = unclock[i];
        if(i >= 1)
            if(clock[i - 1] - (C - v[i].first) > 0) tmp += clock[i - 1] - (C - v[i].first);
        ans = max(ans, tmp);
    }

    cout << ans << "\n";
    return 0;
}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>>  var(n, vector<int>(m, 0))
#define vecb2(var, n, m)   vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m)  vector<vector<ll>>   var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  arr(a,3);
  int k;
  cin >> k;
  rep(i,k+1){
    int j = k-i;
    int tmp1, tmp2;
    tmp1 = a[1] * pow(2,i);
    tmp2 = a[2] * pow(2,j);
    if(a[0] < tmp1 && tmp1 < tmp2){
      prt("Yes");
      return 0;
    }
  }
  prt("No");

}


Measured memory_bytes: 4104
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

M = 10**9+7
n = inp()
if n == 1:
    print(0)
    exit()
ans = pow(10,n,M) - 2*pow(9,n,M) + pow(8,n,M) 
print(ans%M)

Measured memory_bytes: 61868
#include <bits/stdc++.h>
using namespace std;
long long ans;
int N,W;
map<int,long long>mp[2];
void f(int w,long long v){
    if(w<=W){
        mp[1][w]=max(mp[1][w],v);
        ans=max(ans,mp[1][w]);
    }
    for(auto &p:mp[0]){
        mp[1][p.first] = max(mp[1][p.first], p.second);
        if(p.first+w<=W){
            auto &r = mp[1][p.first+w];
            r=max(r,p.second+v);
            ans=max(ans,r);
        }
    }
    swap(mp[0],mp[1]);
}
int main(){
    cin>>N>>W;
    while(N--){
        int w;
        long long v;
        cin>>w>>v;
        f(w,v);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
class Main {
	double r,x = 0.0,y = 0.0;
	public void suzuki(){
		Scanner sc = new Scanner(System.in);
		r = sc.nextDouble();
		x = r * r * 3.141592653589;
		y = 2 * 3.141592653589 * r;
		System.out.printf("%8.6f %8.6f",x,y);
	}
	public static void main(String[] args){
		new Main().suzuki();
	}
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  char prev = '_';
  ll ans = 0;
  rep(i,n){
    if(prev != s[i]){
      prev = s[i];
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}


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

#ifdef ONLINE_JUDGE
#define lld I64
#endif

#define endl '\n'
#define ii pair<int,int>
#define ll long long
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back

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

    string s;
    cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#include "mylib-cpp.h"

using namespace std;

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> dp(n);
    vector<int> a(n);
    for(int i=0;i<m;i++){
        int p;
        cin >> p;
        a[p-1] = 1;
    }
    for(int i=0;i<n;i++){
        if(i == 0){
            if(a[0] != 1) dp[0] = 1;
        }else if(i == 1){
            int f=1;
            if(a[1]) f=0;
            dp[1] = f*(dp[0] + 1);
        }else{
            int f=1;
            if(a[i]) f=0;
            dp[i] = f*(dp[i-2] + dp[i-1]) % 1000000007;
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
  int m,n,s,t,a,b,i,j;
  double d,min=1.0*1e9;//printf("%f\n",min);
  scanf("%d %d %d %d %d %d",&m,&n,&s,&t,&a,&b);
  for(i=0;i<=n;i+=a){
    for(j=0;i+j<=n;j+=b){
      if(i+j==0)continue;
      d=1.0*(s*i+t*j)/(i+j);//printf("%f\n",m-d);
      if(min>fabs(m-d))min=fabs(m-d);//printf("%f %f %f\n",d,min,fabs(m-d));
    }
  }
  printf("%f\n",min);
  return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<string>
using namespace std;
    
int main(){
    int n,m;
    cin>>n;
    cin>>m;
    int a[m];
    int sum =0;
    for(int i=0;i<m;i++){
        cin>>a[i];
        sum+=a[i]; 
    }
    if(n-sum>=0)
    {
        cout<<n-sum;
    }else{
        cout<<-1;
    }
}

Measured memory_bytes: 3648
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
A,B,H,M = LI()

tanshin = H * 30 + M * 0.5;
shouhshin = M * 6;
diff = min(abs(tanshin-shouhshin),360.0-abs(tanshin-shouhshin))

ans = A**2+B**2-2*A*B*math.cos(math.radians(diff))
print(math.sqrt(ans))

Measured memory_bytes: 62556
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=100010;

int n,a[maxn];

ll calc(ll x){
	for(int i=1;i<=n;i++)x=x/a[i]*a[i];
	return x;
}
int main(){
    n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    ll l=0,r=1e15,mid;
    while(l<r){
    	mid=(l+r)>>1;
    	if(calc(mid)>=2)r=mid;else l=mid+1;
    }
    ll ans1=l;
    l=0,r=1e15;
    while(l<r){
    	mid=(l+r)>>1;
    	if(calc(mid)>2)r=mid;else l=mid+1;
    }
    if(ans1>l-1)printf("-1");else printf("%lld %lld",ans1,l-1);
    return 0;
}

Measured memory_bytes: 512
# ?????????????????????????????????????§???????????????????????????????
# @param [Array]   g Edge ?????????????????§??¨???????????°??????
# @param [Integer] s ????§????????????????
# @return [Array]  ?????????????????§???????¨?????????????????´????????????????
# g ??????????????????????????§?????????
# g_i ?????? i ???????????????????????????????????¨??????????????????????????¨??????????´?????????????
class PriorityQueue
  def initialize
    @a = [:snt]
  end

  def empty?
    @a.size == 1
  end

  def enq(val)
    @a << val
    cd = @a.size - 1
    pr = cd / 2
    until pr.zero? || (@a[pr] <=> @a[cd]) < 0
      @a[pr], @a[cd] = @a[cd], @a[pr]
      cd = pr
      pr = cd / 2
    end
  end

  def deq
    rs = @a[1]
    @a[1] = @a[-1]
    @a.delete_at(-1)
    if @a.size > 1
      pr = 1
      cd = [pr * 2, pr * 2 + 1].select { |i| @a[i] }.min_by { |i| @a[i] }
      until cd.nil? || (@a[pr] <=> @a[cd]) < 0
        @a[pr], @a[cd] = @a[cd], @a[pr]
        pr = cd
        cd = [pr * 2, pr * 2 + 1].select { |i| @a[i] }.min_by { |i| @a[i] }
      end
    end
    rs
  end
end

def dijkstra(g, s)
  que = PriorityQueue.new
  d = Array.new(g.size) { Float::INFINITY }
  d[s] = 0
  que.enq [0, s]

  until que.empty?
    v_cost, v = que.deq
    next if d[v] < v_cost
    g[v].each do |e|
      if d[e.to] > d[v] + e.cost
        d[e.to] = d[v] + e.cost
        que.enq [d[e.to], e.to]
      end
    end
  end

  d
end

Edge = Struct.new('Edge', :to, :cost)

v, e, r = gets.split.map(&:to_i)
g = Array.new(v) { [] }
e.times do
  s, t, d = gets.split.map(&:to_i)
  g[s] << Edge.new(t, d)
end

dijkstra(g, r).each do |sum|
  puts (sum == Float::INFINITY ? 'INF' : sum)
end

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

typedef long long ll;
typedef pair<int, int> ii;

string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  int n = s.length();
  unordered_map<int, int> ma;
  ma[0] = 1;
  int cur = 0, res = 0, base = 1;
  for (int i = n - 1; i >= 0; --i) {
    cur = cur + (s[i] - '0') * base % 2019;
    cur %= 2019;
    if (ma.count(cur)) {
      res += ma[cur];
    }
    ma[cur]++;
    base = base * 10 % 2019;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> key(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    pair<int, int> p;
    rep(i, b) {
      int c;
      cin >> c;
      --c;
      p.second |= 1<<c;
    }
    p.first = a;
    key[i] = p;
  }
  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(i, 1<<n) {
    rep(j, m) {
      int t = i | key[j].second;
      dp[t] = min(dp[t], dp[i] + key[j].first);
    }
  }
  if(dp.back() == INF) cout << -1 << endl;
  else cout << dp.back() << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=3010;
int n,A[N],sg[N];
vector<int>G[N];
void dfs(int u,int ff)
{
	for(int v:G[u])
		if(v!=ff&&A[v]<A[u])dfs(v,u),sg[u]|=sg[v]^1;
}
int main()
{
	n=gi();
	for(int i=1;i<=n;i++)A[i]=gi();
	for(int i=1;i<n;i++)
	{
		int u=gi(),v=gi();
		G[u].push_back(v);G[v].push_back(u);
	}
	for(int i=1;i<=n;i++){dfs(i,i);if(sg[i])printf("%d ",i);}
	puts("");
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size(); i++){
    int temp = 0;
    for(char c = 'a'; c <= 'z'; c++){
      bool right = false, left = false;
      for(int j = 0; j <= i; j++)if(s[j] == c) right = true;
      for(int j = i + 1; j < s.size(); j++)if(s[j] == c) left = true;
      if(right & left)temp += 1;
    }
    ans = max(ans, temp);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }

    if (a.filter { it%2==0 }.all { it%3==0 || it%5==0 }) "APPROVED" else "DENIED"
})

Measured memory_bytes: 37748
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var a = Enumerable.Range(1, 30).ToList();
        for (int i = 0; i < 28; i++)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            a.Remove(n);
        }
        Console.WriteLine(a[0]);
        Console.WriteLine(a[1]);
    }
}

Measured memory_bytes: 9976
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

struct edge{
	ll to;
	ll cost;
};

vector<edge>g[100];

ll sum[31][100010];

int main(void){
	ll n,C;
	cin>>n>>C;
	for(int i=0;i<n;i++){
		int s,t,c;
		cin>>s>>t>>c;
		sum[c][s]++;
		sum[c][t+1]--;
	}
	for(int i=1;i<=C;i++){
		for(int j=1;j<100010;j++){
			sum[i][j]=sum[i][j]+sum[i][j-1];
		}
	}
	ll ans = 0;
	for(int j=0;j<100010;j++){
		ll cnt = 0;
		for(int i=1;i<=C;i++){
			if(sum[i][j])cnt++;
		}
		ans = max(ans,cnt);
	}
	cout<<ans<<endl;
    return 0;
}

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

int main() {
	string S;
	int X, Y;
	bool YYMM = false, MMYY = false;
	cin >> S;
	X = (S[0] - '0') * 10 + S[1] - '0';
	Y = (S[2] - '0') * 10 + S[3] - '0';
	if (1 <= X && X <= 12) MMYY = true;
	if (1 <= Y && Y <= 12) YYMM = true;
	if (MMYY && YYMM) cout << "AMBIGUOUS";
	else if (MMYY && !YYMM) cout << "MMYY";
	else if (!MMYY && YYMM) cout << "YYMM";
	else cout << "NA";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
using namespace std;

typedef pair <int, int> pii;
typedef pair <int, pii> ppi;

const int MAX_N = 5e4 + 20, MAX_M = 2e5 + 10, SQRT = 230, inf = 1000000000;
int n, Arr[MAX_N];
int cnt;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> Arr[i];

	for (int i = 1; i + 1 < n; i++) {
		if (Arr[i] > Arr[i - 1] && Arr[i] < Arr[i + 1])
			cnt++;
		if (Arr[i] < Arr[i - 1] && Arr[i] > Arr[i + 1])
			cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
def sum_digits(num):
    total = 0
    while num != 0:
        total += num % 10
        num //= 10
    return total

n, a, b = map(int, input().split())

ans = 0

for i in range(1, n + 1):
    num = i
    total = sum_digits(num)

    if a <= total <= b:
        ans += i

print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
int main(void)
{
	int L[10]={0},V1=0,V2=0,i;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&L[0],&L[1],&L[2],&L[3],&L[4],&L[5],&L[6],&L[7],&L[8],&L[9],&V1,&V2)!=EOF){
	int sum_L=0;
	for(i=0;i<10;i++){
		sum_L+=L[i];
	}
	double length1=0,length2=0;
	for(i=0;i<10;i++){
		length1+=(double) L[i];
		length2+=(double) L[i]*V2/V1;
		if(length1+length2>=sum_L) break;
	}
	printf("%d\n",i+1);
	}
	return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

ll n, k, a, b, co[100001], memo[100001];
vector<ll> vc, cou;

int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		co[a] += b;
		vc.push_back(a);
	}
	vc.push_back(0);
	sort(vc.begin(), vc.end());
	int p = 1;
	cou.push_back(0);
	for(int i=1;i<=n+1;i++){
		if(vc[i]!=vc[i-1]){
			cou.push_back(cou[p-1] + co[vc[i]]);
			memo[p] = vc[i]; 
			p++;
		}
	}
	cout << memo[lower_bound(cou.begin(), cou.end(), k) - cou.begin()] << endl;
	return 0;
}

Measured memory_bytes: 3316
#include <stdio.h>
#define N 100001

typedef struct{
  int parent;
  int left;
  int right;
} node;

node tree[N];

int depth(int);

int main(){

  int n,id,cnum,lef,child;
  int i,j; 

  scanf("%d",&n);

  for(i=0;i<n;i++){
    tree[i].parent = -1;
    tree[i].left = -1;
    tree[i].right = -1;
  }
  for(i = 0;i < n;i++){
    scanf("%d %d", &id, &cnum);
    for(j = 0;j < cnum;j++){
      scanf("%d", &child);
      if(j == 0) tree[id].left = child;
      else tree[lef].right = child;
      tree[child].parent = id;
      lef = child;
    }
  }
  for(i = 0;i < n;i++){ 
    printf("node %d: parent = %d, depth = %d, ", i, tree[i].parent, depth(i));

    if(tree[i].parent == -1) printf("root, [");
    else if(tree[i].left == -1) printf("leaf, [");
    else printf("internal node, [");

    lef = tree[i].left;

    j = 0;
    while(1){
      if(lef == -1) break;
      if(j != 0) printf(", ");
      printf("%d",lef);
      lef = tree[lef].right;
      j++;
    }
    printf("]\n");
  }
  return 0;
}
 
int depth(int n){
  if(tree[n].parent == -1) return 0;
  return depth(tree[n].parent)+1;
}

Measured memory_bytes: 1784
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        long n=Long.parseLong(str[0]);
        long k=Long.parseLong(str[1]);
        if(n%k==0)
        pw.println(0);
        else
        {
            n=n%k;
            pw.println(Math.min((long)Math.abs(n-k),(long)Math.abs(n)));
        }
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 21204
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;

int t[100010];
void Theater() {
	int n;
	cin >> n;
	int sum = 0;
	for (size_t i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		sum += b - a + 1;
	}
	cout << sum << endl;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,q,l,r,N[123456];
string s;
int main(){
    cin>>n>>q;
    cin>>s;
    for(int i=0;i<n;i++){
        if(i!=0)N[i]=N[(i-1)];
        if(s[i]=='A'&&s[(i+1)]=='C')N[i]++;
    }
    for(int i=0;i<q;i++){
        cin>>l>>r;
        cout<<(N[r-2]-N[l-2])<<endl;
    }
}


Measured memory_bytes: 1408
#include <iostream>
#include <utility>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;

int dice_dir[24][6] = {
	{0, 1, 2, 3, 4, 5},
	{0, 3, 1, 4, 2, 5},
	{0, 4, 3, 2, 1, 5},
	{0, 2, 4, 1, 3, 5},

	{5, 3, 4, 1, 2, 0},
	{5, 1, 3, 2, 4, 0},
	{5, 2, 1, 4, 3, 0},
	{5, 4, 2, 3, 1, 0},

	{1, 2, 0, 5, 3, 4},
	{1, 5, 2, 3, 0, 4},
	{1, 3, 5, 0, 2, 4},
	{1, 0, 3, 2, 5, 4},

	{4, 5, 3, 2, 0, 1},
	{4, 2, 5, 0, 3, 1},
	{4, 0, 2, 3, 5, 1},
	{4, 3, 0, 5, 2, 1},

	{2, 0, 1, 4, 5, 3},
	{2, 4, 0, 5, 1, 3},
	{2, 5, 4, 1, 0, 3},
	{2, 1, 5, 0, 4, 3},

	{3, 4, 5, 0, 1, 2},
	{3, 0, 4, 1, 5, 2},
	{3, 1, 0, 5, 4, 2},
	{3, 5, 1, 4, 0, 2},
};

typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;

vector<vpii> constraint;

void init_constraint() {
	for(int i = 0; i < 8; i++)
		constraint.push_back(vpii());
	constraint[1].push_back(pii(0,4));
	constraint[2].push_back(pii(1,3));
	constraint[3].push_back(pii(2,1));
	constraint[3].push_back(pii(0,3));
	constraint[4].push_back(pii(0,5));
	constraint[5].push_back(pii(1,5));
	constraint[5].push_back(pii(4,4));
	constraint[6].push_back(pii(2,5));
	constraint[6].push_back(pii(5,3));
	constraint[7].push_back(pii(3,5));
	constraint[7].push_back(pii(6,1));
	constraint[7].push_back(pii(4,3));
}

int use = 0;
pair<int,int> dice_per[8];
char dice_char[16][16];

bool search(int num) {
	if(num >= 8)
		return true;

	for(int d = 0; d < (num == 0 ? 1 : 8); d++) {
		if(!(use & (1 << d))) {
			use |= (1 << d);

			for(int i = 0; i < 24; i++) {
				bool flg = true;
				for(int j = 0; j < constraint[num].size(); j++) {
					char ca, cb;
					ca = dice_char[                   d                    ][dice_dir[                    i                    ][5 - constraint[num][j].second]];
					cb = dice_char[dice_per[constraint[num][j].first].first][dice_dir[dice_per[constraint[num][j].first].second][    constraint[num][j].second]];

					flg &= (tolower(ca) == tolower(cb)) && (abs(ca - cb) == abs('A' - 'a'));
				}
				if(flg) {
					dice_per[num] = pii(d, i);
					if(search(num + 1))
						return true;
				}
			}

			use &= ~(1 << d);
		}
	}

	return false;
}

int main() {
	init_constraint();

	while(1) {
		use = 0;
		for(int i = 0; i < 8; i++) {
			scanf("%s", dice_char[i]);
			if(dice_char[i][0] == '0')
				goto EXIT;
		}

		cout << (search(0) ? "YES" : "NO") << endl;
	}
EXIT:;
}

Measured memory_bytes: 1184
//AOJ 0000
//include
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<iostream>

//using namespace
using namespace std;

//define

//variable
short a, b;

//function
int main(){
  for(a = 1; a <= 9; a++)
    for(b = 1; b <= 9; b++)
      printf("%dx%d=%d\n", a, b, a * b);
  return 0;
}

Measured memory_bytes: 1096
def fun(N, K):
    if N%K > K:
        return K
    return fun(K, N%K)

N, K= list(map(int, input().split()))
if N%K == 0:
    print(0)
    exit()
N = N%K
while N>abs(N-K):
    N = abs(N-K)
print(N)




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

int main() {
  int N;
  cin >> N;
  vector<double> v(N), ave(N);
  for (int i=0; i<N; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  ave.at(0) = v.at(0);
  for (int i=1; i<N; i++) {
    ave.at(i) = (ave.at(i-1)+v.at(i))/2;
  }
  cout << ave.at(N-1) << endl;
}

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

typedef struct Tree{
  int key;
  struct Tree *r,*l,*p;
} Tree;

Tree *root;

void insert(int k){
  Tree *a = NULL;
  Tree *b = root;
  Tree *t;

  t = malloc(sizeof(Tree));

  t->key = k;
  t->l = NULL;
  t->r = NULL;

  while(b != NULL){
    a = b;
    if(t->key < b->key){
      b = b->l;
    }else{
      b = b->r;
    }
  }

  t->p = a;

  if(a == NULL){
    root = t;
  }else{
    if(t->key < a->key){
      a->l = t;
    }else{
      a->r = t;
    }
  }
}

void ino(Tree *t){
  if(t == NULL) return;
  ino(t->l);
  printf(" %d",t->key);
  ino(t->r);
}

void pre(Tree *t){
  if(t == NULL) return;
  printf(" %d",t->key);
  pre(t->l);
  pre(t->r);
}

int main(){
  int n,x,i;
  char order[10];

  scanf("%d",&n);

  for(i = 0; i < n; i++){

    scanf("%s",order);

    if(order[0] == 'i'){
      scanf("%d",&x);
      insert(x);

    }else if(order[0] == 'p'){
      ino(root);
      printf("\n");
      pre(root);
      printf("\n");
    }

  }
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

vector<string>all;

void dfs(string s){
  int n=s.size();
  if(n==0){
    for(char i='1';i<='9';i++)dfs(s+i);
  }
  else{
    string rs=s;
    reverse(rng(rs));
    all.push_back(rs);
    if(n>10)return;
    for(char i='0';i<='9';i++)if(s[0]+1==i||s[0]==i||s[0]-1==i){
      dfs(i+s);
    }
  }
}

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

  ll K;
  cin>>K;
  dfs("");
  vector<ll>ans;
  for(auto it:all){
    ll a=stol(it);
    ans.push_back(a);
  }
  sort(rng(ans));
  cout<<ans[K-1]<<endl;

  return 0;
}


Measured memory_bytes: 47720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    int n;
    cin>>n;
    ll ans1=0,ans2=0;
    deque<int> a(n,0);
    deque<int> d(n,0);
    rep(i,n) cin>>a[i];
    SORT(a);
    rep(i,n) d[i]=a[i];
    deque<int> b,c;
    b.push_back(a.front());
    a.pop_front();
    while(!a.empty()){
        b.push_front(a.back());
        a.pop_back();
        if(!a.empty()){
            b.push_back(a.back());
            a.pop_back();
        }
        if(!a.empty()){
            b.push_front(a.front());
            a.pop_front();
        }
        if(!a.empty()){
            b.push_back(a.front());
            a.pop_front();
        }
    }
    c.push_back(d.back());
    d.pop_back();
    while(!d.empty()){
        c.push_front(d.front());
        d.pop_front();
        if(!d.empty()){
            c.push_back(d.front());
            d.pop_front();
        }
        if(!d.empty()){
            c.push_front(d.back());
            d.pop_back();
        }
        if(!d.empty()){
            c.push_back(d.back());
            d.pop_back();
        }
    }
    for(int i=0;i<n-1;i++){
        ans1+=abs(b[i]-b[i+1]);
        ans2+=abs(c[i]-c[i+1]);
    }
    ans1=max(ans1,ans2);
    cout<<ans1<<endl;
}


Measured memory_bytes: 1152
while true
    map = []
    until gets == nil || $_.chomp == ''
        map << $_.chomp.scan(/./)
    end

    def map.paint(i,j)
        unless (i<0 || i>=self.size) || (j<0 || j>=self[i].size)
            if self[i][j] == '1'
                self[i][j] = '0'
                self.paint(i-1,j)
                self.paint(i,j-1)
                self.paint(i+1,j)
                self.paint(i,j+1)
            end
        end
        nil
    end

    count = 0
    for i in [*0..map.size-1]
        for j in [*0..map[i].size-1]
            if map[i][j] == '1'
                count += 1
                map.paint(i,j)
            end
        end
    end
    puts count
    break if $_ == nil
end

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        if (Math.abs(a + b) % 2 == 0) {
            System.out.println(Math.abs(a + b) / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    sort(ALL(s));
    int a = atoi(s.c_str());
    sort(ALL(s),greater<char>());
    int b = atoi(s.c_str());
    cout<<b-a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
S = STDIN.read.chomp.to_i

n = S
t = false
tt = {}
i = 0

while true
    if tt.key?(n)
        break
    end
    tt[n] = true
    if n % 2 == 0
        n = n / 2
    else
        n = 3 * n + 1
    end
    i = i + 1
end

puts i + 1

Measured memory_bytes: 1788
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.nextLine
    val n = s.size
    val K = sc.nextInt

    val dp = Array.fill(n + 1, 4, 2)(0)
    dp(0)(0)(0) = 1
    for (i <- 0 until n; j <- 0 until 4; k <- 0 until 2) {
      val nd = s(i) - '0'
      for (d <- 0 until 10) {
        // 配る先
        var ni = i + 1
        var nj = j
        var nk = k

        if (d != 0) {
          // 次に選ぶ数字が0出ない場合は、非0をカウントアップした先に配る
          nj += 1
        }

        if (nj <= K) { // 配った結果非0がKを超える場合は配れないよ
          if (k == 0) {
            if (d <= nd) { // 配り元までの桁がsと同じだったら、配る先はsの同じ桁の数字を超えられない
              if (d < nd) {
                // 配る先では桁数がsと異なるため +1
                nk += 1
              }
              dp(ni)(nj)(nk) += dp(i)(j)(k)
            }
          } else { // 配り元までの桁が同じでないなら、どの数字も配ってOK
            dp(ni)(nj)(nk) += dp(i)(j)(k)
          }
        }
      }
    }
    val ans = dp(n)(K)(0) + dp(n)(K)(1)
    println(ans)
  }
}


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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
#define P pair
#define LEN length()
#define SZ size()
#define fop(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
typedef long long ll;
typedef complex<ll> C;
#define X real()
#define Y imag()
const double nol = 1e-18 ;

int main()
{
    int x,y;
    cin >> x >> y;
    cout << x*x-y << nl;
}


Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    data = input()
    if data == "AC":
        ac += 1
    elif data == "WA":
        wa += 1
    elif data == "TLE":
        tle += 1
    else:
        re += 1
print("AC x ", ac)
print("WA x ", wa)
print("TLE x ", tle)
print("RE x ", re)


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

typedef long long ll;
typedef pair<int,int> ii;

bool palin(int x) {
	stringstream ss; ss<<x;
	string s=ss.str(), t=s;
	reverse(t.begin(), t.end());
	return s==t;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	int ret=0;
	for (int i=a; i<=b; i++)
		if(palin(i))
			ret++;
	cout << ret << endl;
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    long long int n = s.size();
    long long int ans = n*(n - 1)/2 + 1;
    long long int num[26] = {0};
    for(int i = 0; i < n; ++i) num[s[i] - 'a']++;
    for(int i = 0; i < 26; ++i) {
        if(num[i] >= 2) ans -= num[i]*(num[i]-1)/2;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 640
N = int(input())
M = len(str(N))

def nsin(X,n):
    if(int(X/n)):
        return nsin(int(X/n),n)+str(X%n)
    return str(X%n)

res = 0
for m in range(3,M+1):
    for i in range(3 ** m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:
            for j in range(m):
                if tri[j] == '0':
                    nl.append('3')
                elif tri[j] == '1':
                    nl.append('5')
                else:
                    nl.append('7')
            x = ''.join(nl)
            if int(x) <= N:
                res += 1

print(res)


Measured memory_bytes: 67032
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc= new Scanner(System.in);
        int H,W;
        while(true){
          H=sc.nextInt();
          W=sc.nextInt();
          if(H==0 && W==0){
              break;
          }
          for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0 ||i==H-1||j==0||j==W-1){
                    System.out.print("#");
                }
                else{
                    System.out.print(".");
                }
                
            }
            System.out.println("");
          }  
          System.out.println("");
        }
        
    }
}


Measured memory_bytes: 35376
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	vector<int>v;
	int i,j,k;
	for(i=0;i<5;i++){
		scanf("%d",&j);
		v.push_back(j);}
	sort(v.begin(),v.end());
	for(i=4;i>=0;i--){
		printf("%d",v[i]);
		if(i!=0)printf(" ");}
	printf("\n");
	return 0;}


Measured memory_bytes: 2664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(b-a>k){
        cout << ":(";
        return 0;
    } 
    if(c-a>k){
        cout << ":(";
        return 0;
    }
    if(d-a>k){
        cout << ":(";
        return 0;
    }
    if(e-a>k){
        cout << ":(";
        return 0;
    }
    if(c-b>k){
        cout << ":(";
        return 0;
    }
    if(d-b>k){
        cout << ":(";
        return 0;
    }
    if(e-b>k){
        cout << ":(";
        return 0;
    }
    if(d-c>k){
        cout << ":(";
        return 0;
    }
    if(e-c>k){
        cout << ":(";
        return 0;
    }
    if(e-d>k){
        cout << ":(";
        return 0;
    }
    cout << "Yay!";
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}



vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


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

	long long int ansH, ansW, ansN = 0;

	for (int h = 1; h <= 3500; h++) {
		for (int w = 1; w <= 3500; w++) {
			long long int bunsi = N * h * w;
			long long int bunbo = 4 * h * w - N * w - N * h;
			
			if (bunbo <= 0)continue;
			if (bunsi % bunbo != 0)continue;



			ansN = bunsi / bunbo;
			if (ansN > 3500) {
				ansN = 0;
				continue;
			}
			ansH = h;
			ansW = w;
			break;

		}
		if (ansN != 0)break;
	}

	cout << ansH << " " << ansN << " " << ansW << endl;
	 
	return 0;

}




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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a+b >= c ){
    cout << b+c << endl;
  }else{
    cout << a+2*b+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, K= map(int, input().split())
D=list(map(int, input().strip().split()))



while True:
    fl=True
    for j in range(len(str(N))):
        for i in range(K):
            if str(N)[j]==str(D[i]):
                fl=False
                break
        if fl==False:
            break
    if fl:
        break
    N+=1

print(N)

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();

  vector< int64 > A(N + 1);
  range(i, 1, N + 1) A[i] = input() + A[i - 1];

  int64 ans = inf;

  int lmid = 1, rmid = 3;
  range(mid, 2, N - 1) {
    auto eval = [&](int l, int s, int r) {
      return abs((A[r] - A[s]) - (A[s] - A[l]));
    };

    while (eval(0, lmid, mid) > eval(0, lmid + 1, mid)) lmid++;
    while (eval(mid, rmid, N) > eval(mid, rmid + 1, N)) rmid++;

    vector< int64 > v({A[N] - A[rmid], A[rmid] - A[mid], A[mid] - A[lmid], A[lmid]});
    whole(sort, v);

    chmin(ans, v.back() - v.front());
  }

  cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int n,m,q;
int ans = 0;
vector<int>a(55);
vector<int>b(55);
vector<int>c(55);
vector<int>d(55);
void dfs(vector<int> A){
    if(A.size()==n+1){
        int sum = 0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) sum += d[i];
        }
        ans = max(ans,sum);
        return ;
    }
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }

}

int main(){
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007

void solve()
{
	int n, m;
	cin >> n >> m;
	char arr[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> arr[i][j];

	vector<vector<int>> dp(n, vector<int>(m, 0));

	int flag = 0;
	for (int i = 0; i < m; i++)
	{
		if (arr[0][i] == '#')
			flag = 1;
		if (flag)
			dp[0][i] = 0;
		else
			dp[0][i] = 1;
	}

	flag = 0;
	for (int i = 0; i < n; i++)
	{
		if (arr[i][0] == '#')
			flag = 1;
		if (flag)
			dp[i][0] = 0;
		else
			dp[i][0] = 1;
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < m; j++)
		{
			if (arr[i][j] == '.')
			{
				dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			}
			if (dp[i][j] > mod)
				dp[i][j] -= mod;
		}
	}
	cout << dp[n - 1][m - 1];


}

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;

ll A[200][200];

int main() {

	int a,b,c,x,y;

	cin >> a >> b >> c >> x >> y;
	int xymax = max(x, y);
	ll min_cost = (ll) 2 << 60;
	for (int i = 0; i <= xymax; i++) {
		ll cost = max(0, (x - i)) * a + max(0, (y - i)) * b + i * 2 * c;
		/*cout << "current cost: " << cost << endl;
		cout << "\ti = " << i << endl;*/
		min_cost = min(min_cost, cost);
	}
	cout << min_cost << endl;
}

Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try( BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      br.lines()
        .filter(s -> !s.equals("0") && !s.isEmpty())
        .mapToInt(s -> IntStream.range(0,s.length())
          .map(i -> Character.getNumericValue(s.charAt(i)))
          .sum() )
        .forEach(System.out::println);
    }
  }
}


Measured memory_bytes: 30928
from collections import defaultdict

N = int(input())
p = 10**9 + 7

nums = []
for i in range(2, N+1):
    for j in range(2, i+1):
        if i % j == 0:
            if i == j:
                nums.append(i)
            else:
                break

c = 0
count = defaultdict(int)
for i in range(2, N+1):
    for n in nums:
        now = i
        while now % n == 0:
            count[n] += 1
            now //= n

ans = 1
for n in count.values():
    ans = ans * (n+1) % p
print(ans)

Measured memory_bytes: 3316