akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int length = input.nextInt();
		int wide = input.nextInt();
		
		int area = length * wide;
		int para = 2 * length + 2 * wide;
		System.out.println(area + " " + para);
		
		input.close();
	}

}

Measured memory_bytes: 26324
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(int i=0;i<n;i++)
#define fa(i,a,n) for(int i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(int i = a; i <= n; i++)
#define loopb(i,a, n) for(int i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define aint(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortaint(x) sort(aint(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<int> vl;
typedef vector<pii> vpii;
typedef vector<pint> vpint;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const int N = 1e6+5;  
// int a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
int n, m;

int dp[100005];
vector<int>a;
int fun(int pos){
    if(pos == n - 1){
        return 0;
    }
    if(pos >= n){
        return 1e15;
    }
    if (dp[pos] != -1) return dp[pos];
    return dp[pos] = min(abs(a[pos] - a[pos+1]) + fun(pos + 1), abs(a[pos] - a[pos+2]) + fun(pos + 2));
}

void solve() {
    // int k, x, y, p, q, r;
    cin>>n;
    a.resize(n);
    f(i,n) cin >> a[i];
    setmem(dp, -1);
    cout << fun(0);
}

int32_t main() {
    IOS
    int T;
    // cin >> T;
    // while(T--)
        solve();
    cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
    return 0;
}

Measured memory_bytes: 4224
K=int(input())
S=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(S[K-1])


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

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


Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int a,b;
int main(){
	cin>>a>>b;
	if(a<=9&&b<=9){
		cout<<a*b<<endl;
	}else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool ptr[10];
int kaunto[50]={0};
int count=0;
void dfs(int g,int cd){//g==now place ptr==pointer.
	if(g==0&&cd==0){
		kaunto[count]++;
		return;
	}
	else if(cd==0){
		return;
	}
	else if(g<0){
		return;
	}
	for(int i=0;i<10;i++){
		if(ptr[i]){
			continue;
		}
		ptr[i]=true;
		dfs(g-i,cd-1);
		ptr[i]=false;
	}
}
int kaijo(int x){
	int y=1;
	for(int i=1;i<=x;i++){
		y*=i;
	}
	return y;
}
int main(){
	int n[50]={0},s=0,answer=0;
	while(1){
		cin>>n[count];
		cin>>s;
		if(n[count]==0&&s==0){
			break;
		}
		for(int h=0;h<10;h++){
			ptr[h]=false;
		}
		dfs(s,n[count]);
		count++;
	}
	for(int k=0;k<count;k++){
		cout<<kaunto[k]/kaijo(n[k])<<endl;
	}
	return 0;
}


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

ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

ll gcd(ll a, ll b){
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll fact(ll n){
	ll res = 1;
	rep(i, n){
		res *= i + 1;
		res =  res%((ll)(1e9 + 7));
	}
	return res;
}


int main(){
	ll n, m;
	cin >> n >> m;
	vector<string>a(n);
	rep(i, n)cin >> a[i];
	vector<string>b(m);
	rep(i, m)cin >> b[i];

	string ans = "No";
	for(int i = 0; i + m <= n; i++){
		for(int j = 0; j + m <= n; j++){
			ll cnt = 0;
			for(int i_1 = 0; i_1 < m; i_1++){
				for(int j_1 = 0; j_1 < m; j_1++){
					if(i + i_1 < n && j + j_1 < n)
					if(a[i + i_1][j + j_1] == b[i_1][j_1])cnt += 1;
				}
			}
			if(cnt == m*m) ans = "Yes";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b;

	scanf("%d %d", &a, &b);

	if (a < b)
	{
		printf("a < b\n");
	}

	if (a > b)
	{
		printf("a > b\n");
	}

	if (a == b)
	{
		printf("a == b\n");
	}

	return 0;
}


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


int main()
{    
    string s;
    cin >> s;
    //s = "01B0";
    string t = "";
    string temp[3] = {"0", "1", "B"};
    for(int i=0; i<s.length(); ++i){
        if(s.substr(i, 1) == temp[0]){
            t += "0";
        }
        else if(s.substr(i, 1) == temp[1]){
            t += "1";
        }
        else if(s.substr(i, 1)==temp[2] && t.length()!=0){
            // tから文字列を削除する
            t.erase(t.length()-1);
        }
    }
    cout << t << endl;        
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int k,x;
    cin >> k >> x;
    int min = x-k+1;
    int max = x+k-1;
    const int m = -1000000;
    const int M = 1000000;
    if( (min>m) && (max<M) ){
        for(int i=0;i<2*k-1;i++){
            cout << min +i <<" " ; 
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        int n,p; cin >> n >> p;
        if(n==0 && p==0) break;
        int A[n];
        rep(i,n) A[i]=0;
        int now=p;
        bool frag=false;
        while(true){
            rep(i,n){
                if(now==0){
                    now+=A[i];
                    A[i]=0;
                } else {
                    now--;
                    A[i]++;
                    if(A[i]==p) {
                        cout << i << endl;
                        frag=true;
                        break;
                    }
                }
            }
            if(frag) break;
        }
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e9+5;
int ans,maxv,n,W,dp[100005];
struct node{int w,v;}bag[105];
signed main() {
	memset(dp,inf,sizeof(dp));
	cin>>n>>W;
	for (int i=1;i<=n;++i) cin>>bag[i].w>>bag[i].v,maxv=max(maxv,bag[i].v);
	dp[0]=0;
	maxv*=n;
	for (int i=1;i<=n;++i)                    //第i个 
		for (int k=maxv;k>=bag[i].v;--k) {        //枚举最大的值为多少 
			dp[k]=min(dp[k],dp[k-bag[i].v]+bag[i].w);
            if (dp[k]<=W) ans=max(ans,k);
        }
	cout<<ans<<endl;
	return 0;
}
/*
input:
3 8
3 30
4 50
5 60

output:
90

solution:
dp(i,j) -> 前i个数中值为j的最小重量为多少 
*/

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

int main(){
    int n,i,ans;
    cin>>n;
    vector<int> b(n-1);
    for(i=0;i<n-1;i++) cin>>b[i];
    ans=b[0];
    for(i=1;i<n-1;i++){
        ans+=min(b[i-1],b[i]);
    }
    ans+=b[n-2];

    cout<<ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  combination c(n * m);
  mint ans = 0;
  rep2(i, 1, n) {
    mint d = m * m;
    d *= n - i;
    ans += d * i;
  }
  rep2(i, 1, m) {
    mint d = n * n;
    d *= m - i;
    ans += d * i;
  }
  ans *= c(m * n - 2, k - 2);
  cout << ans << endl;
}

Measured memory_bytes: 3328
H,W,D = map(int,input().split())
d = {}
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        d[A[j]] = (i,j)
m = []
for i in range(1,D+1):
    mm = [0]
    for j in range(i+D,H*W+1,D):
        k = (j-i)//D
        dd = mm[k-1]+abs(d[j][0]-d[j-D][0])+abs(d[j][1]-d[j-D][1])
        mm.append(dd)
    m.append(mm)
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    if L%D != 0:
        mm = m[L%D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq]-mm[Lq])
    else:
        mm = m[D-1]
        Lq = L//D
        Rq = R//D
        print(mm[Rq-1]-mm[Lq-1])

Measured memory_bytes: 27484
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n  = s.size();
    lint l = 0, r = 0;
    int k    = 0;
    lint ret = 0;
    for (int i = 0; i < n; ++i) {
        if (k == 0) {
            if (s[i] == '<')
                l++;
            else {
                k = 1;
                r++;
            }
        } else if (k == 1) {
            if (s[i] == '>')
                r++;
            else {
                lint mx = max(l, r);
                lint mi = min(l, r) - 1;
                ret += mx * (mx + 1) / 2;
                ret += mi * (mi + 1) / 2;
                r = 0;
                l = 1;
                k = 0;
            }
        }
    }
    lint mx = max(l, r);
    lint mi = min(l, r) - 1;
    ret += mx * (mx + 1) / 2;
    ret += mi * (mi + 1) / 2;

    cout << ret << "\n";
    // vector<lint> a(n + 1, inf);
    // a[0]     = 0;
    // a[n - 1] = 0;
    // for (int i = 1; i < n; ++i) {
    //     if (s[i] == '<') {
    //         a[i] = a[i - 1] + 1;
    //     } else {
    //         a[i]
    //     }
    // }
    return 0;
}

Measured memory_bytes: 1172
import sys
input=sys.stdin.readline
#for _ in range(int(input())):
n=int(input())
#	n,m=map(int,input().split())
#	s=input().strip()
p=list(map(float,(input().split())))
dp=[[0]*(n+1) for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
	for j in range(n+1):
		if j==0:dp[i][j]=(1-p[i-1])*dp[i-1][j]
		else:dp[i][j]=p[i-1]*dp[i-1][j-1]+(1-p[i-1])*dp[i-1][j]
ans=0
for i in range(n//2+1,n+1):
	ans+=dp[n][i]
print(ans)

Measured memory_bytes: 259720
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
R = [0]*n
G = [0]*n
B = [0]*n
for i in range(n):
    if s[i] == 'G':
        G[i] = 1
    elif s[i] == 'B':
        B[i] = 1
    else:
        R[i] = 1

R = list(accumulate(R))
G = list(accumulate(G))
B = list(accumulate(B))

ans = 0
for i in range(n):
    if s[i] == 'R':
        for j in range(i+1,n):
            if s[j] == 'B':
                ans += G[-1] - G[j]
                if j + (j-i) < n:
                    if s[j+(j-i)] == 'G':
                        ans -= 1
            elif s[j] == 'G':
                ans += B[-1] - B[j]
                if j + j-i < n:
                    if s[j+(j-i)] == 'B':
                        ans -= 1
    elif s[i] == 'B':
        for j in range(i+1,n):
            if s[j] == 'G':
                ans += R[-1] - R[j]
                if j + (j-i) < n:
                    if s[j+(j-i)] == 'R':
                        ans -= 1
            elif s[j] == 'R':
                ans += G[-1] - G[j]
                if j + j-i < n:
                    if s[j+(j-i)] == 'G':
                        ans -= 1
    else:
        for j in range(i+1,n):
            if s[j] == 'B':
                ans += R[-1] - R[j]
                if j + (j-i) < n:
                    if s[j+(j-i)] == 'R':
                        ans -= 1
            elif s[j] == 'R':
                ans += B[-1] - B[j]
                if j + j-i < n:
                    if s[j+(j-i)] == 'B':
                        ans -= 1
print(ans)

Measured memory_bytes: 69588
#include <bits/stdc++.h>
#include <x86intrin.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4,sse4.1,sse4.2,tune=native")

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

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

	rep2(i, 1, n+1){
		if(i * 108 /100 == n){
			cout <<i <<"\n";
			return 0;
		}
		
	}
	cout <<":(\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        int[] hl = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            hl[i] = 0;
        }
        for (int i = 0; i < n-1; i++) {
            if (h[i] > h[i+1]) {
                h[i] -= 1;
                hl[i] = 1;
                if (i != 0) {
                    for (int j = i; j >= 1; j--) {
                        if (h[j-1] > h[j]) {
                            if (hl[j-1] != 0) {
                                System.out.println("No");
                                System.exit(0);
                            } else {
                                if (h[j-1] - h[j] > 1) {
                                    System.out.println("No");
                                    System.exit(0);
                                } else {
                                    h[j-1] -= 1;
                                    hl[j-1] = 1;
                                }
                            }
                        }
                    }
                }
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 61460
#include<iostream>
using namespace std;
int main()
{
	int a,ans;
	cin>>a;
	if(a%10==9) 
		{
			cout<<"Yes";
			return 0;
		}
	a/=10;
	if(a%10==9) 
		{
			cout<<"Yes";
			return 0;
		}
		else cout<<"No";
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
n, m =map(int, input().split())
pp = list(map(int, input().split()))
p = [i-1 for i in pp]

xy = [[] for i in range(n)]
for i in range(m):
  x, y = map(int, input().split())
  x,y = x-1,y-1
  xy[x].append(y)
  xy[y].append(x)
visited = [0 for i in range(n)]

def dfs(s,cnt):
  visited[s] = cnt
  for i in xy[s]:
    if visited[i] == 0:
      dfs(i,cnt)

cnt = 0
for i in range(n):
  if visited[i]:
    continue
  cnt += 1
  dfs(i,cnt)
ans = 0
for i in range(n):
  if visited[p[i]] == visited[i]:
    ans += 1
print(ans)

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

#define rep(i, N) for(ll i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	ll X, K, D; cin >> X >> K >> D;
	if (X < 0)X *= -1;

	ll n = ceil((double)(X) / (double)(D));
	if (n > K) {
		cout << X - K * D << endl;
		return 0;
	}

	if ((K - n) % 2 == 0) {
		cout << -(X - n * D) << endl;
	}
	else {
		cout << X - n * D + D << endl;
	}

	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
  #define Mod 1000000007
  #define INF 9e8
  #define INFL 9e18
  #define EPS 1e-9
  #define pb push_back
  #define mp make_pair
  #define SET(a) memset(a,-1,sizeof(a))
  #define CLR(a) memset(a,0,sizeof(a))
  #define CPY(a,b) memcpy(a,b,sizeof(a))
  #define N 200005
  #define fs first
  #define sc second 
  #define UNIVISITED 0
  #define EXPLORED 1
  #define VISITED 2
  using namespace std;
  typedef  long long int ll;
  typedef pair<ll,ll> ii;
  typedef vector <ii> vii;
  typedef vector <ll> vi;

  ll arr[N],pos[N];

  int main()
  {
 
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c1,c2;
  cin>>c1>>c2;
  if(c1>c2)
    cout<<">";
  else if(c1<c2)
    cout<<"<";
  else
    cout<<"=";




  return 0;


  } 

Measured memory_bytes: 256
import itertools

n=int(input())

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
            ni=0
            for ii in i:
                ni=ni*10+ii
#            print("1:",i,ni)
            if ni<=n:
                icnt+=1    
print(icnt)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n,c;
    cin>>n>>c;
    int d[c][c];
    int sq[n][n];
    int color3[c][3];//color3[i][j] shows number of tiles with axis =j mod 3 is colored with color i.
    long long min=500*500*1000;
    long long temp;
    
    
    for(int i=0; i<c; i++)
    {
        for(int j=0; j<c; j++)
        {
            cin>>d[i][j];
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>sq[i][j];
        }
    }
    
    //initialize color3[c][3]
    for(int i=0; i<c; i++)
    {
        color3[i][0]=0;
        color3[i][1]=0;
        color3[i][2]=0;
    }
    //count color3[][]
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            color3[sq[i][j]-1][(i+j)%3]++;
        }
    }
    for(int i=0; i<c; i++)
    {
        for(int j=0; j<c; j++)
        {
            if(i==j) continue;
            for(int k=0; k<c; k++)
            {
                if(i==k||j==k) continue;
                temp =0;
                for(int m=0; m<c; m++)
                {
                    temp +=color3[m][0]*d[m][i];
                    temp +=color3[m][1]*d[m][j];
                    temp +=color3[m][2]*d[m][k];
                }
                if(temp < min) min = temp;
            }
        }
    }
    cout<<min<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
   int a,b,c;

   scanf("%d %d %d\n", &a,&b,&c);

  if (a<=b && b<=c)
     printf("%d %d %d\n",a,b,c);
  else if (a<=c && c<=b)
     printf("%d %d %d\n",a,c,b);
  else if(b<=a && a<=c)
     printf("%d %d %d\n",b,a,c);
  else if(b<=c && c<=a)
     printf("%d %d %d\n",b,c,a);
  else if(c<=a && a<=b)
     printf("%d %d %d\n",c,a,b);
  else
     printf("%d %d %d\n",c,b,a);

    return 0;
}


Measured memory_bytes: 2056
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  vector<int> v(N);
  int now = 0;
  int ans = 0;
  while(!v[now] && now != 1) {
    v[now] = 1;
    now = A[now];
    ans++;
  }
  if (now == 1) {
    cout << ans << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}

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

int main() {
  int n, k;
  cin>>n>>k;
  int p[n];
  for (int i=0; i<n; i++) cin>>p[i];
  sort(p, p + n);
  int sum = 0;
  for (int i=0; i<k; i++) sum += p[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 3600
N = int(input())
D, X = map(int, input().split())

day_list = []
for i in range(N):
    day_list.append(int(input()))

total_days = []

for x in day_list:

    m = int((D-1)//x)
    m += 1

    total_days.append(m)

total_choco = sum(total_days) + X
print(total_choco)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int N = scanner.nextInt();
		    int[] array = new int[N];
		    int count4 = 0;
		    int count2 = 0;
		    
		    for( int i = 0; i < N; i++ ) 
		    {
		    	array[i] = scanner.nextInt();
		    	if( array[i] % 4 == 0 ) 
		    	{
		    		count4++;
		    	}
		    	else 
		    	{
		    		if( array[i] % 2 == 0 ) 
		    		{
		    			count2++;
		    		}
		    	}
		    }
		    if( N % 2 == 0 ) 
		    {
		    	if( count4 * 2 + count2 >= N ) 
		    	{
		    		System.out.println("Yes");
		    	}
		    	else 
		    	{
		    		System.out.println("No");
		    	}
		    }
		    else 
		    {
		    	if( count2 == 0 ) 
		    	{
		    		if( count4 >= N/2 ) 
		    		{
		    			System.out.println("Yes");
		    		}
		    		else 
		    		{
		    			System.out.println("No");
		    		}
		    	}
		    	else if(count2 == 1)
		    	{
		    		if( count4 + 3 >= N /2 + 2 ) 
		    		{
		    			System.out.println("Yes");
		    		}
		    		else 
		    		{
		    			System.out.println("No");
		    		}
		    	}
		    	else 
		    	{
		    		if( count4 * 2 + count2 >= N )
		    		{
		    			System.out.println("Yes");
		    		}
		    		else 
		    		{
		    			System.out.println("No");
		    		}
		    	}
		    	
		    }
		    scanner.close(); }
		  }

Measured memory_bytes: 50368
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

char get(ll n)
{
    if(n == 1)
        return 'P';
    return 'D';    
}

int main()
{
   FAST/**/
   
   string s;
   cin>>s;
   
   ll n = s.length();
   ll dp[n+1][2];                   // 0 - D
                                    // 1 - P
   rep(n+1)
        dp[i][0] = dp[i][1] = -inf;
   dp[0][0] = dp[0][1] = 0;
   ll prev[n+1][2];
   rep(n+1)
        repi(j,2)
            prev[i][j] = 1;
   rep(n+1)
   {
       if(i == 0)
            continue;
       if(i == 1)
       {
           if(s[i-1] == '?')
                dp[i][1] = 0, dp[i][0] = 1;
           else  
           {
               if(s[i-1] == 'D')
                    dp[i][0] = 1;
               else dp[i][1] = 0;        
           }
       }
       
       else
       {
           if(s[i-1] == '?')
           {
               dp[i][0] = max(dp[i-1][0]+1,dp[i-1][1]+2);
               dp[i][1] = max(dp[i-1][0],dp[i-1][1]);
               if(dp[i][0] == dp[i-1][0]+1)
                    prev[i][0] = 0;
               
               if(dp[i][1] == dp[i-1][0])
                    prev[i][1] = 0;
           }
           
           else
           {
               if(s[i-1] == 'D')
                    dp[i][0] = max(dp[i-1][0]+1,dp[i-1][1]+2);
               else dp[i][1] = max(dp[i-1][0],dp[i-1][1]);
               
               if(dp[i][0] == dp[i-1][0]+1)
                    prev[i][0] = 0;
               if(dp[i][1] == dp[i-1][0])
                    prev[i][1] = 0;
           }
       }
       
       //cout<<"at "<<i<<" = "<<dp[i][0]<<" "<<dp[i][1]<<"\n";
   }
   
   ll fans = max(dp[n][0],dp[n][1]);
   ll las;
   string fin;
   if(dp[n][0]>dp[n][1])
        las = 0;
   else las = 1;
   ll curr = n;
   while(curr>0)
   {
       fin+=get(las);
       las=prev[curr][las];
       curr--;
   }
   reverse(fin.begin(),fin.end());
   cout<<fin;
   
   
   return 0;        
}  
  
   

Measured memory_bytes: 10068
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop

s=input()

a=int(s[:2])
b=int(s[2:])

fa=False
fb=False
if 1 <= a <= 12:
    fa=True
if 1 <= b <= 12:
    fb=True
    
if fa:
    if fb:
        ans="AMBIGUOUS"
    else:
        ans="MMYY"
else:
    if fb:
        ans="YYMM"
    else:
        ans="NA"
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
using Graph = vector<vector<int>>;

int main() {
  //入力
  int N,M;
  cin >> N >> M;
  vector<vector<int>> vec(M); //Mにつけるカッコが()であることに注意
  FOR(i,0,M) {
    int k; cin >> k;
    vec[i].resize(k); //resizeは便利
    FOR(j,0,k) {
      cin >> vec[i][j];
      vec[i][j]--;
    }
  }
  vector<int> p(M); //Mにつけるカッコが()であることに注意
  FOR(i,0,M) cin >> p[i];
  
  //bit探索
  int ans = 0;
  
  for(int bit=0; bit<(1<<N); bit++) {
    bool ok = true; //デフォはtrue(一度でも条件を満たさなかったときにfalseに切り替わる)
    FOR(j,0,M) {
      int c=0;
      for(int id: vec[j]) { //こうすればループ回数を知らなくて良い
        if((bit >> id) & 1) c++; //そのスイッチがオンかどうか
      }
      c %= 2;
      if(c != p[j]) ok = false;
    }
    if(ok) ans++;
  }
  
  cout << ans << endl;
        
  
  
  
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	if(s=="Sunny") cout << "Cloudy" << endl;
	if(s=="Cloudy") cout << "Rainy" << endl;
	if(s=="Rainy") cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a;
  in(a);
  if(a == 7 || a == 5 || a == 3)
    out("YES");
  else
    out("NO");
  memi;
}

Measured memory_bytes: 256
// LM10: The next Ballon d'Or
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }

    public static void main(String[] args)throws IOException {
        /*
Sample Input 1
Copy
3
0.30 0.60 0.80
Sample Output 1
Copy
0.612
        */
        PrintWriter pw = new PrintWriter(System.out);
        FastReader fr = new FastReader();
        int n=fr.i();
        double [] p=new double[n+1];
        for(int ni=1;ni<=n;++ni)
        {
            p[ni]=fr.d();
        }
        double [][] dp=new double[n+1][n+1];
        dp[0][0]=1;
        double cur=1;
        for(int ni=1;ni<=n;++ni)
        {
            cur*=(1-p[ni]);
            dp[ni][0]=cur;
        }
        for(int i=1;i<dp.length;++i)
        {
            for(int j=1;j<dp[i].length;++j)
            {
                dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
            }
        }
        double ans=0;
        for(int j=n/2+1;j<=n;++j)
        {
            ans+=dp[n][j];
        }
        pw.println(ans);

        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 130892
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val q = sc.nextInt()
    val s = sc.next()
    val lr = (0 until q).map { sc.next().toInt() to sc.next().toInt() }
    println(problem122c(n, q, s, lr))
}

fun problem122c(
    n: Int,
    q: Int,
    s: String,
    lr: List<Pair<Int, Int>>
): String {
    val cs = IntArray(n + 1) { 0 }
    for (i in 0 until n) {
        cs[i + 1] = if (i < n - 1 && s[i] == 'A' && s[i + 1] == 'C') cs[i] + 1 else cs[i]
    }
    val ans = mutableListOf<Int>()
    for (i in 0 until q) {
        val (l, r) = lr[i]
        ans.add(cs[r - 1] - cs[l - 1])
    }
    return ans.joinToString("\n")
}

Measured memory_bytes: 66356
W, H, x, y, r = map(int,input().split()) 
x_min = x - r
x_max = x + r
y_min = y - r
y_max = y + r
if 0 <= x_min and \
    x_max <= W and \
    0 <= y_min and \
    y_max <= H:
    print("Yes")
else:
    print("No") 


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n,k;
    cin>>n>>k;
    long long int a=1;
    REP(i,n-1){
    a*=k-1;
    }
    a*=k;
    cout<<a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, cnt = 1;
    cin >> n;
    vector<long> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    long up = 0;
    for(int i = 1; i < n; i++){
        if(l[i-1] > l[i]){
            if(up == 0) up = -1;
            if(up == 1){
                cnt++;
                up = 0;
            }
        }
        else if(l[i-1] < l[i]){
            if(up == 0) up = 1;
            if(up == -1){
                cnt++;
                up = 0;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  string s;
  cin>>n>>s;

  vector<int> r,g,b;
  rep(i,n){
    if(s[i]=='R')r.emplace_back(i);
    if(s[i]=='G')g.emplace_back(i);
    if(s[i]=='B')b.emplace_back(i);
  }
  ll ans = 0;
  rep(i,n){
    for(int j=i+1;j<n;++j){
      if(s[i]==s[j])continue;
      int d = j-i;
      int _k = j+d;
      vector<int>::iterator itr;
      if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
        itr = upper_bound(b.begin(),b.end(),j);
        ans += end(b)-itr;
        if(binary_search(b.begin(),b.end(),_k))ans--;
      }
      if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
        itr = upper_bound(g.begin(),g.end(),j);
        ans += end(g)-itr;
        if(binary_search(g.begin(),g.end(),_k))ans--;
      }
      if((s[i]=='G'&&s[j]=='B')||(s[i]=='B'&&s[j]=='G')){
        itr = upper_bound(r.begin(),r.end(),j);
        ans += end(r)-itr;
        if(binary_search(r.begin(),r.end(),_k))ans--;
      }
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
int main(void){
    int n,ball;
    cin>>n;
    for(int i=0; i<n; i++){
        int a=0,b=0,flg=0;
        for(int j=0; j<10; j++){
            cin>>ball;
            if(ball>a) a=ball;
            else if(ball>b) b=ball;
            else flg=1;
        }
        cout<<(flg==0?"YES":"NO")<<endl;
    }
}


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

int main() {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];

    ll s = 0;
    for (int i = 0; i < N; i++) {
        s += A[i];
    }

    ll sum = 0;
    for (int i = 0; i < N - 1; i++) {
        s -= A[i];
        sum += (A[i] * (s % 1000000007LL)) % 1000000007LL;
        sum = (sum % 1000000007LL);
        
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 5184
N=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(N):
    A.append([i,a[i]])
A.sort(key=lambda x:x[1])
sm=0
t=0
for i in range(N-1):
    sm+=A[i][1]
    if 2*sm<A[i+1][1]:
        t=i+1
print(N -t)

Measured memory_bytes: 72984
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z 
        
N = int(input())
A = list(map(int,input().split()))

ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)


Measured memory_bytes: 14252
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

    vector<int> W(N);
    for (int i = 0; i < N; i++)
        cin >> W[i];

    vector<int> imos(N + 1, 0);
    for (int i = 0; i < N; i++)
        imos[i + 1] += imos[i] + W[i];

    int ans = imos[N];
    for (int i = 1; i < N; i++) {
        int l = imos[i];
        int r = imos[N] - imos[i];

        ans = min(ans, abs(l - r));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#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 int lli;
typedef pair<int,int> mp;

int main(){

  int n;
  while(scanf("%d",&n),n){
    int res=0;
    reg(i,1,n){
      reg(j,1,n-1){
        int tmp=i;
        reg(k,1,j){
          tmp = tmp + i + k;
        }
        if(tmp == n) res++;
      }
    }
    printf("%d\n",res);

  }

  return 0;

}

Measured memory_bytes: 3172
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << "\n"
#define endwith return
constexpr int mod = 1000000007;
using namespace std;
int input() { int t; cin >> t; return t; }
signed main() {
	int x, y; cin >> x >> y;
	puts((y % 2 == 0 && 2 * x <= y && y <= 4 * x ? "Yes" : "No"));
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <cmath>

using namespace std;
double EPS = 1e-10;

void q58() {
	double ax, ay, bx, by, cx, cy, dx, dy;
	for (; cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;) {

		if (abs((ay - by) * (cy - dy) + (cx - dx)*(ax - bx)) <EPS) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}
int main() {
	q58();
	return 0;
}

Measured memory_bytes: 3196
#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#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 ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e5+7;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1e9+7;


int main() {
    FASTIO;    
    int n,x;cin >> n;
    ll sum=0,ma=0;
    FOR(i,0,n){
        
        cin >> x;
        sum += x;
        ma = max(ma,x*1ll);
    }
    
    sum -= ma;
    sum += ma/2;
    cout << sum;
    
    
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

b = [0] * (n-1)

m = 1000
s = 0


# for i in range(n-1):
#    b = a[i+1] - a[i]

for i in range(n-1):
    t = 0
    if a[i+1] > a[i]:
        t = m // a[i]   # 株
        s += t
        m -= a[i] * t
    elif a[i+1] < a[i]:
        t = s * a[i]    # 円
        s = 0
        m += t

if s > 0:
    m += s*a[n-1]

print(m)


Measured memory_bytes: 9192
N=int(input())
a = list(map(int,input().split(" ")))

total=0

for i in range(len(a)):
    if i % 2 == 0 :
        total+=max(a)
        index=a.index(max(a))
        a[index]=0
    else:
        total-=max(a)
        index=a.index(max(a))
        a[index]=0

print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,u,v;
    cin >> N >> u >> v;
    u--;v--;
    vector<ll> A(N-1), B(N-1);
    vector<vector<ll>> G(N);
    rep(i,N-1){
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    queue<ll> que;
    vector<ll> du(N,1e18), dv(N,1e18);
    que.push(u);
    du[u] = 0;
    while(!que.empty()){
        ll a = que.front();
        que.pop();
        for(auto& b:G[a]){
            if(du[b] != 1e18) continue;
            du[b] = du[a] + 1;
            que.push(b);
        }
    }
    que.push(v);
    dv[v] = 0;
    while(!que.empty()){
        ll a = que.front();
        que.pop();
        for(auto& b:G[a]){
            if(dv[b] != 1e18) continue;
            dv[b] = dv[a] + 1;
            que.push(b);
        }
    }
    ll dis = du[v];
    ll M = 0;
    ll id = 0;
    rep(i,N){
        if(dv[i] - du[i] > 0){
            if(M <= dv[i]){
                M = dv[i];
                id = i;
            }
        }
    }
    //cout << M << " " << id << endl;
    //ll ans = M + (dv[id] - du[id] - 1);// + ll(dis-1);
    ll ans = M-1;
    cout << ans << endl;
}

Measured memory_bytes: 12472
ans=0
n = int(input())
p = list(map(int, input().split()))
for i in range(1, n - 1):
        if (p[i - 1] <= p[i] <= p[i + 1]) or (p[i + 1] <= p[i] <= p[i - 1]):
                ans += 1
print(ans)


Measured memory_bytes: 2940
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
c = [0] + list(map(int, input().split()))
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
s = [1]
order = []
vis = [0] * (N + 1)
ps = [0] * (N + 1)
while len(s):
  x = s.pop()
  vis[x] = 1
  order.append(x)
  for y in e[x]:
    if vis[y]: continue
    s.append(y)
    ps[y] = x

size = [1] * (N + 1)
res = [0] * (N + 1)
d = [dd(int) for _ in range(N + 1)]
for x in order[: : -1]:
  for y in e[x]:
    if y == ps[x]: continue
    size[x] += size[y]
    res[c[x]] += (size[y] - d[y][c[x]]) * (size[y] - d[y][c[x]] + 1) // 2

    if len(d[x]) < len(d[y]): d[x], d[y] = d[y], d[x]
    for z in d[y]: d[x][z] += d[y][z]
  d[x][c[x]] = size[x]


for i in range(1, N + 1):
  print(N * (N + 1) // 2 - res[i] - (N - d[1][i]) * (N - d[1][i] + 1) // 2)

Measured memory_bytes: 212896
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 100000000

using namespace std;

int main() {
   set<int> s;
   int n;
   rep(i,3){
   cin >> n;
   s.insert(n);
}
   cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
using namespace std;

long long jousu(int x) {
	long long y = 1;
	for (int i = 0; i < x; i++) {
		y *= 2;
	}
	return y;
}
int main() {
	long long h,t,c=0;
	cin >> h;
	while (h != 1) {
		h /= 2;
		c++;
	}
	cout << jousu(c + 1) - 1 << endl;
}



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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    
    if((n*a) < b)
    {
        cout << (n*a) << endl;
        return 0;
    }
    else
    {
        cout << b << endl;
    }
    return 0;
}


Measured memory_bytes: 256