akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_JEWEL_MAX		100										// 最大宝石数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Jewel[D_JEWEL_MAX];								// 宝石
static int siJCnt;												// 宝石数
static int siOCnt;												// 操作回数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - int降順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int降順
	if (*lipVal1 > *lipVal2) {
		return -1;
	}
	else if (*lipVal1 < *lipVal2) {
		return 1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j, k;
	char lc1Buf[1024];

	// 宝石数・操作回数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siJCnt, &siOCnt);

	// 宝石 - 取得
	for (i = 0; i < siJCnt; i++) {
		fscanf(szpFpI, "%d", &si1Jewel[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	int liMax = 0;

	// 左側の個数
	int liLMax;
	if (siJCnt < siOCnt) {
		liLMax = siJCnt;
	}
	else {
		liLMax = siOCnt;
	}
	for (i = 0; i <= liLMax; i++) {
		int liJCnt = siJCnt - i;
		int liOCnt = siOCnt - i;

		// 右側の個数
		int liRMax;
		if (liJCnt < liOCnt) {
			liRMax = liJCnt;
		}
		else {
			liRMax = liOCnt;
		}
		for (j = 0; j <= liRMax; j++) {

			// 対象宝石数
			int liTCnt = i + j;
			if (liTCnt < 1) {
				continue;
			}

			// 対象宝石
			int li1Jewel[D_JEWEL_MAX];
			if (i > 0) {
				memcpy(li1Jewel, si1Jewel, sizeof(int) * i);
			}
			if (j > 0) {
				memcpy(&li1Jewel[i], &si1Jewel[siJCnt - j], sizeof(int) * j);
			}
			qsort(li1Jewel, liTCnt, sizeof(int), fSortFnc);

			// 負の宝石削除
			int liDCnt = liOCnt - j;
			for (k = 0; k < liDCnt; k++) {
				if (li1Jewel[liTCnt - 1] < 0) {
					liTCnt--;
				}
				else {
					break;
				}
			}

			// 価値合計 - 取得
			int liSum = 0;
			for (k = 0; k < liTCnt; k++) {
				liSum += li1Jewel[k];
			}

			// 最大値 - 更新
			if (liMax < liSum) {
				liMax = liSum;
			}
		}
	}

	return liMax;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

public class Main {
    public static void main(String[] args) throws IOException{
        FastReader sc = new FastReader();
        String str = sc.next();
        char ch = str.charAt(str.length()-1);
        HashSet<Character> hon = new HashSet<>();
        hon.add('2');hon.add('4');hon.add('5');hon.add('7');hon.add('9');
        HashSet<Character> pon = new HashSet<>();
        pon.add('0');pon.add('1');pon.add('8');pon.add('6');
        HashSet<Character> bon = new HashSet<>();
        bon.add('3');
        if (hon.contains(ch)) System.out.println("hon");
        else if (pon.contains(ch)) System.out.println("pon");
        else if (bon.contains(ch)) System.out.println("bon");

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

ans = -1
i = 0

while True:
    temp = x -i
    if temp not in p:
        ans = temp
        break
    temp = x + i
    if temp not in p:
        ans = temp
        break
    i += 1

print(ans)

Measured memory_bytes: 9188
#include<stdio.h>

int main(void){
  int i,n,m,j,b[1000],a[1000][1000],c[1000];

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

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      c[i]=0;
      scanf("%d",&a[i][j]);
    }
  }

  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      c[i]=(a[i][j]*b[j])+c[i];
    }
  }

  for(i=0;i<n;i++){
    printf("%d\n",c[i]);
  }
}



Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  V<ll> p(n);
  rep(i, n) p[i] = a[i] - (i + 1);

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

  auto calc = [&](ll b) {
    ll ret = 0;
    rep(i, n) ret += abs(a[i] - (i + 1 + b));
    return ret;
  };

  ll ans = 1e15;
  ll b;
  if (n % 2 != 0) {
    b = p[n / 2];
    ans = calc(b);
  } else {
    b = (p[n / 2] + p[n / 2 - 1]) / 2;
    ans = min(ans, calc(b));
    ans = min(ans, calc(b + 1));
  }

  cout << ans << endl;
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1e9;
const int MAX = 100001;

int n;

int main(){
    cin >> n;
    vector<int> x(n),copy(n);
    REP(i,n){
        cin >> x[i];
        copy[i] = x[i];
    }
    sort(x.begin(),x.end());
    REP(i,n){
        if(copy[i] < x[n/2]) cout << x[n/2] << endl;
        else cout << x[(n-1)/2] << endl;
    }
}



Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>

int main()
{
	int n, k;
	int source[128];

	while (scanf("%d%d", &n, &k), n){
		memset(source, 0, sizeof(source));
		for (int i = 0; i < k; i++){
			scanf("%d", source + i);
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < k; j++){
				int tmp;
				scanf("%d", &tmp);

				source[j] -= tmp;
			}
		}

		for (n = 0; source[n] >= 0 && n < k; n++);
		puts(n == k ? "Yes" : "No");
	}

	return (0);
}

Measured memory_bytes: 1012
# 入力
N = int(input())
A = list(map(int,input().split()))

P = 10**9+7
bit = [0 for i in range(60)]

# 各bit独立に1が何個あるか数える
for a in A:
    S = bin(a)
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1

# 各bitの1の個数と0の個数の積が、XOR和が1になる数字の個数と一致
ans = 0
for i,a in enumerate(bit):
    ans += a*(N-a)*(2**i)
    ans %= P

print(ans)


Measured memory_bytes: 122808
#include<bits/stdc++.h>
using namespace std;
const int INF=2E5;
typedef pair<int,int> Pair;

int main(){
    int N,M;
    long long x[1010][3]={0};
    array<long long,1010> v;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin >> x[i][0] >> x[i][1] >> x[i][2];
    }
    int Fugo[3];
    long long ans=-INF;
    long long souwa=0;
    for(int i=0;i<8;i++){
        souwa=0;
        for(int j=0;j<3;j++){
            Fugo[j]=1-2*( i >> j & 1);
        }
        for(int j=0;j<N;j++){
            v[j]=Fugo[0]*x[j][0]+Fugo[1]*x[j][1]+Fugo[2]*x[j][2];
        }
        sort(
            v.begin(),
            v.begin()+N,
            [](const long long& x, const long long& y) { return x > y;}
            );
        for(int j=0;j<M;j++){
            souwa+=v[j];
        }
        ans=max(ans,souwa);
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int n;cin>>n;
    ll ans=0;
    for(int i=1;i<n+1;i++){
        if(i%3==0 or i%5==0){
        }
        else{
            ans+=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    if(1<=i&&i<=9)ans++;
    if(100<=i&&i<=999)ans++;
    if(10000<=i&&i<=99999)ans++;
  }
  cout << ans << endl;
  /*
  char s[200];
  cin >> s;
  sort(s,s+strlen(s));
  if(strlen(s)%2==1){
    cout << "No";
    return 0;
  }
  for(int i=0;i<strlen(s)-1;i++){
    if(s[i]!=s[i+1]){
      if(i%2==1){
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";*/
}


Measured memory_bytes: 256
# X秒を測れる砂時計があります。
# はじめ上のパーツに砂が X[g] あり、1秒間に 1[g] 砂が落ちます。
# なお、上のパーツにもう砂が残っていない場合は砂は落ちません。
# t秒後に上のパーツに残っている砂は何gでしょう。

# 制約
# 1 ≦ X ≦ 1000000000
# 1 ≦ t ≦ 1000000000
# X, t は整数

# 標準入力から X, tの値を取得する
x, t = map(int, input().split())

# t秒後の砂の[g]グラム数を計算し、出力する
result = 0

if x > t:   # xがtより大きい場合は、残りx - t[g]
    result = x - t
else:
    result = 0  # tの方が大きい場合は残り 0[g]

print(result)


Measured memory_bytes: 9132
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define MP make_pair

inline int gn(){
    int s=0,f=1; 
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f=-1;ch = getchar();}
    while(isdigit(ch)) {s=s*10+ch-'0';ch = getchar();}
    return s*f;
}

inline ll gl(){
    ll s=0,f=1; 
    char ch = getchar();
    while(!isdigit(ch)) {if(ch == '-') f=-1;ch = getchar();}
    while(isdigit(ch)) {s=s*10+ch-'0';ch = getchar();}
    return s*f;
}

const int N=2e5+100;
ll a[N];
struct node{
    int id;
    ll data;
    bool operator < (const node &rhs)const{
        return data<rhs.data;
    }
}s[N],t[N];

void solve(){
    int n=gn();
    for(int i=1;i<=n;++i){
        a[i]=gl();
        s[i]={i,i+a[i]};
        t[i]={i,i-a[i]};
    }
    sort(s+1,s+1+n);
    sort(t+1,t+1+n);
    ll cnt=0;
    for(int i=1,j=1;i<=n;++i){
        if(j>n)break;
        ll num=0,sum=1;
        while(t[j].data<s[i].data&&j<=n)++j;
        while(t[j].data==s[i].data&&j<=n){
            ++num;
            ++j;
        }
        while(s[i+1].data==s[i].data&&i<=n){
            ++sum;
            ++i;
        }
        cnt+=sum*num;
    }
    cout<<cnt<<endl;
}

int main(){
    // int t;
    // t=gn();
    // while(t--)
        solve();
}

/**
* In every life we have some trouble
* When you worry you make it double
* Don't worry,be happy.
**/


Measured memory_bytes: 11440
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int h,w;
	debug("debug test\n");
	cin>>h>>w;
	string s[h];
	int wall = 0;
	rep(i, h){
		cin>>s[i];
		rep(j, w){
			if(s[i][j] == '#')wall++;
		}
	}

	int INF = 100000;
	vector<vint> d(h, vint(w, INF));
	queue<P> a;
	d[0][0] = 1;
	a.push(P(0, 0));
	while(!a.empty()){
		P p = a.front();a.pop();
		int cost = d[p.first][p.second];
		rep(i, 4){
			int nx = p.first+dx[i];
			int ny = p.second+dy[i];
			if(0 <= nx && nx <= h-1&&0<=ny&&ny<=w-1&&d[nx][ny]==INF&&s[nx][ny]!='#'){
				a.push(P(nx,ny));
				d[nx][ny] = cost+1;
				if(nx == h-1 && ny == w-1){
					cout << h*w-(cost+1)-wall << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}


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

int main() {
  long K, A, B;
  cin >> K >> A >> B;
  
  long answer;
  
  if(A+2 >= B){
    answer = K+1;
  }
  else if(A+2 < B && (K-A+1) % 2 == 0){
    answer = A + (B-A)*(K-A+1)/2;
  }
  else {
    answer = A + (B-A)*((K-A+1)/2) + 1;
  }
  
  cout << answer << endl;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		c[i] = a[i]-b[i];
		if (c[i] < 0 && c[i]%2) {c[i]++;}
		if (c[i] > 0) {c[i] *= 2;}
	}
	ll s = 0;
	for (int i = 0; i < n; i++) {
		s += c[i];
	}
	if (s <= 0) {cout << "Yes";}
	else {cout << "No";}
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n;
char s[305][305];
bool dp[305][305][305];
int pi[305];

int main()
{
  finp;
  cin>>n;
  afor(i,1,n)cin>>s[i]+1;

  afor(i,1,n) //ith row
  {
    afor(j,1,n) //jth col
    {
      //build kmp on ith row
      pi[1] = 0;
      int p = 0;
      afor(j1,2,n)
      {
        char cc = s[i][j1];
        while(p>=1 && cc!=s[i][p+1])p = pi[p];
        if(cc != s[i][p+1])p = 0;
        else p++;
        pi[j1] = p;
      }

      p = 0;
      afor(j1,1,2*n)
      {
        char cc;
        if(j1 <= n)cc = s[j1][j];
        else cc = s[j1-n][j];
        while(p>=1 && cc!=s[i][p+1])p = pi[p];
        if(cc != s[i][p+1])p = 0;
        else p++;
        if(p==n && j1>=n)dp[i][j][(j1 - n)] = true;
        if(p == n)p = pi[p];
      }
    }
  }

  int ans = 0;

  
  afor(A,0,n-1)afor(B,0,n-1)
  {
    bool f = true;
    afor(i,1,n)
    {
      int row = i + A;
      if(row > n)row-=n;
      int col = i + B;
      if(col > n)col-=n;

      int x = (A - B);
      if(x < 0)x+= n;
      if(!dp[row][col][x])
      {
        f = false;
        break;
      }
    }
    if(f)++ans;
  }

  cout<<ans;
  
return 0;
}

Measured memory_bytes: 27648
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void DFSvisit(int);
void dfs();

int n,m[N][N];
int color[N],d[N],f[N],tt;

int main(){

  int u,v,k,i,j,l;

  scanf("%d",&n);

  for(i = 0;i < n; i++){
    for(j = 0; j < n; j++)m[i][j] = 0;
  }
 for(i = 0;i < n; i++){
     scanf("%d %d",&u,&k);
     u--;
   for(j = 0; j < k; j++){
     scanf("%d",&v);
     v--;
     m[u][v] = 1;
   }
 }
 dfs();

  return 0;
}

void DFSvisit(int u){

  int v;

  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0; v < n; v++){
    if(m[u][v] == 0)continue;
    if(color[v] == WHITE){
      DFSvisit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){

  int u;

  for(u = 0; u < n; u++)color[u] = WHITE;
  tt = 0;

  for(u = 0; u < n; u++){
    if(color[u] == WHITE)DFSvisit(u);
  }

  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
    ll n;cin>>n;
    vl s(n);rep(i,n)cin>>s[i];
    ll ans=0;
    rep(i,n){
        rep(j,i){
            rep(k,j){
                if(s[i]==s[j]||s[i]==s[k]||s[j]==s[k])continue;
                if(s[i]<s[j]+s[k]&&s[j]<s[i]+s[k]&&s[k]<s[i]+s[j]){
                    ans++;
                    //cout<<s[i]<<" "<<s[j]<<" "<<s[k]<<endl;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
        int a,b,c,n;
        cin >> n;
        for(int i=0;i<n;++i){
                cin >> a >> b >> c;
                if(a*a+b*b==c*c) cout << "YES\n";
                else if(b*b+c*c==a*a) cout << "YES\n";
                else if(c*c+a*a==b*b) cout << "YES\n";
                else cout << "NO\n";
        }   
        return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

struct UnionFind{
    vector<ll> par;
    vector<ll> sizes;
    UnionFind(ll n) : par(n), sizes(n, 1) {
        rep(i,n) par[i] = i;
    }
    int find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(ll x, ll y) {
        return find(x) == find(y);
    }

    ll size(ll x) {
        return sizes[find(x)];
    }
};

struct Edge{
    ll a, b, cost;
    // コストの大小で順序定義
    bool operator<(const Edge& o) const {
        return cost < o.cost;
    }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph{
    int n;  // 頂点数
    vector<Edge> es;  // 辺集合

    // クラスカル法で無向最小全域木のコストの和を計算する
    // グラフが非連結のときは最小全域森のコストの和となる
    int kruskal() {
        // コストが小さい順にソート
        sort(es.begin(), es.end());

        UnionFind uf(n);
        int min_cost = 0;

        rep(ei, es.size()) {
            Edge& e = es[ei];
            if (!uf.same(e.a, e.b)) {
                // 辺を追加しても閉路ができないなら、その辺を採用する
                min_cost += e.cost;
                uf.unite(e.a, e.b);
            }
        }

        return min_cost;
    }
};

Graph input_graph() {
    Graph g;
    int m;
    cin >> g.n >> m;
    rep(i, m) {
        Edge e;
        cin >> e.a >> e.b >> e.cost;
        g.es.push_back(e);
    }
    return g;
}

int main(){
    int n;
    cin >> n;
    vector<pair<ll,P>> v1, v2;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        v1.push_back({x, {y, i}});
        v2.push_back({y, {x, i}});
    }
    
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    Graph g;
    g.n = n;
    rep(i, n-1){
        Edge e;
        e.a = v1[i].second.second;
        e.b = v1[i+1].second.second;
        ll x1 = v1[i].first;
        ll x2 = v1[i+1].first;
        ll y1 = v1[i].second.first;
        ll y2 = v1[i+1].second.first;
        e.cost = min(abs(x1-x2), abs(y1-y2));
        g.es.push_back(e);
    }

    rep(i, n-1){
        Edge e;
        e.a = v2[i].second.second;
        e.b = v2[i+1].second.second;
        ll x1 = v2[i].first;
        ll x2 = v2[i+1].first;
        ll y1 = v2[i].second.first;
        ll y2 = v2[i+1].second.first;
        e.cost = min(abs(x1-x2), abs(y1-y2));
        g.es.push_back(e);
    }


    cout << g.kruskal() << endl;
    return 0;
}

Measured memory_bytes: 13860
def nyu():
    S= list(map(str,(input())))
    return S


def check(S ):
    Strong_str1 = ""
    Strong_str2 = ""
    Strong_str3 = ""

    for s in range(int(len(S)/2)):
        Strong_str1 += S[s]

    for s in range(int((len(S)+3)/2-1),len(S)):
        Strong_str2 += S[s]

    Strong_str3 = S[::-1]

    # print(Strong_str1)
    # print(Strong_str2)
    # print(Strong_str3)

    if Strong_str1 == Strong_str1[::-1] and Strong_str2 == Strong_str2[::-1] and S == S[::-1]:
        print("Yes")
    else:
        print("No")


            
S = nyu()
check(S)
#print(S)



Measured memory_bytes: 3064
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int n,k;
int t[111111];

int main(){
	int ans=1000000;
		int a=0,b=0;
	cin>>n>>k;
	rep(i,n)cin>>t[i];

	int s=0;

	rep(i,n){
		if(t[i]==1)s=i;
	}

	if(n<=k){
		cout<<1<<endl;
		return 0;
	}

	for(int i=s-k+1;i<s+k-1;i++){
		int tmp=1;
		int a=i-1,b=n-(i+k-1);
		if(a>=0){
			tmp+=a/(k-1);
			if(a%(k-1))tmp++;
		}
		if(b>=0){
			tmp+=b/(k-1);
			if(b%(k-1))tmp++;
	}
			ans=min(ans,tmp);
	}

	cout<<ans<<endl;
		return 0;

}





Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

ans = 0
def gap(a,b):
    c = abs(a-b)
    return min(c,24-c)
def solve():
    global ans
    def dfs(f,i,k):
        global ans
        if i == n:
            ans = k
        else:
            nd = d[i]
            nk = min([gap(nd,j) for j in f])
            if nk > ans:
                nf = [i for i in f]+[nd]
                dfs(nf,i+1,min(k,nk))
            if d[i] != 12:
                nd = 24-d[i]
                nk = min([gap(nd,j) for j in f])
                if nk > ans:
                    nf = [i for i in f]+[nd]
                    dfs(nf,i+1,min(k,nk))

    n = I()
    d = LI()
    f = [0]
    dfs(f,0,float("inf"))
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int n;
stack<int> trail;
int main()
{
	while (cin >> n)
	{
		if (n)
			trail.push(n);
		else
		{
			cout << trail.top() << endl;
			trail.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k = 0;
    cin >> n;
    map<string, int> c;
    while (n--) {
        string s;
        cin >> s;
        k = max(k, ++c[s]);
    }
    for (auto p : c)
        if (p.second == k)
            cout << p.first << '\n';
}


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

int main() {
  int64_t A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  int64_t d;
  if(A-B>0)
    d=A-B;
  else
    d=B-A;
  if((V-W)*T<d)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
    
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n){
    mp[a[i]]++;
  }
  int ans = 0;
  for(auto i: mp){
    if(i.second > i.first){
      ans += i.second - i.first;
    }else if(i.second < i.first){
      ans += i.second;
    }
  }
  cout << ans << endl;
}

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

int main()
{
  char s[110],t[110];
  scanf("%s",s);
  scanf("%s",t);
  int mi=10000000,mx=-1;
  for(int i=0; s[i]; i++)
  {
    mi=min(mi,(int)s[i]);
  }
  for(int i=0; t[i]; i++)
  {
    mx=max(mx,(int)t[i]);
  }
  if(mi<mx)
  {
    cout<<"Yes";
  }
  else if(mi==mx)
  {
    int i=0;
    for(; s[i] && t[i] && s[i]==t[i]; i++);
    if(s[i]||t[i]=='\0')
    {
      cout<<"No";
    }
    else
    {
      cout<<"Yes";
    }
  }
  else
  {
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
def lcm(a, b):
	return a * b // gcd (a, b)

A,B,C,D = [int(x) for x in input().split(' ')]
a = (B - A + 1) 
b = ((B // C) - ((A-1) // C))
c = ((B // D) - ((A-1) // D))
CD = lcm(C,D)
d = ((B // (CD)) - ((A-1) // (CD)))
q = a - b - c + d
print(q)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main(){
    int n; cin>>n;
    vector<int> ans={};
    int j=2;
    rep(i,n){
        while(!IsPrime(j)||j%5!=2){
            j++;
        }
        ans.push_back(j);
        j++;
    }
    rep(i,n){
        cout<<ans[i]<<' ';
    }
}

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

using namespace std;

int main(void)
{
	string s; cin>>s;
	int len = s.size();
	int ans = 0;
	int g_num = 0, p_num = 0;
	for(int i = 0; i < len; i++){
		if(i%2 == 0){
			if(s[i] == 'p')ans--;
		}
		else{
			if(s[i] == 'g') ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

int memo[8193][20];
int rm[20],N;

int solve(int S, int turn)
{
	if(memo[S][turn]!=-1) return memo[S][turn];

	if(turn%2==0) {
		bool ok = false;
		for(int i=1; i<=rm[turn]; i++) {
			int remain = S-i;
			if(remain <= 0) continue;

			if(solve(remain, (turn+1)%N)==1) ok = true;
		}

		if(ok) memo[S][turn] = 1; else memo[S][turn] = 0;
	}
	else {
		bool ok = true;
		for(int i=1; i<=rm[turn]; i++) {
			int remain = S-i;
			if(remain <= 0) continue;

			if(solve(remain, (turn+1)%N)==0) ok = false;
		}

		if(ok) memo[S][turn] = 1; else memo[S][turn] = 0;
	}

	return memo[S][turn];
}

int main()
{
	int S;
	while(cin >> N, N) {
		cin >> S;
		N *= 2;

		for(int i=0; i<=S; i++)
		for(int j=0; j<N; j++)
			memo[i][j] = -1;


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

		cout << solve(S, 0) << endl;
	}
}

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

public class Main {

    private static long n;

    // 15:41-
    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);

            int n = sc.nextInt();
            int q = sc.nextInt();
            String s = sc.next();

            int[] cnts = new int[s.length()];
            for (int i = 1; i < s.length(); i++) {
                cnts[i] = cnts[i - 1];
                if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') cnts[i]++;
            }

            for (int i = 0; i < q; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;

                int ret = cnts[b] - (a == 0 ? 0 : cnts[a - 1]);
                if (a > 0 && s.charAt(a - 1) == 'A' && s.charAt(a) == 'C') ret--;

                out.println(ret);
            }
        }
    }
}


Measured memory_bytes: 69252
N = int(input())
T, A = map(int, input().split())
H = input().split()
min = 1000000000
place = 0

for i in range(N):
  d = (T*1000 - int(H[i])*6) - A * 1000
  if d < 0: d = -d
  if d < min:
    min = d 
    place = i+1

print(place)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};

    int x,y; cin >> x >> y;

    if(a[x] == a[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,m,d,i,j,k,l,ans=0;
	char s[100][101];
	scanf("%d %d %d",&n,&m,&d);
	for(i=0;i<n;i++)
		scanf("%s",s[i]);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(i+d<=n){
				for(k=0;k<d;k++){
					if(s[i+k][j]=='#')
						break;
				}
				if(k==d)
					ans++;
			}
			if(j+d<=m){
				for(k=0;k<d;k++){
					if(s[i][j+k]=='#')
						break;
				}
				if(k==d)
					ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
int main(void){
    long long int a[100][100],b[100][100],c[100][100];
    int i,j,k,n,m,l;
    long long int sum;
    
    scanf("%d %d %d",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%lld",&a[i][j]);
        }
    }

//行列a入力の確認    
    /*
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            printf("%lld ",a[i][j]);
        }
        printf("\n");
    }*/
    
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
           scanf("%lld",&b[i][j]);
        }
    }

//行列b入力の確認
    /*
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            printf("%lld ",b[i][j]);
        }
        printf("\n");
    }
    */
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]=a[i][k]*b[k][j];
                sum = sum + c[i][j];
                 c[i][j]=sum;
            }
            sum=0;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            printf("%lld",c[i][j]);
            if(j!=l-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
    
}



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


void input(); template<typename First,typename... Rest> void input(First&,Rest&...);
void inputVector(); template<typename First,typename... Rest>  void inputVector(std::vector<First>&,Rest&...);
#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define sort(vec) std::sort(all(vec))
#define rev(vec) std::reverse(all(vec))

void calculate(){

}

int main(int,char**){
    std::string t;
    input(t);
    int i,j;
    for(i = 0;i < (int)t.size();++i){
        if(t[i] == 'A'){
            break;
        }
    }
    for(j = (int)t.size();0 < j;--j){
        if(t[j] == 'Z'){
            break;
        }
    }
    std::cout << j - i + 1<< '\n';
}


void input(){return;}
template<typename First,typename... Rest>
void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}

void inputVector(){return;}
template<typename First,typename... Rest> 
void inputVector(std::vector<First> &first,Rest&... rest){
    int N = first.size();
    for(int i = 0;i < N;i++){
        std::cin >> first[i];
    }
    inputVector(rest...);
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll r;
    cin >> r;
    cout << 3 * r * r << endl;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  vector<long long int> num(K,0);
  for(int i=1;i<=N;i++){num.at(i%K)++;}
  long long int res=0;
  for(int a=0;a<K;a++){
    int b=(K-a)%K;
    int c=(K-a)%K;
    if((b+c)%K!=0){continue;}
    res+=num.at(a)*num.at(b)*num.at(c);
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1010, MAX = 1000001;
int a[N][N], isprime[MAX];

int main() {
    int i = 505, j = 505, x = 1;
    int di[] = {0,-1,0,1}, dj[] = {1,0,-1,0};
    a[i][j] = 1;
    for (int p = 0; x < 1000000; p++){
        REP(c,p/2+1){
            x++;
            i += di[p%4];
            j += dj[p%4];
            a[i][j] = x;
        }
    }

    FOR(i,2,MAX) isprime[i] = 1;
    FOR(i,2,MAX){
        if (!isprime[i]) continue;
        for (int x = 2*i; x <= MAX; x += i) isprime[x] = 0; 
    }

    // FOR(i,500,510){
    //     FOR(j,500,510){
    //         printf("%3d ", isprime[a[i][j]]);
    //     }
    //     cout << endl;
    // }

    int m, n;
    while (cin >> m >> n && m){
        VVI dp(N,VI(N,-1)), dpm(N,VI(N));
        REP(i,N) REP(j,N) if (a[i][j] == n) dp[i][j] = isprime[n], dpm[i][j] = n;
        REP(i,N) REP(j,N){
            if (dp[i][j] == -1 || a[i][j] == 0) continue;
            FOR(k,j-1,j+1){
                int p = a[i+1][k];
                if (p > m) continue;
                if (isprime[p]){
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + 1);
                    dpm[i+1][k] = p;
                }else{
                    if (dp[i+1][k] < dp[i][j] || (dp[i+1][k] == dp[i][j] && dpm[i+1][k] < dpm[i][j])){
                        dp[i+1][k] = dp[i][j];
                        dpm[i+1][k] = dpm[i][j];
                    }
                }
            }
        }

        // FOR(i,500,510){
        //     FOR(j,500,510){
        //         printf("%3d ", dp[i][j]);
        //     }
        //     cout << endl;
        // }

        int x = 0, y = 0;
        REP(i,N) REP(j,N){
            if (x < dp[i][j] || (x == dp[i][j] && y < dpm[i][j])){
                x = dp[i][j];
                y = dpm[i][j];
            }
        }
        if (x == 0) y = 0;
        printf("%d %d\n", x, y);
    }
}

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

#define SIZE 32

int main()
{
  int seq[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int inp = 0;
  cin >> inp;
  cout << seq[inp-1] << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define MAX 1000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
void solve() {
    string str;
    cin >> str;
    
    int c = 0;
    int len = str.length();
    for(int i=0;i<len/2;i++) {
    if(str[i] != str[len-1-i])
        c++;
    }
    cout << c << endl;
    return ;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define mod 1000000007;

long long nikou(int n, int r);

long long c[2001][2001];
int done[2001][2001]={};

int main(void){
  int i, j;
  int n,k;
  long long b_wake;
  long long r_wake;
  long long ans;

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

  for(i=1; i<=k; i++){
    ans=0;
    b_wake=0;
    r_wake=0;
    if(i==1){
      ans=(n-k+1)%mod;
    }else{
      if(k-i<0){
        ans=0;
      }else{
        //bの分け方 k-1Ci-1
        b_wake=nikou(k-1,i-1)%mod;
        //rの分け方
        for(j=i-1; j<=i+1; j++){
          //j=i-1 赤が両端にない
          //j=i 赤が右端のみまたは左端のみにある
          //j=i+1 赤が両端にある
          if(n-k<j) break;//二項定理でn-k-1<j-1となるのを防ぐ
          if(j==i){
            r_wake+=2*nikou(n-k-1,j-1)%mod
          }else{
            r_wake+=nikou(n-k-1,j-1)%mod;
          }
        }
        ans=(b_wake*r_wake)%mod;
      }
    }
    printf("%lld\n", ans);
  }

  return 0;
}

long long nikou(int n, int r){
  //n=>rであることが前提 パスカルの三角形
  // printf("nikou(%d,%d)\n", n,r);
  if(done[n][r]==1) return c[n][r];

  if(r==0){
    done[n][r]=1;
    return c[n][r]=1;
  }
  if(r==n){
    done[n][r]=1;
    return c[n][r]=1;
  }

  c[n][r]=(nikou(n-1,r)+nikou(n-1,r-1))%mod;
  done[n][r]=1;
  return c[n][r];
}


Measured memory_bytes: 46336
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll X;
  cin>>X;
  ll a=X/500;
  X-=500*a;
  cout<<1000*a+5*(X/5)<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N,X,Y; cin >> N >> X >> Y; --X; --Y;
    vector <int> ans(N);
    
    rep(i,N){
        vector <int> dist(N,INF);
        queue <int> q;
        q.push(i);
        dist[i]=0;
        
        while(!q.empty()){
            int a=q.front(); q.pop();
            int d=dist[a];
            if (a-1>=0 && dist[a-1]==INF){
                q.push(a-1);
                dist[a-1]=d+1;
            }
            if (a+1<N && dist[a+1]==INF){
                q.push(a+1);
                dist[a+1]=d+1;
            }
            if (a==X && dist[Y]==INF){
                q.push(Y);
                dist[Y]=d+1;
            }
            if (a==Y && dist[X]==INF){
                q.push(X);
                dist[X]=d+1;
            }
        }
        rep(i,N) ans[dist[i]]++;
    }
    rep(i,N) ans[i]/=2;
    for (int i=1; i<=N-1; i++) cout << ans[i] << endl;
    return 0;
}

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

int main() {
    long long N;
    cin >> N;
    int flag=0;
    while(N > 0)
    {
        int X = N%10;
        if(X==7)
        {
            flag=1;
            break;
        }
        N=N/10;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
D = input().split(' ')
N = int(D[0])
M = int(D[1])
D2 = input().split(' ')

A = []
for i in D2:
  A.append(int(i))

A.sort(reverse=True)

used = 0

while True:
  max = A[0]
  n = 0
  while True:
    if A[n] >= int(max / 2):
      A[n] = int(A[n] / 2)
      used = used + 1
    else:
      break
      
    n = n + 1

    if n == N or used == M:
      break
      
  if used == M:
    break
    
  A.sort(reverse=True)
    
sum = 0
for i in range(N):
  sum = sum + A[i]
  
print(sum)

Measured memory_bytes: 14608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
 int ans=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
  }
      cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(true) {
            int H = stdIn.nextInt();
            int W = stdIn.nextInt();
            int i;
            int j;
            if(H == 0 && W == 0) {
                break;
            }
            for(i = 0; i < H; i++) {
                for(j = 0; j < W; j++) {
                    if(j % 2 == 1) {
                        if(i % 2 == 1) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    } else {
                        if(i % 2 == 1) {
                            System.out.print(".");
                        } else {
                            System.out.print("#");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


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

#define ll long long

const int mod=1000000007;

struct mint {
	ll x;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
	if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
    	if (!t) return 1;
    	mint a = pow(t>>1);
    	a *= a;
		if (t&1) a *= *this;
		return a;
	}

	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,k;
	string s;
	cin>>k>>s;
	n=s.size();
	combination c(n+k);
	mint ans=0;
	for(int i=0;i<=k;++i){
		mint now=mint(26).pow(k-i);
		now*=mint(25).pow(i);
		now*=c(i+n-1,n-1);
		ans+=now;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 35588
N = int(input())
A = list(map(int, input().split()))
s = 0
num = 0
l = 0
for i in range(N):
    while l < N and s + A[l] == s ^ A[l]:
        s += A[l]
        l += 1
    num += l - i
    s -= A[i]

print(num)


Measured memory_bytes: 23560
fun main(args: Array<String>) {
  val (N,T) = readLine()!!.split(" ").map{it.toInt()}
  val roots = (1..N).map{
    readLine()!!.split(" ").map{it.toInt()}
  }.filter{ it[1] <= T }

  if(roots.minBy{it[0]}?.get(0) == null) {
    println("TLE")
  } else {
    println(roots.minBy{it[0]}!!.get(0))
  }
}

Measured memory_bytes: 35976
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X,K,Q;
ll A,B,C,D;

ll ans;
bool f=false;

int main(){
    cin>>N;
    for(ll i=-200;i<200;i++){
        for(ll j=-200;j<200;j++){
            if(i*i*i*i*i-j*j*j*j*j==N){
                cout<<i<<" "<<j<<endl;
                f=true;
                break;
            }
        }
        if(f)break;
    }
}


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

int main(void){
    long long n, r = 1;
    long long sum;
    long long h;
    
    cin >> n;
    long long sum_min = n;
    
    for(long long j = 1; j <= n; j++){
        if(j*j > n){
            h = j-1;
            break;
        }
    }
    
    for(long long i = 1; i <= n/h; i++){
        if(n % i == 0){
            sum = i + n/i;
            if(sum_min > sum){
                sum_min = sum;
                r = 0;
            }
        }
    }
    
    cout << sum_min - 2 + r << "\n" << endl;
}


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

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    rep(i, n)
    {
        rep(j, 3)
        {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n, vector<int>(3));
    rep(i, 3)
    {
        dp[0][i] = a[0][i];
    }
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            set<int> s;
            for (int k = 0; k < 3; k++)
            {
                if (j != k)
                {
                    s.insert(dp[i - 1][k]);
                }
            }
            dp[i][j] = *rbegin(s) + a[i][j];
        }
    }
    int maxi = 0;
    for (int i : dp[n - 1])
    {
        maxi = max(maxi, i);
    }
    cout << maxi << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 11136