akhauriyash/Code-Regression huggingface dataset:
import Data.List
main=interact$(\b->if b then "Yes" else "No").f.map read.words
f(n:a)=case length m of
  1 -> 0<x && x<=n`div`2 || x==n-1
  2 -> x+1==y && 0<x && x<n-1 && 2*x+1-n<i && i<=x
  _ -> False
  where
    (i,x)=g$m!!0
    (j,y)=g$m!!1
    m=group.sort$a
g a=(length a, head a)

Measured memory_bytes: 16144
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var t1 = long.Parse(line[0]);
        var t2 = long.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a1 = long.Parse(line[0]) * t1;
        var a2 = long.Parse(line[1]) * t2;
        line = Console.ReadLine().Trim().Split(' ');
        var b1 = long.Parse(line[0]) * t1;
        var b2 = long.Parse(line[1]) * t2;
        var ans = getAns(a1, a2, b1, b2);
        if (ans == -1) Console.WriteLine("infinity");
        else Console.WriteLine(ans);
    }
    static long getAns(long a1, long a2, long b1, long b2)
    {
        if (a1 + a2 == b1 + b2) return -1;
        if (a1 + a2 < b1 + b2) return getAns(b1, b2, a1, a2);
        if (a1 > b1) return 0;
        var c = b1 - a1;
        var d = a1 + a2 - b1 - b2;
        var ans = (c + d - 1) / d;
        return c % d == 0 ? ans * 2 : ans * 2 - 1;
    }
}

Measured memory_bytes: 13140
l = [int(input()) for _ in range(int(input()))]
l.sort()
s = sum(l)
c = 0
if s % 10 != 0:
    c = 1
else:    
    for i in l:
        if i % 10 != 0:
            s -= i
            c = 1
            break
print(('0','{}'.format(s))[c == 1])


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	ll n,m;
	cin >> n >> m;

	int p;
	string s;
	V<int> cnt;
	V<int> ok;
	ll ac = 0, wa = 0;

	REP(i,n+1) {
		cnt.push_back(0);
		ok.push_back(0);
	}

	REP(i,m) {
		cin >> p >> s;
		if(ok[p] == 0) {
			if(s == "AC") {
				ok[p] = 1;
				ac+=1;
			} else {
				cnt[p] += 1;
			}
		}
	}

	REP(i,n+1) {
		if(ok[i] == 1) {
			wa += cnt[i];
		}
	} 

	cout << ac << " " << wa << endl;
}



Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,k,fact[2001],inv[2001];
ll ans;
ll pw(ll a, ll b)
{
    ll rez=1;
    while(b)
    {
        if(b%2)
            rez=(rez*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return rez;
}
ll combi(ll a, ll b)
{
    if(a<b)
        return 0;
    ll rez=fact[a];
    rez=(rez*inv[b])%mod;
    rez=(rez*inv[a-b])%mod;
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    fact[0]=1;
    inv[0]=pw(fact[0],mod-2);
    for(int i=1;i<=2000;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        inv[i]=pw(fact[i],mod-2);
    }
    for(int i=1;i<=k;i++)
    {
        ll urne=i;
        ll bile=k-urne;
        ans=combi(urne+bile-1,urne-1);
        /*for(int j=0;j<i;j++)
        {
            urne=j;
            bile=k;
            ll semn=1;
            if(j%2==1)
                semn=-1;
            ans=ans+combi(urne+bile-1,urne-1)*semn;
            if(ans<0)
                ans+=mod;
        }*/
        urne=i+1;
        bile=(n-k)-(urne-2);
        ll ans1=combi(urne+bile-1,urne-1);
        /*for(int j=0;j<i;j++)
        {
            urne=j;
            bile=n-k-(i-1);
            ll semn=1;
            if(j%2==1)
                semn=-1;
            ans1=ans1+combi(urne+bile-1,urne-1)*semn;
            if(ans1<0)
                ans1+=mod;
        }*/
        ans=(ans*ans1)%mod;
        cout<<ans<<'\n';
    }
    return 0;
}


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

int pow(int a,int n) {
    int ans = 1;
    for(int i = 0; i < n; i++) {
        ans *= a;
    }
    return ans;
}

int main() {
    int L; cin >> L;
    double l = 27.0;
    if(L >= 3)
        cout << pow(L,3) / 27 << endl;
    else cout << pow(L,3) / l << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

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

	if ((A * B) % 2 == 1)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 3600
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type Work = (i64, i64); // A, B

fn main() {
    let n = read::<usize>();
    let mut works: Vec<Work> = Vec::with_capacity(n);
    for _i in 0..n {
        let ab: Vec<i64> = read_vec();
        let a = ab[0];
        let b = ab[1];
        let w: Work = (a, b);
        works.push(w);
    }


    let answer = solve(&mut works);
    let msg = if answer {
        "Yes"
    } else {
        "No"
    };
    println!("{}", msg);
}

fn solve(works: &mut [Work]) -> bool {
    // 1. Sort
    works.sort_by(|a, b| a.1.cmp(&b.1));

    // 2. Check
    let mut total : i64 = 0;
    for w in works {
        total += w.0;
        if total > w.1 {
            return false;
        }
    }
    return true;
}


Measured memory_bytes: 6464
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const int MX = 2000 * 1000 + 7;

bitset <MX> dp[2];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, sum = 0;
    cin >> n;
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        sum += x;

        int t = (i & 1);
        dp[t] = (dp[t ^ 1] | (dp[t ^ 1] << x));
    }

    int t = (n & 1);
    for (int i = (sum + 1) / 2; i <= sum; ++i)
        if (dp[t][i]) cout << i, exit(0);
    return 0;
}



Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++);
int n,u,k;


int main()
{
	cin >> n ; //n頂点
	vector<int> edges[100];
	
	for (int i = 0; i < n;i++)//iは頂点
	{
		cin >> u >> k;		
		for(int j=0;j< k;j++)
		{
			int l;
			cin >> l;
			edges[u-1].push_back(l);
		}//入力終わり	
		for (int m = 0; m < n; m++)//n*n行列を作るぞい　
		{
			vector<int>::iterator result = find(edges[i].begin(), edges[i].end(), m+1);
			if (result != edges[i].end()) cout << 1;
			else cout << 0;
			if (m <= n - 2) cout << " ";
			if (m == n - 1)cout << endl;
		}
	}		
	return 0;
}


Measured memory_bytes: 3132
using System;

public class OneCardPoker
{
    static void Main()
    {
        string[] inputs = Console.ReadLine().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries );
        if ( inputs.Length < 2 ) return;

        int a = Number( inputs[ 0 ] );
        int b = Number( inputs[ 1 ] );
        if ( a == 0 || b == 0 ) return;

        Console.WriteLine( a > b ? "Alice" : a < b ? "Bob" : "Draw" );
    }

    static int Number( string input )
    {
        int number = 0;
        if ( !int.TryParse( input, out number ) ) { return 0; }
        return Check( number );
    }

    static int Check( int number )
    {
        if ( number == 1 ) number = 14;
        return number;
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <math.h>
int main()
{
  int n;
  double x,y,dx,dy,l;
  for(;;){
    scanf("%d",&n);
    if(n==-1) break;
    x = 1.0, y = 0.0;
    while(n-- > 1){
      dx = -y; dy = x;
      l = sqrt(dx * dx + dy * dy);
      dx /= l;
      dy /= l;
      x += dx;
      y += dy;
    }
    printf("%.2lf\n%.2lf\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int i = 1;
  while(A > 0 && C > 0) {
    A -= D;
    C -= B;
    i++;
  }
  if(C > 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;



int main(void){
	int A,B,c[110][110];
	scanf("%d%d",&A,&B);
	printf("100 100\n");
	A--;
	B--;
	rep(i,100){
		rep(j,50){
			if(i%2==0 && j%2==0 && A>0){
				printf(".");
				A--;
			}else{
				printf("#");
			}
		}
		rep(j,50){
			if(i%2==0 && j%2==1 && B>0){
				printf("#");
				B--;
			}else{
				printf(".");
			}
		}
		printf("\n");
	}

	

	return 0;
}

Measured memory_bytes: 256
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 10/3/2019

*/

#include <bits/stdc++.h>
using namespace std;
#define time cout << "\ntime: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#define W 100009
inline void Boost() {
	cin.tie(0);cin.sync_with_stdio(0);
	cout.tie(0);cout.sync_with_stdio(0);
}
long long n,w,DP[101][W],knap[101][2];
long long dp(int i,int value){
	if(value==0 )
		return 0;
	if(value <0 || i>=n )
		return 6969696969;
	if(DP[i][value]!=-1)
		return DP[i][value];
	if(value>=knap[i][1])
		return DP[i][value]=min(knap[i][0]+dp(i+1,value-knap[i][1]),dp(i+1,value));
	else
		return DP[i][value]=dp(i+1,value);
}



int main(void){
	Boost();
	cin >>n >> w;
	for(int i=0 ; i<n ;i++)
		for(int j=0; j<2;j++)
			cin >>knap[i][j];

	memset(DP,-1,sizeof(DP));
	for(int i=W;i>=0 ;i--){
		long long x=dp(0,i);
		if(x<=w){
			cout << i <<endl;
			break;
		}
	}
	
   return 0;
}


Measured memory_bytes: 79232
// Problem : E - Colorful Blocks
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

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

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 998244353;

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = d * d % MOD;
	if (b % 2) return d * a % MOD;
	return d;	
}

const ll MAX = 2e5;
ll fact[MAX + 5], invFact[MAX + 5];
void facts() {
	fact[0] = invFact[0] = 1;
	RI(i, MAX) {
		fact[i] = fact[i - 1] * i % MOD;
		invFact[i] = pow2(fact[i], MOD - 2);
	}
}

ll choose(ll n, ll k) {
	return (fact[n] * invFact[k] % MOD) * invFact[n - k] % MOD;
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	facts();
	ll ans = 0;
	REP(i, k + 1) {
		ll tmp = (m * pow2(m - 1, n - (i + 1))) % MOD;
		tmp = (tmp * choose(n - 1, i)) % MOD;
		//cout << tmp << endl;
		ans = (ans + tmp) % MOD;
	}
	cout << ans << endl;
	return 0;
}
 


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;

bool prime[N];
long long p[N];
long long k;

long long cnt;
long long fac[N];
long long num[N];

long long sum[N];

void isprime() //素数快篩
{
    long long i, j;
    k = 0;
    memset(prime, true, sizeof(prime));
    for (i = 2; i < N; i++)
    {
        if (prime[i])
        {
            p[k++] = i;
            for (j = i * i; j < N; j += i)
                prime[j] = false;
        }
    }
}

void fenjie(long long n) //素因子分解，将一个数拆为素因子的乘积
{
    cnt = 0;
    memset(num, 0, sizeof(num));
    for (long long i = 0; p[i] * p[i] <= n && i < k; i++)
    {
        if (n % p[i] == 0)
        {
            fac[cnt] = p[i];
            while (n % p[i] == 0)
            {
                num[cnt]++;
                n = n / p[i];
            }
            cnt++;
        }
    }
    if (n > 1)
    {
        fac[cnt] = n;
        num[cnt++] = 1;
    }
}

long long getnum(long long n, long long p) //计算n的阶乘中素因子p的指数
{
    long long sum = 0;
    while (n >= p)
    {
        sum += n / p;
        n = n / p;
    }
    return sum;
}

int main()
{
    set<long long> st;
    isprime();
    st.clear();
    long long n, m;
    scanf("%lld%lld", &n, &m);
    fenjie(n);
    for (long long i = 0; i < cnt; i++)
        st.insert(fac[i]);
    fenjie(m);
    long long ans = 0;
    for (long long i = 0; i < cnt; i++)
    {
        if (st.count(fac[i]))
            ans++;
    }
    printf("%lld\n", ans + 1);
    return 0;
}


Measured memory_bytes: 14076
#include<iostream>
#include<algorithm>
#include<vector>
int N;
std::vector<int> A;
std::vector<int> S;
int D[100010];
int g,k;
int main(){
    std::cin>>N;
    for(int i=0;i<N;i++){
        int tmp;
        std::cin>>tmp;
        A.emplace_back(tmp);
        S.emplace_back(tmp);
    }
    std::sort(S.begin(),S.end());
    for(int i=0;i<N;i++){
        auto it=lower_bound(S.begin(),S.end(),A[i]);
        int acc=it-S.begin();
        A[i]=acc;
        D[acc]=i;
    }
    for(int i=0;i<N;i++){
        if((D[i]-i)%2){
            if(i%2)g++;
            else k++;
        }
    }
    std::cout<<std::max(g,k)<<std::endl;
    return 0;
}

Measured memory_bytes: 1652
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, C, X, Y = lr()
if X > Y:
    A, B = B, A
    X, Y = Y, X
# X < Y の条件
AB2 = 2 * C
answer = 0
if AB2 < A + B:
    answer += AB2 * X
    Y -= X; X = 0
else:
    answer += (A + B) * X
    Y -= X; X = 0
if AB2 < B:
    answer += AB2 * Y
else:
    answer += B * Y

print(answer)


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

#define N 100005

typedef struct {
	int parent;
	int appaer;
	int member;
	int root;
}node_t;

node_t node[N] = { 0 };

void joint(int a, int b) {
	int a_root = root(a), b_root = root(b);

	if (a_root != b_root) {
		if (node[a_root].member >= node[b_root].member){
			node[b_root].parent = a_root;
			node[a_root].member += node[b_root].member;
			node[b_root].member = 0;
		}
		else {
			node[a_root].parent = b_root;
			node[b_root].member += node[a_root].member;
			node[a_root].member = 0;
		}
	}

}

int root(int node_n) {
	if (node[node_n].parent == 0)return node_n;
	else return root(node[node_n].parent);
}
int main(void) {
	int n, m, k;
	int a, b;
	int c, d;

	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= n; i++)node[i].member = 1;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &a, &b);
		node[a].appaer++, node[b].appaer++;
			joint(a, b);
	}
	for (int i = 1; i <= n; i++)
		node[i].root = root(i);
	for (int i = 0; i < k; i++) {
		scanf("%d %d", &c, &d);
		if (node[c].root == node[d].root) {
			node[c].appaer++, node[d].appaer++;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (node[node[i].root].member > 1)
			printf("%d ", node[node[i].root].member - node[i].appaer - 1);
		else printf("0 ");
	}
	return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

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

  z = malloc(sizeof(struct 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;// T が空の場合
    else if(z->key < y->key) y->left = z; // z を y の左の子にする
    else y->right = z; // z を y の右の子にする
}


void inParse(Node x){
  if(x->left != NIL) inParse(x->left);
  printf(" %d",x->key);
  if(x->right != NIL) inParse(x->right);
}
void preParse(Node x){
  printf(" %d",x->key);
  if(x->left != NIL) preParse(x->left);
  if(x->right != NIL) preParse(x->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
     if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inParse(root);
      printf("\n");
      preParse(root);
      printf("\n");
    } 
  }

  return 0;
}




Measured memory_bytes: 25156
// B - Resistors in Parallel
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n; cin>>n;
	double a = 0.;
	for(int i=0; i<n; i++){
		double x;cin>>x;
		a += 1./x;
	}
	// printf("%.16g\n",1./a);
	cout<< setprecision(16) <<  1./a << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        long n = sc.nextLong();
        long k = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();
        
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i <= k) {
                sum += x;
            } else {
                sum += y;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 10064
_ = gets
a = gets.split.map(&:to_i)

def bubble_sort(a)
  is_reverse = true
  cnt = 0
  while is_reverse 
    is_reverse = false
    0.upto(a.size - 2) do | i |
      if a[i] > a[i+1]
        a[i], a[i+1] = a[i+1], a[i]
        is_reverse = true
        cnt += 1
      end
    end
  end
  return a, cnt
end

a, cnt = bubble_sort(a)
puts a.join(' ')
puts cnt



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

int main() {

	int A,B,C,D,result = 0;
	vector<int> data;

	cin >> A >> B >> C >> D;

	if (B < C || D < A) {
		cout << 0;
		return 0;
	}

	data.push_back(A);
	data.push_back(B);
	data.push_back(C);
	data.push_back(D);

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


	result = data[2] - data[1];
	if (result < 0) result = 0;

	cout << result;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n;
    cin>>n;
    for (int i=n; i<=999; i++)
    {
        string s=to_string(i);
        if (s[0]==s[1] && s[1]==s[2])
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

void open(){
	freopen("D:/Code/in.txt","r",stdin);
	freopen("D:/Code/out.txt", "w", stdout);
}

int main(void){
	int n;
	sc(n);
	int arr[100010];
	ll sum = 0;
	int one = 0;
	FOR(i,n){
		sc(arr[i]);
		if(arr[i] == 1)one++;
		sum += arr[i];
	}

	if(one > 1){
		printf("NO");
		return 0;
	}

	ll tot = 0;
	
	bool valid = true;
	ll bagi = 1LL * n * (n+1) / 2;
	valid &= (sum % bagi == 0);
	ll kali = sum/bagi;
	int diff[100010];
	REP(i,1,n){

		tot += arr[i] - arr[i-1];
		if(arr[i] > arr[i-1] && arr[i] - arr[i-1] > kali){
			valid = false;
		}
	}

	if(arr[0] > arr[n-1] && arr[0] - arr[n-1] > kali)valid = false;

	// cout << kali << " " << bagi << endl;
	int mini = 2 * INF;
	int mindx;
	FOR(i,n){
		diff[i] = arr[i] - arr[(n+i-1)%n];
		// if(mini > diff[i]){
		// 	mini = diff[i], mindx = i;
		// }
		// if(arr[i] < kali || arr[i] > kali * n)valid = false;
	}

	int st = 0;

	FOR(i,n){
		// cout << diff[i] << " " ;
		if(diff[i] > kali)valid = false;
		else if(diff[i] < kali){
			int iii = diff[i] - kali;
			iii *= -1;
			if(iii % n)
				valid = false;
			else st += iii/n;
		}
	}

	if(st != kali)valid = false;

	// FOR(i,n-1){
	// 	if(diff[(mindx+i)%n] > diff[(mindx+1+i)%n])valid = false;
	// }



	printf("%s", valid ? "YES" : "NO");
    return 0;
}




Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){	
	
	int n,a,b;
	cin >> n >> a >> b;
	vector<int> p(n);
	int mi=0,mdl=0,la=0;
	for(int i=0;i<n;i++){
		cin >> p[i];
		if(p[i]<=a){
			mi++;
		}else if(p[i]>b){
			la++;
		}else{
			mdl++;
		}
	}
	int ans=min({mi,mdl,la});
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3560
import math
n,d = map(int,input().split())
x = [list(map(int,input().split()))for _ in range(n)]

ans = 0

for i in range(n):
  r = math.sqrt(x[i][0]**2+x[i][1]**2)
  if r <= d:
    ans += 1

print(ans)

Measured memory_bytes: 45452
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, m;
	cin >> n >> m;
	map<int, int> M;
	int k;
	int a;
	for (int i = 0; i < n; ++i)
	{
		cin >> k;
		for (int j = 0; j < k; ++j)
		{
			cin >> a;
			++M[a];
		}
	}
	int ans = 0;
	for (int i = 1; i <= m; ++i)
	{
		ans += (M[i] == n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,Ma,Mb=map(int,input().split())
abc = list(list(map(int,input().split()))for i in range(N))
DP = [[[10**9]*(10*N+1) for i in range(10*N+1)]for i in range(N+1)]
DP[0][0][0] = 0
for i in range(N):
    for j in range(10*N+1):
        for k in range(10*N+1):
            if j >= abc[i][0] and k >= abc[i][1]:
                DP[i+1][j][k] = min(DP[i][j][k],DP[i][j-abc[i][0]][k-abc[i][1]]+abc[i][2])
            else:
                DP[i+1][j][k] = DP[i][j][k]
ans = 10**9
for i in range(1,10*N//max(Ma,Mb)+1):
    ans = min(DP[-1][i*Ma][i*Mb],ans)
if ans >= 10**8:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 98268
import java.util.Scanner;
 
public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		System.out.println(
				String.valueOf(
						new char[]{
								s.next().charAt(0),
								s.next().charAt(0),
								s.next().charAt(0)
								}
						)
				.toUpperCase()
				);
	}
}

Measured memory_bytes: 23508
#include<iostream>
#include<vector>
using namespace std;
int ati(string a) {
	int ret = 0;
	for (int i = 0; i < a.size(); i++) {
		ret *= 10;
		ret += a.at(i) - '0';
	}
	return ret;
}
int  mprimes(int k) {
	int i;
	for ( i = k; i > 1; i--) {
		int count = 0;
		for (int j = 2; j < i; j++) {
			if (i % j == 0)count++;
		}
		if (count == 0) break;
	}
	return i;
}
bool root(int k, vector<int>* p) {
	int pp = 0;
	int kk = k;
	for (int i = 2; i <= kk; i++) {
		int count = 0;
		while (k % i == 0) {
			count++;
			k /= i;
		}
		if (count)p->at(pp++) = count;
	}
	for (int i = 0; i < p->size(); i++) {
		if (p->at(i) % 2 != 0) return false;
	}
	return true;
}
int main() {
	string a, b;
	int k;
	cin >> a >> b;
	a += b;
	k = ati(a);
	vector<int> p(mprimes(k), 0);
	if (root(k, &p)) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 3632
def I(): return int(input())
def MI(): return map(int, input().split())
def SI(): return input().rstrip()
from collections import defaultdict

#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

h,w=MI()
uf=UnionFind(h*w)
lis=[[0]*w for i in range(h)]
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
step=[[0,1],[0,-1],[-1,0],[1,0]]
for i in range(h):
    for j in range(w):
        for x,y in step:
            if not (0<=i+x<h and 0<=j+y<w):
                continue
            if lis[i][j]!=lis[i+x][j+y]:
                uf.union(w*i+j,w*(i+x)+(j+y))
ans=0
dic=defaultdict(lambda:[0,0])
for i in range(h):
    for j in range(w):
        dic[uf.find(w*i+j)][lis[i][j]==1]+=1
for p in dic.keys():
    ans+=dic[p][0]*dic[p][1]
print(ans)

            
            
                
                
    
        
    
            
            










            
            
                
                
    
        
    
            
            



Measured memory_bytes: 98876
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    if(S[K-1] == 'A') S[K-1] = 'a';
    if(S[K-1] == 'B') S[K-1] = 'b';
    if(S[K-1] == 'C') S[K-1] = 'c';

    cout << S << endl;
}



Measured memory_bytes: 3640
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,f;
  int num=0;
  map<string,int>mp;
  int con[1001][1001]={};
  cin >> n >> f;
  string str[1001];
  for(int i=0;i<n;i++){
    int m;
    cin >> m;
    vector<string>it(m);
    
    for(int j=0;j<m;j++){
	cin >> it[j];	
    	if(!mp[it[j]]){
	  num++;
	  mp[it[j]]=num;
	  str[num]=it[j];
	}
    }
    for(int j=0;j<m;j++){
      for(int k=m-1;k>=0;k--){
	if(j==k)continue;
	if(it[j]>it[k])continue;
	con[mp[it[j]]][mp[it[k]]]++;
      }
    }
  }
  vector< pair<string,string> > ans;
  pair<string,string>abuf;
  int anum=0;
  for(int i=1;i<=num;i++){
    for(int j=0;j<=num;j++){
      if(con[i][j]>=f){
	abuf.first=str[i];
	abuf.second=str[j];
	ans.push_back(abuf);
	anum++;
      }
    }
  }
  sort(ans.begin(),ans.end());
  cout << anum << endl;
  for(int i=0;i<anum;i++){
    cout << ans[i].first << " "<< ans[i].second<<endl;
  }
  return 0;
}

Measured memory_bytes: 7268
/*
const int N = 1e5+100;
const int LIM = 17; // cf 620div2

vector<int> g[N];
int par[N][LIM+1], depth[N];

void build(int cur, int p) {
    depth[cur] = depth[p]+1;
    par[cur][0] = p;
    _rep(i,1,LIM) 
        par[cur][i] = par[par[cur][i-1]][i-1];
    for(auto it : g[cur]) {
        if(it != p) build(it, cur);
    }
    return;
}
int lca_len(int a, int b) {
    int len = 0;
    if(depth[a] > depth[b]) swap(a, b);
    for(int i = LIM; i >= 0; i--) {
        if(depth[par[b][i]] >= depth[a])
            b = par[b][i], 
            len += (1<<i);
    }
    if(a == b) return len;
    for(int i = LIM; i >= 0; i--) {
        if(par[a][i] != par[b][i]) {
            a = par[a][i]; 
            b = par[b][i];
            len += (1<<(i+1));
        }
    }
    return len+2;
}

void taskE() {
    int n; cin >> n;
    
    _for(i,1,n) {
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    build(1, 0);
    int q; cin >> q;
    while(q--) {
        int x,y,a,b,k; cin >> x >> y >> a >> b >> k;
        int x1 = lca_len(a, b);
        int x2 = min(lca_len(a, x)+lca_len(y, b), lca_len(a, y)+lca_len(x, b)) + 1;

        int ans = INT_MAX;
        if(x1%2 == k%2) ans = x1;
        if(x2%2 == k%2) ans = min(ans, x2);
        cout << (ans <= k ? "YES\n" : "NO\n");
    }
    return;
}
*/


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define _for(i,a,b) for(int i = (a); i < (b); i++) 
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

//https://atcoder.jp/contests/abc160/tasks/abc160_f
const int N = 2e5+100;
const int mod = 1e9+7;
int siz[N],n;
ll mul[N],fac[N],ans[N];
vector<int> g[N];

ll fpow(ll a, ll b) {
    ll ret = 1;
    while(b) {
        if(b&1)  ret = ret*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
    return ret;
}
void predfs(int u, int fa) {
    siz[u] = mul[u] = 1;
    for(int v : g[u]) {
        if(v == fa) continue;
        predfs(v,u);
        siz[u] += siz[v];
        mul[u] = mul[u]*mul[v]%mod;
    }
    mul[u] = mul[u]*siz[u]%mod;
}
void dfs(int u, int fa, ll tmp) {
    for(int v : g[u]) if(v != fa) tmp = tmp*mul[v]%mod;
    ans[u] = fac[n-1]*fpow(tmp, mod-2)%mod;
    for(int v : g[u]) 
        if(v != fa) 
        dfs(v, u, tmp*fpow(mul[v], mod-2)%mod*(n-siz[v])%mod);
}
void taskF() {
    scanf("%d", &n);
    _for(i,1,n) {
        int x,y;         
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    fac[0] = 1;
    _rep(i,1,n) fac[i] = fac[i-1]*i%mod;
    predfs(1, 0);
    dfs(1,0,1);
    _rep(i,1,n) printf("%lld\n", ans[i]);
    return;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    //taskA();
    //taskB();
    //taskC();
    //taskD();
    //taskE();
    taskF();
    return 0;
}




Measured memory_bytes: 19444
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll R=2e5+69, INF=2e9+6969;

ll a,b,c,d;
ll ans = 0;

int main()
{
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	ans = a*c;
	ans = max(a*d, ans);
	ans = max(b*d, ans);
	ans = max(b*c, ans);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3824
pub fn main() {

  fn read() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf);
    buf
  }

  fn read_vec() -> Vec<i64> {
    read().split_whitespace().
      map(|e| e.parse().unwrap()).collect()
  }

  let _ = read();
  let a = read_vec();
  // let mut buf = String::new();
  // std::io::stdin().read_line(&mut buf);
  // buf.clear();
  //
  // std::io::stdin().read_line(&mut buf);
  // let a: Vec<i64> = buf.split_whitespace().
  //   map(|e| e.parse().unwrap()).collect();

  let mut ans:i64 = 0;
  let mut high:i64 = 0;
  for i in a {
    if high > i {
      ans += high - i;
    } else {
      high = i;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 5864
def solve() :
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    if n == 0 :
        print(x)
        return None


    p.sort()

    i = 0
    while True :
        idx = x - i
        if not idx in p :
            print(idx)
            return None

        idx = x + i
        if not idx in p :
            print(idx)
            return None

        i += 1

if __name__ == "__main__":
    solve()

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

using namespace std;

using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}
 
template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

ll n, k, x;
ld V[200005], SP2[200005], maxim = -1e9;

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

	cin>>n>>k;
	for (int i=1; i<=n; i++)
	{
		cin>>x;
		V[i] = 1.0 * (x*(x+1)/2) / x;
	}

	for (int i=1; i<=n; i++)
		SP2[i] = SP2[i-1] + V[i];

	for (int i=k; i<=n; i++)
	{
		ld ans = SP2[i] - SP2[i-k];
		maxim = max(maxim, ans);
	}
	cout<<fixed<<setprecision(12)<<maxim;
	return 0;
}

Measured memory_bytes: 6528
from collections import deque
import copy
n,m = map(int,input().split())
Map = [[]for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    Map[a-1].append(b-1)
    Map[b-1].append(a-1)


Visited = [False for i in range(n)]
depth = [0 for i in range(n)]
q = deque()
q.append(0)
while q:
    st = q.popleft()
    for i in Map[st]:
        if Visited[i]==True:
            continue
        depth[i] = depth[st]+1
        Visited[i] = True
        q.append(i)
ans = []
depth[0] = 0
for i in range(1,n):
    for j in Map[i]:
        if depth[i]-1==depth[j]:
            ans.append(j+1)
            break

if len(ans)==0:
    print('No')
else:
    print('Yes')
    for i in ans:
        print(i)

Measured memory_bytes: 38740
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};


//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int width, height, n;
	while(true){

		cin >> width >> height;
		if(width == 0 && height == 0){
			break;
		}
		cin >> n;
		vector<PII> bad(n);
		VVI table(height, VI(width));
		REP(i, n){
			int x, y;
			cin >> x  >> y;
			x--;
			y = height - y;
			table[y][x] = -1;
		}
		table[height - 1][0] = 1;
		int value;
		for(int y = height -1; y >= 0; --y){
			REP(x, width){
				if(table[y][x] == -1) continue;
				if(x > 0){
					value = table[y][x -1];
					table[y][x] += value > -1 ? value : 0;
				}
				if(y < height - 1){
					value = table[y + 1][x];
					table[y][x] += value > -1 ? value : 0;
				}
			}
		}
		cout << table[0][width -1] << endl;

	}

	return 0;
}

Measured memory_bytes: 1220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC123_C
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] trans = new long[5];

            long minNumber = long.MaxValue;
            int minTrans = 0;

            for (int i = 0; i < 5; ++i)
            {
                trans[i] = long.Parse(Console.ReadLine());

                if (trans[i] < minNumber)
                {
                    minNumber = trans[i];
                    minTrans = i;
                }
            }

            long answer = 0;

            if (n <= trans[minTrans])
            {
                answer = 5;
            }
            else
            {
                answer = (long)Math.Ceiling((double)n / trans[minTrans]) + 4;
            }

            Console.WriteLine($"{answer}");
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

long long max(long long a,long long b){
  if(a>b){return a;}return b;
}

long long stree[524288],ssize=262144;

void init(){
  long long i;
  for(i=0;i<2*ssize;i++){stree[i]=0;}
}

void upd(long long p,long long x){
  p+=ssize;
  while(p>0){
    stree[p]=max(stree[p],x);
    p/=2;
  }
}

//call : k=1
long long query(long long a,long long b,long long k,long long st,long long fi){
  long long te=(st+fi)/2;
  if(a<=st && fi<=b){return stree[k];}
  if(b<=st || fi<=a){return -1;}
  return max(query(a,b,2*k,st,te),query(a,b,2*k+1,te,fi));
}

int main(){
  long long i,j,n,m,a,k,rw,res=0;
  long long st,fi,te;
  while(scanf("%lld%lld",&n,&m),n!=0){
    init();
    rw=0;res=0;
    upd(0,1);
    upd(m,1);
    for(i=0;i<n;i++){
      scanf("%lld",&a);
      rw+=a;
      k=rw%m;
      st=k+1;fi=2*m-1;
      while(st<=fi){
        te=(st+fi)/2;
        if(query(k+1,te+1,1,0,ssize)==0){
          st=te+1;
        }
        else{fi=te-1;}
      }
      res=max(m-st+k,res);
      upd(rw%m,1);
      upd((rw%m)+m,1);
    }
    printf("%lld\n",res);
  }
}



Measured memory_bytes: 5932
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
    t = []
    x = i
    for j in range(n-1):
        t.append(s[j])
        if x % 2 != 0:
            t.append('+')
        x = x // 2
    t.append(s[-1])
    m = 0
    for i in t:
        if i != '+':
            m *= 10
            m += int(i)
        else:
            ans += m
            m = 0
    ans += m
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
  	int ans[N+1]; memset(ans, 0, sizeof(ans));
  	int ans2[N+1]; memset(ans2, 0, sizeof(ans2));
  	for(int i = 1; i <= N; i++){
    	for(int j = 1; j <= N; j++){
        	for(int z = 1; (i*i+j*j+z*z+i*j+j*z+z*i) <= N; z++){
				int n = (i*i+j*j+z*z+i*j+j*z+z*i);
              	ans[n]++;
            }
        }
    }
  	for(int i = 1; i <= N; i++){
    	cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 3564
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str = sc.nextLine();
      char temp;
      
      for(int i = 0; i < str.length(); i ++){
         temp = str.charAt(i);
         if(Character.isUpperCase(temp)){
            temp = Character.toLowerCase(temp);
         }else{
            temp = Character.toUpperCase(temp);
         }
         System.out.print(temp);
      }
      System.out.println();
   }//main
}//class

Measured memory_bytes: 26620
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
  int sx,sy,tx,ty;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

  vector<char> s;
  s.push_back('D');
  rep(i,tx-sx+1)
    s.push_back('R');
  rep(i,ty-sy+1)
    s.push_back('U');
  rep(i,tx-sx+1)
    s.push_back('L');
  rep(i,ty-sy)
    s.push_back('D');
  rep(i,tx-sx)
    s.push_back('R');
  rep(i,ty-sy+1)
    s.push_back('U');
  rep(i,tx-sx+1)
    s.push_back('L');
  rep(i,ty-sy+1)
    s.push_back('D');
  s.push_back('R');
  s.push_back('\0');

  char* str=&s[0];

  printf("%s\n",str);
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  private static long calculateNumA(long n, long k, long b) {
//    System.out.println((b - k) * (n / b));
//    System.out.println(n + 1 - (((n / b)) * b + k));
    return (b - k) * (n / b) + Math.max(n + 1 - (((n / b)) * b + k), 0);
  }

  private static long solve(long n, long k) {
    if (k == 0) {
      return n * n;
    }

    long sum = 0;
    for (long b = k+1; b <= n; b++) {
      long numA = calculateNumA(n, k, b);
//      System.out.printf("%d %d\n", b, numA);  
      sum += numA;
    }
    return sum;
  }

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int k = s.nextInt();
    System.out.println(solve(n, k));
  }
}


Measured memory_bytes: 21844
t = [(i * i + j * j, (i, j)) for i in range(1, 151) for j in range(i + 1, 151)]
t.sort()
d = {a[1]: b[1] for a, b in zip(t, t[1:])}
res = []
for e in iter(input, '0 0'):
    h, w = map(int, e.split())
    ans = d[h, w]
    res.append(' '.join(map(str, ans)))
print('\n'.join(map(str, res)))


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

long long s;
long long a, b;

int main()
{
	cin >> s;
	a = s % 1000000000;
	b = s / 1000000000;
	if (a)
	{
		cout << 0 << ' ' << 0 << ' ' << 1000000000 - a << ' ' << b + 1 << ' ' << 1000000000 << ' ' << 1 << endl;
	}
	else
	{
		cout << 0 << ' ' << 0 << ' ' << 0 << ' ' << b << ' ' << 1000000000 << ' ' << 1 << endl;
	}
	
}

Measured memory_bytes: 512
import math
a,b,C=map(int,input().split())
radC=math.radians(C)
S=(1/2)*a*b*math.sin(radC)
L=a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(radC))
h=b*math.sin(radC)
print('{:.8f}'.format(S))
print('{:.8f}'.format(L))
print('{:.8f}'.format(h))


Measured memory_bytes: 5708
n = int(input())
a = list(map(int,input().split()))

hako = [0]*n

for i in range(n,0,-1):
    tmp = i
    su = 0
    while tmp<=n:
        su += hako[tmp-1]
        tmp += i
    if su % 2 == a[i-1]:
        continue
    else:
        hako[i-1] = 1

print(hako.count(1))
for i in range(n):
    if hako[i] == 1:
        print(i+1,end=" ")

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

int main() {
	int n;
	cin >> n;
	int memo[n], stones[n];
	
	for(int i=0;i<n;i++){
	cin>>stones[i];
	}
	memo[0] = 0;
	memo[1] = abs(stones[0] - stones[1]);
	for (int i = 2; i < n; i++) {
		memo[i] = min(abs(stones[i] - stones[i - 1]) + memo[i - 1], abs(stones[i] - stones[i - 2]) + memo[i - 2]);
	}
	cout<<memo[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;
 
int main(){
  string s;
  cin>>s;
  int ssz=s.size();
  int ans[ssz]={};
  vector<int> rlist;
  rep(i,ssz-1){
    if(s[i]=='R'&&s[i+1]=='L'){
      rlist.push_back(i);
    }
  }
  rep(i,rlist.size()){
    int j=rlist[i];
    while(j>=0){
      if(s[j]=='L')break;
      if((rlist[i]-j)%2==0)ans[rlist[i]]++;
      else ans[rlist[i]+1]++;
      --j;
    }
    j=rlist[i]+1;
    while(j<ssz){
      if(s[j]=='R')break;
      if((j-rlist[i]-1)%2==0)ans[rlist[i]+1]++;
      else ans[rlist[i]]++;
      ++j;
    }
  }
  rep(i,ssz){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
}

Measured memory_bytes: 1276
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        string s, t;
        cin >> s >> t;
        int a, b;
        cin >> a >> b;
        string u;
        cin >> u;

        if(s == u)
            a--;
        else
            b--;

        cout << a << ' ' << b << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        for(int i=1;i<=a;i++){
            cout<<b;
        }
    }
    else{
        for(int t=1;t<=b;t++){
            cout<<a;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 256