akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
double h, w, n, m, k, t, s, p, q, last, first, cnt, ans , dp[2000][200], a[400000], b[400000];
string str, ss;
bool f[200][200];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<int>>vec;
vector<edge>ed;
vector<LL>v;
map<Pll, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n ;
	double sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	cnt = 1000000;
	rep(i, n) {
		if (cnt >abs(sum-a[i]) ) {
			ans = i;
			cnt = abs(sum - a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2304
N, X=map(int, input().split())
L=list(map(int, input().split()))
L=[0]+L
 
l=int(0)
counter=int(0)
while l+L[counter]<=X and counter<=N:
  l+=L[counter]
  counter+=int(1)
  if counter==N+1:
    break
  
print(counter)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    ArrayList<Pair> list1 = new ArrayList<>(n);
    ArrayList<Pair> list2 = new ArrayList<>(n);
    Map<Pair, Integer> map = new HashMap<>();
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      Pair p = new Pair(a, b);
      list1.add(p);
      list2.add(p);
      int current = map.getOrDefault(p, 0);
      map.put(p, current + 1);
    }
    list1.sort((o1, o2) -> o2.c - o1.c);
    list2.sort((o1, o2) -> o2.c - o1.c);
    int list1Cursor = 0;
    int list2Cursor = 0;
    long total1 = 0;
    long total2 = 0;
    boolean isTurnList1 = true;
    for (int i = 0; i < n; i++) {
      if (isTurnList1) {
        for (;;) {
          Pair pair = list1.get(list1Cursor);
          list1Cursor += 1;
          int current = map.get(pair);
          if (current <= 0) continue;
          map.put(pair, current - 1);
          total1 += (long) pair.a;
          break;
        }
      } else {
        for (;;) {
          Pair pair = list2.get(list2Cursor);
          list2Cursor += 1;
          int current = map.get(pair);
          if (current <= 0) continue;
          map.put(pair, current - 1);
          total2 += (long) pair.b;
          break;
        }
      }
      isTurnList1 = !isTurnList1;
    }
    System.out.println(total1 - total2);
  }

  private static class Pair {
    private final int a;
    private final int b;
    private final int c;

    private Pair(int a, int b) {
      this.a = a;
      this.b = b;
      this.c = a + b;
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Pair pair = (Pair) o;
      return a == pair.a &&
              b == pair.b;
    }

    @Override
    public int hashCode() {
      return Objects.hash(a, b);
    }
  }
}

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

void solve()
{
    int n;
    cin >> n;
    int ac = 0, wa = 0, te = 0, re = 0;
    while(n--){
        string s;
        cin >> s;
        if(s == "AC")   ac++;
        if(s == "WA")   wa++;
        if(s == "TLE")  te++;
        if(s == "RE") re++;
    }
    cout << "AC " << "x " << ac << endl;
    cout << "WA " << "x " << wa << endl;
    cout << "TLE " << "x " << te << endl;
    cout << "RE " << "x " << re << endl;
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

string str;

ll k;

ll dp[30][110][30];
ll pre[30];
ll h[30];
// ll mii[30];
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> str >> k;
	int n = str.size();
	// rep(i,0,26)
	// {
	// 	if(i == str[0]-'a')
	// 	dp[ii][0][i] = 0;
	// 	else
	// 	dp[ii][0][i] = 1;
	// 	mii[i] = 1e18;
	// }
	ll ans = 1e18;

	memset(dp,0,sizeof dp);
	rep(i,0,26)
	{
		pre[i] = 1e18;
	}
	rep(ii,0,26)
	{
		
		rep(i,0,26)
		{
			if(i == str[0]-'a')
			dp[ii][0][i] = 0;
			else
			dp[ii][0][i] = 1;
		}
		rep(i,0,26)
		{
			if(i != ii)
				dp[ii][0][i] = 1e9+7;
		}
		rep(i,1,n)
		{
			rep(j,0,26)
			{
				dp[ii][i][j] = 1e9+1;
				rep(jj,0,26)
				{
					if(j == jj)
						continue;
					dp[ii][i][j] = min(dp[ii][i][j],dp[ii][i-1][jj]);
				}
				if(str[i] != 'a' + j)
				{
					dp[ii][i][j] += 1;
				}
			}
		} 
		// ll mi = 1e9+7;
		// int cnt = 0;
		// int t = 0;
		// rep(i,0,26)
		// {
		// 	if(mi > dp[ii][n-1][i])
		// 	{
		// 		cnt = 1;
		// 		t = i;
		// 		mi = dp[ii][n-1][i];
		// 	}
		// 	else if(mi == dp[ii][n-1][i])
		// 	{
		// 		cnt++;
		// 	}
		// }
	}
	k--;
	rep(i,0,26)
	{
		rep(j,0,26)
		{
			pre[i] = min(pre[i],dp[i][n-1][j]);
		}
		// de(pre[i]);
	}

	rep(i,0,26)
	{
		h[i] = 1e18;
		rep(j,0,26)
		{
			if(i != j)
			h[i] = min(h[i],pre[j]);
		}
	}
	rep(i,0,26)
	{
		rep(j,0,26)
		{
			ll mi = 1e18;
			rep(ii,0,26)
			{
				rep(jj,0,26)
				{

					if(j != ii && i != jj)
					{
						if(k % 2 == 0)
						{
							mi = min(mi,dp[i][n-1][j]*(k/2)+dp[ii][n-1][jj]*(k/2)+h[jj]);
						}
						else
						{
							mi = min(mi,dp[i][n-1][j]*(k/2+1)+dp[ii][n-1][jj]*(k/2)+h[j]);
						}
					}
				}
			}
			ans = min(ans,mi);
		}
	}
	// 	//mii[ii] = mi;
	// 	ll anss = 1e18;
	// 	if(cnt >= 2)
	// 	{
	// 		anss = dp[n-1][t] * k;
	// 	}
	// 	else
	// 	{
	// 		// de("***");
	// 		if(ii == t)
	// 		mii[ii] = mi;
	// 		else
	// 		anss = dp[n-1][t] * k;
	// 	}

	// 	ans = min(ans,anss);
	// }
	// 	ll ans_2 = 0;
	// 	sort(mii,mii+26);
	// 	if(k % 2 == 0)
	// 	{
	// 		ans_2 = (mii[0] + mii[1])*(k/2);
	// 	}
	// 	else
	// 	{
	// 		ans_2 = (mii[0] + mii[1])*(k/2) + mii[0];
	// 	}
	// 	ans = min(ans,ans_2);
		// ll zmi = 1e18;

		// rep(i,0,26)
		// {
		// 	if(zmi > mii[i])
		// 	{
		// 		zmi = mii[i];
		// 		cntt = 1;
		// 	}
		// 	else if(zmi == mii[i])
		// 	{
		// 		cntt++;
		// 	}
		// }
		// if(cntt >= 2)
		// {
		// 	ans = min(ans,zmi*k);
		// }
	
	cout << ans<< endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;
   string s;
   cin>>n>>s;
   int sw[1000000],se[1000000];
   sw[0]=0,se[0]=0;
   for (int i = 1; i <= n; i++)
   {
       /* code */
       if (s[i-1]=='E')
       {
           /* code */
           se[i]=se[i-1]+1;
           sw[i]=sw[i-1];
       }
       else
       {
            sw[i]=sw[i-1]+1;
            se[i]=se[i-1];
       }
   }
   long ans1=0,ans2=1000000000;
   for (int i = 1; i <= n; i++)
   {
       ans1=sw[i-1]+se[n]-se[i];
       ans2=min(ans1,ans2);
   }
   
   cout<<ans2<<endl;
    
}

Measured memory_bytes: 7556
const main = (input) => {
  input = input.trim().split('\n')
  const n = Number(input[0])
  const arr = input[1].split(' ').map(Number)

  const ans = new Array(n).fill(0)

  for (let i=0; i<arr.length; i++) {
    ans[arr[i]-1]++
  }

  for (let i=0; i<ans.length; i++) {
    console.log(ans[i])
  }
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

namespace ConsoleApp15
{
    class Class90
    {
        static void Main()
        {
            var nabcd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nabcd[0], a = nabcd[1], b = nabcd[2], c = nabcd[3], d = nabcd[4];
            var S = Console.ReadLine();

            bool turn = false;
            bool pos = true;
            int counta = 0;
            int countb = 0;
            for(int i = a; i < Math.Max(c, d); i++)
            {
                if (S[i] == '.') { counta++;countb = 0; }
                if (S[i] =='#') { counta = 0;countb++; }

                if (Math.Max(a,b)<=i&&i <= Math.Min(c, d) && counta >= 3) turn = true;
                if (countb >= 2) { pos = false;break; }
            }

            if (c < d)
            {
                Console.WriteLine(pos ? "Yes" : "No");
            }
            else
            {
                Console.WriteLine(pos && turn ? "Yes" : "No");
            }
        }
    }
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a[100];
int cells[100][100]; // r * c

int main() {
  int N, M;
  cin >> N >> M;

  int INF = 1e9;
  vector<ll> A1(1 << N, INF);
  vector<ll> A2(1 << N, INF);

  rep0(i, M) {

    A1 = A2;
    ll a, b;
    cin >> a >> b;

    ll temp = 0;
    rep0(j, b) {
      ll c;
      cin >> c;
      temp += 1 << (c - 1);
    }

    // cout << temp << BR;
    rep0(j, 1 << N) {
      A2[0] = 0;
      if ((temp | j) == temp) {
        A2[j] = min(A1[j], a);
      } else {
        A2[(temp | j)] = min(A2[(temp | j)], A2[j] + a);
      }
    }
  // SHOW(A2);
  }
  // SHOW(A2);
  ll ans = A2[(1 << N) - 1];
  if (ans >= 1e9) ans = -1;
  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 256
S=input()
if S=="SUN":
  print(7)
elif S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
else:
  print(1) 

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

using namespace std;

using ll = long long;

bool Check() {
    vector<vector<int>> c(3, vector<int>(3));
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
            cin >> c[i][j];

    for (int a1 = 0; a1 <= 100; ++a1)
        for (int a2 = 0; a2 <= 100; ++a2)
            for (int a3 = 0; a3 <= 100; ++a3) {
                int b1 = c[0][0] - a1, b2 = c[0][1] - a1, b3 = c[0][2] - a1;
                if (b1 < 0 || b2 < 0 || b3 < 0) continue;

                if (a2 + b1 == c[1][0] && a2 + b2 == c[1][1] && a2 + b3 == c[1][2]
                    && a3 + b1 == c[2][0] && a3 + b2 == c[2][1] && a3 + b3 == c[2][2])
                    return true;
            }
    return false;
}

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

    if (Check()) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define INF (1 << 31) - 1

int main() {
  ll N;
  cin >> N;
  ll M = N;
  ll ans = 0;
  for(ll i=2;i*i<=N;i++){
    if(M%i == 0){
      ll count = 0;
      while(M%i ==0){
        M = M/i;
        count++;
      }
      for(ll j=1; j<=count+2; j++){
        if(j*(j+1)/2 > count){
          ans += j-1;
          break;
        }
      }
    }
    
  }
  
  if(M!=1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int h,w,m;
    cin>>h>>w>>m;
    map<P,int> mp;
    P r[h],c[w];
    for(int i=0;i<h;i++)r[i]=P(0,i);
    for(int j=0;j<w;j++)c[j]=P(0,j);
    for(int i=0,a,b;i<m;i++){
        cin>>a>>b;
        a--,b--;
        mp[P(a,b)]++;
        r[a].first++;
        c[b].first++;
    }
    sort(c,c+w,greater<P>());
    int ans=0;
    for(int i=0;i<h;i++){
        int res=r[i].first;
        int v=c[0].first,t=v-1;
        if(t<0)t++;
        else{
            for(int j=0;j<w;j++){
                if(v>c[j].first)break;
                if(mp[P(r[i].second,c[j].second)])continue;
                t++;
                break;
            }
        }
        ans=max(ans,res+t);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 45836
#import time

N = int(input())
datas = [int(input()) for _ in range(N)]
#start = time.time()
now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]

for i in range(1,N-1):
    if i == max_index:
        now_max = max(datas[i+1:])
        max_index = datas.index(now_max,i+1)
    new_diff = now_max - datas[i]
    if diff < new_diff:
        diff = new_diff

print(diff)
#print('time :',time.time()-start)


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

int main(){
	int h[10];
	for(int i=0;i<10;i++)cin>>h[i];
	sort(h,h+10);
	cout<<h[9]<<endl<<h[8]<<endl<<h[7]<<endl;
	return 0;
	}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  int k,s;
  cin >> k >> s;
  int ans=0;
  int n=min(k,s);
  int m=max(0,s-2*k);
  for(int i=n;i>=m;i--){
    for(int j=n;j>=m;j--){
      if(0<=s-(i+j) && s-(i+j)<=k)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3532
import java.util.*;

public class Main {
  public static void main(String[] args) {
  	
    try (Scanner scan = new Scanner(System.in)) {
      
      int n = scan.nextInt();
      int d = scan.nextInt();
      int result = 0;
      for (int i = 0; i < n; i++) {
      	result += calc(d, scan);
      }
      System.out.println(result);
    }
  }
  
  private static int calc(int d, Scanner scan) {
  	if (Math.sqrt(Math.pow(scan.nextInt(), 2) + Math.pow(scan.nextInt(), 2)) <= d) {
    	return 1;
    }
    
    return 0;
  }
}

Measured memory_bytes: 50252
N= int(input())
memo = [-1] * 100001

def Base10toN(X, n):
    if (int(X / n)):
        return Base10toN(int(X / n), n) + str(X % n)
    else:
        return str(X % n)

def f(amount):
    if memo[amount] != -1:
        return memo[amount]
    if amount <= 5:
        memo[amount] = amount
        return amount
    s = Base10toN(amount, 6)
    fs = f(amount - 6 ** (len(s) - 1))
    n = Base10toN(amount, 9)
    fn = f(amount - 9 ** (len(n) - 1))
    if (fs < fn):
        memo[amount] = fs + 1
        return fs + 1
    else:
        memo[amount] = fn + 1
        return fn + 1

print(f(N))

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,q,a,b,ans[200000]={0},x=0;
  string s;
  cin>>n>>q>>s;
  rep(i,n){
    if(x==1&&s[i]=='C') ans[i+1]=ans[i]+1,x=0;
    else ans[i+1]=ans[i],x=0;
    if(s[i]=='A') x=1;
  }
  rep(i,q) cin>>a>>b,cout<<ans[b]-ans[a]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
const long long INF = 1LL <<60;  
 
int main(void){
  long c[200001]={};
  long long res=0;
  long long i,j,k;
  long tmp;
  long n;
  
  cin>>n;
  long a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    c[a[i]]++;
  }
  for(i=1;i<=n;i++){
    res+=c[i]*(c[i]-1)/2;
  }
  for(i=0;i<n;i++){
    cout<<res-(c[a[i]]-1)<<endl;
  }
  
  //cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 6664
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;

ll ans = 0, a[MAXX], b[MAXX], c[MAXX] ,n , t, k= 1, m = 0, x, f1 , f2, a1 = 0, b1 = 0;
signed main()
{
    FAST;
    cin >> n;
    for(ll i = 0; i < n ; i++){
    	cin >> a[i];
    	a1 = a1*10 + a[i];
	}
	for(ll i = 0; i < n ; i++){
    	cin >> b[i];
    	b1 = b1*10 + b[i];
    	c[i] = i+1;
	}
	do{
		m = 0;
		for(ll i = 0; i < n; i++){
			m = 10*m +c[i];
		}
		if(m == a1){
			f1 = k;
		}
		else if(m == b1){
			f2 = k;
		}
		k ++;
	}while(next_permutation(c, c+n));
	if(a1 == b1){
		cout << 0;
		return 0;
	}
	cout << abs(f1-f2);
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i=0; i<N; i++) cin >> A.at(i);
    map<ll, ll> hist;
    for (ll i=0; i<N; i++) {
        if (hist.count(A.at(i))) hist[A.at(i)]++;
        else hist[A.at(i)] = 1; 
    }
    ll all_choice = 0;
    for (auto p : hist) {
        all_choice += (p.second*(p.second-1))/2;
    }
    for (ll i=0; i<N; i++) {
        cout << all_choice - (hist[A.at(i)]*(hist[A.at(i)]-1))/2 + ((hist[A.at(i)]-1)*(hist[A.at(i)]-2))/2 << endl;
    }
}

Measured memory_bytes: 11008
# AOJ DSL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A

import sys

line = input()
n, q = list(map(int, line.split()))
rel = {}
for i in range(0, n):
    rel[i] = []
parent = [i for i in range(0, n)]

def find(x):
    if parent[x] == x:
        return x
    else:
        y = find(parent[x])
        parent[x] = y
        return y

def unite(x, y):
    rx = find(x)
    ry = find(y)
    if rx < ry:
        parent[ry] = rx
    else:
        parent[rx] = ry

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

for _ in range(0, q):
    line = input()
    query, x, y = list(map(int, line.split()))
    if query == 0:
        unite(x, y)
    elif query == 1:
        print(1 if same(x, y) else 0)




Measured memory_bytes: 7044
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(void) {
  int n, a[10];
  scanf("%d", &n);
  long long ans1 = 1, ans2 = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    ans1 *= 3;
    if (!(a[i] & 1)) {
      ans2 *= 2;
    }
  }
  printf("%lld\n", ans1 - ans2);
  return 0;
}


Measured memory_bytes: 128
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long 
using namespace std; 

const long long N = 2e3, OO = 1e12, M = 1e9 + 7, M2 = 998244353, sq = 31622, lg = 23;
typedef pair <int, int> pii;
vector <int> G[N], GR[N];
int d[3][N][N], pr[3][N][N];

void BFS(int x) {
	queue <int> q;
	q.push(x);
	d[0][x][x] = 0;
	d[1][x][x] = 0;
	pr[0][x][x] = x;
	pr[1][x][x] = x;
	while(q.size()) {
		int u = q.front();
		q.pop();
		for(auto i : G[u]) {
			if(d[0][x][i] == OO) {
				q.push(i);
				d[0][x][i] = d[0][x][u] + 1;
				pr[0][x][i] = u;
			}
		}
	}
	q.push(x);
	while(q.size()) {
		int u = q.front();
		q.pop();
		for(auto i : GR[u]) {
			if(d[1][x][i] == OO) {
				q.push(i);
				d[1][x][i] = d[1][x][u] + 1;
				pr[1][x][i] = u;
			}
		}
	}
}

void add(int x, int y) {
	G[x].pb(y);
	GR[y].pb(x);
}

int32_t main() {
	use_fast;
	int n, m;
	cin >> n >> m;
	vector <pii> e;
	for(int i = 0; i < 2; i++) 
		for(int j = 1; j <= n + 100; j++) 
			for(int k = 1; k <= n + 100; k++)
				d[i][j][k] = OO;
	for(int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		e.pb({x, y});
		add(x, y);
	}
	for(int i = 1; i <= n; i++) 
		BFS(i);
	int g = OO, x = 0, y = 0, z = 0;
	for(int i = 1; i <= n; i++) {
		for(auto u : e) {
			int t = d[0][i][u.ff] + d[1][i][u.ss] + 1;
			if(t < g) {
				g = t;
				x = i, y = u.ff, z = u.ss;
			}
		}
	}
	if(g == OO)
		return cout << -1, 0;
	cout << g << endl;
	cout << x << endl;
	while(y != x) {
		cout << y << endl;
		y = pr[0][x][y];
	}
	while(z != x) {
		cout << z << endl;
		z = pr[1][x][z];
	}
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 71552
from itertools import accumulate

N = int(input())
As = list(map(int, input().split()))

accAs = list(accumulate(As))
sumA = accAs[-1]

ans = float('inf')
for i in range(N-1):
    len1 = accAs[i]
    len2 = sumA - len1
    ans = min(ans, abs(len1-len2))

print(ans)


Measured memory_bytes: 25768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n;
  cin>>n;
  ll k;
  cin>>k;
  if(k>(n-1)*(n-2)/2){
    cout<<-1<<endl;
    return 0;
  }
  vector<P> v;
  for(int i=0;i<(n-1);i++) v.push_back(P(1,i+2));
  int iidx=2,jidx=3;
  for(int i=0;i<(n-1)*(n-2)/2-k;i++){
    v.push_back(P(iidx,jidx));
    jidx++;
    if(jidx>n){
      iidx++;
      jidx=iidx+1;
    }
  }
  cout<<v.size()<<endl;
  for(int i=0;i<v.size();i++){
    cout<<v[i].first<<" "<<v[i].second<<endl;
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	string s; cin >> s;
	if (s[0] == s.back()) cout << (s.length() % 2 == 0 ? "First" : "Second") << endl;
	else cout << (s.length() % 2 == 1 ? "First" : "Second") << endl;
	return 0;
}

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

int main() {
    std::vector<int> counts(100001,0);
    std::vector<int> vec(100001, -1);
    for (int i = 2; i <= 100000; i++) {
        vec[i] = i;
    }
    for (int i = 2; i <= 100000; i++) {
        if (vec[i] == -1)
            continue;
        for (int p = i * 2; p <= 100000; p += i) {
            vec[p] = -1;
        }
        
    }
    for (int i = 1; i <= 100000; i++) {
        if (vec[i] != -1 && vec[(i+1)/2] != -1) {
            counts[i] = counts[i-1] + 1;
        }
        else {
            counts[i] = counts[i-1];
        }
    }
    
    int q, l, r;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        std::cin >> l >> r;
        std::cout << counts[r] - counts[l-1] << std::endl;
    }

}


Measured memory_bytes: 1408
import sys
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i],c[i] = map(int,input().split())
 
for i in range(1000):
    flag = True
    if len(str(i)) == n:
        for j in range(m):
            if str(i)[s[j]-1] != str(c[j]):
                flag = False
 
        if flag:
            print(i)
            sys.exit()
print(-1)

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

using namespace std;

const int N = 100005;

bool palim(string s) {
	for(int i = 0; i < s.size() / 2; i++) {
		if(s[i] != s[s.size() - 1 - i]) {
			return false;
		}
	}
	return true;
}

int main() {
	string s;
	cin >> s;

	if(!palim(s)) return printf("No\n"), 0;

	s.resize(s.size() / 2);

	if(!palim(s)) return printf("No\n"), 0;

	printf("Yes\n");
}


Measured memory_bytes: 3616
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k == X:
                ans+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
  int i,x,y,I,s,v;
  int box[2000];
  int array[2000];
  while(1){
    for(i=0;i<2000;i++){
      box[i]=0;
      array[i]=0;
	    }
	cin>>x>>y>>s;
      if(x==0&&y==0&&s==0) break;
      for(i=1;i<=s;i++){
	for(I=1;I<=s;I++){
	  v=i*x/100+I*x/100+i+I;
	 
	  if(s==v) {
	    box[i]=i;
	    array[i]=I;
	  
	  }
	}
      }
      int max=0,P;
      for(i=1;i<=s;i++){
	P=box[i]*y/100+array[i]*y/100+box[i]+array[i];
	
	if(max<P) max=P;

      }

      cout<<max<<endl;
    }
  
    return 0;
}

Measured memory_bytes: 1176
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b = readInts()
    from fractions import gcd
    ans = a // gcd(a,b) * b
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5044
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	a := make([]int, 3)
	con.Scan(&a[0], &a[1], &a[2])
	sort.Ints(a)
	if a[1]-a[0] == a[2]-a[1] {
		con.Println("YES")
	} else {
		con.Println("NO")
	}
	return nil
}


Measured memory_bytes: 640
#include <stdio.h>

using namespace std;

int main(){
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	int A[n][m],B[m][l];
	long long int C[n][l];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			C[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < l; j++){
			scanf("%d",&B[i][j]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int k = 0; k < l; k++){
			for(int j = 0; j < m; j++){
				C[i][k] += A[i][j]*B[j][k];
			}
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < l-1; j++){
			printf("%lld ",C[i][j]);
		}
		printf("%lld\n",C[i][l-1]);
	}
}






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

int main()
{
    int n;
    cin >> n;

    for(int i=1; i<10 ; i++)
    {
        for(int j=i; j<10 ; j++)
        {
            if(n == i*j)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a > b:
  if a - v*t <= b - w*t:
    print('YES')
  else:
    print('NO')
else:
  if a + v*t >= b+w*t:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 9180
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e12;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,k;
void solve()
{
    cin>>n>>m>>k;
    if(n>M||m>M)
        {cout<<"0 0"<<endl;return;}
    else
    {
        ll a=min(n,k);
        n-=a;k-=a;
        m-=min(m,k);
        cout<<n<<" "<<m<<endl;
    }
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << (a-b) % c << endl;
  
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
	char S[101],T[101];
	scanf("%s%s",S,T);
	int L=strlen(S);
	for(int i=0;i<L;i++){
		if(strcmp(S,T)==0){
			printf("Yes\n");
			return 0;
		}
		char c=S[0];
		for(int j=0;j<L-1;j++){
			S[j]=S[j+1];
		}
      	S[L-1]=c;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 1
1 100 1
)");
#define cin input
#endif

int main()
{
	int n, d;
	cin >> n >> d;

	vector<int> a(n);

	for (auto& i : a)
		cin >> i;
	
	vector<ll> ld(n), rd(n);
	vector<int> lp(n), rp(n);

	multimap<ll, int> q;

	REP (i, n)
	{
		ld[i] = a[i] - (ll)i * d;
		lp[i] = i;
		rd[n - i - 1] = a[n - i - 1] - (ll)i * d;
		rp[n - i - 1] = n - i - 1;
		if (i)
		{
			if (ld[i] > ld[i - 1])
			{
				ld[i] = ld[i - 1];
				lp[i] = lp[i - 1];
			}
			if (rd[n - i - 1] > rd[n - i])
			{
				rd[n - i - 1] = rd[n - i];
				rp[n - i - 1] = rp[n - i];
			}
		}
	}

	ll r = (ll)d * (n - 1);

	REP (i, n)
	{
		ll ldd = ld[i] - (a[i] - (ll)i * d);
		ll rdd = rd[i] - (a[i] - (ll)(n - i - 1) * d);

		if (i && i != n - 1)
		q.insert(make_pair(min(ldd, rdd), i));

		r += a[i] * 2;
	}

	r -= a[0];
	r -= a[n - 1];

	for (auto p : q)
	{
		r += p.first;
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 18176
#include<map>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define MOD 1000000007
#define inf 1e18
#define fr(a,b,c) for(ll a=b;a<c;++a)
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll t,n,i,j;

int main()
{
    fastio;
    cin>>n;
    ll a,ans=0;
    n--;
    ans=(n*(n+1))/2;
    cout<<ans<<endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);

  for(int i=0; i<N; i++){
    cin >> p.at(i);
  }

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

  int ans=0;

  for(int i=0; i<K; i++){
    ans=ans+p.at(i);
  }

  cout << ans << endl;

return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

long double n;

signed main() {
    cin >> n;
    rep1(I,4000) rep1(J,4000) {
        long double i = I, j = J;
        if ((n*i*j)/(4*i*j - n*i - n*j) == (int)((n*i*j)/(4*i*j - n*i - n*j)) && (n*i*j)/(4*i*j - n*i - n*j) > 0) {cout << i << " " << j << " " << (int)((n*i*j)/(4*i*j - n*i - n*j)) << endl;return 0;}
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
void func(vector<vector<int> > &G, int *depth)
{
    queue<int> q;
    int p = 1;
    q.push(p);
    depth[p] = 0;
    while (q.empty() == false)
    {
        p = q.front();
        q.pop();
        rep(i, 0, G[p].size())
        {
            if (depth[G[p][i]] == -1)
            {
                q.push(G[p][i]);
                depth[G[p][i]] = depth[p] + 1;
            }
        }
    }
}
int main()
{
    int n;
    cin >> n;
    int ans[n + 1], u, k, v;
    vector<vector<int> > G(n + 1, vector<int>(0));
    rep(i, 0, n)
    {
        ans[i + 1] = -1;
        cin >> u >> k;
        rep(j, 0, k)
        {
            cin >> v;
            G[u].push_back(v);
        }
    }
    func(G, ans);
    rep(i, 1, n + 1)
    {
        printf("%d %d\n", i, ans[i]);
    }
}


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

int main()
{
int n,m;
cin>>n>>m;
int a[n] = {0};
bool b[n] = {0};
int count1 = 0,count2 = 0;
for (int i = 0; i < m; ++i)
{
	int x;
	string s;
	cin>>x>>s;
	if(b[x - 1] == 1) continue;
	else
	{
		if(s[0] == 'A') 
		{
			count1++;
			count2+= a[x - 1];
			b[x - 1] = true;
		}
		else a[x - 1]++;
	}
}
cout<<count1<<" "<<count2<<endl;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String w = sc.next();
		String s;
		int count=0;
		while(true) {
			s= sc.next();
			if(s.equals("END_OF_TEXT")) break;
			if( w.equals(s.toLowerCase()) ) count++;
		}
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 26124
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, xa[52], ya[52], xb[52], yb[52], xc[102], yc[102], xd[52], yd[52], xe[52], ye[52], f[103][103]; long long d[103][103];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
void rec(int x, int y) {
	f[y][x] = true;
	for (int i = 0; i < 4; i++) {
		int tx = x + dx[i], ty = y + dy[i];
		if (0 <= tx && tx <= 2 * n + 1 && 0 <= ty && ty <= 2 * n + 1) {
			if (d[y][x] == d[ty][tx] && !f[ty][tx]) rec(tx, ty);
		}
	}
}
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> xa[i] >> yb[i] >> xb[i] >> ya[i];
			xc[2 * i] = xa[i], yc[2 * i] = ya[i], xc[2 * i + 1] = xb[i], yc[2 * i + 1] = yb[i];
		}
		sort(xc, xc + 2 * n);
		sort(yc, yc + 2 * n);
		memset(xd, 0, sizeof(xd));
		memset(yd, 0, sizeof(yd));
		memset(xe, 0, sizeof(xe));
		memset(ye, 0, sizeof(ye));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2 * n; j++) {
				if (xa[i] == xc[j] && !xd[i]) xa[i] = j + 1, xd[i] = 1;
				if (ya[i] == yc[j] && !yd[i]) ya[i] = j + 1, yd[i] = 1;
				if (xb[i] == xc[j] && !xe[i]) xb[i] = j + 1, xe[i] = 1;
				if (yb[i] == yc[j] && !ye[i]) yb[i] = j + 1, ye[i] = 1;
			}
		}
		memset(d, 0, sizeof(d));
		memset(f, 0, sizeof(f));
		for (int i = 0; i < n; i++) {
			for (int j = xa[i]; j < xb[i]; j++) {
				for (int k = ya[i]; k < yb[i]; k++) {
					d[j][k] += (1LL << i);
				}
			}
		}
		int ret = 0;
		for (int i = 0; i <= 2 * n + 1; i++) {
			for (int j = 0; j <= 2 * n + 1; j++) {
				if (!f[i][j]) {
					rec(j, i); ret++;
				}
			}
		}
		cout << ret << endl;
	}
}

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

string text;
int counter = 0, n;

int main()
{
    cin >> n >> text;
    
    for (int i = 0; i < n - 2; i++)
    {
        if (text[i] == 'A')
        {
            if (text[i + 1] == 'B')
            {
                if (text[i + 2] == 'C')
                {
                    counter++;
                }
            }
        }
    }
    
    cout << counter;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(a,b) memset(a,0,sizeof(a))
#define debug(x) cerr<<#x<<"="<<x<<endl;
typedef long long ll;
const int maxn=1e5+100;

int main()
{
	char a,b;
	cin>>a>>b;
	if (a>b) cout<<">"<<endl;
	else if (a<b) cout<<"<"<<endl;
	else cout<<"="<<endl;
	return 0;
}

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

struct node{
  struct node *right; /* ????????? */
  struct node *left;  /* ????????? */
  struct node *parent;/* ??? */
  int key;            /* ??????????????? */
};
typedef struct node * Node;
#define NIL NULL

Node root = NIL;

Node treeMinimum(Node x){
	return(NIL);

}

Node treeSearch(Node u, int k){
	if(u == NIL){
		return(NIL);
	}
	if(u->key < k){
		return(treeSearch(u->right, k));
	}else if(u->key > k){
		return(treeSearch(u->left, k));
	}else{
		return(u);
	}
}

Node treeSuccessor(Node x){
	return(NIL);

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  return;

}

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

  /* ??????????????? */
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  z->parent = NIL;

  /* 2???????卒蔵??即T?????????????????? */
  while(x != NIL){
	  /* z????????\????????????????????? */
	  y = x;
	  if(z->key < x->key){
		  x = x->left;
	  }else{
		  x = x->right;
	  }
  }

  /* p[z] = y? */
  z->parent = y;

  /* 2???????卒蔵??即T??????(????????属???0)??? */
  if(y == NIL){
	  root = z;
  }else if(z->key < y->key){
	  y->left = z;
  }else{
	  y->right = z;
  }

  return;
}

void inorder(Node u){
	if(u == NIL){
		return;
	}
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
	return;
}
void preorder(Node u){
	if(u == NIL){
		return;
	}
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
	return;
}

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

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <iostream>

using namespace std;

bool isDigit (char ch) {
    if (ch >= '0' && ch <= '9') return true;
    else return false;
}

int main() {

    int a, b;
    string post, ans = "Yes";

    cin >> a >> b;
    a--; b--;
    cin >> post;

    for (int i = 0; i <= a; i++) {
        if (!isDigit(post[i])) {
            ans = "No";
        }
    }
    if (post[a + 1] != '-') {
        ans = "No";
    }
    for (int i = a + 2; i < post.length(); i++) {
        if (!isDigit(post[i])) {
            ans = "No";
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//	-*- mode: C++ -*-
//	Search II
//		You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.
//
//	Input
//		In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.
//
//	Output
//		Print C in a line.
//
//	Constraints
//		Elements in S is sorted in ascending order
//		n ≤ 100000
//		q ≤ 50000
//		0 ≤ an element in S ≤ 10^9
//		0 ≤ an element in T ≤ 10^9
//	Sample Input 1
//		5
//		1 2 3 4 5
//		3
//		3 4 1
//	Sample Output 1
//		3
//	Sample Input 2
//		3
//		1 2 3
//		1
//		5
//	Sample Output 2
//		0
//	Sample Input 3
//		5
//		1 1 2 2 3
//		2
//		1 2
//	Sample Output 3
//		2

#include <iostream>
#include <vector>

bool	bSearch(std::vector<unsigned int>	S,
				unsigned int				t)
{
	unsigned int	left	= 0;
	unsigned int	right	= S.size() - 1;

	while(left <= right){
		unsigned int	middle	= (left + right) / 2;

		if(S[middle] == t){
			return	true;
		}
		else if(S[middle] < t){
			left	= middle + 1;
		}
		else{
			right	= middle - 1;
		}
	}

	return	false;
}

int	main(int	argc,
		 char*	argv[])
{
	unsigned int	n	{0};

	std::cin >> n;

	std::vector<unsigned int>	S;
	for(auto i = 0; i < n; i++){
		unsigned int	s	{0};
		std::cin >> s;
		S.push_back(s);
	}

	unsigned int	q	{0};

	std::cin >> q;

	std::vector<unsigned int>	T;
	for(auto i = 0; i < q; i++){
		unsigned int	t	{0};
		std::cin >> t;
		T.push_back(t);
	}

	unsigned int	C	{0};
	for(auto t : T){
		if(bSearch(S, t)){
			++C;
		}
	}

	std::cout << C << '\n';
	return	0;
}



Measured memory_bytes: 4040
def main():
    n = int(input())
    m = [[0] * n for _ in range(n)]
    for _ in range(n):
        u, k, *v = map(int, input().split())
        for i in range(k):
            m[u - 1][v[i] - 1] = 1
    for row in m:
        print(' '.join(map(str, row)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5668
def factrial(n): # 試し割り算法で素因数分解
  factors = []
  while n%2 == 0:
    factors.append(2)
    n //= 2
    
  for i in range(3, int(n**0.5)+1):
    while n%i == 0:
      factors.append(i)
      n //= i
      
  if n != 1: factors.append(n)
  
  return factors


n = int(input())
mod = 10**9+7

d = {}
for i in range(1, n+1): # 1〜nまでの各値を素因数分解
  fac = factrial(i)
  for j in fac: # 分解して取得した要素の回数をカウント
    if j in d: d[j] += 1
    else: d[j] = 1

ans = 1
for k,v in d.items():
  # 取得した要素に1を足した値を合計値にかけ合わせる
  # 約数として"1"はカウントされていない為、このタイミングで追加する
  ans *= (v+1) 
  ans %= mod
print(ans)

Measured memory_bytes: 9396
import java.util.*;

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

		int n=s.nextInt(),k=s.nextInt();
		int[]w={s.nextInt(),s.nextInt(),s.nextInt()};
		String t=s.next();

		int[][]a=new int[k][3];
		for(int i=0;i<n;++i) {
			int[] A = a[i%k];
			int p = Math.max(A[1],A[2]);
			int q = Math.max(A[2],A[0]);
			int r = Math.max(A[0],A[1]);
			A[0]=p;
			A[1]=q;
			A[2]=r;
			int j="spr".indexOf(t.charAt(i));
			A[j]+=w[j];
		}

		int v=0;
		for(int i=0;i<k;++i)
			v+=Arrays.stream(a[i]).max().getAsInt();
		System.out.println(v);

	}
}


Measured memory_bytes: 43388
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    string s;
    cin >> s;

    int leftOfBs = s.length();
    bool b = false;
    lin res = 0;

    for(int i = s.length() - 1; i>= 0; i--)
    {
        if(s[i] == 'W')
        {
            b = true;
            continue;
        }
        else if(!b)
            leftOfBs--;
        else
        {
            leftOfBs--;
            res += (leftOfBs - i);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
typedef long long ll;

int ar[maxn];
int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    int n, k, x;
    cin >> n >> k;
    for(int i = 0; i < k; i++){
        cin >> x;
        for(int i = 0; i < x; i++){
            int cnt;
            cin >> cnt;
            ar[cnt] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)ans += (ar[i] == 0);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;


int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={-1,0,1,-1,1,-1,0,1};

int main() {

	string s[50];
	int h,w;
	cin>>h>>w;
	
	for(int i=0;i<h;i++)
		cin>>s[i];

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int cnt=0;
			if(s[i][j]=='.'){
				for(int k=0;k<8;k++){
					int x,y;
					x=i+dx[k];
					y=j+dy[k];
					if(x>=0&&x<h&&y>=0&&y<w&&s[x][y]=='#'){
						cnt++;
					}

				}
				s[i][j]='0'+cnt;
			}

		}
		
		
	}
	for(int i=0;i<h;i++)
		cout << s[i] << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;

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

    set<ll> cnd;
    for (ll i = 1LL; i <= N; i *= 6) {
        cnd.insert(i);
    }
    for (ll i = 1LL; i <= N; i *= 9) {
        cnd.insert(i);
    }

    vector<ll> dp(100010, 1e18);
    dp[0] = 0;

    vector<ll> anst;
    for (auto x: cnd) {
        for (int i = 0; i + x <= 100005; i++) {
            dp[i + x] = min(dp[i + x], dp[i] + 1);
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 4048
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    
    for (int i = 0; i < S.length(); ++i){
      if (S.equals(T)){  
        System.out.println("Yes");
        return;
       }
      
      char[] s1 = S.toCharArray();
      char[] s2 = new char[S.length()];
      
      for(int j = 0; j < S.length(); ++j){
        if(j == 0){
          s2[S.length()-1] = s1[0];
        }else{
          s2[j-1] = s1[j];
        }
      }
      S = String.valueOf(s2);
    }
 
        System.out.println("No");
   
  }
}

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

int main(){
    ll h;cin>>h;
    ll count = 0,ans = 0;
    while(h>0)
    {
        ans += pow(2,count);
        h /=2;
        count++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU
 
main = getContents >>= print . solve . map read . tail . words

solve cards = ans where
    f (r, a) v = (odd w, a + (div w 2) + k)  where
        (k, w) = if r && v > 0 then (1, v - 1) else (0, v)
    (_, ans) = foldl f (False, 0) cards 

Measured memory_bytes: 79228