akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int N = nk[0];
        int K = nk[1];

        double ans = 0;

        for(int i = 1; i <= N; i++)
        {
            int n = 0;
            if (K < i)
            {
                n = 0;
            }
            else
            {
                n = (int)Math.Ceiling(Math.Log(K / (double)i, 2));
            }

            ans += 1 / Math.Pow(2, n);
        }

        ans /= N;

        Console.WriteLine(ans.ToString("F15"));
    }

    class MyNum
    {
        int bunbo;
        int bunshi;

        void Add(MyNum n)
        {
            this.bunbo = this.bunbo * n.bunbo;
            this.bunshi = this.bunshi * n.bunbo + n.bunshi * this.bunbo;
        }


    }




    static long calcGCD(long num1, long num2)
    {
        if(num1 < num2)
        {
            var tmp = num1;
            num1 = num2;
            num2 = tmp;
        }

        while(true)
        {
            long res;
            long div = Math.DivRem(num1, num2, out res);

            if (res == 0)
            {
                return num2;
            }
            else
            {
                num1 = num2;
                num2 = res;
            }
        }
    }
}


static class MathUtil
{
    public static T Max<T>(params T[] datas)
    {
        return datas.Max();
    }

    public static T Min<T>(params T[] datas)
    {
        return datas.Min();
    }

    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}




Measured memory_bytes: 13268
n,a,b,c,d=map(int,input().split())
s=input()

if c<d:
    if s[a-1:d].find("##")!=-1:
        print("No")
    else:
        print("Yes")

else:
    if s[a-1:c].find("##")!=-1:
        print("No")
    else:
        if s[b-2:d+1].find("...")!=-1:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 3572
n = int(input())
r = int((n*2)**.5)
if r*(r+1)!=n*2:
    print('No')
    exit()


# nは三角数
res = [[] for i in range(r+1)]
tmp = 0
for i in range(r-1):
    # 添字iに[1,2,...,r-i]
    # 添字i+1以降に[1,2,3...]
    for k in range(tmp,r-i+tmp):
        res[i].append(k+1)
        res[i+k-tmp+1].append(k+1)
    #for j in range(i+1,r+1):
    #    res[j].append(tmp+j)
    tmp += r-i
res[-2].append(n)
res[-1].append(n)

print('Yes')
print(len(res))
for l in res:
    print(len(l),*l)
    #print(*l)


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {

    if (i == 0) {
      for (int k = 0; k < N; k++) {
        if (k == N - 1) {
          cout << A[k] << endl;
        } else {
          cout << A[k] << ' ';
        }
      }
      continue;
    }

    int inum = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > inum) {
      int jnum = A[j];
      A[j + 1] = jnum;
      A[j] = inum;
      j -= 1;
    }
    for (int l = 0; l < N; l++) {
      if (l == N - 1) {
        cout << A[l] << endl;
      } else {
        cout << A[l] << ' ';
      }
    }
  }
}



Measured memory_bytes: 3088
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

int main(){
  long ii,jj,kk;
  vector<int> a;
  for(ii=1;ii<=9;ii++){
    for(jj=1;jj<=9;jj++){
      cout << ii << "x" << jj << "=" << ii*jj << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;



int main(){

	string inp;
	int joi,ioi;

	while(cin>>inp){
		joi=0,ioi=0;
		for(int i=0;i<inp.size()-2;i++){
			if(inp[i]=='J'&&inp[i+1]=='O'&&inp[i+2]=='I') joi++;
			if(inp[i]=='I'&&inp[i+1]=='O'&&inp[i+2]=='I') ioi++;
		}
		cout<<joi<<endl;
		cout<<ioi<<endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  vector<int> nums;

  cin >> n;
  for(int i=0; i<n; i++){
    int temp;
    cin >> temp;
    nums.push_back(temp);
  }

  int max = -1;
  int ans = 1;
  for(int i=0; i<n-1; i++){
    if(max < nums.at(i)) max = nums.at(i);

    if(nums.at(i) <= nums.at(i+1) && nums.at(i+1) >= max){
      ans += 1;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long int r,temp,x,y;
  while(scanf("%lld",&x)!=EOF){
    scanf("%lld",&y);
    if(x<y){
      temp=x;
      x=y;
      y=temp;
    }
    long long int a=x;
    long long int b=y;
    while(y!=0){
      r=x%y;
      x=y;
      y=r;
    }
    long long int lcm=a*b/x;
    printf("%lld %lld\n",x,lcm);
  }
  return(0);
}

Measured memory_bytes: 1024
s = input()
n = len(s)

if not s == s[::-1]:
  print("No")
  exit()

x = s[:(n - 1) // 2]

if not x == x[::-1]:
  print("No")
  exit()

y = s[(n + 1) // 2::]

if not y == y[::-1]:
  print("No")
  exit()

print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define maxn 200005

using namespace std;

int a[maxn];
int app[maxn];
int n,k;

int main() {
	scanf("%d%d",&n,&k);
	int cnt=0;
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		app[a[i]]++;
		if (app[a[i]]==1) cnt++;
	}
	sort(app+1,app+n+1);
	int pos=1;
	while (app[pos]==0) pos++;
	int ans=0;
	for (int i=1;cnt-i>=k;i++)
		ans+=app[i+pos-1];
	printf("%d\n",ans);
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string t, b;
  cin >> t >> b;
  int dp[1005][1005] = {};
  reps(i, b.size()){
    reps(j, t.size()){
      if(b[i - 1] == t[j - 1]){
	if(i == 1){
	  dp[i][j] ++;
	} else {
	  dp[i][j] += dp[i - 1][j - 1];
	}
      }
    }
    reps(j, t.size()){
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
      //cout << dp[i][j] << " ";
    }
    //cout << '\n';
  }
  cout << dp[b.size()][t.size()] << '\n';
  return 0;
}



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

int gcd(int a, int b){
    if(a < b) gcd(b,a);

    if(b == -1) return a;

    return a%b == 0 ? b : gcd(b, a%b);
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    vector<int> l(n+1), r(n+1);
    l[0] = -1; 
    r[n] = -1;

    for (int i = 1; i < l.size(); i++)
        l[i] = gcd(l[i-1], a[i-1]);

    //for(auto e:l) std::cout << e << " ";
    //std::cout << endl;

    for (int i = n-1; i >= 0; i--)
        r[i] = gcd(r[i+1], a[i]);

    //for(auto e:r) std::cout << e << " ";
    //std::cout << endl;

    int ans = 1;
    for (int i = 0; i < n; i++)
        ans = max(ans, gcd(l[i],r[i+1]));
    
    std::cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
string s;
 
void init() {
    cin >> s;
}
 
string solve(){
	if(s.at(5) == '1') return "TBD";
	if(s.at(6) - '0' > 4) return "TBD";
	return "Heisei";
}
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	init();
	
    cout << solve() << "\n";
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3e5+5;
char s[N],a[N],b[N],c[5];
int main() {
	//freopen("in.txt","r",stdin);
	int n,q,t=0,ta=0,tb=0;
	scanf("%s%d",s,&q),n=strlen(s);
	for(int i=0,op;i<q;i++) {
		scanf("%d",&op);
		if(op==1) t^=1;
		else {
			scanf("%d%s",&op,c),op--;
			if(op^t) b[tb++]=c[0];
			else a[ta++]=c[0];
		}
	}
	if(!t) {
		for(int i=ta-1;i>=0;i--) printf("%c",a[i]);
		for(int i=0;i<n;i++) printf("%c",s[i]);
		for(int i=0;i<tb;i++) printf("%c",b[i]);
	}
	else {
		for(int i=tb-1;i>=0;i--) printf("%c",b[i]);
		for(int i=n-1;i>=0;i--) printf("%c",s[i]);
		for(int i=0;i<ta;i++) printf("%c",a[i]);
	}
	return 0;
}

Measured memory_bytes: 896
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	map<int,ll> mp;
	string s; cin >> s;
	mp[0]=1;
	ll ans=0;
	ll now=0;
	ll base=1;
	reverse(s.begin(), s.end());
	for(int i=0;i<s.size();i++){
		//now*=10;
		now+=(s[i]-'0')*base%2019;
		now%=2019;
		base*=10;
		base%=2019;
		ans+=mp[now];
		mp[now]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3808
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <list>
#include <vector>

using namespace std;

const int MAXV = 10010;

int v, e;
vector<int> g[MAXV];
int visited[MAXV];
int indegree[MAXV];
list<int> result;

void DFS(int s) {
  queue<int> q;
  q.push(s);
  visited[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    result.push_back(u);
    for (auto v: g[u]) {
      if (!--indegree[v]) {
        q.push(v);
        visited[v] = 1;
      }
    }
  }
}

void TopologicalSort() {
  memset(indegree, sizeof(int), 0);
  memset(visited, sizeof(int), 0);
  for (int i = 0; i < v; ++i) {
    for (auto t: g[i]) {
      ++indegree[t];
    }
  }
  for (int i = 0; i < v; ++i) {
    if (!indegree[i] && !visited[i]) {
      DFS(i);
    }
  }
}

int main() {
  scanf("%d %d", &v, &e);
  for (int i = 0; i < e; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    g[s].push_back(t);
  }

  TopologicalSort();
  for (int u: result) {
    printf("%d\n", u);
  }

  return 0;
}



Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        double sum=0;
        for (int i=0;i<n;i++) {
            double val = sc.nextDouble();
            String cur = sc.next();

            if (cur.equals("JPY")) {
                sum += val;
            } else {
                sum += val * 380000;
            }
        }

        System.out.println(sum);

        sc.close();
    }
}

Measured memory_bytes: 22348
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        mut s: Chars,
    }
    let mut a = vec![0; n + 1];
    for i in 0..n {
        if s[i] == '#' {
            a[i+1] += 1;
        }
        a[i+1] += a[i];
    }


    println!("{}", (0..=n).map(|i|a[i] + n-i - (a[n]-a[i])).min().unwrap());
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include<math.h>
using namespace std;
int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double D = sqrt((x2 - x1)* (x2 - x1) + (y2 - y1) * (y2 - y1));
cout << fixed <<D << endl;
        return 0;
    }
         


Measured memory_bytes: 3268
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

char query(int a,int b,int c){
	int ml=min(a,b);
	int mr=max(a,b);
	int co=(mr+ml)/(ml+1);
	if(co==1){
		if(a<b){
			if(c%2==0)return 'B';
			else return 'A';
		}else{
			if(c%2==0)return 'A';
			else return 'B';
		}
	}
	int N=a+b;
	double L=((double)b+1-(double)co/(co+1)*N)/(1-co)*(co+1)-2;
	double R=((double)b-1-(double)co/(co+1)*N)/(1-co)*(co+1)+2;
	//printf("%f %f\n",L,R);
	for(int i=R;i>=L;i--){
		if(i<0||i>a+b)continue;
		int A=i-i/(co+1)+(a+b-i)/(co+1);
		if(a!=A)continue;
		int acon=i%(co+1);
		if(acon==co&&N-i&&(a+b-i)%(co+1)==0)continue;
		if(i&&acon==0&&(a+b-i)%(co+1)==co)continue;
		
		if(c<i){
			if(c%(co+1)<co)return 'A';
			else return 'B';
		}else{
			if((a+b-c)%(co+1)==0)return 'A';
			return 'B';
		}
	}
	assert(0);
	return 'A';
}
int main(){
	int q;scanf("%d",&q);
	while(q--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		c--;d--;
		for(int i=c;i<=d;i++){
			printf("%c",query(a,b,i));
		}
		printf("\n");
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] a = new long[n];
        for(int i=0; i<n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        long count = 0;
        for(int i=1; i<n; i++) {
            if(a[i]>=a[i-1]) {
                continue;
            }else {
                count += a[i-1]-a[i];
                a[i] = a[i-1];
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 60416
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll X[100000];

ll beki(ll a, ll b) {
  if(b == 0) return 1;
  ll ret = beki(a, b / 2);
  ret = ret * ret % MOD;
  if(b & 1) ret = ret * a % MOD;
  return ret;
}

signed main(){
  int N, K;
  cin >> N >> K;

  for (int i = K; i > 0; i--) {
    X[i] = beki((K / i), N);
    for (int j = 2 * i; j <= K; j += i) {
      X[i] -= X[j];
    }
  }

  ll ans = 0;
  for (int i = 1; i < K + 1; i++) {
    ans += X[i] * i;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    int sum = 0;
    if(x == 1)
    {
        if(y == 1)
        {
            sum = (400000 + 300000 * 2);
        }
        else if(y == 2)
        {
            sum = 300000 + 200000;
        }
        else if(y == 3)
        {
            sum = 300000 + 100000;
        } else
            sum = 300000;
    }
    else if(x == 2)
    {
        if(y == 1)
        {
            sum = 300000 + 200000;
        }
        else if(y == 2)
        {
            sum = 200000 + 200000;
        }
        else if(y == 3)
        {
            sum = 200000 + 100000;
        } else
            sum = 200000;
    }
    else if(x == 3)
    {
        if(y == 1)
        {
            sum = 300000 + 100000;
        }
        else if(y == 2)
        {
            sum = 200000 + 100000;
        }
        else if(y == 3)
        {
            sum = 100000 + 100000;
        } else
            sum = 100000;
    } else
    {
        if(y == 1)
        {
            sum = 300000;
        }
        else if(y == 2)
        {
            sum = 200000;
        }
        else if(y == 3)
        {
            sum = 100000;
        } else
            sum = 0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  ll m = INF;
  for (int i = -100; i < 101; i++){
    ll sum = 0;
    for (int j = 0; j < n; j++){
      sum += (a[j] - i) * (a[j] - i);
    }
    if (sum < m){
      m = sum;
    }
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  char ch, ch_out;

  while(1){
    scanf("%c",&ch);
    if(ch == '\n') break;

    if(ch >= 'A' && ch <= 'Z'){
      ch_out = ch + 'a' - 'A';
      
    } else if(ch >= 'a' && ch <= 'z'){
      ch_out = ch + 'A' - 'a';

    } else ch_out = ch;

    printf("%c", ch_out);
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 524
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i=0; i<N; i++) {
            B[i] = sc.nextInt();
        }

        int ans = solve(N, A, B);

        System.out.println(ans);
    }

    private static int solve(int N, int[] A, int[] B) {

        List<Integer> pos = new ArrayList<>();
        List<Integer> neg = new ArrayList<>();

        for (int i=0; i<N; i++) {
            if (A[i] - B[i] >= 0) {
                pos.add(A[i] - B[i]);
            } else {
                neg.add(B[i] - A[i]);
            }
        }

        Collections.sort(pos, Collections.reverseOrder());
        Collections.sort(neg, Collections.reverseOrder());

        int count = 0;
        int possum = 0;
        while (neg.size() > 0) {
            count++;
            int value = neg.remove(0);

            // System.err.println("current negative = " + value);
            while (possum < value && pos.size() > 0) {
                possum += pos.remove(0);
                // System.err.println("current pos:" + possum);
                count++;
                if (value <= possum) break;
            }

            if (possum < value) return -1;

            possum -= value;
        }

        return count;
    }
}


Measured memory_bytes: 66668
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break

    count = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    count += 1

    print(count)



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }







int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    // 解説みた
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    
    rep(i, 2) rep(j, 2) {
        string t;
        t += (i == 0 ? 'S' : 'W');
        t += (j == 0 ? 'S' : 'W');
        
        rep3(k, 2, sz(s)) { // s[k]求めていく
            if (t[k - 1] == 'S') { // tの末尾が羊か
                if (s[k - 1] == 'o') {
                    t += t[k - 2];
                } else {
                    t += (t[k - 2] == 'S' ? 'W' : 'S');
                }
            } else {
                if (s[k - 1] == 'o') {
                    t += (t[k - 2] == 'S' ? 'W' : 'S');
                } else {
                    t += t[k - 2];
                }
            }
        }
        
        // 手前の2つから最後の文字まで求まった
        // 最後の2つから0番目, 最後と0番目から1番目もあってるか
        
        int flg = 0;
        
        if (t[n - 1] == 'S') {
            if (s[n - 1] == 'o') {
                if (t[n - 2] != t[0]) flg = 1;
            } else {
                if (t[n - 2] == t[0]) flg = 1;
            }
        } else {
            if (s[n - 1] == 'o') {
                if (t[n - 2] == t[0]) flg = 1;
            } else {
                if (t[n - 2] != t[0]) flg = 1;
            }
        }
        
        if (t[0] == 'S') {
            if (s[0] == 'o') {
                if (t[n - 1] != t[1]) flg = 1;
            } else {
                if (t[n - 1] == t[1]) flg = 1;
            }
        } else {
            if (s[0] == 'o') {
                if (t[n - 1] == t[1]) flg = 1;
            } else {
                if (t[n - 1] != t[1]) flg = 1;
            }
        }
        
        if (flg == 0) {
            cout << t << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 712
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
	string s,t;
	cin>>s>>t;
	bool ans=false;
	for(int i=s.size()-t.size();i>=0;i--){
		string k="";
		for(int j=i;j<i+(int)t.size();j++){
			if(s[j]=='?')k.push_back(t[j-i]);
			else k.push_back(s[j]);
		}
		if(k==t){
			ans=true;
			for(int j=0;j<i;j++){
				if(s[j]=='?')cout<<"a";
				else cout<<s[j];
			}
			cout<<t;
			for(int j=i+(int)t.size();j<(int)s.size();j++){
				if(s[j]=='?')cout<<"a";
				else cout<<s[j];
			}
			break;
		}
	}
	if(ans==false)cout<<"UNRESTORABLE"<<endl;
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 100005;
const i64 INF = 1e18;
const int MOD = 323232323;

int main ()
{
    i64 a, b, c, k;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
    if (k & 1) printf("%lld\n", b - a);
    else printf("%lld\n", a - b);
}


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

int h,w,n;
vector<vector<int> > a;

void drop(vector<vector<int> > &v){
  for(int j=0;j<w;j++){
    for(int i=h-1;i>0;i--){
      if(v[i][j] == -1){
	for(int k=i-1;k>=0;k--){
	  if(v[k][j] >= 0){
	    for(int l=0;k-l>=0;l++){
	      v[i-l][j] = v[k-l][j];
	      v[k-l][j] = -1;
	    }
	    break;
	  }
	}
      }
    }
  }
}


void chain(vector<vector<int> > &v){
  int cnt;
  bool f = true;
  bool f2[30][30];
  while(f){
    f = false;
    drop(v);
    fill(f2[0],f2[30],false);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(v[i][j] >= 0){
	  cnt = 1;
	  for(int k=i+1;k<h;k++){
	    if(v[i][j] == v[k][j]) cnt++;
	    else break;
	  }
	  if(cnt >= n){
	    f = true;
	    for(int k=i;k<i+cnt;k++) f2[k][j] = true;
	  }
	  
	  cnt = 1;
	  for(int k=j+1;k<w;k++){
	    if(v[i][j] == v[i][k]) cnt++;
	    else break;
	  }
	  if(cnt >= n){
	    f = true;
	    for(int k=j;k<j+cnt;k++) f2[i][k] = true;
	  }
	}
      }
    }

    if(f)
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  if(f2[i][j]) v[i][j] = -1;
  }
}


bool check(vector<vector<int> > v){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(v[i][j] >= 0) return false;
  return true;
}

void print(vector<vector<int> > v){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cout << v[i][j] << " ";
    cout << endl;
  }
}

bool solve(){
  vector<vector<int> > b;
  chain(a);
  if(check(a)) return true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(a[i][j] != a[i][j+1]){
	b = a;
	swap(b[i][j],b[i][j+1]);
	chain(b);
	//if(i == 3 && j == 2) print(b);
	if(check(b)) return true;
      }
    }
  }
  return false;
}

int main(){
  while(cin >> h >> w >> n){
    a.assign(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	char c;
	cin >> c;
	if(c == '.') a[i][j] = -1;
	else a[i][j] = c - 'A';
      }
    }
    cout << (solve() ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 1228
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, ll> dict;
    for(int i=0;i<N;++i)
    {
        cin >> A[i];
        dict[A[i]]++;
    }

    ll sum = 0;
    for( auto i = dict.begin(); i != dict.end() ; ++i ) {
        sum += ( i->second * (i -> second - 1) ) / 2;
    }

    ll ans, x, y;
    for(int i=0;i<N;++i)
    {
        ans = sum;
        if(dict[A[i]] > 1){
            x = ( dict[A[i]] * (dict[A[i]] - 1) ) / 2;
            y = ( (dict[A[i]] - 1) * (dict[A[i]] - 2) ) / 2;
            ans = sum - x + y;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 12160
#ifndef bhartiya
    // #pragma GCC optimize("Ofast")
    // #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

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

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cout << "\n\nTime elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7

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


int main() 
{ 
    start_routine();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll n; cin>>n;
        string a,b,c;
        cin>>c>>a>>b;
        ll cont = 0;
        rep(i,n){
            if(c[i] == a[i] && a[i] == b[i]){
                continue;
            }
            else if(c[i] != a[i] && a[i] != b[i] && c[i] != b[i]){
                cont += 2;
            }
            else{
                cont++;
            }
        }
        cout<<cont<<endl;
    }
    end_routine();
}

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

int main(){
  int a,b,c,d,time;
  cin >>a>>b>>c>>d;
  if(a>=d||b<=c){
    time=0;
  }else if(a<=c){
    time=min(b-c,d-c);
  }else{
    time=min(b-a,d-a);
  }
  cout << time << endl;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  if (s[0] == 'A') {
    string t(&s[2], s.size() - 3);
    if (count(t.begin(), t.end(), 'C') == 1) {
      size_t cnt = (size_t)count_if(s.begin(), s.end(), [](char t) -> bool {
        return 'a' <= t && t <= 'z';
      });
      if (cnt == s.size() - 2) {
        cout << "AC\n";
        return 0;
      }
    }
  }
  cout << "WA\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007




signed main(){

	int N, C, K;
	int T[100000];
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++)
		cin >> T[i];

	sort(T, T + N);

	int ans = 0;
	for (int i = 0; i < N;){
		int t = T[i] + K;
		int person = 0;
		while (T[i] <= t && person < C) { i++; person++; }

		ans++;
	}

	cout << ans << endl;

	return 0;
}


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

int main(void) {
	int N, K;
	cin >> N >> K;
	double sum = 0.0;
	for (int i = 1; i <= N; i++) {
		int t = i;
		double e = 0;
		while (t < K) {
			t *= 2;
			e++;
		}
		// cout << i << "=" << e << endl;
		double prob = double((double)1 / (double)N) * pow(0.5, e);
		// cout << "prob=" << prob << endl;
		sum += prob;

	}

	cout << std::setprecision(12) << sum << endl;

}

Measured memory_bytes: 256
n = int(input())
hh = list(map(int, input().split()))

result = 'Yes'

if n == 1:
  pass

else:
  num = hh[0]
  flg = False

  for i in range(1, n):
    h = hh[i]

    if num - h >= 2:
      result = 'No'
      break

    # 1小さいとき、1を足した数
    if num - h == 1:
      num = h + 1
      
    else:
      num = h

print(result)
  

Measured memory_bytes: 15020
#include <iostream>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main(){
  string N;
  cin >> N;
  cout << ((N[0] == N[1] && N[0] == N[2]) || (N[3] == N[1] && N[3] == N[2]) ? "Yes" : "No") << endl;
  return 0;
}

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

int main(){
	double R0, W0, C, R;
	while(1){
		double i= 0;
		cin>>R0>>W0>>C>>R;
		if(R0 == 0 && W0 == 0 && C == 0 && R == 0) break;
		
		if(R0/W0 < C){
			for(i = 1; i <=  2147483647 ;i++){
				if((R0 + i * R)/W0 >= C){
					break;
				}
			}
		}
		cout<<i<<endl;
	}
	return 0;
}



Measured memory_bytes: 3228
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//
ll dp[55][55][3000]; //i番目までのカードからj枚使って総和をkにできる総数
//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	int a, b, c; cin >> a >> b >> c;

	if (a == b && b == c) Print(1);
	else if (a == b || b == c || c == a)Print(2);
	else Print(3);

	//
	// your code finished

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	int H, W;
	cin >> H >> W;
	vector<string>a(H);
	rep(i, H)cin >> a[i];
	vector<bool>yoko(H, false), tate(W, false);
	rep(i, H) {
		rep(j, W) {
			if (a[i][j] == '#')yoko[i] = true;
		}
	}
	rep(i, W) {
		rep(j, H) {
			if (a[j][i] == '#')tate[i] = true;
		}
	}
	rep(i, H) {
		if (!yoko[i])continue;
		rep(j, W) {
			if (!tate[j])continue;
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a>12)printf("%d\n",b);
	else if(a>5)printf("%d\n",b/2);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#include<vector>
#define int long long int
#define mod 100000000000
int power(int a,int b)
{
	if(b==0)
	  return 1;
	int r=power(a,b/2);
	r=r%mod;
	if(b%2==0)
	  return (r*r)%mod;
	else
	{
		int x=r*r;
		x=x%mod;
		return (a*x)%mod;
	}
}
int32_t main()
{
    int n;
    cin>>n;
    if(n%2!=0)
      cout<<0<<endl;
   else
   {
	   int answer=0;
	   int val=5;
	   while(val<=n)
	   {
		   int p=n/val;
		   p=p/2;
		   answer=answer+p;
		   val=val*5;
	   }
	   cout<<answer<<endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	char a;
	int c[5]={0};
	while(cin>>c[4]>>a>>c[3]>>a>>c[2]>>a>>c[1]>>a>>c[0]){
		sort(c,c+5);
		//cout<<c[4]<<" "<<c[3]<<" "<<c[2]<<" "<<c[1]<<" "<<c[0];
		if(c[4]==c[1]||c[3]==c[0])cout<<"four card"<<endl;
		else if((c[4]==c[2]&&c[0]==c[1])||(c[0]==c[2]&&c[3]==c[4]))cout<<"full house"<<endl;
		else if((c[4]==(c[3]+1)&&c[3]==(c[2]+1)&&c[2]==(c[1]+1)&&c[1]==(c[0]+1))||(c[0]==1&&c[1]==10&&c[2]==11&&c[3]==12&&c[4]==13))cout<<"straight"<<endl;
		else if((c[4]==c[2]&&c[1]!=c[0])||c[3]==c[1]||(c[2]==c[0]&&c[4]!=c[3]))cout<<"three card"<<endl;
		else if((c[4]==c[3]&&(c[2]==c[1]||c[1]==c[0]))||(c[3]==c[2]&&c[1]==c[0])||(c[1]==c[0]&&(c[4]==c[3]||c[3]==c[2])))cout<<"two pair"<<endl;
		else if(c[4]==c[3]||c[3]==c[2]||c[2]==c[1]||c[1]==c[0])cout<<"one pair"<<endl;
		else cout<<"null"<<endl;
	}
}


Measured memory_bytes: 1176
#include<bits/stdc++.h>
typedef long long ll; 
#define pb push_back
#define mp make_pair
#define mod 998244353
#define vi vector <ll>
using namespace std ; 
ll power(ll x,ll y,ll m)
{            //power(x,y)=x^y  %m;
	ll res=1%m;
	while(y)
	{
	    if(y&1)
	    res=(res*x)%m;
	    x=(x*x)%m;
	    y=(y>>1)%m;
	}
	return res;
}
ll mod_inverse(ll x,ll m)
{
	return power(x,m-2,m);
}
// ll dp[85][100][2];
// ll n;
// ll a[95];
// ll recur(ll day,ll stock,ll paisa,ll parity)
// {
//     cout<<day<<" "<<stock<<" "<<paisa<<"\n";
//     if(day>=n)
//     return 0;
//     if(day==n-1 && stock!=0)
//     {
//         return a[day]*stock;
//     }
//     if( parity!=-1 && dp[day][stock][parity]!=-1)
//     return dp[day][stock][parity];
//     ll ans=-100000000;
//     for(ll i=0;i<=paisa/a[day];i++)
//     {
//         ans=max(ans,paisa-i*a[day]+recur(day+1,stock+i,paisa-i*a[day],0));
//     }
//     for(ll j=0;j<=stock;j++)
//     {
//         ans=max(ans,paisa+j*a[day]+recur(day+1,stock-j,paisa+j*a[day],1));
//     }
//     if(parity!=-1)
//     return dp[day][stock][parity]=ans;
//     else
//     return ans;
    
// }
int main ()
{
    ios_base :: sync_with_stdio ( false );
    cin.tie( NULL );
    cout.tie( NULL );
ll t = 1 ;
//cin>>t;
while (t--)  
{
  ll n;

 cin>>n;
 ll a[n];
 
 for(ll i=0;i<n;i++)
 cin>>a[i];
 ll m=0;
 ll fg=0;
 ll fg1=0;
 ll stock=0;
 ll paisa=1000;
 ll paisaprev=1000;
for(ll i=0;i<n;i++)
{
    if(m==0)
    {ll tt=0;
    while(i+1<n && a[i+1]<=a[i])
    {
        tt=1;
        i++;
    }
    
    
    
    fg++;
    m=1;
    stock=(paisa/a[i]);
    paisaprev=paisa;
    paisa-=stock*a[i];
    i--;
    //cout<<paisa<<" "<<stock<<" ";
        
    }
    else
    {
       while(i+1<n && a[i+1]>=a[i])
    {
        i++;
    }
    fg1++;
    
    paisa+=stock*a[i];
    stock=0;
     //cout<<paisa<<" "<<stock<<" ";
        
        m=0;
    }
}
if(fg==fg1)
{
    cout<<paisa<<"\n";
    continue;
 
}
else
{
    cout<<paisaprev<<"\n";
}
 
}

 return 0;
}

Measured memory_bytes: 3616
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

//ll modexp(ll x, ll y, ll p)
//{
//	ll res = 1;
//	x = x % p;
//	while (y > 0)
//	{
//		if (y & 1)
//			res = (res * x) % p;
//		y = y >> 1;
//		x = (x * x) % p;
//	}
//	return res;
//}

//ll mulmod(ll a, ll b,ll m)
//{
//	return ((a % m) * (b % m)) % m;
// }

// ll sub_mod(ll a, ll b, ll m){
//    if (a >= b)
//        return a - b;
//    else
//        return m - b + a;
// }

// ll add_mod(ll a, ll b){
//    if (0 == b)
//        return a;

//    b = mod - b;
//    if (a >= b)
//        return a - b;
//    else
//        return mod - b + a;
// }

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

// ll modInv(ll a)
// {
//     ll g = gcd(a, mod);
//     if (g != 1)
//         return -1;
//     else
//         return modexp(a, mod-2, mod);
// }

int main()
{
	fastio;
    ll n=0;
    cin>>n;
    for(ll i=1;i<=9;++i){
        for(ll j=1;j<=9;++j){
            if(i*j==n)
            {
                cout<<"Yes";
               return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 998244353;

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

int main() {
    int n; cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin>>a[i];
    }
    sort(a.begin(), a.end());

    ll t = a[0];
    for (int i = 1; i < n; i++) {
        (t*=gcd(a[i], (ll)i))%=MOD;
    }
    cout<<t<<endl;

    return 0;
}

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

using namespace std; 
const int MAX_N = 100005; 
int dp[MAX_N]; 
int h[MAX_N]; 
int n, k; 

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &k); 
	for (int i = 1; i <= n; i++) {
		scanf("%d", &h[i]); 
	}

	for (int i = 2; i <= n; i++) {
		dp[i] = 1000000007;
		for (int j = 1; j <= k && i - j >= 1; j++) {
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); 
		}
	}

	printf("%d", dp[n]); 
	return 0; 
}

Measured memory_bytes: 1024
N = int(input())
P = list(map(int,input().split()))
P.insert(0,10**6)
cnt = 0
flag=0
for i in range(1,N+1):
    if P[i]==i:
        flag += 1
    else:
        if flag%2==0:
            cnt += flag//2
        else:
            cnt += flag//2+1
        flag = 0
if flag%2==0:
    cnt += flag//2
else:
    cnt += flag//2+1
print(cnt)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

string vo = "aeiou";

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

	int n;
	cin >> n;
	int cnt;
	int ans;
	while (n != 0) {
		vector<string> v;
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			string z;
			z.push_back(s[0]);
			for (int j = 1; j < s.length(); j++) {
				for (int k = 0; k < 5; k++) {
					if (s[j - 1] == vo[k]) {
						z.push_back(s[j]);
						break;
					}
				}
			}
			v.push_back(z);
		}
		sort(v.begin(), v.end());
		ans = 0;
		for (int i = 1; i < n; i++) {
			int l1 = min(v[i - 1].length(), v[i].length());
			int l2 = max(v[i - 1].length(), v[i].length());
			int cnt = 0;
			while (cnt<l1&&v[i-1][cnt]==v[i][cnt]){
				cnt++;
			}
			if (l1 == cnt&&l1==l2) {
				ans = -1;
				break;
			}
			ans = max(cnt, ans);
		}
		if (ans != -1)cout << ans + 1 << endl;
		else cout << ans << endl;
		cin >> n;
	}
}


Measured memory_bytes: 3204
s = input()
if s == 'SUN':
  print(7)
if s == 'MON':
  print(6)
if s == 'TUE':
  print(5)
if s == 'WED':
  print(4)
if s == 'THU':
  print(3)
if s == 'FRI':
  print(2)
if s == 'SAT':
  print(1)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int j = 0; j < M; j++){}

int main() {
    int N;
    cin >> N;
    int V[N],C[N];

    for (int i = 0; i < N; i++){
        cin >> V[i];
    }
    for (int i = 0; i < N; i++){
        cin >> C[i];
    }


    int val = 0;
    for (int i = 0; i < N; i++){
        if(V[i] > C[i]){
            val += V[i] - C[i];
        }
    }
    cout << val << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
const int N=2e4+10;
const ll MOD2=998244353;
const ll MOD=1e9+7;

int main(){
    fastio;
    srng;
    #ifdef ALEXPC
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    cout.precision(13);
    int n;
    cin>>n;
    vector<ld> a(n);
    FOR(i,n){
        cin>>a[i];
    }
    sort(all(a));
    ld ans=a[0];
    FORT(i,1,n-1){
        ans=(ans+a[i])/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 12:16-

            String s = sc.next();
            boolean a = check(s.substring(0, 2));
            boolean b = check(s.substring(2));

            if (a && b) {
                out.println("AMBIGUOUS");
            } else if (!a && !b) {
                out.println("NA");
            } else if (a) {
                out.println("MMYY");
            } else {
                out.println("YYMM");
            }
        }
    }

    private static boolean check(String str) {
        int x = Integer.parseInt(str);
        return x > 0 && x <= 12;
    }
}


Measured memory_bytes: 21588
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 1000000007
s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
for i in range(n):
    ans += a[i]*(s[n]-s[i+1])
print(ans%mod)

Measured memory_bytes: 31552
using System;
using System.Collections.Generic;

namespace m_solutions2020_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var A = CIn.ReadLong();
      var B = CIn.ReadLong();
      var C = CIn.ReadLong();
      var K = CIn.ReadInt();

      while (K > 0 && A >= B)
      {
        K--;
        B *= 2;
      }

      while (K > 0 && B >= C)
      {
        K--;
        C *= 2;
      }

      if (A < B && B < C)
      {
        Console.WriteLine("Yes");
      }
      else
      {
        Console.WriteLine("No");
      }
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 27816