akhauriyash/Code-Regression huggingface dataset:
N=int(input())
for i in range(0,N):
    x,y,z=map(int,input().split())
    if x**2==y**2+z**2:
        print("YES")
    elif y**2==x**2+z**2:
        print("YES")
    else:
        if z**2==x**2+y**2:
            print("YES")
        else:
            print("NO")
    i+=1


Measured memory_bytes: 5596
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	int d = 0;
	int a = 0;
	for (d = 0;; d++)
	{
		a += d;
		if (a == N)
		{
			break;
		}
		if (a > N)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	cout << d + 1 << endl;

	rep(i, 0, d)
	{
		int p = i * (i + 1) / 2 + 1;

		cout << d << " ";
		cout << p << " ";
		rep(j, 0, d - 1)
		{
			if (j < i)
			{
				p += 1;
			}
			else
			{
				p += j + 1;
			}
			cout << p;
			if (j == d - 2)
			{
				cout << endl;
			}
			else
			{
				cout << " ";
			}
		}
	}

	int p = 0;
	cout << d << " ";
	for (int i = 1; p < N; i++)
	{
		p += i;
		cout << p;
		if (p == N)
		{
			cout << endl;
			break;
		}
		else
		{
			cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


int N;
int P[1<<17];
void rec(int mask, int L, int R, int A, int B) {
    //eprintf("%d %d %d %d\n", L, R, A, B);
    if (R-L == 2) {
	P[L] = A;
	P[L+1] = B;
	return;
    }

    int pivot = -1;
    REP (t, N) if (mask>>t&1) {
	if ((A>>t&1) != (B>>t&1)) {
	    pivot = t;
	    break;
	}
    }

    int cnt = 0;
    REP (t, N) if (mask>>t&1 && t != pivot) {
	cnt += A>>t&1;
    }

    int lmid = A, rmid = B;
    REP (t, N) if (mask>>t&1 && t != pivot) {
	lmid &= ~(1<<t);
	rmid &= ~(1<<t);
    }
    if (A>>pivot&1) {
	lmid |= 1<<pivot;
    } else {
	rmid |= 1<<pivot;
    }

    if (cnt % 2 == 0) {
	REP (t, N) if (mask>>t&1 && t != pivot) {
	    lmid |= 1<<t;
	    rmid |= 1<<t;
	    break;
	}
    }

    int nmask = mask & ~(1<<pivot);
    rec(nmask, L, (L+R)/2, A, lmid);
    rec(nmask, (L+R)/2, R, rmid, B);
}

int A, B;

void MAIN() {
    scanf("%d%d%d", &N, &A, &B);

    if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
	puts("NO");
	return;
    }

    rec((1<<N)-1, 0, 1<<N, A, B);
    puts("YES");
    rprintf("%d", P, P+(1<<N));

}

int main() {
    int TC = 1;
    //    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1536
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

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

  bool res = false;
  for (int i = 1; i < 10; ++i) {
    for (int j = 1; j < 10; ++j) {
      if (n == i * j)
        res = true;
    }
  }

  if (res) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
s = gets.strip.to_s
if s[0]=="A"
  t = s[2..(s.size-2)]
  if t.count("C") == 1
    sn = s.delete("A").delete("C")
    if sn == sn.downcase
      puts "AC"
    else
      puts "WA"
    end
  else
    puts "WA"
  end
else
  puts "WA"
end

Measured memory_bytes: 14276
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
n=I()
lis=LI()
liked=[[] for i in range(n)]
for i in range(n):
    liked[lis[i]-1].append(i+1)
#print(liked)
count=0
for i in range(n):
    if lis[i] in liked[i]:
        count+=1
print(count//2)

Measured memory_bytes: 62096
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<string> S(N);
    rep(i,N)cin >> S[i];
    int L[N][26] = {0};
    rep(i,N){
        string K = S[i];
        rep(j,S[i].size()){
            int tmp = K[j] - 'a';
            L[i][tmp]++;
        }
    }
    char c = 97 + 2;

    vector<int> ct(N,0);    //tmp
    vector<int> ans(26);     //何個のアルファベットが使えるか
    rep(i,26){
        rep(j,N){
            ct[j] = L[j][i];
        }
        sort(all(ct));
        ans[i] = ct[0];
    }
    string UNKO;
    rep(i,26){
        char big = 97 + i;
        int lim = ans[i];
        rep(j,lim){
            UNKO.push_back(big);
        }
    }
    cout << UNKO << endl;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextWord() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func min(v1, v2 int) int {
	if v1 < v2 {
		return v1
	}
	return v2
}

func main() {
	var dp [105][100005]int

	sc.Split(bufio.ScanWords)
	n := nextInt()
	ww := nextInt()
	var w, v []int
	for i := 0; i < n; i++ {
		w = append(w, nextInt())
		v = append(v, nextInt())
	}

	vMax := 100 * 1000
	// init
	for i := 0; i < n; i++ {
		for sumV := 0; sumV <= vMax; sumV++ {
			dp[i][sumV] = math.MaxInt32
		}
	}
	dp[0][0] = 0

	// i番目の品物
	for i := 0; i < n; i++ {
		for sumV := 0; sumV <= vMax; sumV++ {
			if sumV >= v[i] {
				dp[i+1][sumV] = min(dp[i][sumV], dp[i][sumV-v[i]]+w[i])
			}
			dp[i+1][sumV] = min(dp[i+1][sumV], dp[i][sumV])
		}
	}
	var ans int
	for sumV := vMax; sumV >= 0; sumV-- {
		if dp[n][sumV] <= ww {
			ans = sumV
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 82688
import sys


N, M = map(int, input().split())
edge = []
for s in sys.stdin.readlines():
    a, b, c = map(int, s.split())
    edge.append((a - 1, b - 1, c))

path = [-float('inf')] * N
path[0] = 0

for i in range(N - 1):
    for j in range(M):
        a, b, c = edge[j]
        if path[b] < path[a] + c:
            path[b] = path[a] + c


for i in range(N - 1):
    for j in range(M):
        a, b, c = edge[j]
        if path[b] < path[a] + c:
            path[b] = float('inf')

print(path[-1])


Measured memory_bytes: 3444
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]*=-1
heapq.heapify(a)
for i in range(m):
  x=(-1)*((heapq.heappop(a)*(-1))//2)
  heapq.heappush(a,x)
for i in range(n):
  a[i]*=-1
print(sum(a))

Measured memory_bytes: 14180
N = int(input())
A = list(map(int,input().split()))

dp = [[None for j in range(N-i)] for i in range(N)]

for i,a in enumerate(A):
    dp[i][N-i-1] = a * (1 if N%2 else -1)

for k in range(N-2,-1,-1):
    for l in range(k+1):
        r = k-l
        if k%2:
            dp[l][r] = min(dp[l+1][r] - A[l], dp[l][r+1] - A[-1-r])
        else:
            dp[l][r] = max(dp[l+1][r] + A[l], dp[l][r+1] + A[-1-r])

print(dp[0][0])

Measured memory_bytes: 139996
#include <bits/stdc++.h>
using namespace std;
int A, B, C, X, ans;
int main(){
    cin >> A >> B >> C >> X;
    for(int i = 0; i <= A; i++)
        for(int j = 0; j <= B; j++)
            for(int k = 0; k <= C; k++)
                if(500 * i + 100 * j + 50 * k == X) ans++;
    cout << ans << endl;
    return 0;
}

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

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

struct range {
    int start;
    int end;
};

#define TRAINS_MAX 200000
#define TOWNS_MAX 500
#define QUERIES_MAX 100000

int main(void) {
    int towns, trains, queries;
    get_int3(&towns, &trains, &queries);
    int i, j;
    static int map[TOWNS_MAX+1][TOWNS_MAX+1];

    static int cum_row[TOWNS_MAX+1][TOWNS_MAX+1];
    static int cum_col[TOWNS_MAX+1][TOWNS_MAX+1];
    for(i = 0; i < trains; i++) {
        struct range r;
        get_int2(&r.start, &r.end);
        map[r.start][r.end]++;
    }

    for(i = 1; i <= towns; i++) {
        for(j = 1; j <= towns; j++) {
            cum_col[i][j] = cum_col[i][j-1] + map[i][j];
        }
    }
    for(j = 1; j <= towns; j++) {
        for(i = 1; i <= towns; i++) {
            cum_row[i][j] = cum_row[i-1][j] + map[i][j];
        }
    }

    // cumulative
    for(i = 1; i <= towns; i++) {
        for(j = 1; j <= towns; j++) {
            map[i][j] = map[i-1][j-1] + cum_col[i][j] + cum_row[i][j] - map[i][j];
        }
    }

    int ans[QUERIES_MAX];
    int ans_idx = 0;
    for(i = 0; i < queries; i++) {
        int src, dst;
        get_int2(&src, &dst);
        ans[ans_idx++] = map[dst][dst] - map[src-1][dst] - map[dst][src-1] + map[src-1][src-1];
    }
    for(i = 0; i < ans_idx; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int M, D;
  cin >> M >> D;
  int res = 0;
  for (int d = 10; d <= D; d++) {
    int d1 = d % 10, d10 = d / 10;
    if (d1 >= 2 && d10 >= 2 && d1 * d10 <= M) res++;
  }
  cout << res << '\n';
  return 0;
}


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

int main(void){
    int N;
    int a[200000] = {};
    int r[200000] = {};
    vector<int> result;

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

    for(int i=N-1; i>=0; --i){
        int sum_multiples=0;

        for(int j=2; j*(i+1)-1<N; ++j){
            sum_multiples += r[j*(i+1)-1];
        }
        
        if(sum_multiples%2 != a[i]){
            r[i] = 1;
            result.insert(result.begin(),i+1);
        }
    }

    if(result.size()==0){
        cout << 0 << endl;
        return 0;
    }
    
    cout << result.size() << endl;
    for(auto i=result.begin(); i!=result.end(); ++i){
        cout << *i;
        if(i+1!=result.end())
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3320
import java.util.*;
public class Main{
    public static void main(String[] agrs){
        Scanner sc=new Scanner(System.in);
        int w,h;
        while(sc.hasNextInt()){
         h=sc.nextInt();
         w=sc.nextInt();
         if(w==0||h==0)break;
         for(int i=0;i<h/2;i++){
             for(int j=0;j<w/2;j++){
                 System.out.print("#.");
                  
                 }if(w%2==1)System.out.print("#");
                 System.out.println();
             for(int j=0;j<w/2;j++){
                 System.out.print(".#");
                 } if(w%2==1)System.out.print(".");
                  System.out.println();
             }if(h%2==1){
                 for(int j=0;j<w/2;j++){
                     System.out.print("#.");
                      
                 }
                 if(w%2==1)System.out.print("#");
                 System.out.println();
                  
         }System.out.println();
             
        }
    }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    string s;
    cin >> s;
    lli f = 0;
    for1(i, 0, s.length())
    {
        if (i % 2 == 0 && s[i] != 'h')
        {
            f = 1;
            break;
        }
        else if (i % 2 && s[i] != 'i')
        {
            f = 1;
            break;
        }
    }
    if (f || s.length() % 2)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    // vector<lli> v;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF=(1LL<<50);
int N,M,L;
int t[2000];
ll u[100005];
ll dp[2001][2001];

ll calc(int a,int b){
  if(a>b)swap(a,b);
  return (u[b]-u[a-1])/(ll)L;
}

int main(){
  scanf("%d %d %d",&N,&M,&L);
  for(int i=0;i<N;i++)scanf("%d",&t[i]);
  sort(t,t+N);
  
  for(int i=1;i<=M;i++){
    scanf("%lld",&u[i]);
    u[i]+=u[i-1];
  }
  ll ans=INF;
  fill(dp[0],dp[2001],INF);
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(dp[i][j]==INF)continue;
      int k=max(i,j)+1;
      if(k<N){
        dp[k][j]=min(dp[k][j],dp[i][j]+calc(t[i],t[k]));
        dp[i][k]=min(dp[k][i],dp[i][j]+calc(t[j],t[k]));
      }else{
        ans=min(ans,dp[i][j]+calc(t[N-1],t[min(i,j)]));
      }
    }
  }

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

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {

            long n = Input();
            long[] As = Input3();
            long[] f = new long[200001];
            long[] c1 = new long[200001];
            long[] c2 = new long[200001];
            long sum = 0;
            long ans = 0;
            
            for(long i = 0; i < n; i++)
            {
                f[As[i]]++;
               // Console.WriteLine(f[As[i]]);
            }


            for (long i = 0; i <= n; i++)
            {
                if (f[i] > 1)
                {
                    c1[i]= Choose(f[i], 2);
                    sum += c1[i];
                }
            }

            for (long i = 0; i <= n; i++)
            {
                if (f[i]-1 > 1)
                {
                    c2[i] = Choose(f[i]-1, 2);
                }
            }

            

                for (long i = 0; i < n; i++)
                {
                    ans = sum - c1[As[i]] + c2[As[i]];
                Console.WriteLine(ans);//+" "+c1[i]+" "+c2[i]);
                }


                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;

class Bucket{
  public:
  vector<ll> buc,v;
  ll N,sqn,K;
  Bucket(){};
  Bucket(ll n){
    N = n;
    sqn = sqrt(N);
    K = (n + sqn - 1) /sqn;
    buc.assign(K,0);
    v.assign(K * sqn,0);
  }
  ll get(int x){
    return v[x] + buc[x/sqn];
  }
  void add(int x,int y,ll n){
    ll res = 0;
    for (int k = 0; k < K; ++k) {
      int l = k * sqn, r = (k + 1) * sqn;
      if (r <= x || y <= l)
        continue;
      if (x <= l && r <= y) {
        buc[k] += n;
      } else {
        for (int i = max(x, l); i < min(y, r); ++i) {
          v[i] += n;
        }
      }
    }
  }
  void Debug(){
    for(int i = 0; i < N;++i){
      cout << buc[i/sqn] << ' ';
    }
    cout << endl;
    for(int i = 0; i < N;++i){
      cout << v[i] << ' ';
    }
    cout << endl;
  }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,q,a,s,t,x;
  cin >> n >> q;
  Bucket buc(n);
  rep(i,q){
    cin >> a;
    if(a){
      cin >> s;
      cout << buc.get(s-1) << endl;
    }
    else{
      cin >> s >> t >> x;
      buc.add(s-1,t,x);
    }
  }
  return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

template <class T> using MaxHeap = priority_queue<T>;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    intmax_t N, M; cin >> N >> M;

    MaxHeap<intmax_t> que;
    for (size_t i = 0; i < N; ++i) {
        intmax_t a; cin >> a;
        que.emplace(a);
    }

    while (M--) {
        intmax_t maxv = que.top();
        que.pop();
        que.emplace(maxv / 2);
    }

    intmax_t res = 0;
    while (!que.empty()) {
        res += que.top();
        que.pop();
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 1400
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())+['T']
X, Y = mapint()
H = []
V = []

now_dirc = 1
cnt = 0
for s in S:
    if s=='F':
        cnt += 1
    else:
        if now_dirc==1:
            H.append(cnt)
        else:
            V.append(cnt)
        now_dirc*=-1
        cnt = 0

def check(now, goal, lis):
    dp = [0]*20000
    dp[10000+now] = 1
    for l in lis:
        nxdp = [0]*20000
        for i in range(20000):
            if i-l>=0 and dp[i-l]==1:
                nxdp[i] = 1
            if i+l<20000 and dp[i+l]==1:
                nxdp[i] = 1
        dp = nxdp
    if dp[goal+10000]:
        return True
    else:
        return False
    
if check(H[0], X, H[1:]) and check(0, Y, V):
    print('Yes')
else:
    print('No')

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

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

    int P[N] = {}, ai;
    rep(i, Q) {
        cin >> ai;
        ai--;
        P[ai]++;
    }

    int point_i;
    rep(i, N) {
        point_i = K - Q + P[i];
        if (point_i > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
int main(){
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    for(int bit = 0; bit < (1 << n-1); bit++){
        ll t = s[0] - '0';
        llrep(i,n-1){
            if(bit & (1 << i)){
                // cout << t << endl;
                ans += t;
                t = s[i+1] - '0';
            }else{
                t *= 10;
                t += s[i+1] - '0';
            }
        }
        // cout << t << endl;
        ans += t;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

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

    int ans = 0;
    for(int i=1; i<n-1; i++){
        if(p[i-1] > p[i] && p[i] > p[i+1]) ans++;
        if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define N 1000010
int a[N],b[N],ca=0,cb=0;
char s[100010];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    int flag1=0,flag0=0,ok=0;
    if(s[1]=='1')ok=1;
     int ans=0;
    for(int i=1;i<=n;i++)
        if(s[i]=='1')
        {
            flag0=0;
            if(!flag1)ca++,flag1=1;
            a[ca]++;
            ans=max(ans,a[ca]);
        }
        else
        {
            ans=max(ans,a[ca]);
            flag1=0;
            if(!flag0)cb++,flag0=1;
            b[cb]++;
        }
     for(int i=2;i<=ca;i++)a[i]+=a[i-1];
     for(int i=2;i<=cb;i++)b[i]+=b[i-1];

    if(k>=cb)ans=n;
    for(int i=1;i+k-1<=cb;i++)
    {
        int r=i+k-1;
        int lb=b[r]-b[i-1];
        int x,y;
        if(ok)
            x=max(1,i),y=min(ca,i+k);
        else
            x=max(1,i-1),y=min(ca,i+k-1);
        int la=a[y]-a[x-1];
        ans=max(ans,la+lb);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

const int N = 505;

int n, m;
int cnt[N][N];

int main() {
    
    scanf("%d %d", &n, &m);
    
    vector<pair<int, int> > oddPoints;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf("%d", &cnt[i][j]);
            cnt[i][j] %= 2;
        }
    }
    
    
    vector<pair<pair<int, int>, pair<int, int> > > moves;
    int isBegin = false;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            for (int j = 1; j <= m; j++) {
                if (cnt[i][j] % 2 == 1) {
//                     oddPoints.push_back({i, j});
                    isBegin = 1 - isBegin;
                }
                if (j < m && isBegin) {
                    moves.push_back({{i, j}, {i, j + 1}});
                } else if (j == m && isBegin && i < n) {
                    moves.push_back({{i, j}, {i + 1, j}});
                }
            }
        } else {
            for (int j = m; j >= 1; j--) {
                if (cnt[i][j] % 2 == 1) {
//                     oddPoints.push_back({i, j});
                    isBegin = 1 - isBegin;
                }
                if (j > 1 && isBegin) {
                    moves.push_back({{i, j}, {i, j - 1}});
                } else if (j == 1 && isBegin && i < n) {
                    moves.push_back({{i, j}, {i + 1, j}});
                }
            }
        }
    }
//     for (int i = 1; i < oddPoints.size(); i += 2) {
//         auto pFrom = oddPoints[i - 1];
//         auto pTo = oddPoints[i];
//         
//         findPath(pFrom, pTo);
//         
//         while (pFrom.first != pTo.first) {
//             pair<int, int> nextPoint = pFrom;
//             nextPoint.first++;
//             moves.push_back({pFrom, nextPoint});
//             pFrom = nextPoint;
//         }
//         
//         while (pFrom.second != pTo.second) {
//             pair<int, int> nextPoint = pFrom;
//             if (pTo.second - pFrom.second > 0) {
//                 nextPoint.second++;
//             } else {
//                 nextPoint.second--;
//             }
//             moves.push_back({pFrom, nextPoint});
//             pFrom = nextPoint;
//         }
//     }
    
    printf("%d\n", moves.size());
    
    for (auto p : moves) {
        auto pFrom = p.first;
        auto nextPoint = p.second;
        printf("%d %d %d %d\n", pFrom.first, pFrom.second, nextPoint.first, nextPoint.second);
    }
    
    return 0;
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;


int dp[1000005][2];
int32_t main(){
    ios::sync_with_stdio(false);
    string n;
    cin>>n;
    n="0"+n;
    memset(dp,0,sizeof(dp));

    for(int i=n.size()-1;i>=0;i--){
        int N=n[i]-'0';
        if(i==n.size()-1){
            dp[i][0]=N;
            dp[i][1]=10-N;
        }
        else{
            dp[i][0]=min(dp[i+1][0]+N,dp[i+1][1]+1+N);
            dp[i][1]=min(dp[i+1][0]+10-N,dp[i+1][1]+9-N);
        }
    }
    cout<<min(dp[0][0],dp[0][1])<<"\n";
    return 0;
}

Measured memory_bytes: 16968
#include <iostream>
#include <cstdlib>
using namespace std;
#define INF 1000000000
int count = 0;
void merge(int a[],int left,int mid,int right)
{
    int n1 = mid-left,n2 = right-mid,i,j,k;
    int *m1 = (int*)malloc((n1+1)*sizeof(int)),*m2 = (int*)malloc((n2+1)*sizeof(int));
    for(i=0;i<n1;i++)
        m1[i] = a[left+i];
    for(i=0;i<n2;i++)
        m2[i] = a[mid+i];
    m1[n1] = m2[n2] = INF;
    i = j = 0;
    for(k=left;k<right;k++)
    {
        count++;
        if(m1[i]<=m2[j])
        {
            a[k] = m1[i];
            i++;
        }
        else
        {
            a[k] = m2[j];
            j++;
        }
    }
    free(m1);
    free(m2);
}
void mergesort(int a[],int left,int right)
{
    int mid;
    if(right-left>1)
    {
        mid = (left+right)/2;
        mergesort(a,left,mid);
        mergesort(a,mid,right);
        merge(a,left,mid,right);
    }
}
int main()
{
    int n,i;
    int a[500000];
    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<<count<<endl;
    return 0;
}

Measured memory_bytes: 6704
MOD = 1000003
facts = [1,1] #階乗
for ind in range(1, MOD):
    i = ind+1
    facts.append(facts[-1]*i % MOD)

def invmod(x, MOD=MOD):
    return pow(x, MOD-2, MOD)

def task(x, d, n, MOD=MOD):
    if x == 0:
        return 0
    if d == 0:
        return pow(x, n, MOD)
    
    xdivd = (x*invmod(d)) % MOD
    if MOD <= xdivd + n -1:
        return 0
    ans = (facts[xdivd + n -1]*invmod(facts[xdivd - 1])) % MOD
    ans = (ans*pow(d, n, MOD)) % MOD
    return ans

Q = int(input())
for _ in range(Q):
    x, d, n = map(int, input().split())
    ret = task(x, d, n)
    print(ret)

Measured memory_bytes: 45228
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        String A[] = {"Sunny","Cloudy","Rainy","Sunny"};
        for(int i=0;i<3;i++){
            if(S.equals(A[i])){
                System.out.println(A[i+1]);
            }
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std ;
int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(0);
    cout.tie(0);
    int n ;
    cin >>n ;
    if(n >= 30)
    {
     cout << "Yes" << endl ;
    }
    else cout << "No\n"  ;
}


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

#define MOD 1000000007;

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

    //0:dammy, 1:'A' 2:'G', 3:'C', 4:'T'
    //"AGC, GAC, ACG, A*GC, AG*C" を含まない
    ll dp[N + 1][5][5][5] = {0};
    dp[0][0][0][0] = 1;
    for(int n = 0; n < N; n++){
        for(int i = 0; i < 5; i++){
            for(int j = 0; j < 5; j++){
                for(int k = 0; k < 5; k++){
                    for(int l = 1; l < 5; l++){
                        if(i == 1 && j == 2 && l == 3) continue;
                        if(i == 1 && k == 2 && l == 3) continue;
                        if(j == 1 && k == 2 && l == 3) continue;
                        if(j == 2 && k == 1 && l == 3) continue;
                        if(j == 1 && k == 3 && l == 2) continue;
                        dp[n + 1][j][k][l] += dp[n][i][j][k];
                        dp[n + 1][j][k][l] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            for(int k = 0; k < 5; k++){
                ans += dp[N][i][j][k];
                ans %= MOD;
            }
        }
    }

    /*    
    for(int n = 1; n < N + 1; n++){
        for(int i = 1; i < 5; i++){
            for(int j = 1; j < 5; j++){
                for(int k = 1; k < 5; k++){
                    cout << dp[n][i][j][k] << " ";
                }
                cout << " ";
            }
            cout << " ";
        }
        cout << endl;
    }
    */
    
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    string s;
    cin>>s;
    int n=s.size(),a=0,b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1') a++;
        else b++;
    }
    printf("%d\n",b>a?2*a:2*b);
}


Measured memory_bytes: 512
n=int(input())
sp=[[i for i in input().split()] for j in range(n)]
i=1
isp=[[]for i in range(n)]
for s,p in sp:
    isp[i-1]=[s,-int(p),i]
    i+=1
isp=sorted(isp)
for s,p,i in isp:
    print(i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]" << endl; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N;
    string S;
    cin >> N >> S;
    vvec<int> dp(N+1, vec<int>(N+1, 0));
    rep(i,N){
        rep(j,N){
            if(i == j)continue;
            if(S[i] == S[j])dp[i+1][j+1] = dp[i][j] + 1;
        }
    }
    auto calc = [&](int x, int y) -> ll{
        int sx = x;
        int sy = y;
        while(x < N && y < N){
            if(dp[x][y]+1 == dp[x+1][y+1]){
                x++;
                y++;
            }
            else break;
        }
        int gx = x;
        int gy = y;
        if(gx < sy)return gx - sx + 1;
        else return sy - 1 - sx + 1;
    };
    ll ans = 0;
    dbg(dp);
    rep(i,N+1)rep(j,N+1){
        if(i > j)continue;
        if(dp[i][j] == 1){
            chmax(ans, calc(i,j));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 101060
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans = 0;

int main(){
	int T;
	cin >> n>> T;
	int ans = iINF;
	forn(i) {
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			ans = min(ans, c);
		}
	}
	if (ans < iINF) {
		cout << ans << endl;
	}
	else {
		cout << "TLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD = 1000000007;


     signed main(){
   int n;
   cin>>n;
   int a[n],k=1000;
   for(int i=0;i<n;i++)cin>>a[i];
   int t=0;

   for(int i=0;i<n-1;i++){
       if(a[i]<a[i+1]){
           t+=k/a[i];
           k%=a[i];
       }
       if(a[i]>a[i+1]){
           k+=t*a[i];
           t=0;
       }
   }
   cout<<k+t*a[n-1]<<endl;
  
  

     }


 


 






    





      

        


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

vector<int> uf;

int root(int x){
  if(x==uf[x]) return x;
  else return uf[x]=root(uf[x]);
}

void uni(int x,int y){
  x=root(x);
  y=root(y);
  if(x!=y) uf[x]=y;
}

int main(){
  int n,m;
  cin >> n >> m;
  uf=vector<int>(n);
  for(int i=0;i<n;i++){
    uf[i]=i;
  }
  vector<list<int>> l(m);
  int k,ll;
  for(int i=0;i<n;i++){
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> ll;
      l[ll-1].push_back(i);
    }
  }
  int rr;
  for(int i=0;i<m;i++){
    rr=l[i].front();
    for(auto it:l[i]){
      uni(rr,it);
    }
  }
  int r=root(0);
  for(int i=0;i<n;i++){
    if(root(i)!=r){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(void) {
	string s; cin >> s;
	int q, cnt = 0; cin >> q;
	rep(i, q) {
		int t; cin >> t;
		if (t == 1) {
			cnt++;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (cnt % 2 == 0) {
				if(f==1) s.insert(0,1, c);
				else s.push_back(c);
			}
			else {
				if (f == 1)s.push_back(c);
				else s.insert(0, 1, c);
			}
		}
	}
	if (cnt % 2 == 0) {
		cout << s << endl;
	}
	else {
		for (int i = s.size() - 1; i >= 0; i--) {
			cout << s[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> d(n);
    rep(i, 0, n){
        int a;
        cin >> a;
        a--;
        d[a]++;
    }
    sort(all(d));
    reverse(all(d));
    int ans = 0;
    rep(i, k, n){
        ans += d[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;
char judge(char tmp){
	if(tmp == 'o')return 'o';
	if(tmp == 'x')return 'x';
	return 'N';
}
char check(char *str){
	/*height*/
	for(int i = 0; i < 9; i+=3){
		if(str[i] == str[i+1] && str[i] == str[i+2]){
			if(judge(str[i]) != 'N')return judge(str[i]);
		}
	}
	/*width*/
	rep(i,3){
		if(str[i] == str[i+3] && str[i] == str[i+6]){
			if(judge(str[i]) != 'N')return judge(str[i]);
		}
	}
	/*slanting*/
	if(str[0] == str[4] && str[0] == str[8]){
		if(judge(str[0]) != 'N')return judge(str[0]);
	}
	if(str[2] == str[4] && str[2] == str[6]){
		if(judge(str[2]) != 'N')return judge(str[2]);
	}

	return 'd';
}
int main(){
	char str[16]={0};
	while(~scanf("%s",str)){
		printf("%c\n",check(str));
	}
	return 0;
}

Measured memory_bytes: 1136
#include <iostream>

int main()
{
    std::size_t g = 0, p = 0;
    char c;
    while(std::cin >> c)
    {
        switch(c)
        {
        case 'g':
            g++;
            break;
        case 'p':
            p++;
            break;
        }
    }
    std::cout << (g + p) / 2 - p << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[26],b[26];
char s[99];
int main(){
	int n;
	for(int i=0; i<26; i++)
		a[i] = 99;
	for(scanf("%d",&n); n--;){
		scanf("%s",s);
		memset(b,0,sizeof(b));
		for(int i=0; s[i]; i++)
			b[s[i]-'a']++;
		for(int i=0; i<26; i++)
			a[i] = min(a[i],b[i]);
	}
	for(int i=0; i<26; i++)
		while(a[i]--)
			putchar(i+'a');
	puts("");
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    int sz = to_string( N ).size();

    int ans = 0;
    if( sz % 2 == 1 ){
        ans += N - pow( 10, sz - 1 ) + 1;
        sz--;
    }

    REP( i, sz / 2 ){
        ans += 9 * pow( 100, i );
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;
using ll = long long ;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int n, k;
int main(){

  int n, k;
  cin >> n >> k;

  vector<int>a(n);
  int pos;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == 1)pos = i;
  }
  int ans = 0;
  int range1 = 0;
  int range2 = 0;
  for(int i = 0; i < n; i=i+k-1){
    if(i + k-1 >= pos){
      range1 = pos - i + 1;
      break;
    } ans++;
  }
  for(int i = n-1; ; i = i-k+1){
    if(i-k+1 <= pos){
      range2 = i - pos + 1;
      break;
    } ans++;
  }
//  cout << range1 << '\n';
//  cout << range2 << '\n';
  ans += (range1 + range2 - 1 + k - 1) / k;

  cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int tnp, flag = 0;
    for(int i = 9; i > 0; i--)
    {
        if(n % i == 0)
            tnp = n/i;
        if(tnp <= 9)
        {
            cout << "Yes";
            flag = 1;
            break;
        }
    }
    if(flag == 0)
        cout << "No";
    return 0;   
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  cout << 1.0 * (n /2 + n % 2) / n << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
Vs = list(map(int, input().split()))

ans = 0
for x in range(N+1):
    for y in range(N+1):
        if x+y > N or x+y > K:
            break
        rest = min(K-x-y, x+y)
        As = Vs[:x] + Vs[N-y:]
        As.sort()
        score = sum(As)
        for i in range(rest):
            if As[i] < 0:
                score -= As[i]
        ans = max(ans, score)

print(ans)


Measured memory_bytes: 3064