akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<LL> a(n);
  LL mii = 0;
  LL mai = 0;
  REP(i, 0, n) {
    cin >> a[i];
    if (a[i] < a[mii]) mii = i;
    if (a[i] > a[mai]) mai = i;
  }
  int init = abs(a[mii]) > abs(a[mai]) ? mii : mai;
  cout << 2 * n-1 << endl;
  if (a[init] >= 0) {
    REP(i, 0, n) { cout << init + 1 << " " << i + 1 << endl; }
    REP(i, 0, n-1) { cout << i + 1 << " " << i + 2 << endl; }
  }
  if (a[init] < 0) {
    REP(i, 0, n) { cout << init + 1 << " " << i + 1 << endl; }
    for (int i = n - 2; i >= 0; --i) {
      cout << i + 2 << " " << i + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



int main(){
	int a,b,h,m;
    cin >> a >> b >> h >> m;
    
    double ans;
    
    double kakudo = (double)m;
    kakudo -= (h*5.0 + m/12.0);
    
    double yogen = 2*a*b*cos((2.0*M_PI*kakudo) / 60.0);
    ans = a*a + b*b - yogen;
    
    
    printf("%.12f\n", sqrt(ans));
	
	return 0;
}

Measured memory_bytes: 4064
# coding: utf-8
# Your code here!
import math

N = int(input())
count = 0
count2 = 0

al=[chr(ord('a') + i) for i in range(26)]

thresh = [26**i for i in range(1,12)]
for i in range(1,len(thresh)):
 thresh[i] = thresh[i] + thresh[i-1]
 
for i in range(len(thresh)):
    if thresh[i] <N:
        continue
    else:
        char_num = i+1#何文字
        name_str = ['a' for i in range(char_num)]
        if char_num > 1:
            count = N-thresh[i-1]#char_numの何個目か
            #print('char_num', char_num)
            for i in range(char_num):
                count2 = int((count-1)/(26**(char_num-i-1)))
                if (count2 > 0)&(i!=(char_num-1)):
                    if count2 <= 25:
                        name_str[i] = al[count2]
                        count = count - ((26**(char_num-i-1))*count2)
                    else:
                        name_str[i] = al[count2-1]
                        count = count - ((26**(char_num-i-1))*count2)
        else:
            count = N
        if count > 0:
            name_str[-1] = al[count-1]
        break
    
    
out = ""
for i in name_str:
    out = out + i
print(out) 

Measured memory_bytes: 9248
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int W, H, x, y, r;
    
    scanf("%d %d %d %d %d", &W,&H,&x,&y,&r);
    
    if (x+r > W || y+r > H || x<0 || y<0) {
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
int main()
{
	int a;
	long long sum = 0;
	scanf("%d", &a);
	for(int i = 1; i <= a; i++)
	{
		if(i % 3 && i % 5)
			sum += i;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 3768
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    ll n, sum = 0;
    cin>>n;

    ll arr[n+1];
    for(ll i=0; i<n; i++){
        cin>>arr[i];
        sum += arr[i];
    }

    vector<vector<ll> > dp(n, vector<ll> (n, 0));

    for(ll i=0; i<n; i++){
        dp[i][i] = arr[i];
    }

    for(ll i=0; i<n-1; i++){
        dp[i][i+1] = max(arr[i], arr[i+1]);
    }

    for(ll len = 3; len <= n; len++){
        for(ll i=0; i<=n - len; i++){
            ll j = i + len - 1;

            // cout<<i+2<<" "<<j<<" "<<i<<" "<<j-2<<" "<<i-1<<" "<<j-1<<endl;
            dp[i][j] = max(arr[i] + min(dp[i+2][j], dp[i+1][j-1]), arr[j] + min(dp[i][j-2], dp[i+1][j-1]));
        }
    }

    ll x = dp[0][n-1];
    ll y = sum - x;

    cout<<(x - y)<<endl;

    return 0;
}


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

namespace Atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());//初項
            int max = 1000000;//最大項数
            int m = 1;//項数
            List<int> ProgressList = new List<int>();
            int prevVal = s;
            int val = prevVal;
            do
            {
                if (m > 1)
                {
                    ProgressList.Add(prevVal);
                    val = GetProgression(prevVal);

                    if (FindMatch(ProgressList, val))
                    {
                        ProgressList.Add(val);
                        Console.WriteLine(m);
                        break;
                    }
                }
                m++;
                prevVal = val;
            } while (m <= 1000000);

            //
            Console.ReadLine();

        }

        private static int GetProgression(int n)
        {
            if (n % 2 == 0)
                return (n / 2);
            else
                return n * 3 + 1;
        }

        private static bool FindMatch(List<int> list, int m)
        {
            
            for (int n = 0; n < list.Count; n++)
                if (list[n] == m)
                    return true;
            return false;
        }
    }
}


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

int main() {
	string s[200];
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		cout << s[i] << endl << s[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {		
		String tmpthe = "";
		String tmpthis = "";
		String tmpthat = "";
		int shift_num = 0;

		Scanner scanner = new Scanner(System.in);
		scanner.useDelimiter("\\n");
		while(scanner.hasNext()){
			String input = scanner.next();
			for(int i=0; i<26; i++){
				tmpthe = shift("the", i);
				tmpthis = shift("this", i);
				tmpthat = shift("that", i);
				if((input.indexOf(tmpthe) != -1) || (input.indexOf(tmpthis) != -1) || (input.indexOf(tmpthat) != -1)){
					shift_num = i;
					break;
				}
			}
			System.out.println(shiftR(input, shift_num));
			tmpthat = "";
			tmpthis = "";
			tmpthat = "";
			shift_num=0;
		}
	}

	public static String shift(String s, int num){
		String tmp = "";
		for(int i=0; i<s.length(); i++){
				if((s.charAt(i)+num%26) > 'z'){
					tmp = tmp + String.valueOf((char)(s.charAt(i)+(num%26)-'z'+'a'-1));
				}else{
					tmp = tmp + String.valueOf((char)((s.charAt(i)+num%26)));
				}
		}
		return tmp;
	}

	public static String shiftR(String s, int num){
		String tmp ="";
		for( int i=0; i<s.length(); i++){
			if(s.charAt(i) >= 'a' && s.charAt(i) <= 'z'){
				if(s.charAt(i)-num < 'a'){
					tmp = 	tmp + String.valueOf((char)(s.charAt(i)-num+26));
				}else{
					tmp = tmp + String.valueOf((char)((s.charAt(i)-num)));
				}
			}else{
				tmp = tmp + String.valueOf((char)(s.charAt(i)));
			}
		}
		return tmp;
	}
}

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

int main(){
  string S; cin >> S;
  if(S[5] == '0'){
    if(S[6] == '1' || S[6] == '2' || S[6] == '3' || S[6] == '4'){
      cout << "Heisei";
      return 0;
    }
  }
  cout << "TBD";
}

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

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;

    vector<pair<int, int>> rc(n);

    for (int i = 0; i < n; i++) {
        cin >> rc[i].first >> rc[i].second;
        rc[i].first--;
        rc[i].second--;
    }

    rc.emplace_back(h - 1, w - 1);
    n++;

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

    using i64 = long long;

    const i64 mod = 1000000000 + 7;

    vector<i64> inv(h + w + 1);
    vector<i64> fact(h + w + 1);
    vector<i64> fact_inv(h + w + 1);

    for (i64 i = 1; i < h + w + 1; i++) {
        inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    }

    fact[0] = 1;
    fact_inv[0] = 1;

    for(int i = 1; i < h + w + 1; ++i) {
        fact[i] = fact[i - 1] * i % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }

    auto comb = [&](int n, int k) {
        if (n < 0 || k < 0) {
            return i64(0);
        }

        if (n < k) {
            return i64(0);
        }

        return fact[n] * fact_inv[n - k] % mod * fact_inv[k] % mod;
    };

    auto f = [&](int x, int y) {
        return comb(x + y, y);
    };

    vector<i64> dp(n);

    for (int i = 0; i < n; i++) {
        dp[i] = f(rc[i].first, rc[i].second);

        for (int j = 0; j < i; j++) {
            dp[i] = (dp[i] - dp[j] * f(rc[i].first - rc[j].first, rc[i].second - rc[j].second) % mod + mod) % mod;
        }
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <algorithm>

using namespace std;

int T, P, R;

int WAcnt[50][10];
int ACcnt[50];
int pena[50];
int gtID[50];

bool input() {
  int i;
  int tID, pID, time;
  char s[8];

  scanf("%d %d %d", &T, &P, &R);
  if (!T && !P && !R) return false;

  fill(WAcnt[0], WAcnt[0] + 50 * 10, 0);
  fill(ACcnt, ACcnt + 50, 0);
  fill(pena, pena + 50, 0);
  for (i = 0; i < R; i++) {
    scanf(" %d %d %d %s", &tID, &pID, &time, s);
    tID--;
    pID--;
    if (s[0] == 'C') {
      ACcnt[tID]++;
      pena[tID] += WAcnt[tID][pID] * 1200 + time;
    } else {
      WAcnt[tID][pID]++;
    }
  }

  return true;
}

int main() {
  int i, j, tmp;


  while (input()) {
    for (i = 0; i < T; i++) {
      gtID[i] = i;
    }

    for (i = 0; i < T - 1; i++) {
      for (j = T - 1; j > i; j--) {
        if (ACcnt[j - 1] < ACcnt[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;
        } else if (ACcnt[j - 1] == ACcnt[j] && pena[j - 1] > pena[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;

        } else if (pena[j - 1] == pena[j] && gtID[j - 1] > gtID[j]) {
          tmp = ACcnt[j];
          ACcnt[j] = ACcnt[j - 1];
          ACcnt[j - 1] = tmp;
          tmp = pena[j];
          pena[j] = pena[j - 1];
          pena[j - 1] = tmp;
          tmp = gtID[j];
          gtID[j] = gtID[j - 1];
          gtID[j - 1] = tmp;

        }
      }



    }

    for (i = 0; i < T; i++) {
      printf("%d %d %d\n", gtID[i] + 1, ACcnt[i], pena[i]);
    }


  }


  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp

int top = 0;
int stk[100000];

static void push(int x) {
    stk[++top] = x;
}

static int pop() {
    return stk[top--];
}

int main() {

    char str[50];
    while(scanf("%s", str) != EOF) {
        char op = str[0];
        if (op == '+') {
            int a = pop();
            int b = pop();
            push(a+b);
        }
        else if (op == '-') {
            int a = pop();
            int b = pop();
            push(b-a);
        }
        else if (op == '*') {
            int a = pop();
            int b = pop();
            push(a*b);
        }
        else {
            push(atoi(str));
        }
    }

    cout << pop() << "\n";

    return 0;
}


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

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>();


        static void Main(string[] args)
        {
            var ll = ReadLongArr();
            var res = ll[0] + ll[1] + ll[2];

            if(res > 21)
            {
                Console.WriteLine("bust");

            }
            else
            {
                Console.WriteLine("win");

            }
        }


        public static int Digit(long num)
        {
            // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
            return (num == 0) ? 1 : ((int)Math.Log10(num) + 1);
        }

        public static long nCm(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            var a = n * nCm(n - 1, m - 1) / m;
            return a % 1000000007;
        }

        private static string ReadString()
        {
            return Console.ReadLine();
        }
        private static string[] ReadStringArr()
        {
            return Console.ReadLine().Split(' ');
        }
        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadLongArr()
        {
            string[] s = ReadStringArr();
            long[] l = new long[s.Length];
            for(int i=0; i<l.Length; i++)
            {
                l[i] = long.Parse(s[i]);
            }

            return l;
        }
    }

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
int n,p[8],q[8];

int my_order(int *x){
  int rtn=0;
  REP(i,n){
    int remain=0,tmp=1;
    for(int j=i+1;j<n;j++) if(x[j]<x[i]) remain++;
    for(int j=1;j<=n-i-1;j++) tmp*=j;
    rtn+=tmp*remain;
  }
  return rtn;
}

int main(){
  cin>>n;
  REP(i,n) cin>>p[i];
  REP(i,n) cin>>q[i];
  
  cout<<abs(my_order(p)-my_order(q));
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String a = "";
        int length = str.length();
        for(int i=0;i<length;i++){
            char c = str.charAt(i);
            if(Character.isUpperCase(c)) a += Character.toLowerCase(c);
            else a += Character.toUpperCase(c);
        }
        System.out.println(a);
        sc.close();
    }
}


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

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define sz(v) ll(v.size())


void solve(string s, string t){
    ll dp[sz(s)+1][sz(t)+1];
    fill(dp[0], dp[sz(s)+1], 0);
    ll ssize = sz(s);
    ll tsize = sz(t);
    rep(i, ssize) {
        rep(j, tsize) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    ll i = ssize;
    ll j = tsize;
    string ans = "";
    while(dp[i][j] != 0) {
        if (is(s[i-1], t[j-1])) {
            ans = s[i-1] + ans;
            i--;
            j--;
        } else if (is(dp[i][j], dp[i-1][j])) {
            i--;
        } else if (is(dp[i][j], dp[i][j-1])) {
            j--;
        }
    }
    cout << ans << endl;
}

int main() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    solve(s, t);
    return 0;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long  a, b, c, d;
    cin >> a >> b >> c >> d;

    long long ans;

    long long ac, ad, bc, bd;

    ac = a*c;
    ad = a*d;
    bc = b*c;
    bd = b*d;

    ans = ac;

    if(ans < ad) ans = ad;
    if(ans < bc) ans = bc;
    if(ans < bd) ans = bd;

    cout << ans << endl;
}

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

void printa(vector<int> a, int n)
{
    for (int i = 0; i < n - 1 ; i++) cout << a.at(i) << " ";
    cout << a.at(n-1) << endl;
}
int main()
{
    int n;
    vector<int> a;
    
    cin >> n;
    for (int i = 0; i < n; i++) { int tmp; cin >> tmp; a.push_back(tmp); }
    printa(a, n);
    for (int i = 1; i < n; i++) {
        int v = a.at(i); 
        int j;
        for (j = i - 1; j >= 0 && v < a.at(j); j--) a.at(j+1) = a.at(j);
        a.at(j+1) = v;
        printa(a, n);
  }

  return 0; 
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> P(N), C(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for(int i = 0; i < N; i++) cin >> C[i];
    long long ans = -1e18;
    vector<int> used(N, 0);
    vector<vector<long long>> vec(N);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(used[i] == 1) continue;
        int flag = 0;
        int ind = i, ind2 = i;
        while(flag == 0 || ind != ind2){
            flag = 1;
            vec[cnt].push_back(C[ind]);
            used[ind] = 1;
            ind = P[ind];
        }
        cnt++;
    }
    vector<vector<long long>> memo(cnt, vector<long long>(N, -1e18));
    for(int i = 0; i < cnt; i++){
        long long siz = vec[i].size();
        long long temp = 0;
        long long res = 0;
        for(int j = 0; j < siz; j++){
            long long t = 0;
            for(int k = 0; k < siz; k++){
                t += vec[i][(j + k) % siz];
                memo[i][k] = max(memo[i][k], t);
            }
            temp += vec[i][j];
        }
        if(temp > 0) {
            res += K / siz * temp;
            long long temp2 = 0;
            if(K / siz > 0){
                temp2 = (K / siz - 1) * temp;
                long long m = *max_element(memo[i].begin(), memo[i].begin() + siz);
                temp2 += m;
            }
            if(K % siz > 0){
                long long t = *max_element(memo[i].begin(), memo[i].begin() + K % siz);
                res += t;
            }
            ans = max(res, ans);
            ans = max(temp2, ans);
        }
        else{
            long long r = -1e18;
            int flag = 0;
            for(int j = 0; j < min(K, siz); j++){
                r = max(r, memo[i][j]);
                flag = 1;
            }
            if(flag == 1) res += r;
            ans = max(res, ans);
        }
    }
    cout << ans << endl;
}


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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

	int h1(int key){ return key % M;}
	int h2(int key){ return 1 + (key % (M-1));}

int find(char str[]){

    /* your task */
	long long key,i,h;
	key = getKey(str);
	for(i = 0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0)return 1;
		else if( strlen(H[h]) == 0)return 0;
		
	}
	return 0;
}

int insert(char str[]){
	
    /* your task */
	long long key,i,h;
	key = getKey(str);
	for(i = 0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0)return 1;
		else if( strlen(H[h]) == 0){
			strcpy(H[h],str);
			return 0;
		}
		
	
	}
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 15460
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a; cin>>a;
    if(a==0){
        cout<<1;
    }
    else{
        cout<<0;
    }
    
    
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) {
        L[i] = A[left+i];
    }
    for(int i = 0; i < n2; i++) {
        R[i] = A[mid+i];
    }
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++) {
        cnt++;
        if(L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        }
        else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right) {
    if(left+1 < right) {
        int mid = (left + right) /2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}

int main() {
    int A[MAX],n,i;
    cnt = 0;
    
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];
    
    mergeSort(A,0,n);
    
    for(i = 0; i < n; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 6888
//shara's here
//私は私は大きい男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define all(a) a.begin(),a.end()
#define vl vector<ll>
#define vll vector<vector<ll> >
#define ins insert
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
	ll dusk[]={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
};	ll dawn;
	cin >> dawn;
	dawn--;
	cout << dusk[dawn] << endl;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	





return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


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


using ll = long long int;

using namespace std;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, ans;
    cin >> n;
    ans = 0;
    if (n % 2 == 1)
    {
        ans = 0;
    }
    else
    {
        /*
        ll k, r;
        k = n / 2;
        r = n % 5;
        ll m[] = {0, 3, 1, 4, 2};
        k -= m[r];
        if (k > 0)
        {
            ans = k / 5;
            ans += (k % 5);
        }*/
        /*
        ll x;
        x = n;
        while(x > 1)
        {
            ll c = x;
            ll k2, k5;
            k2 = k5 = 0;
            while(c % 2 == 0)
            {
                ++k2;
                c /= 2;
            }
            c = x;
            while(c % 5 == 0)
            {
                ++k5;
                c /= 5;
            }
            cout << x << "  k2 = " << k2 << "  k5 = " << k5 << endl;
            x -= 2;
        }
        */
        
        ll x, k2, k5;
        x = 10;
        k2 = k5 = 0;
        while(n >= x)
        {
            k5 += n / x;
            x *= 5;
        }
        x = 2;
        while(n >= x)
        {
            k2 += n / x;
            x *= 2;
        }
        ans = min(k2, k5);
    }
    
    
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
#= Local routines ===================================================#
sub getScore{
	my $n = shift;
	my $sum = 0;

	my $tmp = $n;
	while ($tmp){
		$sum += $tmp % 10;
		$tmp = int($tmp / 10);
	}
	return $n / $sum;
}


sub func{
	my $n = shift;
	my $add = 9;
	my $mul = 10;

	my $min = {N => $n, SCORE => getScore($n)};

	my $exp = $n;
	while($exp){
		my $tmp = (int($n / $mul) * $mul) + $add;
		
		my $score = getScore($tmp);
		if ($min->{SCORE} > $score){
			$min->{N} = $tmp;
			$min->{SCORE} = $score;
		}
		
		$add = ($add * 10) + 9;
		$mul *= 10;
		$exp = int($exp / 10);
	}

	return $min->{N};
}

sub main(){
	my $in = <>;chomp $in;

	my $nextN = 1;
	foreach (1 .. $in){
		$nextN = func($nextN);
		print $nextN, "\n";
		$nextN++;
	}

	return 0;
}

#----- 実行 -----#
exit( main() );




Measured memory_bytes: 768
#M

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

mod=10**9+7

dp=[[0]*(K+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0]=1


for i in range(N):
    S=1
    for j in range(K):
        S+=dp[i][j+1]
        if j+1>a[i]:
            S-=dp[i][j-a[i]]
        dp[i+1][j+1]=S%mod
        
print(dp[-1][-1])





Measured memory_bytes: 119660
N = int(input())
S = str(input())

import string
alphabet = list(map(chr, range(ord('A'), ord('Z')+1)))

ans = ''
for s in S:
  a = list(map(chr, range((ord(s)+N-ord('A')) % 26 + ord('A'),
                          (ord(s)+N-ord('A')) % 26 + ord('A')+1)))
  ans = ans + a[0]
print(ans)

Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <random>
#include <time.h>
#include <chrono>
#include <cmath>
using namespace std;


int main() {
    string str;
    cin >> str;
    bool is_key = false;

    if (str.substr(0, 7).compare("keyence") == 0) {
        is_key = true;
    }
    else if (str.substr(0, 6).compare("keyenc") == 0) {
        if (str.substr(str.length() - 1, 1).compare("e") == 0) {
            is_key = true;
        }
    }
    else if (str.substr(0, 5).compare("keyen") == 0) {
        if (str.substr(str.length() - 2, 2).compare("ce") == 0) {
            is_key = true;
        }
    }
    else if (str.substr(0, 4).compare("keye") == 0) {
        if (str.substr(str.length() - 3, 3).compare("nce") == 0) {
            is_key = true;
        }
    }
    else if (str.substr(0, 3).compare("key") == 0) {
        if (str.substr(str.length() - 4, 4).compare("ence") == 0) {
            is_key = true;
        }
    }
    else if (str.substr(0, 2).compare("ke") == 0) {
        if (str.substr(str.length() - 5, 5).compare("yence") == 0) {
            is_key = true;
        }
    }
    else if (str.substr(0, 1).compare("k") == 0) {
        if (str.substr(str.length() - 6, 6).compare("eyence") == 0) {
            is_key = true;
        }
    }
    else {
        if (str.substr(str.length() - 7, 7).compare("keyence") == 0) {
            is_key = true;
        }
    }

    if (is_key) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
#define debug(n) cout<<n<<endl
#define debug2(a, b) cout<<a<<" "<<b<<endl;
#define forn(i, in, fin) for(int i = in; i<fin; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
using namespace std;
 
vector< double > p;
vector< vector<double> > dp;
lli posibles;
lli n; 
 
double eps = 1e-9;
 
double f(lli index, lli taken)
{
    if(taken > posibles) return 0;
    if(index == n) return (double)1;

    if( dp[index][taken] != -1) return dp[index][taken];
 
    double actual = p[index];
    dp[index][taken] = 1;
 
    return dp[index][taken] *= f(index+1, taken) * actual + f(index+1, taken+1)*(1-actual);
}
 
 
 
int main()
{
    fastIO();
    cin>>n;
    p.resize(n);
    posibles = (n-1)/2;
    dp.assign(n, vector<double>(3000, -1));
    for(double &x: p)
        cin>>x;
    cout<< fixed << setprecision(10) << f(0,0) <<endl;
    return 0;
}

Measured memory_bytes: 70912
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

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

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll N = 1000000007;// 10^9+7


string s;
long long sum[4][100005] = { 0 }, ans = 0, maxn[4] = { 0 };

int main() {
	long long i, j, cnt = 0;

	cin >> s;
	for (i = 1; i <= s.size(); ++i) {
		for (j = 0; j < 3; ++j) {
			sum[j][i] = sum[j][i - 1];
			if (s[i - 1] == 'A' + j) ++sum[j][i];
		}
		sum[3][i] = sum[3][i - 1];
		if (s[i - 1] == '?') ++sum[3][i];
	}

	for (i = 0; i < 4; ++i) maxn[i] = 1;

	for (i = 0; i < s.size(); ++i) {
		if (s[i] == '?' && cnt < 4) ++cnt;
		for (j = 0; j < cnt; ++j) {
			if (s[i] == '?') maxn[j] *= 3;

			maxn[j] %= N;
		}
	}

	for (i = 1; i <= s.size(); ++i) {
		ans %= N;
		if (s[i - 1] == 'B') {
			ll next = maxn[0];next %= N;
			// AC
			next *= sum[0][i - 1];next %= N;
			next *= sum[2][s.size()] - sum[2][i];next %= N;
			ans += next; ans %= N;

			//?C
			next = maxn[1];next %= N;
			next *= sum[3][i - 1];next %= N;
			next *= sum[2][s.size()] - sum[2][i];next %= N;
			ans += next;ans %= N;

			// A?
			next = maxn[1];	next %= N;
			next *= sum[0][i - 1];	next %= N;
			next *= sum[3][s.size()] - sum[3][i];next %= N;
			ans += next;ans %= N;

			//??
			next = maxn[2];	next %= N;
			next *= sum[3][i - 1];	next %= N;
			next *= sum[3][s.size()] - sum[3][i];	next %= N;
			ans += next;	ans %= N;
		}
		else if (s[i - 1] == '?') {
			ll next = maxn[1];	next %= N;
			// AC
			next *= sum[0][i - 1];	next %= N;
			next *= sum[2][s.size()] - sum[2][i];	next %= N;
			ans += next;	ans %= N;

			//?C
			next = maxn[2];	next %= N;
			next *= sum[3][i - 1];	next %= N;
			next *= sum[2][s.size()] - sum[2][i];	next %= N;
			ans += next;	ans %= N;

			// A?
			next = maxn[2];	next %= N;
			next *= sum[0][i - 1];	next %= N;
			next *= sum[3][s.size()] - sum[3][i];	next %= N;
			ans += next;	ans %= N;
			//??
			next = maxn[3];	next %= N;
			next *= sum[3][i - 1];	next %= N;
			next *= sum[3][s.size()] - sum[3][i];	next %= N;
			ans += next;	ans %= N;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[100100];
map<ll,ll> m;
vector<ll> v4;
vector<ll> v2;

int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		m[a[i]]++;
	}
	for(auto it=m.begin();it!=m.end();it++){
		if(it->second>=4){
			v4.push_back(it->first);
		}else if(it->second>=2){
			v2.push_back(it->first);
		}
	}
	ll ans=0;
	sort(v2.begin(),v2.end(),greater<ll>());
	sort(v4.begin(),v4.end(),greater<ll>());
	if(v4.size()){
		ans=max(ans,v4[0]*v4[0]);
	}
	if(v2.size()>=2){
		ans=max(ans,v2[0]*v2[1]);
	}
	if(v2.size()>=1&&v4.size()>=1)
		ans=max(ans,v2[0]*v4[0]);
	cout<<ans<<endl;
	return 0;
}
	



Measured memory_bytes: 7296
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
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 n,k,q,ans;
ll a[Max];
//ll score[Max];
void solve(){
	cin>>n>>k>>q;
	ll x=q;
	while(q--){
		ll t;
		cin>>t;
		a[t]++;
	}
	rep(i,1,n+1){
		if(k-(x-a[i])>0)cout<<"Yes\n";else cout<<"No\n";
	}
	//cout<<ans;
}
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
 

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

	ll N;
	cin >> N;
	if(N==3){cout<<61<<endl;return 0;}
	const ll A=0,C=1,G=2,T=3;
	ll dp[N+1][4][4][4][4]={};
	FOR(i,0,4){
		FOR(j,0,4){
			FOR(k,0,4){
				FOR(l,0,4){
					if(i==A&&j==G&&k==C)continue;
					if(i==A&&j==C&&k==G)continue;
					if(i==G&&j==A&&k==C)continue;
					if(j==A&&k==G&&l==C)continue;
					if(j==A&&k==C&&l==G)continue;
					if(j==G&&k==A&&l==C)continue;
					if(i==A&&k==G&&l==C)continue;
					if(i==A&&j==G&&l==C)continue;
					dp[4][i][j][k][l]=1;
				}
			}
		}
	}
	ll ans=0;
	FOR(t,5,N+1){
		FOR(h,0,4)FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4){
			if(i==A&&j==G&&k==C)continue;
			if(i==A&&j==C&&k==G)continue;
			if(i==G&&j==A&&k==C)continue;
			if(j==A&&k==G&&l==C)continue;
			if(j==A&&k==C&&l==G)continue;
			if(j==G&&k==A&&l==C)continue;
			if(i==A&&k==G&&l==C)continue;
			if(i==A&&j==G&&l==C)continue;
			(dp[t][i][j][k][l]+=dp[t-1][h][i][j][k])%=MOD;
		}
	}
	FOR(i,0,4)FOR(j,0,4)FOR(k,0,4)FOR(l,0,4){
		if(i==A&&j==G&&k==C)continue;
		if(i==A&&j==C&&k==G)continue;
		if(i==G&&j==A&&k==C)continue;
		if(j==A&&k==G&&l==C)continue;
		if(j==A&&k==C&&l==G)continue;
		if(j==G&&k==A&&l==C)continue;
		if(i==A&&k==G&&l==C)continue;
		if(i==A&&j==G&&l==C)continue;
		(ans+=dp[N][i][j][k][l])%=MOD;
	}
	cout << ans << endl;
}

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

int main() {
  int64_t n,a,b;
  int64_t k,l;
  cin >>n >>a >>b;
  k = n/(a+b);
  l = n%(a+b);
  if(l>=a){
    cout <<(k+1)*a <<endl;
  }
  else{
    cout <<k*a+l <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MX = 2e5+5;

int A[MX];

int32_t main() {

    ios_base::sync_with_stdio(0); cin.tie(0);

    int N; cin >> N;

    for (int i = 2; i <= N; ++i) {
        int x; cin >> x;

        A[x]++;
    }

    for (int i = 1; i <= N; ++i) {
        cout << A[i] << "\n";
    }

}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e3+10,mod=1e9+7,inf=1e9+10;
int fen[M],fen2[M],ind2[M],ind1[M];
int cnt[M][M][2],dp[M][M],n;
char ty[2*M];
int a[2*M];
void add(int ind)
{
	for(ind;ind<=M-2;ind+=ind&-ind)
	{
		fen[ind]++;
	}
}
void add2(int ind)
{
	for(ind;ind<=M-2;ind+=ind&-ind)fen2[ind]++;
}
int get1(int ind)
{
	int ans=0;
	for(;ind;ind-=ind&-ind)
	{
		ans+=fen[ind];
	}
	return ans;
}
int get2(int ind)
{
	int ans=0;
	for(;ind;ind-=ind&-ind)
	{
		ans+=fen2[ind];
	}
	return ans;
}
void fdp(int i,int j)
{
	dp[i][j]=inf;
	if(i!=n+1)
	{
		int tmp=(ind1[i]-1)-cnt[i][j][0];
		dp[i][j]=min(dp[i][j],dp[i+1][j]+tmp);
	}
	if(j!=n+1)
	{
		int tmp=(ind2[j]-1)-cnt[i][j][1];
		dp[i][j]=min(dp[i][j],dp[i][j+1]+tmp);
	}
}
main()
{
	cin>>n;
	for(int i=1;i<=2*n;i++)
	{
		cin>>ty[i]>>a[i];
	}
	for(int i=1;i<=2*n;i++)
	{
		int hlp;
		if(ty[i]=='B')add2(a[i]),hlp=get2(a[i]-1),ind2[a[i]]=i;
		else add(a[i]),hlp=get1(a[i]-1),ind1[a[i]]=i;
		for(int j=1;j<=n+1;j++)
		{
			bool flag=0;
			int t1=a[i],t2=j;
			if(ty[i]=='B')swap(t1,t2),flag=1;
			cnt[t1][t2][flag]=hlp;
			if(ty[i]=='B')cnt[t1][t2][flag]+=get1(j-1);
			else cnt[t1][t2][flag]+=get2(j-1);
			//cout<<t1<<" "<<t2<<" "<<cnt[t1][t2][flag]<<" "<<flag<<endl;
		}
	}
	for(int i=n+1;i>=1;i--)
	{
		for(int j=n+1;j>=1;j--)
		{
			if(i==n+1 && j==n+1)continue;
			fdp(i,j);
		}
	}
	cout<<dp[1][1];
}

Measured memory_bytes: 47488
#include<iostream>
using namespace std;
int main(){
	
	for(int i=0; i<5; i++){
		int N,A,B,C,D,E,F,G,H,I;
		cin >> N >> A >> B >> C >> D >> E >> F >> G >> H >> I;

		if(N == 0)break;

		cout << N-A-B-C-D-E-F-G-H-I << endl;
}
	
	return 0;
}



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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int k;
    long long int a,b;
    cin>>k;
    cin>>a>>b;
    int f=1;
    for(int i=a;i<=b;i++){
    	if(i%k==0){
    		cout<<"OK";
    		f=0;
    		break;
		}
	}
	if(f!=0){
		cout<<"NG";
	}
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int searchnum(int,int,int);

int main(void) {
	int n,s;
	while(1) {
		scanf("%d %d",&n,&s);
		if(n==0 && s==0)break;
		printf("%d\n",searchnum(10,n,s));
	}
	return 0;
}

int searchnum(int now,int n,int s) {
	int i;
	int sum=0;
	if(n==1) {
		if(s<now && s>=0)return 1; else return 0;
	}
	if(now<n)return 0;
	if(s<0)return 0;
	for(i=now-1;i>=0;i--) {
		sum+=searchnum(i,n-1,s-i);
	}
	return sum;
}

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

int main() {
  int N;
  cin >> N;
  
  int a = N%10, b = N/10%10, c = N/100%10, d = N/1000%10; 
  //cout << N%10 << N/10%10 << N/100%10 << N/1000%10 << endl;
  if (a == b && a == c) {
    cout << "Yes" << endl;
  }
  else if (b == c && b == d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
for _ in range(input()):
    k = int(raw_input(),16)
    a= ""
    if k&(1<<31):
        a = "-"
        k ^= 1<<31
    b = int(k*1.0/(1<<7))
    print a + str(b) + str(k*1.0/(1<<7)-b)[1:]

Measured memory_bytes: 6480
package main

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

func calc(lW, lE, rW, rE int) int {
	return lW + rE
}

func main() {
	defer stdout.Flush()
	_ = readInt()
	s := readString()
	rW := 0
	rE := 0
	for _, r := range s {
		if r == 'W' {
			rW++
		} else if r == 'E' {
			rE++
		} else {
			panic("not W and E")
		}
	}
	lW := 0
	lE := 0
	min := 3*100000 + 100
	for _, r := range s {
		if r == 'W' {
			rW--
		} else if r == 'E' {
			rE--
		}
		x := calc(lW, lE, rW, rE)
		if x < min {
			min = x
		}
		if r == 'W' {
			lW++
		} else if r == 'E' {
			lE++
		}
	}
	println(min)
}

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	buf := make([]byte, 0, 301000)
	r.Buffer(buf, 301000)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}


Measured memory_bytes: 1280
N=int(input())
AA=list(map(int,input().split()))
AA=sorted(AA)[::-1]
n=N//2
if N%2==0:
    print(sum(AA[0:n-1])+sum(AA[1:n])+AA[n-1])
else:
    print(sum(AA[0:n])+sum(AA[1:n+1]))

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Union Find tree
//-------------------------------------------------
class UnionFind
{
private:
    ::std::vector<int> par;
    ::std::vector<int> rank;
public:
    UnionFind(int n):par(n), rank(n){
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (rank[rx]>rank[ry]){
            par[ry] = rx;
        }else{
            par[rx] = ry;
            if (rx==ry) rank[ry]++;
        }
    }
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z; cin>>x>>y>>z; x--; y--;
        uf.unite(x,y);
    }
    vector<bool> used(n);
    int ans=0;
    rep(i,n){
        int r = uf.root(i);
        if (!used[r]) ans++;
        used[r] = true;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int table[55];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string a,b,c;cin>>a>>b>>c;
    if(a.back()==b.front()&&b.back()==c.front()) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<double> x(N), y(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
	}

	vector<int> p(N, 0);
	for (int i = 0; i < N; ++i) { p[i] = i; }

	double ans = 0;
	double cnt = 0;
	do {
		double tmp = 0;
		for (int i = 1; i < N; ++i) {
			int I = p[i], J = p[i - 1];
			double X = (x[I] - x[J]) * (x[I] - x[J]);
			double Y = (y[I] - y[J]) * (y[I] - y[J]);
			tmp += sqrt(X + Y);
		}
		ans += tmp;
		cnt += 1.0;
	} while (next_permutation(p.begin(), p.end()));

	ans = ans / cnt;
	cout.precision(15);
	cout << fixed << ans << endl;

	return 0;
}


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

int main() {
	string S, T;
	cin >> S >> T;
	int a=0, b=0, c=0, x, y, z;
	rep(i, S.size()) {
		if (i+T.size() > S.size()) break;
		a = 0;
		rep(j, T.size()) {
			if(T.at(j) == S.at(i+j)) a++;
		}
		chmax(b, a);
	}
	std::cout << T.size()-b << '\n';
}


Measured memory_bytes: 3628