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

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

#define INF INT_MAX
#define MOD 100000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

vector<int>A;

bool ok(int m,int N){
  ll now=A[m];
  for(int i=0;i<N;i++){
    if(i==m)continue;
    if(A[i]>now*2)return false;
    else now+=A[i];
  }
  return true;
}

int main(){
  int N;
  cin>>N;
  A.resize(N);
  for(int i=0;i<N;i++)cin>>A[i];
  sort(rng(A));
  int r=N;
  int l=-1;
  int m;
  while(r-l>1){
    m=(r+l)/2;
    if(ok(m,N))r=m;
    else l=m;
  }
  cout<<N-r<<endl;
  return 0;
}


Measured memory_bytes: 640
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll power(ll x, ll n, ll m = MOD){
    if(n == 0) return 1LL;
    ll res = power(x * x % m, n/2, m);
    if(n % 2 == 1) (res *= x) %= m;
    return res;
}

void solve(){
    ll N;
    cin >> N;
    if(N == 1){
        print(0);
    }else{
        ll ans = 2 * (power(10,N) - power(9,N) + MOD * 2) % MOD - (power(10,N) - power(8,N) + MOD * 2) % MOD + MOD;
        ans %= MOD;
        print(ans);

    }
}

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

Measured memory_bytes: 3608
use proconio::input;

fn main() {
    input! {
        n: usize,
        f: [[usize; 10]; n],
        p: [[i64; 11]; n],
    };
    let mut max_score = -1_000_000_000_000_000_i64;
    for bits in 0..1 << 10 {
        let mut ls = vec![];
        for l in 0..10 {
            if (bits >> l) & 1 == 1 {
                ls.push(l);
            }
        }
        if ls.is_empty() {
            continue;
        }

        let mut score = 0_i64;
        for i in 0..n {
            let f_i = &f[i];
            let p_i = &p[i];
            let mut count = 0;
            for &l in ls.iter() {
                if f_i[l] == 1 {
                    count += 1;
                }
            }
            score += p_i[count];
        }
        max_score = std::cmp::max(max_score, score);
    }
    let ans = max_score;
    println!("{}", ans);
}


Measured memory_bytes: 2236
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  cout << (N+1) / 2 << endl;
  return 0;
}

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

struct UnionFind{
    vector<int> par;
    int cnt;
    UnionFind(int n) : par(n, -1), cnt(n) {}
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x != y){
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y]; par[y] = x; cnt--;
        }
    }
    int find(int x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -par[find(x)];
    }
    int size(){
        return cnt;
    }
};

int main(){
    int n, m, k;
    cin >> n >> m;
    vector<int> v[m];
    for(int i = 0; i < n; i++){
        cin >> k;
        while(k--){
            int l;
            cin >> l;
            l--;
            v[l].push_back(i);
        }
    }
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        for(int j = 1; j < v[i].size(); j++){
            uf.unite(v[i][j], v[i][j-1]);
        }
    }
    cout << (uf.size() == 1 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>
int main() {
	int A, B,x,y,max;
	scanf("%d %d", &A, &B);
	if (A - B <= A + B) {
		x = A + B;
		if (x <= A * B)
			max = A * B;
		else
			max = x;
	}
	else {
		y = A - B;
		if (y <= A * B)
			max = A * B;
		else
			max = y;
	}
	printf("%d", max);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int H, W;
vector<string> fi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    cin >> H >> W;
    fi.resize(H);
    rep(i, H)
    {
        cin >> fi[i];
    }
    // output
    // 多点をスタートとして扱う
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int, int>> que;
    rep(i, H)
    {
        rep(j, W)
        {
            if (fi[i][j] == '#') {
                dist[i][j] = 0;
                que.push(make_pair(i, j));
            }
        }
    }

    // BFS
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        rep(dir, 4)
        {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
                continue;
            }
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(make_pair(nx, ny));
            }
        }
    }
    int res = 0;
    rep(i, H)
    {
        rep(j, W)
        {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int x, y, z, k; cin >> x >> y >> z >> k;

  vl a(x), b(y), c(z);
  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];
  
  vl ab;
  rep(i,x) rep(j,y) ab.push_back(a[i] + b[j]);

  sort(ALL(ab), greater<ll>());

  int sz = min(3000, x*y);
  vl abc;
  rep(i,sz) rep(j,z) abc.push_back(ab[i] + c[j]);

  sort(ALL(abc), greater<ll>());

  rep(i,k) cout << abc[i] << endl;
  return 0;
}


Measured memory_bytes: 43368
#include        <bits/stdc++.h>
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define MOD     1000000007
#define pii     pair<int,int>
#define vi      vector<int>
#define fio     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define N       200010
#define M       21
using namespace std;

int main()
{
    fio;
    int n;
    cin>>n;
    int a[205];
    memset(a,0,sizeof a);
    
    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j+=i){
            a[j]++;
        }
    }
    int c=0;
    for(int i=1; i<=n; i++){
        if((i&1)&&a[i]==8)c++;
    }
    cout<<c;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println(execute(sc.nextLine()));

    }

    public static String execute(String str) {
        String top = str.substring(0,1);
        String last = str.substring(str.length() - 1);
        int length = str.length() - 2;

        return top + length + last;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main() {
  long n = 0;
  long t[5] = {0, 0, 0, 0, 0};
  
  cin >> n;
  for (int i = 0; i < 5; i++) cin >> t[i];
  
  long min_t = t[0];
  for (int i = 0; i < 5; i++) {
    min_t = min(min_t, t[i]);
  }
  
  ldiv_t time = ldiv(n,min_t);
  if (time.rem > 0) {
    time.quot += 1;
  }
  
  
  cout << time.quot + 4LL << "\n";
  
}

Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;


void solve();

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

void solve(){
    /* (´~`) */
    ll N;cin>>N;
    vl P(N*N);rep(i,N*N)cin>>P[i],--P[i];

    vvl d(N,vl(N)),ob(N,vl(N,1));
    rep(i,N)rep(j,N){
        d[i][j]=min(min(i,N-1-i),min(j,N-1-j));
    }

    queue<pl> q;
    ll ans=0;
    rep(i,N*N){
        ll sy=P[i]/N,sx=P[i]%N;
        ans+=d[sy][sx];
        ob[sy][sx]=0;
        q.emplace(sy,sx);
        while(q.size()){
            pl p=q.front();q.pop();
            ll y=p.first,x=p.second;
            rep(j,4){
                ll ty=y+D4[j],tx=x+D4[j+1];
                if(ty<0||ty>=N||tx<0||tx>=N)continue;
                if(d[ty][tx]<=d[y][x]+ob[y][x])continue;
                d[ty][tx]=d[y][x]+ob[y][x];
                q.emplace(ty,tx);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8976
N = gets.to_i
array = gets.split(' ').map(&:to_i)
array.sort!

ans = 0

(0..N-3).each do |i|
  (i+1..N-2).each do |j|
    (j+1..N-1).each do |k|
      a = array[i]
      b = array[j]
      c = array[k]
      if a + b > c
        ans += 1 if (a != b) && (b != c)
      else
        break
      end
    end
  end
end
puts ans


Measured memory_bytes: 14340
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z = (Node *)malloc(sizeof(Node));

    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;

    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node *find(Node *u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key) {
            u = u->left;
        } else {
            u = u->right;
        }
    }

    return u;
}

int main() {
    int n, x;
    string com;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "find") {
            cin >> x;
            Node *t = find(root, x);
            if (t != NIL) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        } else if (com == "insert") {
            cin >> x;
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
} 


Measured memory_bytes: 22048
while 1:
    sum = 0
    n, x = map(int, input().split())
    if (n == 0 and x == 0):
        break
    for i in range(1, n+1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if(x == i + j + k):
                    sum += 1
    print(sum)



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

using namespace std;
#define N 100010
ll n,h[N],f[N];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    f[0]=0,f[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
     f[i]=min(f[i-2]+abs(h[i]-h[i-2]),f[i-1]+abs(h[i]-h[i-1]));   
    }
    cout<<f[n-1]<<endl;
 return 0;   
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll N, M;  cin>>N>>M;
  for(ll i = M/N; i>= 1; i--){
    if(M%i==0&&M/i>=N){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 384
# include <iostream>
using namespace std;
bool search(int *a,int n,int tar)
{
	for(int i = 0;i < n;i++) if(a[i] == tar) return true;
	return false;
}
int main(void)
{
	int *a,ans = 0,n,m,k;
	scanf("%d",&n); a = new int [n];
	for(int i = 0;i < n;i++) scanf("%d",&a[i]);
	scanf("%d",&m);
	for(int i = 0;i < m;i++) 
	{
		scanf("%d",&k);
		ans += search(a,n,k);
	}
	printf("%d\n",ans);
	return 0;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define fi first
#define se second
using pii = pair<int,int>;

vector<vector<pii>> vv;

pii dfs(int x, int p){
	pii ret(x,0);
	for(pii y: vv[x]){
		if(y.fi == p) continue;
		pii tmp = dfs(y.fi, x);
		tmp.se += y.se;
		if(tmp.se < ret.se) continue;
		ret = tmp;
	}
	return ret;
}

int main(){
	int n;
	while(cin>>n,n){
		vector<vector<pii>> tt(n);
		vv = vector<vector<pii>>(n);
		vector<int> p(n-1);
		vector<int> d(n-1);
		rep(i,n-1) cin>>p[i];
		rep(i,n-1) cin>>d[i];
		rep(i,n-1){
			int a = i+1;
			int b = p[i]-1;
			tt[a].push_back(pii(b,d[i]));
			tt[b].push_back(pii(a,d[i]));
		}

		int ans = 0;
		rep(i,n){
			if(tt[i].size() == 1) continue;
			for(pii x: tt[i]){
				if(tt[x.fi].size() == 1) continue;
				vv[i].push_back(x);
				ans += x.se;
			}
		}
		pii ty;
		rep(i,n){
			if(vv[i].size()){
				ty = dfs(i, -1);
				break;
			}
		}
		ty = dfs(ty.fi, -1);
		ans -= ty.se;
		rep(i,n-1){
			ans += d[i];
		}		
		cout<<ans<<endl;
	}
}

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

using namespace std;

int main(){
    string S;
    cin >> S;
    if (S == "RRR")
        puts("3");
    else if (S == "RRS" or S == "SRR")
        puts("2");
    else if (S == "SSS")
        puts("0");
    else
        puts("1");
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  string s, t;
  cin >> s >> t;

  int len = s.length();

  char st[128] {};
  char ts[128] {};

  bool ok = true;

  for (int i = 0; i < len; ++i) {
    char a = s[i];
    char b = t[i];
    if (st[a] && st[a] != b) ok = false;
    else st[a] = b;

    if (ts[b] && ts[b] != a) ok = false;
    else ts[b] = a;
  }

  puts(ok ? "Yes" : "No");

  return 0;
}



Measured memory_bytes: 776
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n, j, k=0, a;
      cin >> n;
      
      cin >> a;
      while (a%2 == 0){
        k++;
        a /= 2;
      }

      j = k;
      k=0;
      
      for (int i=0; i < n-1; i++){
        cin >> a;
        
        while (a%2 == 0){
          k++;
          a /= 2;
  	    }
        if (k < j){
          j = k;
        }
        k=0;
        
      }
      
      cout << j << endl;
      
    }

Measured memory_bytes: 256
/*Exhaustive Search*/
#include<iostream>
using namespace std;
bool solve(int i, int m, int n,int A[]){
  if(m == 0) 
    return true;
  else if(i >= n) 
    return false;
  else 
    return solve(i+1, m, n, A) || solve(i+1, m-A[i], n, A);
}
int main(){
  int n, m, q;
  cin >> n;
  int A[n];
  for(int i = 0; i < n; i++) 
    cin >> A[i];
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> m;
    if(solve(0, m, n, A)) 
      cout << "yes";
    else
      cout << "no";
    cout << endl;
  }
}

Measured memory_bytes: 1156
module AOJ_Volume0061;

import std.stdio,std.string,std.conv,std.array;

int main()
{
	int v[101];
	int[] rank;
	while(true)
	{
		string[] s = readln.chomp.split(",");
		int a = s[0].to!int;
		int b = s[1].to!int;

		if(a == 0 && b == 0) break;
		v[a] = b;

		if(rank.length == 0)
		{
			rank ~= b;
		}
		else
		{
			bool flag = true;
			foreach(i;0..rank.length)
			{
				if(b == rank[i]) flag = false;
			}

			if(flag) rank ~= b;
		}
	}

	rank.sort.reverse;
	string s;
	while((s = readln.chomp).length != 0)
	{
		int team = s.to!int;
		foreach(i;0..rank.length)
		{
			if(rank[i] == v[team])
			{
				writeln(i+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1076
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
k,n = map(int,input().split())
a = [int(x) for x in input().split()]
a.sort()
a.append(a[0]+k)
for i in range(n):
    if neko < a[i+1] - a[i]:
        neko = a[i+1] - a[i]
print(k-neko)

Measured memory_bytes: 26444
A, B, N = map(int, input().split())

m = A - 1
for i in range(A):
    lim = [B*(A-i-1)/A, B*(A-i)/A]
    if lim[0] > N:
        m -= 1
        continue
    else:
        num = int(lim[0])
        is_found = False
        while True:
            if num >= lim[0] and num < lim[1]:
                is_found = True
                break
            elif num >= lim[1]:
                break
            else:
                num += 1
        if is_found:
            break
        else:
            m -= 1
            continue
print(m)


Measured memory_bytes: 9200
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int inf=1e9+7;
int main()
{
	int N;
	cin>>N;
	vector <pair<int,int> > V;
	for(int i=-1;i<=1;i+=2)
	{
		for(int j=0;j<N;j++)
		{
			int x;
			cin>>x;
			V.push_back(make_pair(x,i));
		}
	}
	sort(V.begin(),V.end());
	int cnt=0;
	long long ans=1;
	for(int i=0;i<2*N;i++)
	{
		if(cnt*V[i].second<0)	
		{
			ans*=abs(cnt);
			ans%=inf;
		}
		cnt+=V[i].second;
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  if ((c-a-b) < 0) {
    cout << "No" << endl;
    return 0;
  }
  if ((c-a-b)*(c-a-b) > 4*a*b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
const int mod=1e9+7;
#define inf 0x3f3f3f3f3f3f3f3fLL
LL xx[maxn],yy[maxn];
LL power(LL x)
{
	LL tp=2,tot=1;
	while(x)
	{
		if(x&1)tot=(tot%mod*tp%mod)%mod;
		tp=(tp*tp)%mod;
		x>>=1;
	}
	return tot%mod;
}
int main()
{
	LL n,m,tx=0,ty=0;
	cin>>n>>m;
	for(LL i=1;i<=n;i++)
		cin>>xx[i];	
	sort(xx+1,xx+n+1);
	for(LL i=1;i<=n;i++)
	{
		tx+=(2*i-1-n)*xx[i]%mod;
		tx=tx%mod;	
	}
	for(LL i=1;i<=m;i++)
		cin>>yy[i];	
	sort(yy+1,yy+1+m);
	for(LL i=1;i<=m;i++)
	{
		ty+=(2*i-1-m)*yy[i]%mod;
		ty=ty%mod;		
	}
	cout<<tx*ty%mod<<endl;
	return 0;
}

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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}



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

  ll g = gcd(A, B);

  cout << A * B / g << endl;



  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 256
from numpy import cumsum

N = int(input())
S = input()
ss = S.replace("#", "1").replace(".", "0")
* ls, = map(int, ss)
cum_ls = cumsum(ls)
first_black = -1
last_black = N
for i in range(N):
    if S[i] == "#":
        first_black = i
        break
for i in reversed(range(N)):
    if S[i] == "#":
        last_black = i
    else:
        break
if first_black == -1:
    print(0)
else:
    # print(cum_ls)
    mans = 10**10
    for i in range(N):
        #print("  ", cum_ls[i], (N-(i+1) - (cum_ls[-1] - cum_ls[i])))
        mans = min(mans, cum_ls[i] + (N-(i+1) - (cum_ls[-1] - cum_ls[i])))
        # print(mans)

    ans = min(S[first_black:].count("."), S[first_black:].count(
        "#"), S[:last_black].count("#"), mans)

    print(ans)


Measured memory_bytes: 25848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int a = in.nextInt();
		int b = in.nextInt();
		String ans;

		if(a == b){
			ans = "a == b";
		}else if(a < b){
			ans = "a < b";
		}else{
			ans = "a > b";
		}
		System.out.println(ans);
	}
}



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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n,m;
  cin >> n >> m;
  int64_t a[n] = {0};
  int64_t total = 0;
  for(int64_t i=0;i<n;i++){
    cin >> a[i];
    total += a[i];
  }
  
  double voteNeeded = total/4.0/(double)m;
  int64_t count = 0;
  for(int64_t i=0;i<n;i++){
    if(a[i]>=voteNeeded) count++;
  }

  if(count>=m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 3632
def main():
  H,W,D=map(int,input().split())
  A=[]
  for h in range(H):
    for w,a in enumerate(map(int,input().split())):
      A+=[[a,h,w]]
  A.sort(key=lambda x:x[0])

  B=[0]*(H*W)
  for i in range(D):
    while i+D<W*H:
      B[i+D]=B[i]+abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
      i+=D

  for q in range(int(input())):
    l,r=map(int,input().split())
    print(B[~-r]-B[~-l])

main()


Measured memory_bytes: 24896
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000004
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{fin;
  int n,i,j,k,val;
  cin>>n>>k;
  int a[n],dp[n];
  memset(dp,0,n);
  for(i=0;i<n;i++)
    cin>>a[i];
  dp[n-1]=0;
  for(i=n-2;i>=0;i--)
    {
      dp[i]=999999999;
      for(j=1;j<=k;j++)
      {
        if(i+j<n)
          dp[i]=min(dp[i],abs(a[i+j]-a[i])+dp[i+j]);
        else
          break;
      }
    }
    cout<<dp[0]<<"\n";
}


Measured memory_bytes: 1024
# 最初に入れておくとinputが早くなる
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)


def kyori(l1, l2):
    goukei = 0
    for i in range(len(l1)):
        goukei += (l1[i] - l2[i]) ** 2
    return goukei**0.5


n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if (kyori(x[i], x[j]).is_integer()):
            #print(i, j, kyori(x[i], x[j]).is_integer())
            ans += 1
print(ans)

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

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

    int N, R;
    cin >> N >> R;

    cout << (N >= 10 ? R : R + 100*(10 - N)) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
const ll key = 998244353;
int main() {
	int h;
	while (cin >> h, h) {
		int score = 0;
		int board[10][5];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> board[i][j];
			}
		}
		while (true) {
			bool f = true;
			int del[10][5] = {};
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < 5; j++) {
					if (board[i][j] == 0)continue;
					int cnt = 1; int k = 1;
					while (j + k < 5 && board[i][j + k] == board[i][j]) {
						k++; cnt++;
					}
					k = -1;
					while (j + k >= 0 && board[i][j + k] == board[i][j]) {
						k--; cnt++;
					}
					if (cnt >= 3) {
						del[i][j] = 1;
						f = false;
					}
				}
			}
			if (f)break;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < 5; j++) {
					if (del[i][j] == 1) {
						score += board[i][j];
						board[i][j] = 0;
					}
				}
			}
			for (int roo = 0; roo < h; roo++) {
				for (int j = 0; j < 5; j++) {
					for (int i = 0; i < h-1; i++) {
						if (board[i + 1][j] == 0) {
							swap(board[i][j], board[i + 1][j]);
						}
					}
				}
			}
		}
		cout << score << endl;
	}
	return 0;
}


Measured memory_bytes: 3068
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
from fractions import Fraction
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


MOD = 1000000007


def func(v1, v2):
    ans = 1
    ans += pow(2, v1, MOD) - 1
    ans += pow(2, v2, MOD) - 1

    return ans % MOD


def solve():
    N = int(input())

    num_zero = 0

    d = defaultdict(lambda: [0, 0])
    for _ in range(N):
        A, B = map(int, input().split())
        if A == 0 and B == 0:
            num_zero += 1
            continue
        elif A == 0:
            d[(0, 0)][0] += 1
        elif B == 0:
            d[(0, 0)][1] += 1
        else:
            g = gcd(abs(A), abs(B))
            A //= g
            B //= g
            if B > 0:
                if A > 0:
                    d[(A, B)][1] += 1
                else:
                    d[(B, -A)][0] += 1
            else:
                if A < 0:
                    d[(-A, -B)][1] += 1
                else:
                    d[(-B, A)][0] += 1

    ans = 1
    for k, v in d.items():
        ans *= func(v[0], v[1])
        ans %= MOD

    print((ans + num_zero + MOD - 1) % MOD)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 147008
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    int x = atoi((a + b).c_str());
    int sq = (int)sqrt(x);
    yorn(sq * sq == x);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int res_odd=0;
  int res_even=0;

  for(int i=1;i<N+1;++i){
    if(i%2==0){
      ++res_even;
    }
    else{
      ++res_odd;
      }
  }
    double res;
    res= (double) res_odd/(res_odd+res_even);
  cout << res <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int A, B, X;
    cin >> A >> B >> X;
    cout << (A <= X && X <= A + B ? "YES" : "NO") << endl;
    
    return 0;
}

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

int main(void){
    int n = 0, k = 0;
    int h[200001] = {0};
    long long int ans = 0, sum = 0;

    scanf("%d%d", &n, &k);

    for(int i = 0; i < n; i++){
        scanf("%d", &h[i]);
        sum += h[i];
    }
/*
    for(int j = 0; j < k; j++){
        int highest = 0;
        for(int i = 0; i < n; i++){
            if(h[i] > h[highest]){
                highest = i;
            }
        }
        h[highest] = 0;
    }
    for(int i = 0; i < n; i++){
        ans += h[i];
    }
    */

/*
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            if(h[i] < h[j]){
                int tmp = 0;
                tmp = h[j];
                h[j] = h[i];
                h[i] = tmp;
            }
        }
    }
*/
    sort(h, h + n, greater<int>());
/*    for(int i = 0; i < n; i++){
        printf("%d\n", h[i]);
    }
    printf("\n");
*/
    for(int i = k; i < n; i++){
        ans += h[i];
    }
    printf("%lld\n", ans);

    return 0;

} 


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool ret = true;
  int n = S.length();

  for(int i=0; i<n/2; i++) {
    ret &= S[i] == S[n-(i+1)];
  }
  string ss = S.substr(0, (n-1)/2);
  for(int i=0; i<ss.length()/2; i++) {
    ret &= ss[i] == ss[ss.length()-(i+1)];
  }
  ss = S.substr((n+3)/2-1, n);
  for(int i=0; i<ss.length()/2; i++) {
    ret &= ss[i] == ss[ss.length()-(i+1)];
  }
  if(ret) std::cout << YES << std::endl;
  else std::cout << NO << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}



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

using namespace std;

int main()
{
    int n,neg=0;
    cin>>n;
    long long sum=0,mini=INT_MAX;
    vector<long long> v(n);

    for(int i=0;i<n;i++){
        cin>>v[i];
        sum+=abs(v[i]);
        if(v[i]<0) neg++;
        mini=min(mini,abs(v[i]));
    }
    if(neg%2==1){
        cout << sum-2*mini<<endl;
    }else {
        cout<<sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;
template<typename T>
T gcd(T a, T b){
    return b ? gcd(b, a % b) : a;
}    

int main(){ 
    int n,l;
    cin >> n >> l;
    vector<string> S(n);

    rep(i,n){ cin >> S[i];} 
    sort(ALL(S));
    rep(i,n){ cout << S[i];} 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	pair<double,int> a[8],b[6];
	int c=0;
	rep(i,0,3){
		rep(j,0,8) cin>>a[j].se>>a[j].fi;
		sort(a,a+8);
		rep(j,0,2) printf("%d %.2lf\n",a[j].se,a[j].fi);
		rep(j,0,2){
			b[2*i+j].fi=a[2+j].fi;
			b[2*i+j].se=a[2+j].se;
		}
	}
	sort(b,b+6);
	rep(i,0,2) printf("%d %.2lf\n",b[i].se,b[i].fi);;
}

Measured memory_bytes: 1248
def resolve():
    from collections import deque
    x = input()
    final = deque([])
    final.append(x[0])
    for i in range(1, len(x)):
        if x[i] == "S":
            final.append("S")
        else:
            if not final:
                final.append("T")
            else:
                last = final.pop()
                if last == "S":
                    continue
                else:
                    final.append("T")
                    final.append("T")
    print(len(final))
resolve()

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

int main() {
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  int E = A+B;
  int F = C+D;

  if (E < F) {
    cout << "Right" << endl;
  }
  else if (E > F) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()

    for (h in 1..3500L) {
        for (n in h..3500L) {
            var l = 1L
            var u = 4000L

            while (u - l > 1) {
                val w = (l + u) / 2

                if (4 * h * n * w == N * n * w + N * h * w + N * h * n) {
                    println("$h $n $w")
                    return
                }

                val lhs = 4.0 / N
                val rhs = 1.0 / h + 1.0 / n + 1.0 / w

                if (lhs > rhs) {
                    u = w
                } else {
                    l = w
                }
            }
        }
    }
}


Measured memory_bytes: 31704
while True:
    h, w = map(int, input().split())
    if not h and not w:
        break
    result = []
    w2 = w >> 1
    if w % 2:
        for i in range(h):
            if i % 2:
                result.append(".#" * w2 + ".")
            else:
                result.append("#." * w2 + "#")
    else:
        for i in range(h):
            if i % 2:
                result.append(".#" * w2)
            else:
                result.append("#." * w2)
    print("\n".join(result) + "\n")

Measured memory_bytes: 7556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    rep(i,s.size()) {
        if(s[i]=='7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3656
<?php

# スペース区切りの整数の入力
fscanf(STDIN, "%d", $count);

$now_x = 0;
$now_y = 0;
$now_t = $t;

$isgo = true;
for( $i=0;$i<$count;$i++ ){
    fscanf(STDIN, "%d %d %d", $t, $x , $y);
    $diff = abs($now_x-$x) + abs($now_y-$y);
    $diff_t = $t - $now_t;
    if( $diff_t%2 != $diff%2 || $diff > $diff_t ){
        $isgo = false;
        break;
    }
    $now_x = $x;
    $now_y = $y;
    $now_t = $t;
}

if( $isgo ){
    echo 'Yes'."\n";
}else{
    echo 'No'."\n";
}


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

int main(){
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n);
  vector<int> y(m);
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];
  sort(x.rbegin(),x.rend());
  sort(y.begin(),y.end());
  int a = max(X,x[0]);
  int b = min(Y,y[0]);
  if(a >= b) puts("War");
  else puts("No War");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<set>
using namespace std;
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A<C) A=C;
    if(D<B) B=D;
    if(B-A>=0)  cout << B-A << endl;
    else    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
        int n, x;
        int i, j, k;
        int sum;
        
        while (1) {
            scanf("%d %d", &n, &x);
            if (n == 0 && x == 0) {
                break;
            }
            
            sum = 0;
            
            for (i = 1; i <= n - 2; i++){
                for (j = i + 1; j <= n - 1; j++){
                    for (k = j + 1; k <= n ; k++){
                        if (i + k + j == x){
                            sum++;
                        }
            }
            }
            }
            printf("%d\n", sum);
        }
        
        return 0;
    }

Measured memory_bytes: 600
n, x, *li = $stdin.read.split("\n").flat_map{|line| line.split(" ").map(&:to_i) }

d = 0
cnt = 0
i = 0
li << 0
while d <= x && i <= n
  cnt += 1
  d += li[i]
  i += 1
end
puts cnt


Measured memory_bytes: 3836
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int> a(n), b(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }

    vector<vector<int>> dp1(n + 1, vector<int>(t)), dp2(n + 1, vector<int>(t));
    irep(i, n) rep(j, t)
    {
        if (i == 0) {
            dp1[i][j] = dp2[i][j] = 0;
        } else {
            dp1[i][j] = dp1[i - 1][j];
            if (j - a[i - 1] >= 0) {
                dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - a[i - 1]] + b[i - 1]);
            }

            dp2[i][j] = max(dp2[i - 1][j], dp1[i - 1][j] + b[i - 1]);
            if (j - a[i - 1] >= 0) {
                dp2[i][j] = max(dp2[i][j], dp2[i - 1][j - a[i - 1]] + b[i - 1]);
            }
        }
    }

    int result = 0;
    rep(j, t)
    {
        result = max(result, dp2[n][j]);
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 70912
#include <cstdio>
#include <stack>

using namespace std;

int stoi(const char *c) {
    int res = 0;
    for (int i = 0; c[i] != '\0'; ++i) {
        res = res * 10 + c[i] - '0';
    }
    return res;
}

int main() {
    int currentValue;
    char c[10];
    stack<int> stk;
    while (scanf("%s", c) != EOF) {
        if (0 <= c[0] - '0' && c[0] - '0' <= 9) stk.push(stoi(c));
        else {
            currentValue = stk.top();
            stk.pop();
            switch (c[0]) {
                case '+':
                    currentValue = stk.top() + currentValue;
                    break;
                case '-':
                    currentValue = stk.top() - currentValue;
                    break;
                case '*':
                    currentValue = stk.top() * currentValue;
                    break;
                default:;
            }
            stk.pop();
            stk.push(currentValue);
        }
    }
    printf("%d\n", stk.top());
    return 0;
}



Measured memory_bytes: 2696
import java.io.*;
import java.util.*;

public class Main {

	
	public static void main(String[] args) {
		FastScanner in=new FastScanner();
		PrintWriter out=new PrintWriter(System.out);
	//	int t=in.nextInt();
	//	while(t-->0)
		solve(in,out);
		out.close();
	}

    static void solve(FastScanner in,PrintWriter out){
     char s[]=in.next().toCharArray();
     char t[]=in.next().toCharArray();
     int min=Integer.MAX_VALUE;
     for(int i=0;i<s.length-t.length+1;i++){
         int c=0;
         for(int j=i;j<i+t.length;j++){
            if(s[j]!=t[j-i]) c++;
         }
         min=Math.min(min,c);
     }
     out.println(min);
    }    
	


	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 32968
#include<bits/stdc++.h>
using namespace std;
long knapSack(int W, int wt[], long val[], int n) {
  int i, w;
  long K[n+1][W+1];
  for (i = 0; i <= n; i++) {
	   for (w = 0; w <= W; w++){
		     if (i==0 || w==0)
			      K[i][w] = 0;
		     else if (wt[i-1] <= w)
				    K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]);
		     else
				    K[i][w] = K[i-1][w];
	    }
  }

  return K[n][W];
}

int main() {
  int n,  W;
  cin >> n >> W;
  int wt[n];
  long val[n];
  for(int i=0;i<n;i++){
    cin >> wt[i] >> val[i];
  }
	printf("%ld", knapSack(W, wt, val, n));
	return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf 
#define itn int
using namespace std;
const int N=2e5+5;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
char s[N];
int main(){
	cin>>(s+1);
	auto ksm=[](ll a,ll b){
		ll ans=1;
		for(;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;
		return ans;
	};
	int n=strlen(s+1);
	ll ans=ksm(3,n);
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='1')cnt++;
		else ans=(ans-ksm(2,cnt+1)*ksm(3,n-i)%mod+mod)%mod;
	}
	o(ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int x1 , y1 , x2 , y2 ,x3 ,y3 ,x4 ,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int rx , ry ;
    rx = x2 - x1 ;
    ry = y2 - y1;
    if (x2 > x1 && y2 >= y1)
    {
        rx = x2 - x1;
        ry = y2 - y1;
        x3 = x2 - ry;
        y3 = y2 + rx;
        x4 = x3 - rx;
        y4 = y3 - ry;
        
    }
    else if (x1 >= x2 && y2 >= y1)
    {
        rx = x1 - x2;
        ry = y2 - y1;
        x3 = x2 - ry;
        y3 = y2 - rx;
        x4 = x3 + rx;
        y4 = y3 - ry;
    }
    else if (x1 > x2 && y2 <= y1)
    {
        rx = x1 - x2;
        ry = y1 - y2;
        x3 = x2 + ry;
        y3 = y2 - rx;
        x4 = x3 + rx;
        y4 = y3 + ry;
    }
    else
    {
        rx = x2 - x1;
        ry = y1 - y2;
        x3 = x2 + ry;
        y3 = y2 + rx;
        x4 = x3 - rx;
        y4 = y3 + ry;
    }
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;


    return 0;
}

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

int P,N[6];
int coin[6]={1,5,10,50,100,500};

int pay(int money)
{
  int cnt=0;
  for(int i=6-1;i>=0;i--){
    if(money>=coin[i]){
      int tmp=min(money/coin[i],N[i]);
      cnt+=tmp;
      money-=coin[i]*tmp;
    }
  }
  return cnt;
}

int change(int money)
{
  int cnt=0;
  for(int i=6-1;i>=0;i--){
    if(money>=coin[i]){
      cnt+=money/coin[i];
      money%=coin[i];
    }
  }
  return cnt;
}


int main()
{
  while(cin>>P,P){
    for(int i=0;i<6;i++)cin>>N[i];
    int ans=10000;
    for(int i=P;i<P+1000;i++){
      ans=min(ans,pay(i)+change(i-P));
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0