akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}
	int sx[] = { -1,0, 1,-1,1,-1,0,1 }, sy[] = { 1,1,1,0,0,-1,-1,-1 };
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int n = 0;
			if (grid[i][j] == '.') {
				for (int k = 0; k < 8; k++) {
					if (i + sx[k] >= 0 && j + sy[k] >= 0 && i + sx[k] < h && j + sy[k] < w && grid[i + sx[k]][j + sy[k]] == '#') {
						n++;
					}
				}
				cout << n;
			}
			else {
				cout << "#";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace templete
{
    class abc87_c
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = ReadLine().Split().Select(int.Parse).ToArray();
            int max=-10000000;

            for(int i=0; i<n; i++)
            {
                int tmp=0;
                for(int k=0; k<=i; k++)
                {
                    tmp += a[k];
                }

                for(int j=i; j<n; j++)
                {
                    tmp += b[j];
                }
                max = Max(max, tmp);
            }
            WriteLine(max);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
    using namespace std;
    signed main(){
    int n,m,x,y,a[105],b[105];
    bool f=false;
    if(x>y)
    swap(x,y);
    cin>>n>>m>>x>>y;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<m;i++)
    cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    for(int i=x+1;i<=y;i++){
    if(a[n-1]<i && i<=b[0]){
    f=true;
    goto A;
    }
    }
    A:if(f)
    cout<<"No ";
    cout<<"War"<<endl;
    return(0);
    }

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{

    while(1)
    {
        int i,n=0;
    char x[1000];
        scanf("%s",&x);
        if(x[0]=='0')
            break;
        else
        {
            for(i=0;i<strlen(x);i++)
            {
                n+=x[i]-'0';
            }
            printf("%d\n",n);
        }
    }
    return 0;
}


Measured memory_bytes: 2032
#include <stdio.h>
 
typedef struct {
    int n[6];
}dice;
 
int equal1(dice dx, dice dy)
{
    int i;
    for (i = 0; i < 6; i++)
        if (dx.n[i] != dy.n[i])
            return 0;
    return 1;
}
 
void rots(dice *d)
{
    dice temp;
    temp = *d;
 
    d->n[0] = temp.n[4];
    d->n[1] = temp.n[0];
    d->n[2] = temp.n[2];
    d->n[3] = temp.n[3];
    d->n[4] = temp.n[5];
    d->n[5] = temp.n[1];
}
 
void rotw(dice *d)
{
    dice temp;
    temp = *d;
 
    d->n[0] = temp.n[2];
    d->n[1] = temp.n[1];
    d->n[2] = temp.n[5];
    d->n[3] = temp.n[0];
    d->n[4] = temp.n[4];
    d->n[5] = temp.n[3];
}
 
int equal2(dice dx, dice dy)
{
    int i;
    dice temp;
    temp = dx;
    for (i = 0; i < 4; i++) {
        if (equal1(temp, dy)) return 1;
        rotw(&temp);
    }
    return 0;
}
 
int main(void)
{
    dice d[2];
    int i, j;
 
    for (i = 0; i < 2; i++)
        for (j = 0; j < 6; j++)
            scanf("%d", &d[i].n[j]);
 
    j = 0;
 
    for (i = 0; i < 32; i++) {
        if (equal2(d[0], d[1])) {
            j++;
            break;
        }
        rots(&d[0]);
        if (equal2(d[0], d[1])) {
            j++;
            break;
        }
        rots(&d[0]);
        if (equal2(d[0], d[1])) {
            j++;
            break;
        }
        rotw(&d[0]);
        rots(&d[0]);
        rotw(&d[0]);
        rotw(&d[0]);
        rotw(&d[0]);
    }
 
    if (j)
        printf("Yes\n");
    else
        printf("No\n");
 
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    string S; cin >> S;
    ll K; cin >> K;

    rep(i, S.size()) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
        if (i == K - 1 && S[i] == '1') {
            cout << 1 << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

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

    int n = count(s.begin(), s.end(), 'p');
    cout << s.size() / 2 - n << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int main(){
	bool flag = true;
	int n,t,x,y,xx = 0,yy = 0,tt = 0,ans,all;
	cin >> n;
	while(n--){
		cin >> t >> x >> y;
		all = abs(x - xx) + abs(y - yy);
		ans = t - all - tt;
		if(ans % 2 != 0 || ans < 0) flag = false;
		tt = t;
		xx = x;
		yy = y;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,b,n,s,f,q,i,z,p,k,d,t,u,e,g;string s1,s2,s3,s4;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n;
  if(n<=2)
  cout<<0;
  else
  {
    for(i=1e3;i>=0;i--)
    {
      p=n-(i*3);
      if(p==0)
      {
        cout<<i;return 0;
      }
      else if(p>3)
      {
        cout<<i+1;return 0;
      }
    }
  }  
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
vv = inpl()

vv.sort()

for i in range(1,N):
    vv[i] = (vv[i]+vv[i-1])/2

print(vv[-1])


Measured memory_bytes: 4196
#include<stdio.h>
int main()
{
    int n,i,a,max=0,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        sum+=a;
        if(a>max)
        {
            max=a;
        }
    }       
    sum=sum-max;
    if(max<sum)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AGrouping2 solver = new AGrouping2();
        solver.solve(1, in, out);
        out.close();
    }

    static class AGrouping2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            out.print(in.nextInt() / 3);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

        public void close() {
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <string>

using namespace std;



long long func(long long k) {
        if (k <= 1) return 1;
        return k * func(k-1);
}

long long solver(string str) {
        int n = (int)str.size();
        vector<int> cnt(26, 0);
        for (int i=0; i<n; i++) cnt[ (str[i] - 'a') ]++;
int ecnt = 0;
for (int i = 0; i<26; i++) if (cnt[i]%2==1) ecnt++;

if (n%2 == 0 && ecnt > 0) return 0;
if (n%2 == 1 && ecnt != 1) return 0;

for (int i=0; i<26; i++) cnt[i]/=2;

int sum = 0;
for (int i=0; i<26; i++) sum += cnt[i];
long long ans = func(sum);

for (int i=0; i<26; i++) {
        ans /= func(cnt[i]);
}

return ans;
}

int main() {
        string str;

        cin >> str;

        cout << solver(str) << endl;

        return 0;
        
}

Measured memory_bytes: 1188
#include <cstdio>
#include <algorithm>
#include <vector>

const int MAXN = 8004;

char S[MAXN];
bool dx[MAXN], dx2[MAXN];
bool dy[MAXN], dy2[MAXN];

int iabs(int x) {
  return (x>=0 ? x : -x);
}

int main() {
  int X, Y;
  std::vector<int> xx, yy;
  fgets(S, MAXN, stdin);
  scanf("%d%d", &X, &Y);

  int i, cnt = 0;
  bool isY = false;
  for (i = 0; S[i] == 'F'; ++i) --X;
  for (; S[i]; ++i) {
    switch(S[i]) {
    case 'T':
      if (cnt > 0) {
        if (isY) yy.push_back(cnt);
        else xx.push_back(cnt);
      }
      cnt = 0;
      isY = !isY;
      break;
    case 'F':
      ++cnt;
    }
  }
  if (cnt > 0) {
    if (isY) yy.push_back(cnt);
    else xx.push_back(cnt);
  }

  // 이제 xx와 yy 각각의 덧셈과 뺄셈으로 x, y를 만들 수 있는지 확인하자.
  dx[0] = true;
  dy[0] = true;
  for (const auto &x: xx) {
    for (int i = 0; i < MAXN; ++i) {
      if (dx[i]) {
        dx2[iabs(i - x)] = dx2[iabs(i + x)] = true;
      }
    }
    std::copy(dx2, dx2 + MAXN, dx);
    std::fill(dx2, dx2 + MAXN, false);
  }
  for (const auto &y: yy) {
    for (int i = 0; i < MAXN; ++i) {
      if (dy[i]) {
        dy2[iabs(i - y)] = dy2[iabs(i + y)] = true;
      }
    }
    std::copy(dy2, dy2 + MAXN, dy);
    std::fill(dy2, dy2 + MAXN, false);
  }

  if (iabs(X) >= MAXN || iabs(Y) >= MAXN) puts("No");
  else if (dx[iabs(X)] && dy[iabs(Y)]) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e4 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int A, B, C;
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    int mx = inf;
    A = read(), B = read(), C = read();
    if ((~A & 1) || (~B & 1) || (~C & 1)) {
        writeln(0);
    } else {
        writeln(Min(Min(A * B, A * C), B * C));
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		ArrayList<String> words = new ArrayList<String>();
		for(int i=0;i<N;i++){
			String w = sc.next();
			if(i !=0 ){
				String lastword = words.get(i-1);
				int wordcnt = lastword.length(); 
				Character initial = w.charAt(0);
				if(words.indexOf(w) != -1 || !(initial.equals(lastword.charAt(wordcnt-1)))){
				System.out.println("No");
				return;
				}
			}
			words.add(w);
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std ;

#define ll long long
#define N 100010

char s[ N ] ;
int cur1 , cur2 , ans ;

//rock和paper，paper赢
//同样则不加分 
//rock-g , paper-p

int main() {
	scanf( "%s" , s + 1 ) ;
	int n = strlen( s + 1 ) ;
	if( s[ 1 ] == 'p' ) ans = -1 ;
	cur2 = 1 ;
	for( int i = 2 ; i <= n ; i ++ ) {
		if( s[ i ] == 'p' ) {
			if( cur1 < cur2 ) {
				cur1 ++ ;
			}else ans -- , cur2 ++ ;
		}else {
			if( cur1 < cur2 ) {
				cur1 ++ ;
				ans ++ ;
			}else cur2 ++ ;
		}
	}
	printf( "%d\n" , ans ) ;
	return 0 ;
}

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

int N;
int Max(int a, int b) {if(a > b) return a; else return b;}

//公約数を求める
int culc(int t, int u, int v){
  int ret = 1;
  int a;
  //i, j, kの最大値/2からその最大値までに公約数はない
  for(a = 1; a <= (Max(t, Max(u, v)))/2; a++){
    //後にでてくるaほど大きい
    if(!(t%a) && !(u%a) && !(v%a))	ret = a;
  }
  a = (Max(t, Max(u, v)));
  if(!(t%a) && !(u%a) && !(v%a))	ret = a;
  return ret;
}

int main(void){
  cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N; j++){
      for(int k=1; k<=N; k++){
        ans += culc(i, j, k);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string a, b;
	cin >> a >> b;

	if (SZ(a) != SZ(b))
	{
		if (SZ(a) > SZ(b))
			cout << "GREATER";
		else
			cout << "LESS";
		cout << endl;
		return 0;
	}

	if (a > b)
		cout << "GREATER" << endl;
	else if (a == b)
		cout << "EQUAL" << endl;
	else
		cout << "LESS" << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int X; cin >> X;
  if(X >= 30){
    cout << "Yes" << endl;
  }
  else{
        cout << "No" << endl;
  }
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=998244353;
int read() {
	int x=0, f=1; char ch=' ';
	while(!isdigit(ch)) {ch=getchar(); if(ch=='-') f=-1;}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48), ch=getchar();
	return x*f;
}
ll f[3005][3005];
int main() {
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	f[a][b]=1;
	for(int i=a;i<=c;i++) {
		for(int j=b;j<=d;j++) {
			if(i>a) f[i][j]+=f[i-1][j]*j;
			if(j>b) f[i][j]+=f[i][j-1]*i;
			if(i>a&&j>b) f[i][j]-=(ll)(i-1)*(j-1)*f[i-1][j-1];
			f[i][j]%=mod;
		}
	}
	cout<<(f[c][d]%mod+mod)%mod;
}


Measured memory_bytes: 73980
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

ll f(ll n){ return (n & 1) ? 3 * n + 1 : n / 2; }

int main(){
    ll s;
    cin >> s;
    vector<bool> fl(1e6 + 10);
    fl[s] = 1;
    for(ll i = 2;; i++){
        s = f(s);
        if(fl[s]){
            cout << i << endl;
            return 0;
        }
        fl[s] = 1;
    }
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
ll dp[(1<<18)+5][51];
int main(){
int n;
cin>>n;
for(int i=0;i<=(1<<18);i++)for(int j=0;j<51;j++)dp[i][j]=inf;
V<ll> a(n),b(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
dp[0][0]=0;
for(int bit=0;bit<(1<<n);bit++){
	int cnt=0;
	for(int i=0;i<n;i++)if(bit&(1<<i))cnt++;
	V<P> data;
	int now=cnt;
	for(int i=0;i<n;i++)if(!(bit&(1<<i)))data.push_back(P(i,now++));
	for(int i=0;i<=50;i++){
		if(dp[bit][i]>=inf)continue;
		for(auto p:data){
			int next;
		if(abs(cnt-p.fi)%2==0)next=a[p.fi];
		else next=b[p.fi];
		 if(next>=i)chmin(dp[bit|(1<<p.fi)][next],dp[bit][i]+abs(p.se-cnt));
		}
	}
}
ll ans=inf;
for(int i=0;i<=50;i++)chmin(ans,dp[(1<<n)-1][i]);
if(ans<inf)cout<<ans<<endl;
else cout<<-1<<endl;
}


Measured memory_bytes: 104832
// https://atcoder.jp/contests/abc134/tasks/abc134_d

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int a[200001];
bool b[200001];
int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
        int x = a[i];
        for (int j = i << 1; j <= n; j += i) {
            x ^= b[j];
        }
        b[i] = x;
        if (x)
            ans++;
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        if (b[i]) {
            cout << i << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 1920
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N=int(input())
A=[int(x) for x in input().split()]

ans=A[0]
for i in range(N):
  ans=gcd(ans,A[i])
  
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    ll k;
    cin>>n>>k;
    vector<int> A(n);
    rep(i,n){
        cin>>A[i];
        A[i]--;
    }

    vector<bool> seen(n,false);
    deque<int> a;
    int cur=0;
    while(true){
        if(seen[cur]){
            while(a[0]!=cur){
                k--;
                a.pop_front();

                if(k==0){
                    cout<<a[0]+1<<endl;
                    return 0;
                }
            }
            break;
        }

        a.push_back(cur);
        seen[cur]=true;
        cur=A[cur];
    }
    cout<<a[k%a.size()]+1<<endl;
}

Measured memory_bytes: 4828
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int keta(int a) {
	return to_string(a).size();
}
signed main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	else {
		loop(i, n / 2, n) {
			if (s[i] != s[i - n / 2]) {
				cout << "No" << endl; return 0;
			}
		}
		cout << "Yes" << endl;
	}
}


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

int main() {
    int a, b, c;
    int d=0;
    cin >> a >> b >> c;
    for (int i=a; i<=b; ++i) {
        if (c%i ==0) ++d;
    }
    cout << d << endl;

    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;

ll power(ll a , ll n)
{
    unsigned long long int result=1,x=a;
    while(n>0)
    {
        if(n % 2 ==1)
            result = (result * x)%MOD;
        x = (x * x)%MOD;
        n=n/2;
    }
    return result;
}

ll GCD(ll a , ll b)
{
    if(b==0)
        return a;
    else
        return GCD(b,a%b);
}

int main()
{
    FIO;
    int t;
    t=1;
    //cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;


        int a[n];

        for(int i=0;i<n;i++)
            cin >> a[i];

        for(int i=k;i<n;i++)
        {
            if(a[i]>a[i-k])
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
        }
    }   
    return 0;
}


Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}

typedef long long int64;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

typedef vector< vector< int > > Graph;
 
int V;
Graph g, rg; //グラフの隣接リストと逆辺の隣接リスト
vector< int > vs; //帰りがけ順の並び
vector< bool > used; //すでに調べたか
vector< int > cmp; // 強連結成分のトポロジカル順序

void init(int size){
  V = size;
  g.resize(V), rg.resize(V);
}
void add_edge(int from, int to){
  g[from].push_back(to);
  rg[to].push_back(from);
}
void dfs(int v){
  used[v] = true;
  for(int i = 0; i < g[v].size(); i++){
    if(!used[g[v][i]]) dfs(g[v][i]);
  }
  vs.push_back(v);
}
void rdfs(int v, int k){
  used[v] = true;
  cmp[v] = k;
  for(int i = 0; i < rg[v].size(); i++){
    if(!used[rg[v][i]]) rdfs( rg[v][i], k);
  }
}
int topo(){
  cmp.resize( V, -1);
  vs.clear();
  used = vector< bool >( V, false);
  for(int v = 0; v < V; v++){
    if(!used[v]) dfs(v);
  }
}

int main(){
  int n, m;
  cin >> n;
  init(n);
  cin >> m;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    --a, --b;
    add_edge( a, b);
  }
  bool flag = false;
  topo();
  for(int i = n - 1; i >= 0; i--){
    cout << vs[i] + 1 << endl;
    if(i > 0){
      bool hoge = true;
      for(int j = 0; j < g[vs[i]].size(); j++){
        if(g[vs[i]][j] == vs[i - 1]){
          hoge = false;
          break;
        }
      }
      flag |= hoge;
    }
  }
  cout << flag << endl;
}

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

int main() {
 int N;
// bool P = 0;
// bool W = 0;
// bool G = 0;
 bool Y = 0;
 cin >> N;

 for (int i = 0; i < N; i++) {
  string color;
  cin >> color;
//  if (color == "P")
//    P = 1;
//  else if (color == "W")
//    W = 1;
//  else if (color == "G")
//    G = 1;
//  else if (color == "Y")
  if (color == "Y")
    Y = 1;
 }
// if (P + W + G + Y == 4)
 if (Y == 1)
   cout << "Four";
// else if (P + W + G + Y == 3)
 else
   cout << "Three";
}


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

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			var s = new string[] { cin.Next(), cin.Next(), cin.Next() };
			var i = new int[] { 0, 0, 0 };
			int now = 0;
            while (i[now] < s[now].Length)
            {
				var x = now;
				now = s[now][i[now]] - 'a';
				i[x]++;
            }
            switch (now)
            {
				case 0:
                    Console.WriteLine("A");
					break;
				case 1:
					Console.WriteLine("B");
					break;
				case 2:
                    Console.WriteLine("C");
					break;
            }
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
# include <stdio.h>

int main(){
  int a, b, sum;
  scanf("%d%d", &a, &b);
  
  if(a == b) {
    sum = a + b;
  }
  else if(a > b){
    sum += a;
    a--;
    if(a >= b) sum += a;
    if(a < b) sum += b;
  }
  else if(a < b){
    sum += b;
    b--;
    if(a >= b) sum += a;
    if(a < b) sum += b;
  }
    printf("%d", sum);
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef pair<lld,lld> pr;
lld const mod = 1e9+7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld n,m;
  cin>>n>>m;
  lld cnt=0;
  //even
  cnt+=n*(n-1)/2;
  cnt+=m*(m-1)/2;
  cout<<cnt<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>
const int MAX_V = 1000000;
int main() {
	int prime[MAX_V+1];
    int i, k, v,a=0,n;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;
            }
            
        } 
        
    }
    while(1){
      scanf("%d",&n);
      if(n==0)break;
      for(i=0;i<=n-2;i++){
          int isprime = prime[i];
          int isprimex = prime[i+2];
          if(isprime && isprimex){
             if(a<i)a=i;
          }
        }
        printf("%d %d\n",a,a+2);
    	a=0;
    }
    return 0; 
    
}

Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std ; 
int main()
{
    int a , b , c , d ; 
    cin >> a >> b >> c >> d ; 
    int res = a+b ; 
    int res2 = c+d ; 
    if(res > res2)
        cout << "Left" ; 
    else if(res < res2)
        cout << "Right" ; 
    else 
        cout << "Balanced" ; 
    
}


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


int count(int num){
	int res=0;
	while(num > 0){
		if(num % 2 == 0){
			res++;
			num /= 2;
		}else{
			break;
		}
	}
	return res;
}


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}
	int zero=0;
	int one=0;
	int more=0;
	for(int i=0; i<n; i++){
		int res = count(a.at(i));
		if(res == 0){
			zero++;
		}else if(res == 1){
			one++;
		}else{
			more++;
		}
	}
	if(zero > more && !(zero-more==1 && one==0)){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m;
    cin >> n >> m;
    int ans = n;
    vector<bool> use(m,true);
    vector<vector<int>> a(n,vector<int>(m));
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) cin >> a[i][j],a[i][j]--;
    for (int z = 0;z < m;++z) {
        vector<int> b(m,0);
        for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (use[a[i][j]]) {
            b[a[i][j]]++;
            break;
        }
        int idx = 0;
        for (int i = 0;i < m;++i) if (b[i] > b[idx]) idx = i;
        ans = min(ans,b[idx]);
        use[idx] = false;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>

using namespace std;

//使うときは、最初にparentの初期化を！
const int MAX_N=200001;
class uft {//union-find tree
public:
    int parent[MAX_N];
    int size[MAX_N];
    void initialize();
    int root(int x);
    int sz(int x);//頂点xが属するグループに含まれている要素数を返す
    bool same(int x,int y);
    void unite(int x,int y);
};
void uft::initialize(){
    for(int i=0;i<MAX_N;i++){
        parent[i]=i;
    }
}
int uft::root(int x){
    if(parent[x]==x){
        return x;
    }
    return parent[x] = root(parent[x]);
}
int uft::sz(int x){
    return size[root(x)];
}
bool uft::same(int x,int y){
    if(root(x)==root(y)){
        return true;
    }else{
        return false;
    }
}
void uft::unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x == y) return;
    parent[x] = y;
    size[y] = size[y]+size[x];
}


int main(){
    int N,M;
    int p[100000];
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>p[i];
        p[i]--;
    }
    uft u;
    u.initialize();
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        x--; y--;
        u.unite(x,y);
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(u.root(i)==u.root(p[i])) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  double ax,ay,bx,by,cx,cy,dx,dy,ans1,ans2,x,y;
   for(int i=0;i<n;i++){
     cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy;
     x = ax - bx;
     y = ay - by;
     ans1 = y / x;
     x = cx - dx;
     y = cy - dy;
     ans2 = y / x;
     if(ans1==ans2) cout << "YES" << endl;
     if(ans1!=ans2) cout << "NO" << endl;
   }
   return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  bool flg=false;
  for(int i=1;i<3;i++){
    if(s[i]!=s[i-1]){
      flg=true;
    }
  }
  cout<<(flg?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
#define MAP_SIZE 10

class Pos {
  public:
    Pos(int x, int y) : x(x), y(y) {}
    int x;
    int y;
    bool alive(Pos p) {
      if (p.x - 1 <= this->x && this->x <= p.x + 1 && p.y - 1 <= this->y && this->y <= p.y + 1) return true;
      return false;
    }
};

int x[12] = {-2, -2, -2, 2, 2, 2, -1, 0, 1, -1, 0, 1};
int y[12] = {-1, 0, 1, -1, 0, 1, -2, -2, -2, 2, 2, 2};
bool move(Pos p, vector<Pos> sc, int n) {
  if (p.x < 0 || MAP_SIZE <= p.x || p.y < 0 || MAP_SIZE <= p.y) return false;
  if (n == -1) return true;
  if (!p.alive(sc[n--])) return false;
  sc.pop_back();
  bool result = false;
  for (int i = 0; i < 12; i++) {
    if (move(Pos(p.x + x[i], p.y + y[i]), sc, n)) result = true;
    if (result) break;
  }
  return result;
}

int main() {
  int x, y;
  while (cin >> x >> y) {
    if (x == 0 && y == 0) break;
    Pos p = Pos(x, y);

    int n;
    cin >> n;
    vector<Pos> sc;
    sc.insert(sc.begin(), p);
    for (int i = 0; i < n; i++) {
      int scX, scY;
      cin >> scX >> scY;
      Pos s = Pos(scX, scY);
      sc.insert(sc.begin(), s);
    }
    cout << (move(p, sc, n) ? "OK" : "NA") << endl;
  }
  return 0;
}

Measured memory_bytes: 2940
#include <stdio.h>
const int MAX_V = 1000000;
int main() {
	int prime[MAX_V+1];
    int i, k, v,a=0,n;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0;
            }
            
        } 
        
    }
    while(1){
      scanf("%d",&n);
      if(n==0)break;
      for(i=0;i<=n-2;i++){
          int isprime = prime[i];
          int isprimex = prime[i+2];
          if(isprime && isprimex){
             if(a<i)a=i;
          }
        }
        printf("%d %d\n",a,a+2);
    	a=0;
    }
    return 0; 
    
}

Measured memory_bytes: 5616
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    string S; cin >> S;
    ll Q; cin >> Q;
    
    deque<char> dq;
    for (int i = 0; i < S.size(); i++) dq.push_back(S[i]);
    
    bool need_reverse = false;
    for (int i = 0; i < Q; i++) {
        int T; cin >> T;
        if (T == 1) {
            need_reverse = !need_reverse;
        } else {
            int F; cin >> F;
            string C; cin >> C;
            if (F == 1) {
                if (need_reverse) dq.push_back(C[0]);
                else dq.push_front(C[0]);
            } else {
                if (need_reverse) dq.push_front(C[0]);
                else dq.push_back(C[0]);
            }
        }
    }
    string ans = "";
    while (!dq.empty()) {
        ans += dq.front();
        dq.pop_front();
    }
    if (need_reverse) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  for (int i=1; i<20000; i++){
    int x,y;
    x = i*0.08;
    y = i*0.1;
    if (x==a && y==b){
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int n, ans = 0;
	string s;
	cin >> n >> s;
	n--;
	int i = 0;
	while (i < n)
	{
		while (i < n && s[i] == 'R')
			i++;
		while (i < n && s[n] == 'W')
			n--;
		if (i < n)
		{
			swap(s[i], s[n]);
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3772
using System;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            //入力
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] a = new int[n];

            for(int i = 0;i < n;i++)
                a[i] = int.Parse(input[i]);
            
            int count = 0;
            int min = 0;
            
            for(int i = 0;i < n;i++)
            {
                if(i == 0)
                {
                    count++;
                    min = a[0];
                    continue;
                }

                if(min > a[i])
                {
                    count++;
                    min = a[i];
                }
            }

            Console.WriteLine(count);
          
        } 
    }  

Measured memory_bytes: 33116
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N, K;
  cin >> N >> K;
  double ans = 0.0;
  
  // 1回目で終わるやつは足しておく
  ans += max(0, N-K+1);
  
  // 1回目でK未満を引いた場合を足す
  for(int i=1; i<min(N+1, K); i++){
    // denomは使い回せそうだけど、とりあえずめんどいのでサボる
    double denom = 2; // denominator
    while(i*denom < K) denom*=2;
//    cout << i << ", " << denom << endl;
    ans += (double) (double)1.0/(double)denom;
  }
  ans /= (double)N;  
  printf("%.10f\n", ans);;
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; cin >> a;
	string str1, str2; cin >> str1 >> str2;
	string res;
	for(int i=0; i<a; i++)
	{
		res += str1[i];
		res += str2[i];
	}
	cout << res << '\n';
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int n, k[10001];
	int i, j, l;
	int cnt = 0;

	while (true) {
	
		cin >> n;

		if (n == 0) return 0;

		for (i = 0; i < n; i++) {

			cin >> k[i];

			if (k[i] == 0) cnt++;

		}

		if (n == 1) {

			i = -9999;
			if (k[0] <= 1) {
				cout << "NA" << endl;
			}
		}



		else {

			for (i = 0; i < n; i++) {

				if (k[i] >= 2) { break; }

			}

		}

		if (i >= (n - 1)) { cout << "NA" << endl;}
		else cout << n - cnt + 1 << endl;

		cnt = 0;

	}
	return 0;
}


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

A.sort()
countlist=[]
num=0
for i in range(N):
    if A[i]!=num:
        countlist.append(1)
        num=A[i]
    else:
        countlist[-1]+=1
countlist.sort()

cnt=0
shu=len(set(A))
if shu>K:
    ans=sum(countlist[:shu-K])
else:
    ans=0
print(ans)

Measured memory_bytes: 26812
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

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

  int nwins = 0;
  for (size_t i = 0; i < S.size(); ++i) {
    if (S[i] == 'o') {
      ++nwins;
    }
  }
  
  if (nwins + (15 - S.size()) >= 8) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}


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

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

    int n,m;
    cin>>n>>m;
    vector<ll> a(n+1);
    a[0]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]=(a[i]+a[i-1])%m;
    }
    map<ll,ll> mp;
    ll ans=0;
    for(int i=0;i<=n;i++){
        ans+=mp[a[i]]++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<< #X <<": "<<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};

const int INF=100000000;
int mode=1;

int main(){
	string s,t;
	int some=-1;
	bool TF=false;
	cin>>s>>t;
	for(int i=0;i<s.size()-t.size()+1;i++){
		for(int j=0;j<t.size();j++){
			if(s[i+j]!='?'){
				if(s[i+j]!=t[j]){
					break;
				}
			}
			if(j==t.size()-1){
				some=i;
			}
		}
	}
	if(some==-1){
		cout<<"UNRESTORABLE"<<endl;
	}
	else{
		for(int i=0;i<s.size();i++){
			if(s[i]!='?'){
				cout<<s[i];
			}
			else{
				if(some<=i && i<some+t.size()){
					cout<<t[i-some];
				}
				else{
					cout<<"a";
				}
			}
		}
	}
	END
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := ReadInt()
	A := ReadInts(N)
	sort.Ints(A)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + A[i]
	}
	ans := 1
	for i := N - 2; i >= 0; i-- {
		if 2*s[i+1] >= A[i+1] {
			ans++
		} else {
			break
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main() {
  int N;
  cin >> N;
  for (int i=0;i<N;i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      break;
    }
    if (i == N-1){
      cout <<"Three" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256