akhauriyash/Code-Regression huggingface dataset:
mv=((2,0),(2,1),(2,-1),(-2,0),(-2,1),(-2,-1),
    (0,2),(1,2),(-1,2),(0,-2),(1,-2),(-1,-2))

while True:
    x,y=map(int,raw_input().split())
    if x==y==0:break
    n=input()
    pos=map(int,raw_input().split())
    pos=[(pos[2*i],pos[2*i+1]) for i in range(n)]

    que=[(x,y,0)]
    while que!=[]:
        X,Y,p=que[0][0],que[0][1],que[0][2]
        del que[0]
        S=set()
        if p>=n:
            print "OK"
            break
        for k in range(-1,2):
            for l in range(-1,2):
                S.add((pos[p][0]+k,pos[p][1]+l,p+1))
        for dx,dy in mv:
            mx=X+dx
            my=Y+dy
            if 0<=mx<10 and 0<=my<10 and (mx,my,p+1) in S:
                que.append((mx,my,p+1))
    else:
        print "NA"

Measured memory_bytes: 4288
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main(void){
	char s1[100] = { };
	char s2[100] = { };
	cin >> s1;
	strcpy(s2, s1);
	char p[100] = {};
	cin >> p;
	strcat(s1, s2);
	if (strstr(s1, p) == NULL){
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 3104
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using namespace std;
vector<pair<int, int>> xv;
long long a[100005];
long long b[100005];
int n;


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	b[0] = a[0];
	for (int i = 1; i < n; i++) {
		b[i] = a[i] + b[i - 1];
	}
	int ans = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (2*b[i] < a[i + 1]) break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
n = input()
k = int(input())

keta = len(n)

# dp0 = ヨユーなやつ, dp1 = ギリなやつ
dp0 = [[0 for j in range(keta+1)] for i in range(keta+1)]
dp1 = [[0 for j in range(keta+1)] for i in range(keta+1)]

dp1[0][0] = 1

for i in range(keta):
    for j in range(keta+1):
        # ギリギリのやつ(dp1)の処理
        if n[i] == '0': # i+1桁目が0の場合
            dp1[i+1][j] = dp1[i][j] # 真上からスライド
        else: # i+1桁目が1~9の場合
            if j < keta:
                dp1[i+1][j+1] = dp1[i][j] # 左上からスライド
        
        # ヨユーなやつ(dp0)の処理
        if n[i] == '0': # i+1桁目が0の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
                # 何もない(ギリである0しか入れられないため)
        else: # i+1桁目が1~9の場合
            # i桁目がヨユーな状態ではi+1桁目には何でも入れられる
            dp0[i+1][j] += dp0[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp0[i][j] * 9 # i+1桁目に1~9を入れた場合
            # i桁目までギリだったときの、i+1桁目のヨユーなやつのカウント
            dp0[i+1][j] += dp1[i][j] # i+1桁目に0を入れた場合
            if j < keta:
                dp0[i+1][j+1] += dp1[i][j] * (ord(n[i])-ord('0')-1) # i+1桁目にrange(1, n[i])を入れた場合

if k > keta:
    print(0)
else:
    print(dp0[keta][k] + dp1[keta][k])

Measured memory_bytes: 3440
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <utility>
#include <numeric>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i=0;(i)<(n);(i)++)
#define repi(i, n) for (int i=0;(i)<=(n);(i)++)
#define repr(i, n) for (int i=n;(i)>=0;(i)--)
#define print(x) (cout<<x<<endl)
#define inf (ll)1e18;

int main() {
    int n; cin>>n;
    vvi a(n, vi(n)); rep(i,n) rep(j,n) cin>>a[i][j];
    
    // ワーシャルフロイドで更新されたらアウト
    rep(k,n) {
        rep(i,n) {
            rep(j,n) {
                if (a[i][j]>a[i][k]+a[k][j]) {
                    print(-1);
                    return 0;
                }
            }
        }
    }

    ll ans=0;
    rep(i,n) {
        rep(j,i) {
            ll tmp=inf;
            rep(k,n) {
                if (k==i or k==j) continue;
                tmp = min(tmp, (ll)a[i][k]+a[k][j]);
            }
            if (tmp>a[i][j]) ans+=a[i][j];
        }
    }
    print(ans);
}

Measured memory_bytes: 640
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int A = int.Parse(input[0]);
		int B = int.Parse(input[1]);
		int C = int.Parse(input[2]);
		if (A == B)
        {
			Console.WriteLine(C);
        }
		else if (B == C)
        {
      		Console.WriteLine(A);
        }
      	else
        {
      		Console.WriteLine(B);          
        }
	}
}

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

vector <ll> lower;
vector <ll> upper;

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

	ll i,j,k,l,m,n,t,a,b;

	cin >> n;

	for(i=0;i<n;i++)
	{
		cin >> a >> b;
		lower.push_back(a);
		upper.push_back(b);
	}

	sort(lower.begin(),lower.end());
	sort(upper.begin(),upper.end());

	if(n%2 == 0)
	{
		l = lower[n/2]+lower[n/2-1];
		k = upper[n/2]+upper[n/2-1];
	}	
	else
	{
		l = lower[n/2];
		k = upper[n/2];
	}

	cout << k - l +1 << '\n';
}

Measured memory_bytes: 6660
while True:
    n=int(input())
    if n==0:
        break
    ice=list([0]*10)
    for i in range(n):
        c=int(input())
        ice[c]+=1
    for i in range(10):
        if ice[i]>0:
            for j in range(ice[i]):
                print(*'*',end='')
            print()
        else:
            print('-')


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


char data[20][20];
int w, h;


class State{
public:
  char x, y;
  char data[20][20];
  char cnt;

  bool operator <(const State &s) const {
    if(x != s.x) return x < s.x;
    if(y != s.y) return y < s.y;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	if(this->data[i][j] != s.data[i][j]) {
	  return this->data[i][j] < s.data[i][j];
	}
      }
    }
    return false;
  }

  void cp(char data[20][20]) {
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	this->data[i][j] = data[i][j];
      }
    }
  }

};

int solve(int sx, int sy) {
  const int dx[4] = {1,0,-1,0};
  const int dy[4] = {0,1,0,-1};
  queue<State> Q;
  State s;

  s.x = sx;
  s.y = sy;
  s.cp(data);
  s.cnt = 1;

  Q.push(s);

  while(!Q.empty()) {
    s = Q.front();
    Q.pop();
    if(s.cnt > 10) break;

    for(int i = 0; i < 4; i++) {
      int nx = s.x;
      int ny = s.y;
      for(int j = 1; ; j++) {
        nx += dx[i];
        ny += dy[i];
	if(nx < 0 || nx >= w) break;
	if(ny < 0 || ny >= h) break;
	if(s.data[ny][nx] == '1') {
	  if(j == 1) break;
	  State tmp = s;
	  tmp.data[ny][nx] = '0';
	  nx -= dx[i];
	  ny -= dy[i];
	  tmp.x = nx;
	  tmp.y = ny;
	  tmp.cnt++;
	  Q.push(tmp);
	  break;
	} else if(s.data[ny][nx] == '3') {
	  return s.cnt;
	}
      }
    }
  }
  return -1;
}

main() {
  int sx, sy;
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> data[i][j];
	if(data[i][j] == '2') {
	  sx = j;
	  sy = i;
	  data[i][j] = '0';
	}
      }
    }
    cout << solve(sx, sy) << endl;
  }
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a, b, t[1000], r;

int main() {
	cin >> n >> a >> b;
	rep(i,n) cin >> t[i];
	sort(t, t+n);
	rep(i,n) r += (t[i]<a || b<=t[i]);
	cout << r << ln;
}

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

int main(){
  int n;
  cin >> n;
  int house[4][3][10] = {};
  int b,f,r,v;
  for(int i=0; i<n; i++){
    cin >> b >> f >> r >> v;
    house[b-1][f-1][r-1] += v;
  }

  for(int bi=0; bi<4; bi++){
    for(int fi=0; fi<3; fi++){
      for(int ri=0; ri<10; ri++){
        cout << " " << house[bi][fi][ri];
      }
      cout << endl;
    }
    if(bi != 3){
      cout << "####################" << endl;
    }
  }


}

Measured memory_bytes: 3040
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::min;
use itertools::Itertools;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr >() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn count_two(n: u64) -> u64 {
    fn go(count: u64, num: u64) -> u64 {
        if num % 2 == 0 {
            go(count + 1, num / 2)
        } else {
            count
        }
    }
    go(0, n)
}

fn main() {
    let n:u64 = read();
    let ss:Vec<String> = (0..n).map(|_|read()).collect();
    let mut hm = HashMap::new();
    for s in ss {
        let first_letter = s.chars().next().unwrap();
        let entry = hm.entry(first_letter).or_insert(0);
        *entry += 1;
    }
    let ans:u64 = ['M', 'A', 'R', 'C', 'H'].iter()
        .map(|l|*hm.get(l)
        .unwrap_or(&0_u64))
        .combinations(3)
        .map(|x|x[0] * x[1] * x[2]).sum();
    println!("{}", ans);
}



Measured memory_bytes: 7516
let i=readLine()!.characters.split(" ").map{Int(String($0))!},m=Int(1e9+7)
func f(x:Int)->Int{return (1...x).reduce(1){$0*$1%m}}
print(f(i[0])*f(i[1])*max(2-abs(i[0]-i[1]),0)%m)

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  bool fwins=false;
  rep(i,n) {
    cin>>a;
    if(a%2==1) fwins=true;
  }
  if(fwins) puts("first");else puts("second");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int n, k, a;
    int cnt[200000] = {};

    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        cnt[a - 1]++;
    }
    sort(cnt, cnt + n);
    reverse(cnt, cnt + n);
    for (int i = 0; i < k; i++)
    {
        n -= cnt[i];
    }
    cout << n << endl;
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int D, T, S;
    cin >> D >> T >> S;
    if (S * T >= D) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

    return 0;
}



Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll>Q;



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

Measured memory_bytes: 3624
from collections import defaultdict
dp = defaultdict(lambda:int(10**9))

N = int(input())
L = list(map(int, input().split()))
dp[0] = 0
for i in range(0, N):
    if i+1 < N:
        dp[i+1] = min(dp[i+1], dp[i] + abs(L[i+1] - L[i]))
        if i+2 < N:
            dp[i+2] = min(dp[i+2], dp[i] + abs(L[i+2] - L[i]))

print(dp[N-1])


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

#define  rep(i,n)   for(int i=0; i<(int)n; i++)
#define  per(i,n)   for(int i=((int)n)-1; i>=0; i--)
#define  mem(x,y)   memset(x,y,sizeof(x))
#define  read(f)    freopen(f, "r", stdin)
#define  write(f)   freopen(f, "w", stdout)
#define  pii        pair<int,int>
#define  mp         make_pair
#define  ff         first
#define  ll         long long
#define  ss         second
#define  pb         push_back
#define  __         printf("\n")
#define  N          1000000

vector <int> divisor[N + 5];

void count_div()
{
    for( int i = 1; i <= N; i++ )
    {
        for( int j = i ; j <= N; j += i )
            divisor[j ].pb( i );
    }
    return;
}

int main()
{
    count_div();
    int n;
    while( cin >> n )
    {
        ll t = n, sum = 0;
        rep( i, n - 1 )
        {
            sum += divisor[t - ( i + 1 )].size();
        }
        cout << sum << endl;
    }
    return 0;
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  int l, r=0, a[n];
  vector<int> list;
  int cost;
  while(cin>>l){
    a[r]=l;
    r++;
  }
  sort(a,a+n);
  
  for(int i = a[0]; i<=a[n-1]; i++){
    cost=0;
    for(int j=0; j<n; j++){
      cost=cost+pow(a[j]-i, 2);
    }
    list.push_back(cost);
  } 
  vector<int>::iterator iter = min_element(list.begin(), list.end());
  cout<<iter[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
using ll = long long;
using namespace std;

signed main(){
    ll input, i = 1;
    cin >> input;
    while(1){
        if(i * i > input){
            i--;
            break;
        }
        i++;
    }
  	ll answer = i * i;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
l, r = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(n, 2).T

def main():
    
    return np.sum(r - l + 1)

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    k--;
    int sk = s[k]-'A';
    s[k] = 'a'+sk;
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , d;
    long long int c = 1;
    cin >> n;
    int a[1000] = {};
    for ( int i = 1 ; i <= n ; i++ ) {
        d = i;
        for ( int j = 2 ; j <= i ; j++ ) {
            while ( d % j == 0 ) {
                d /= j;
                a[j - 1] += 1;
            }
        }
    }
    for ( int i = 0 ; i < n ; i++ ) {
        c *= a[i] + 1;
        c %= 1000000007;
    }
    cout << c;
}


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


int main() {
    int a,b;
    cin >> a >> b;
    if(a>b){
        cout << 2*a-1 <<endl;
    }
    else if(a<b)
    {
        cout << 2*b-1 <<endl;
    }
    else {
        cout <<2*a <<endl;
    }
}

Measured memory_bytes: 256
import math

# 有理数型をインポート

# 組合せの総数
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result


X, Y = (int(i) for i in input().split())

i = (2*X-Y)//3
j = (2*Y-X)//3

if(  i < 0 or j < 0 or (2*X-Y)%3!=0 or (2*Y-X)%3!=0 ):
    print(0)
else:
    print(cmb(i+j, i) % 1000000007)


Measured memory_bytes: 45748
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin>>n;
        if(n==0) break;
        double s[n];
        double sum=0;
        for(int i=0;i<n;i++){
            cin>>s[i];
            sum+=s[i];
        }
        double ave=sum/n;
        double powsum=0;
        for(int i=0;i<n;i++){
            powsum+=pow((s[i]-ave),2);
        }
        double sigma=sqrt(powsum/n);
        cout<<fixed<<setprecision(8)<<sigma<<endl;
    }
}


Measured memory_bytes: 3276
/*
倒数第一次操作前,有蓝边(u,v),删除蓝边(u,v)并加入红边(u,v) 
倒数第二次操作前,有蓝边(u,v),以及蓝边(u,z)/(v,z)/(x,y)...(z为u,v两点所能到达的点)
可以发现最后一次操作时边(u,v)必须同时出现在红树和蓝树中 

反向操作，从后往前手玩 
倒数第一次操作，删除红边(u,v)并加入蓝边(u,v) 
倒数第二次操作，删除红边(u,z)/(v,z)/(x,y)，加入蓝边(u,z)/(v,z)/(x,y) 
如果在倒数第一次操作前将u,v两点缩为一点U
则倒数第二次操作为删除红边(U,z)，加入蓝边(U,z)(z为U所能到达的点)
...
如果恰能操作n-1次，则YES,否则NO 

将红树和蓝树建在一起
当连接两点之间的边等于2(一条红边一条蓝边，用map维护两点之间的边数)
则这两个点可以进行一次反向操作
维护队列q,记录当前可以进行操作的点对。
每次操作：
+ 取出队头(u,v)，缩点(并茶几,fa[v]=u)，删除边(u,v),(v,z),加入边(u,z)(z为原来v所连接的边)。
+ 当加入边时，当(u,z)的边数为2，将该点对加入队列 
*/
#include<iostream>
#include<queue>
#include<set>
#include<map>
#define MAXN 100000+233
#define QWQ 1000000
#define ll long long
using namespace std;

int n;
int u,v;
set<int>edge[MAXN];
queue<pair<int,int> >q;
map<ll,int>ma;
int fa[MAXN];

//map
ll ys(ll x,ll y)
{
	if(x>y) swap(x,y);
	return x*QWQ+y;
}
//并茶几 
int findd(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=findd(fa[x]);
}
void init()
{
	for(int i=1;i<=n;i++)
		fa[i]=i;
}
void edge_clean(int u,int v)
{
	edge[u].erase(v);
	edge[v].erase(u);
	ma.erase(ys(u,v));
}
void edge_add(int u,int v)
{
	edge[u].insert(v);
	edge[v].insert(u);
	ma[ys(u,v)]++;
	if(ma[ys(u,v)]==2)
		q.push(make_pair(u,v));
}
bool solve()
{
	init();
	for(int i=1;i<n;i++)
	{
//		cout<<i<<endl;
		if(q.empty()) return 0;
		int u=q.front().first,v=q.front().second;
		q.pop();
		u=findd(u);v=findd(v);
//		cout<<i<<endl;
		if(edge[u].size()<edge[v].size())swap(u,v);
		fa[v]=u;
		edge_clean(u,v);
//		cout<<i<<endl;
		set<int>::iterator it,it2;
//		cout<<"v="<<v<<endl;
		for(it=edge[v].begin();it!=edge[v].end();it=it2)
		{
			it2=it;it2++;
//			cout<<"*it="<<*it<<endl;
//			system("pause");
			int to=*it;to=findd(to);/////
			edge_clean(to,v);
			edge_add(to,u);
		}
//		cout<<i<<endl;
	}
	return 1;
}
int main()
{
//	freopen("1.in","r",stdin);
	cin>>n;
	for(int i=1;i<=(n-1)*2;i++)
	{
		cin>>u>>v;
//		cout<<"qwq "<<u<<" "<<v<<endl;
		edge[u].insert(v);
		edge[v].insert(u);
		ma[ys(u,v)]++;
		if(ma[ys(u,v)]==2)
			q.push(make_pair(u,v));
	}
//	for(int i=1;i<=n;i++)
//	{
//		set<int>::iterator it;
//		cout<<i<<":";
//		for(it=edge[i].begin();it!=edge[i].end();it++)
//		{
//			cout<<*it<<" ";
//		}
//		cout<<endl;
//	}
//	cout<<"qwq\n";
	if(solve()) cout<<"YES";
	else cout<<"NO"; 
}

Measured memory_bytes: 36608
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int gyou, retsu, a, b; cin >> gyou >> retsu >> a >> b;
    int ans = gyou * retsu - (retsu * a + (gyou - a) * b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, l;
  cin >> n >> l;
  ll a[n], ans = 0;
  rep(i, 0, n) {
    a[i] = i + l;
    ans += a[i];
  }
  if (-1 * n >= l)
    ans -= a[n - 1];
  else if (l > 0)
    ans -= a[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  b, c, d, e, X, Y;
  //  double  c;
  long long  A[200003]={};
  long long  B[100003]={};
  int  C[100003]={};

  int  flag[103]={};

//  long long  a, b, c, d, X, Y;
  char s[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
//  int flag=0;
  int tmp=0;
//  int min=1000000;
  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int ans=0;
  int max=0;
  int addr=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
//  scanf("%d%d", &a,&c);
//  cnt = strlen(t);
// printf("%d\n",a);
    scanf("%d%d", &a,&b);
/*  for(i=0;i<a;i++){
    scanf("%lld", &A[i]);
  }
//  puts("");
  addr=a;
  for(i=0;i<b;i++){
    scanf("%lld%lld", &B[0],&B[1]);
    for(j=0;j<B[0];j++,addr++){
      A[addr]=B[1];
      cnt++;
    }
  }
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   
  ans=a*3;
  ans=(ans+b)/2;
  printf("%d\n", ans);

  
//  printf("%lf\n",ans);
  //  //  if(flag==0)   printf("TLE\n");
//    if(max < cnt - max)  printf("Yes\n");
//    else  printf("No\n");
  
return 0;
}


Measured memory_bytes: 128
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package dp;

/**
 *
 * @author aakas
 */
import java.util.*;
public class Main {
    static int n;
    static int m;
    static int[] w;
    static long[] va;
    static boolean[][] v;
    static long[][] dp;
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        w = new int[n];
        va = new long[n];
        v = new boolean[n][m+1];
        dp = new long[n][m+1];
        for(int i=0;i<n;i++)
        {
            w[i] = sc.nextInt();
            va[i] = sc.nextLong();
        }
        System.out.println(s(0,m));
    }
    public static long s(int i,int m)
    {
        if(i>n-1)
            return 0;
        if(m<w[i])
            return s(i+1,m);
        if(v[i][m])
            return dp[i][m];
        v[i][m] = true;
        return dp[i][m] = Math.max((long)(va[i]+s(i+1,m-w[i])),s(i+1,m));
    }
}


Measured memory_bytes: 126916
#include<stdio.h>
int main()
{
  int a;
  int b;
  int c;
  scanf("%d %d %d",&a,&b,&c);
  if(a<b&&b<c){
            printf("Yes\n");
           }
  else{
       printf("No\n");
      }
  return 0;
}

Measured memory_bytes: 580
#include    <iostream>
#include    <algorithm>
#include    <vector>

using namespace std;

int main() {
    vector<int> cum;
    int n, sum, tmp;
    
    while(true) {
        cin >> n;
        if(n == 0) { break; }
        
        cum.resize(n+1);
        cum[0] = 0;
        sum = (-2147483647);
        
        for(int i = 1; i <= n; i++) {
            cin >> tmp;
            cum[i] = cum[i-1] + tmp;
        }

        for(int i = 0; i < n; i++) {
            for(int j = i+1; j <= n; j++) {
                sum = max(sum, cum[j] - cum[i]);
            }
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3008
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=100010;
int n,first[maxn],nxt[maxn<<2],to[maxn<<2],e;
void AddEdge(int u,int v) {
	to[++e]=v;nxt[e]=first[u];first[u]=e;
	to[++e]=u;nxt[e]=first[v];first[v]=e;
}
int f[maxn],A[maxn];
void dp(int x,int fa) {
	f[x]=0;
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa) dp(to[i],x);
	int m=0;
	for(int i=first[x];i;i=nxt[i]) if(to[i]!=fa) A[++m]=f[to[i]];
	sort(A+1,A+m+1);
	rep(i,1,m) f[x]=max(f[x],A[i]+m-i+1);
}
int main() {
	n=read();
	rep(i,2,n) AddEdge(read(),i);
	dp(1,0);
	printf("%d\n",f[1]);
	return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main() {
    int n; cin >> n;
    int total = 0;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    total += v[0];
    rep(i, n-1){
        if (v[i+1] > v[i]){
            total += v[i+1] - v[i];
        }
    }
    cout << total << endl;
    return 0;
}


Measured memory_bytes: 256
C = [[int(i) for i in input().split()] for j in range(3)]


c0 = C[0][0]-C[1][0]
c1 = C[0][1]-C[1][1]
c2 = C[0][2]-C[1][2]

d0 = C[1][0]-C[2][0]
d1 = C[1][1]-C[2][1]
d2 = C[1][2]-C[2][2]

e0 = C[0][1]-C[0][2]
e1 = C[1][1]-C[1][2]
e2 = C[2][1]-C[2][2]

if (c0 == c1 and c1 == c2) and (d0 == d1 and d1 == d2) and (e0 == e1 and e1 == e2):
    print('Yes')
else:
    print('No')

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

int main(){
  
  int a,b,d,e,f;
  cin >> a >> b;
  
  d = a+b;
  e = a-b;
  f = a*b;
    
    cout << max( max(d,e),max(e,f) ) << endl;
   
}
  


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

//挿入ソートで数列を昇順に並び替えるプログラム
int main(){
    int N, i, j, prev, array[100] = {};
    cin >> N;

    //N個の整数を配列に格納
    i = 0;
    while(i < N){
        cin >> array[i];
        cout << array[i];
        if (i < N-1) cout << ' ';
        i++;
    }
    cout << endl;

    //挿入ソート
    i = 1;
    while(i < N){
        prev = array[i];
        j = i - 1;
        while(j >= 0 && array[j] > prev){
            array[j+1] = array[j];
            j--;
        }
        array[j+1] = prev;
        
        j = 0;
        while(j < N){
            cout << array[j];
            if (j < N-1) cout << ' ';
            j++;
        }
        cout << endl;
        i++;
    }

    return 0;
}


Measured memory_bytes: 3076
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	long long h;
	long long n;
	cin >> h;
	cin >> n;
	long long sum = 0;
	long long A[1000000+1];
	for (long long i = 0; i < h; i++) {
		cin >> A[i];
	}
	if (h <= n) {
		cout << 0 << endl;
	}
	else {
		sort(A, A + h);
		for (long long i = 0; i < h - n; i++) {
			sum += A[i];
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a,b;
  scanf("%d %d %d",&n,&a,&b);
  printf("%d %d\n",MIN(a,b),MAX(0,a+b-n));
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#define int long long
using namespace std;

int q;
int t, a, b;
priority_queue<int> queL;
priority_queue<int, vector<int>, greater<int>> queR;

signed main() {
	int i;
	
	int bsum = 0;
	int queLsum = 0;
	int queRsum = 0;
	
	cin >> q;
	while (q--) {
		cin >> t;
		if (t == 1) {
			cin >> a >> b;
			bsum += b;
			
			if (queR.empty() || a < queR.top()) {
				queL.push(a);
				queLsum += a;
			}
			else {
				queR.push(a);
				queRsum += a;
			}
			
			int n = queL.size() + queR.size();
			while (queL.size() > (n + 1) / 2) {
				int res = queL.top();
				queLsum -= res;
				queL.pop();
				queR.push(res);
				queRsum += res;
			}
			while (queL.size() < (n + 1) / 2) {
				int res = queR.top();
				queRsum -= res;
				queR.pop();
				queL.push(res);
				queLsum += res;
			}
		}
		else {
			int x = queL.top();
			int fxL = x * queL.size() - queLsum;
			int fxR = queRsum - x * queR.size();
			int fx = fxL + fxR;
			cout << x << " " << fx + bsum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3828
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{

	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	int max1 = 0;
	int max2 = 0;
	int array[3];
	array[0] = A;
	array[1] = B;
	array[2] = C;
	int idx;

	for (int i = 0; i < 3; i++)
	{
		if (array[i] > max1)
		{
			max1 = array[i];
			idx = i;
		}
	}

	array[idx] = 0;
	for (int i = 0; i < 3; i++)
	{
		if (array[i] > max2)
		{
			max2 = array[i];
			idx = i;
		}
	}
	array[idx] = 0;

	char ch[4] = {'\0'};

	ch[0] = max1 + '0';
	ch[1] = max2 + '0';
	int res = atoi(ch);

	for (int i = 0; i < 3; i++)
	{
		res = res + array[i];
	}

	printf("%d", res);

	return 0;
}


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

using ll = long long;
#define REP(i, n) for(int (i)=0; (i)< (n); ++i)
#define REPR(i, n) for(int (i)=(n); (i)>=0; --i)
#define FOR(i, n, m) for(int (i)=(n); (i)<(m); ++i)

int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> p(A), q(B), r(C);
  REP(i, A){
    cin >> p[i];
  }
  REP(i, B){
    cin >> q[i];
  }
  REP(i, C){
    cin >> r[i];
  }
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());
  priority_queue<int> pq;
  REP(i, X){
    pq.push(p[i]);
  }
  REP(i, Y){
    pq.push(q[i]);
  }
  REP(i, C){
    pq.push(r[i]);
  }
  ll ans = 0;
  REP(i, X+Y){
    ans += pq.top(); pq.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    LR = [None] * N
    for i in range(N):
        X, L = map(int, input().split())
        LR[i] = (X - L, X + L)

    LR.sort(key=itemgetter(0))
    ans = N
    cur_R = LR[0][1]
    for L, R in LR[1:]:
        if L < cur_R:
            ans -= 1
            if R < cur_R:
                cur_R = R
        else:
            cur_R = R

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23928
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	factors := factorize(n)

	count := 0
	for _, pair := range factors {
		i := 1
		for pair[1] >= i {
			pair[1] -= i
			i++
			count++
		}
	}

	fmt.Printf("%d\n", count)
}

func factorize(n int) [][]int {
	factors := [][]int{}
	for f := 2; f*f <= n; f++ {
		i := 0
		for n%f == 0 {
			n = n / f
			i++
		}
		if i > 0 {
			factors = append(factors, []int{f, i})
		}
	}
	if n > 1 {
		factors = append(factors, []int{n, 1})
	}
	return factors
}


Measured memory_bytes: 1864
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	int c[99],m[99]={6,8,4,4,3,5,8,6,4,8,4,5,8,8,5,3,8,4,5,5,8,8,6,8,8,8,3,6,6,8,6,6},d[99]={37,154,5,1,6,9,155,16,7,152,6,4,153,158,5,7,159,8,6,7,156,157,2,146,147,144,5,0,3,145,17,1},
	buffer=0,t,p=0,i,w[99]={65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,32,46,44,45,39,63};

	c[32]=26,c[39]=27,c[44]=28,c[45]=29,c[46]=30,c[63]=31;
	for(i=0;i<=25;i++)
		c[65+i]=i;
	while(t=getchar())
	{
		if(t==10||t==-1)
		{
			if(p>0)
				putchar(w[buffer<<5-p]);
			if(t==-1)
				break;
			puts("");
			buffer=p=0;
		}
		else
		{
			i=c[t];
			buffer<<=m[i];
			buffer|=d[i];
			p+=m[i];
			for(;p>=5;p-=5)
			{
				putchar(w[buffer>>p-5]);
				buffer&=~(31<<p-5);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
int n, k, a, b;
ll x;
int main() {
	io	
	cin>>x;
	ll cur = 100;
	for(int i = 1; i<=(x-100)+1; i++) {
		double curx = cur;
		cur += (ll)(0.01*(curx));
		if(cur >= x) {
			cout<<i;
			break;
		}
	}
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int dp[101][10001];
int w[101],v[101];
int n,W;

int solve(int i,int j){
//    static int cou=0;
//    cou++;
//    cout << cou << endl;
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res;
    if(i==n){
        res=0;
    }else if(j<w[i]){
        res=solve(i+1,j);
    }else{
        res=max(solve(i+1,j),solve(i+1,j-w[i])+v[i]);
    }
    dp[i][j]=res;
    return res;
}

int main(){
    cin >> n >> W;
    REP(i,n+1)REP(j,W+1)dp[i][j]=-1;
    REP(i,n){
        cin >> v[i] >> w[i];
    }

    int ans=solve(0,W);
    cout << ans << endl;
}



Measured memory_bytes: 7040
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(const void *a, const void *b) {
  return *(char *)a - *(char *)b;
}
int compareReverse(const void *a, const void *b) {
  return *(char *)b - *(char *)a;
}
int main() {
  char s[101], t[101];
  unsigned slen, tlen, i, lmin;
  scanf("%s", s);
  scanf("%s", t);
  slen = strlen(s);
  tlen = strlen(t);
  lmin = slen > tlen ? tlen : slen;
  qsort(s, slen, sizeof(char), compare);
  qsort(t, tlen, sizeof(char), compareReverse);
  for (i = 0; i < lmin; i++) {
    if (s[i] < t[i]) {
      puts("Yes");
      return 0;
    } else if (s[i] > t[i]) {
      puts("No");
      return 0;
    }
  }
  puts(slen < tlen ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	int a, b, c; scanf("%d%d%d", &a, &b, &c);
	if (a <= c&&c <= b) {
		puts("Yes");
	}
	else puts("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    double x[2];
    double y[2];
    double r[2];
    rep(i,2)cin>>x[i]>>y[i]>>r[i];
    double d=hypot(x[1]-x[0],y[1]-y[0]);
    if(d>r[0]+r[1])cout<<0<<endl;
    else if(r[0]>r[1]&&r[0]-r[1]>d)cout<<2<<endl;
    else if(r[1]>r[0]&&r[1]-r[0]>d)cout<<-2<<endl;
    else cout<<1<<endl;
  }


}

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

// O(n^3)のアルゴリズム
int solve(int n, int x)
{
  int cnt = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = i + 1; j <= n; j++)
    {
      for (int k = j + 1; k <= n; k++)
      {
        if (i + j + k == x)
        {
          cnt++;
        }
      }
    }
  }
  return cnt;
}

int main()
{
  int n, x;
  while (1)
  {
    cin >> n >> x;
    if (n == 0 && x == 0)
    {
      return 0;
    }
    cout << solve(n, x) << endl;
  }
}


Measured memory_bytes: 3092
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for _ in range(n)]
cnt = 0
G = [int(pow(4, i) + 3*pow(2, i-1) + 1) for i in range(10)[::-1]] + [1]
G = [v for v in G if v <= n]
m = len(G)
for i in range(m):
    insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')

Measured memory_bytes: 63296
m,d = gets.split(" ").map(&:to_i)
count = 0
if d <= 21 then
    count = 0
else
    for i in 1..m do
        for j in 22..d do
            k = j / 10 
            l = j % 10
            mul = k * l
            if i == mul && k >= 2 && l >= 2 then
                count += 1
            end
        end
    end
end
puts count

Measured memory_bytes: 1788
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	long double ans=0;
	for(int i=1;i<=n;i++)
	{
		double ans_t = 1.0;
		int t=i;
		while(t<k){
			t*=2;
			ans_t *= 0.5;
		}
		ans += ans_t;
	}
	printf("%.12Lf\n",ans/n);
}

Measured memory_bytes: 256
MOD = 10**9 + 7

N, K = map(int, input().split())

def getFacts(n, MOD):
    facts = [1] * (n+1)
    for x in range(2, n+1):
        facts[x] = (facts[x-1] * x) % MOD
    return facts
facts = getFacts(2*N, MOD)
def getInvFacts(n, MOD):
    invFacts = [0] * (n+1)
    invFacts[n] = pow(facts[n], MOD-2, MOD)
    for x in reversed(range(n)):
        invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
    return invFacts
invFacts = getInvFacts(2*N, MOD)
def getComb(n, k, MOD):
    if n < k:
        return 0
    return facts[n] * invFacts[k] * invFacts[n-k] % MOD

ans = 0
for x in range(min(K, N-1)+1):
    ans += getComb(N, x, MOD) * getComb(N-1, x, MOD)
    ans %= MOD

print(ans)


Measured memory_bytes: 40412
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int s = sc.nextInt();
    HashSet<Integer> set = new HashSet<>();
    set.add(s);
    int n = s;
    int i = 2;
    while (true) {
      int f = n % 2 == 0 ? n / 2 : 3 * n + 1;
      if (set.contains(f)) break;
      set.add(f);
      i++;
      n = f;
    }
    System.out.println(i);
  }
}

Measured memory_bytes: 21204
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    sort(all(v));
    v[n-1]/=2;
    cout<<accumulate(all(v),0);

    

    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private string S;
    public void Solve()
    {
        S = Console.ReadLine();
        HashSet<char> hs = new HashSet<char>();
        foreach(char c in S)
        {
            if (!hs.Add(c))
            {
                Console.WriteLine("no");
                return;
            }
        }
        Console.WriteLine("yes");
    }
}



Measured memory_bytes: 13396
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
      string s;
      cin >> s;

      if(s.back() == 's')
        s += "es";
     else
        s += 's';

    cout << s;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);   
    //TEST
     solve();
}



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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String[] NLarr = scan.nextLine().split(" ");
		
		//N개의 string을 입력받는다
		int N = Integer.parseInt(NLarr[0]);
		
		//각 string은 L의 길이를 갖는다
		int L = Integer.parseInt(NLarr[1]);
		
		
		//N개의 string을 저장할 배열을 생성한다.
		String[] strArr = new String[N];
		String str = "";
		
		//N개의 string을 입력받아 배열을 초기화한다.
		for(int i=0; i<N;){
			str = scan.next().toLowerCase();
			if(str.length() == L){
				strArr[i] = str;
				i++;
			}
		}
		
		scan.close();
			
		Arrays.sort(strArr);
		
		//최종 출력
		String print="";
		
		for(String _print : strArr){
			print += _print;			
		}
		
		System.out.println(print);
	}
}

Measured memory_bytes: 27732
def N(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[1]
  t1[1]=d1[5]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[0]
  t1[5]=d1[4]
  return t1
def S(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[4]
  t1[1]=d1[0]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[5]
  t1[5]=d1[1]
  return t1
def E(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[3]
  t1[1]=d1[1]
  t1[2]=d1[0]
  t1[3]=d1[5]
  t1[4]=d1[4]
  t1[5]=d1[2]
  return t1
def W(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[2]
  t1[1]=d1[1]
  t1[2]=d1[5]
  t1[3]=d1[0]
  t1[4]=d1[4]
  t1[5]=d1[3]
  return t1
d1=[0 for i in range(6)]
d2=[0 for i in range(6)]
d1[:]=(int(x) for x in input().split())
d2[:]=(int(x) for x in input().split())

if d1[2]==d2[0]:
  d2=E(d2)
elif d1[2]==d2[1]:
  d2=N(d2)
  d2=E(d2)
elif d1[2]==d2[3]:
  d2=E(d2)
  d2=E(d2)
elif d1[2]==d2[4]:
  d2=S(d2)
  d2=E(d2)
elif d1[2]==d2[5]:
  d2=W(d2)
elif d1[2]!=d2[2]:
  print("No")
  exit()

if d1==d2:
  print("Yes")
  exit()

for i in range(3):
  d2=N(d2)
  if d1==d2:
    print("Yes")
    exit()

print("No")

  


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	bool f=false;
	if(a<b&&b<c)
    {
    	cout<<"Yes";
    	return 0;
	}
	while(1)
	{
	   if(a>=b&&k>0)
	   {
	   b*=2;
	   k--;
	   continue;
	   }
	   if(b>=c&&k>0)
	   {
	   c*=2;
	   k--;
	   continue;
	   }	
	   if(a<b&&b<c&&k>=0)
	   {
	   	cout<<"Yes";
	   	return 0;
	   }
	   if(k==0)
	   {
	   if(a>=b||b>=c)
	   cout<<"No";
	   return 0;
	   }
	}
}

Measured memory_bytes: 3640