akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
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 int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct edge{ll to, cost;};
vector<edge> G[222];
vector<int> UG[222];
vector<int> color;

vector<ll> dijkstra(ll s,ll n,vector<edge> G[]){
    vector<ll> d={};
    d.resize(n);
    REP(i,n) d[i]=LINF;
    // 最短距離firstが小さい順に取り出せるようにする
    priority_queue<LP, vector<LP>, greater<LP>> que;
    d[s] = 0;// スタート地点を0で初期化
    que.push(LP(0,s));// キューに初期位置のコスト、初期位置をpush

    while(que.size()){
        LP p = que.top();que.pop(); // p: 今の{最短距離、頂点番号}
        ll v = p.second;//今の頂点番号
        if(d[v] < p.first) continue;// 今見ている頂点の歴代最小距離 < 今見ている頂点の最短距離
        for(int i=0; i < G[v].size();i++){// 今の頂点に隣接する頂点を調べる
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){// 遷移先の頂点の歴代最小距離 > 今の距離 + 遷移コスト
                d[e.to] = d[v] + e.cost;// 歴代最小距離の更新
                que.push(P(d[e.to],e.to));// 更新した遷移先の頂点をキューに突っ込む
            }
        }
    }
    return d;
}

bool dfs(int v, int cur=0){
    color[v] = cur;
    for(auto nv:UG[v]){
        if(color[nv]!=-1){
            if(color[nv]==cur) return false;
            continue;
        }
        if(!dfs(nv,1-cur)) return false;
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i,N){
        REP(j,N){
            char c;
            cin >> c;
            if(c == '1'){
                UG[i].push_back(j);
                edge e;
                e.to = j;
                e.cost = 1;
                G[i].emplace_back(e);
            }
        }
    }
    ll ans = 0;
    REP(i,N){
    auto dist = dijkstra(i, N, G);
       for(auto d : dist) chmax(ans, d);
    }
    color.assign(N,-1);
    bool bipartite =true;
    REP(v,N){
        if(color[v]!=-1) continue;
        if(!dfs(v)) bipartite = false;
    }
    if(bipartite) cout << ans + 1 << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
using namespace std;
map<int,int>vis;

 main()
{
            int x,n;
            cin>>x>>n;
            for(int i =0; i<n; i++){
                int a;
                cin>>a;
                vis[a] = 1;
            }
            for(int i = x,j = x; ; i--,j++){
                if(!vis[i]){
                    return cout<<i<<endl,0;
                }
                if(!vis[j]){
                    return cout<<j<<endl,0;
                }
            }

    return 0;
}


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

class segment_tree
{
	using T = ll;
	static const T id = 0;
	T op(T a, T b) const {
		return max(a, b);
	}

	int expand(int x) {
		int res;
		for (res = 1; res < x; res <<= 1);
		return res;
	}
	const int n;
	vector<T> dat;
public:
	segment_tree(int n_)
		: n(expand(n_)), dat(n + n, id) {}
	void update(int p, T val) {
		dat[p += n] = val;
		while (p >>= 1) dat[p] = op(dat[p << 1], dat[(p << 1) | 1]);
	}
	T find(int l, int r) const {
		T res1 = id, res2 = id;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) res1 = op(res1, dat[l++]);
			if (r & 1) res2 = op(dat[--r], res2);
		}
		return op(res1, res2);
	}
};

int main()
{
	int N;
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i]; --h[i];
	}
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	segment_tree dp(N);
	for (int i = 0; i < N; i++) {
		dp.update(h[i], dp.find(0, h[i]) + a[i]);
	}
	cout << dp.find(0, N) << endl;
	return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  //1行目
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  
  //2 ~ H+1行目
  for(int i = 0; i < H; i++){
    cout << "#";
    string s;
    cin >> s;
    cout << s;
    cout << "#" << endl;
  }
  
  //H+2行目
  for(int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 133B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(40).
01 N          PIC  9(2).
01 D          PIC  9(2).
01 TBL-AREA.
   03 X1      OCCURS 10.
      05 Y1   OCCURS 10.    
        07 X  PIC S9(02). 
01 I          PIC  9(02).
01 J          PIC  9(02).
01 K          PIC  9(02).
01 P1         PIC  9(02).
01 P2         PIC  9(02).
01 CNT        PIC  9(02).
01 DST        PIC  9(05).
01 RT1        PIC  9(03)V9(03).
01 RT2        REDEFINES RT1.
   03 RT2-1   PIC  9(03).
   03 RT2-2   PIC  9(03).
01 OUT-CNT    PIC  Z9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N D.
*>      
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    ACCEPT INP
    MOVE 1 TO P1
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > D
      PERFORM VARYING P2 FROM P1 BY 1 
                UNTIL INP(P2:1) = ' '
      END-PERFORM   
      MOVE INP(P1:P2 - P1) TO X(I J)
      COMPUTE P1 = P2 + 1
    END-PERFORM
  END-PERFORM.
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    COMPUTE K = I + 1
    PERFORM VARYING K FROM K BY 1 UNTIL K > N
      MOVE 0 TO DST
      PERFORM VARYING J FROM 1 BY 1 UNTIL J > D
        COMPUTE DST = DST + (X(I, J) - X(K, J)) ** 2
      END-PERFORM 
      COMPUTE RT1 = DST ** 0.5
      IF (RT2-2 = 0)
        ADD 1 TO CNT
      END-IF
    END-PERFORM  
  END-PERFORM.
*>
  MOVE CNT TO OUT-CNT.
  DISPLAY OUT-CNT.
*>
  STOP RUN.


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int i,j;
	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}

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

namespace ABC
{
    class ABC167C
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            string line;
            string[] sa;
            line = Console.ReadLine();
            sa = line.Split(' ');
            int n = int.Parse(sa[0]);
            int m = int.Parse(sa[1]);
            int x = int.Parse(sa[2]);

            int[,] a = new int[n, m + 1];
            for (int i = 0; i < n; ++i)
            {
                line = Console.ReadLine();
                sa = line.Split(' ');

                for (int j = 0; j < m + 1; ++j)
                {
                    a[i, j] = int.Parse(sa[j]);
                }
            }

            int nb = 0x00;
            for (int i = 0; i < n; ++i)
            {
                nb = (nb << 1) | 0x01;
            }

            int price = proc(n, m, a, x, nb);
            if (price < 0)
            {
                Console.WriteLine(-1);
                return;
            }

            
            for(nb -= 1; nb > 0; --nb)
            {
                int priceCurrent = proc(n, m, a, x, nb);
                if (priceCurrent >= 0)
                {
                    price = Math.Min(price, priceCurrent);
                }
            }
            Console.WriteLine(price);

#if DEBUG
            Console.WriteLine();
#endif
        }

        static int proc(int n, int m, int[,] a, int x, int nb)
        {
            int price = 0;
            int pos = 0;
            int[] score = new int[m];
            while (nb > 0)
            {
                if ((nb & 0x01) == 0x01)
                {
                    price += a[pos, 0];
                    for (int j = 0; j < m; ++j)
                    {
                        score[j] += a[pos, j + 1];
                    }
                }
                nb = nb >> 1;
                pos += 1;
            }

            for (int j = 0; j < m; ++j)
            {
                if (score[j] < x)
                {
                    return -1;
                }
            }
            return price;
        }
    }
}


Measured memory_bytes: 27784
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[3300][3300][4];//dp[i][j][k]:=(i,j)でi行目k個拾った時の最大値
ll tre[3300][3300];//1-ind

int main(){cout<<fixed<<setprecision(20);
		   int r,c,k;
           cin>>r>>c>>k;
           int a,b;
           ll v;
           rep(i,0,k){
             cin>>a>>b>>v;
             tre[a][b]=v;
           }
           /////////////////////
           rep(i,1,r+1){
            rep(j,1,c+1){
              rep(k,0,4){
                if(tre[i][j]){
                  if(i-1>=0){//u
                    if(k==1)rep(l,0,4)chmax(dp[i][j][k],dp[i-1][j][l]+tre[i][j]);
                    if(k==0)rep(l,0,4)chmax(dp[i][j][k],dp[i-1][j][l]);
                  }
                  if(j-1>=0){//l
                    chmax(dp[i][j][k],dp[i][j-1][k]);
                    if(k-1>=0)chmax(dp[i][j][k],dp[i][j-1][k-1]+tre[i][j]);
                  }
                }
                else{
                  if(i-1>=0)rep(l,0,4)chmax(dp[i][j][0],dp[i-1][j][l]);
                  if(j-1>=0)chmax(dp[i][j][k],dp[i][j-1][k]);
                }
              }
            }
           }
           
           ll ans=0;
           rep(l,0,4)chmax(ans,dp[r][c][l]);
           cout<<ans<<endl;
}

Measured memory_bytes: 373676
n = int(input())

a = []
a = list(map(int, input().split()))

counter = 0
check = 0

for i in range(n):
    if a[i] % 2 == 0:
        check += 1



while check == n:
    check = 0
    for i in range(n):
        a[i] = a[i]/2
    for i in range(n):
        if a[i] % 2 == 0:
            check += 1
    counter += 1
print(counter)




Measured memory_bytes: 3060
n = int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
l = xx[n//2-1]
r = xx[n//2]

for i in x:
    if i == l:
        print(r)
    elif i == r:
        print(l)
    elif i < l:
        print(r)
    else:
        print(l)
        

Measured memory_bytes: 25348
/*input
 
?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???



*/
import java.io.*;
import java.util.*;

 
public class Main
{
 
	static OutputStream outputStream = System.out;
	static PrintWriter out = new PrintWriter(outputStream);
	static InputStream inputStream = System.in;
	static InputReader br = new InputReader(inputStream);

	
	
	static String s;
	static int n;


	static long[][] dp;

	static long mod=1000000007;

	static long find(int i,int rem)
	{
		if(i>=n)
		{
			if(rem==5) return 1L;
			return 0L;
		}


		if(dp[i][rem]!=-1) return dp[i][rem];


		if(s.charAt(i)=='?')
		{
			long ans=0;

			for(int j=0;j<=9;j++)
			{
				ans+=find(i+1,((10*rem)+j)%13);
				ans%=mod;
			}
			return dp[i][rem]=ans;
		}
		int nr=(10*rem)+(s.charAt(i)-'0');
		nr%=13;

		return dp[i][rem]=(find(i+1,nr)%mod);
	}



	

	public static void main(String[] args)throws IOException
	{
		
 
		s=br.next();
		n=s.length();

		dp=new long[n][13];

		for(int i=0;i<n;i++) Arrays.fill(dp[i],-1);

		out.println(find(0,0)%mod);



		

 
		out.close();
 
	}





















	static class InputReader {
		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 long nextLong() {
			return Long.parseLong(next());
		}
 
	}
	
}

Measured memory_bytes: 50572
#include <stdio.h>
#include <limits.h>
 
int main()
{
    int i, n, a;
    int min=INT_MAX, max=INT_MIN;
    long long sum=0;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%d", &a);
        if(a<min) min=a;
        if(max<a) max=a;
        sum+=a;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = Integer.parseInt(sc.next());
		int[] odd = new int[100000];
		int[] even = new int[100000];
		for (int i = 0; i < N; i++) {
			if ((i & 1) == 1) {
				even[Integer.parseInt(sc.next()) - 1] += 1;
			} else {
				odd[Integer.parseInt(sc.next()) - 1] += 1;
			}
		}
		int om, on, em, en;
		om = on = em = en = 0;
		int omi, emi;
		omi = emi = -1;
		for (int i = 0; i < 100000; i++) {
			if (odd[i] > om) {
				on = om;
				om = odd[i];
				omi = i;
			} else if (odd[i] > on) {
				on = odd[i];
			}
			if (even[i] > em) {
				en = em;
				em = even[i];
				emi = i;
			} else if (even[i] > en) {
				en = even[i];
			}
		}
		if (omi == emi) {
			System.out.println(N - Math.max(om + en, on + em));
		} else {
			System.out.println(N - (om + em));
		}
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vector<vll> cnt(10, vll(10));
    rep1(i, n) {
        int top = to_string(i).front() - '0', bottom = to_string(i).back() - '0';
        cnt[top][bottom]++;
    }
    ll ans = 0;
    for (int i=1; i<=9; ++i) for (int j=1; j<=9; ++j) {
        ans += cnt[i][j] * cnt[j][i];
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  int l = S.length();

  if (l == 7) {
    if (S != "keyence") {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
    }
    return 0;
  }

  int c = l - 7;
  for (int i = 0; i <= l - c; ++i) {
    if (S.substr(0, i) + S.substr(c + i, 7 - i) == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int num = sc.nextInt();

		int taroPoint = 0;
		int hanakoPoint = 0;

		for(int i=0; i<num; i++) {
			String taro = sc.next();
			String hanako = sc.next();
			if(taro.compareTo(hanako) < 0) {
				hanakoPoint += 3;
			} else if(taro.compareTo(hanako) > 0) {
				taroPoint += 3;
			} else {
				hanakoPoint++;
				taroPoint++;
			}
		}

		sc.close();

		System.out.println(taroPoint + " " + hanakoPoint);

	}

}



Measured memory_bytes: 30700
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  int a=n[0]-'0',b=n[1]-'0',c=n[2]-'0',d=n[3]-'0';
  if(a-b-c-d==7)cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
  else if(a-b-c+d==7)cout << a << '-' << b  << '-' << c << '+' << d << '='<< 7 << endl;
  else if(a-b+c+d==7)cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
  else if(a+b+c+d==7)cout << a << '+' << b << '+' << c << '+' << d  << '=' << 7 << endl;
  else if(a-b+c-d==7)cout << a << '-' << b  << '+'  << c << '-' << d << '=' << 7 << endl;
  else if(a+b-c-d==7)cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
  else if(a+b+c-d==7)cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
  else if(a+b-c+d==7)cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <sstream>
#include <limits>  

using namespace std;

const int N_MAX = numeric_limits<int>::max();

int maxprofit(vector<int> arr){
  int tmp_min = arr[0];
  int max_profit = -N_MAX;
  for(int i=1; i<arr.size(); i++){
    max_profit = max(max_profit, arr[i] - tmp_min);
    if(arr[i] <= tmp_min) tmp_min = arr[i];
  }
  return max_profit;
  
}

int main(){
  int n;
  int x;
  vector<int> arr;

  cin >> n;

  for(int i=0; i<n; i++){
    cin >> x;
    arr.push_back(x);
  }
  cout << maxprofit(arr) << endl;
  return 0;
}



Measured memory_bytes: 4728
#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define Y 1000000000

int search(int,int *,int);

int main()
{
  int n,i,S[N],q,T,cnt=0;

  scanf("%d",&n);
  if(n>N) exit(1);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
    if(S[i]>Y) exit(2);
  }
  scanf("%d",&q);
  if(q>50000) exit(3);
  for(i=0;i<q;i++){
    scanf("%d",&T);
    if(T>Y) exit(2);
    if(search(n,&S[0],T)) cnt++; //1が返って来たらカウントする
  }

  printf("%d\n",cnt);
  
  return 0;
}

int search(int n,int *S,int T)
{
  int left=0,right=n,mid;

  while(left<right){
    mid=(left+right)/2;
    if(T==S[mid]) return 1; //一致したら１を返す
    if(T<S[mid]) right=mid; 
    else if(T>S[mid]) left=mid+1;
  }
  return 0;
}



Measured memory_bytes: 2244
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    string s; cin >> s;
    
    // cumulative sum
    vector<int> vL_W(N+1, 0); for(int i=1; i<=N; ++i){ if(s[i-1]=='W'){ ++vL_W[i]; } vL_W[i]+=vL_W[i-1]; }
    vector<int> vR_E(N+1, 0); for(int i=N; i>=1; --i){ if(s[i-1]=='E'){ ++vR_E[i-1]; } vR_E[i-1]+=vR_E[i]; }
    
    int min_num=INT_MAX;
    for(int i=0; i<N; ++i){
        min_num = min(min_num, vL_W[i] + vR_E[i+1]);
    }
    
    cout << min_num << endl;
    
    return 0;
}

Measured memory_bytes: 2964
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MOD 1000000007
using namespace std;



int main(){
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long dp[110][110000];
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n, ans = 0;
  string s;
  cin >> n >> s;
  rep(i,1000){
    int a[3] = { i/100, (i/10)%10, i%10};
    int f = 0;
    rep(j, n){
      if(s[j]==('0'+a[f])) f++;
      if(f==3) break;
    }
    if(f==3) ans++;
  }
  cout << ans << endl;
}


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

int main() {
  int N,M,Q; cin >> N >> M >> Q; 
  vector<tuple<int,int,int,int>> mat(Q);
  for (int i =0; i<Q; i++) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    mat.at(i) = make_tuple(a,b,c,d);
  }

  int ans =0;  
  for (int tmp = 1; tmp <= (1 << N+M-1); tmp++) {
    bitset<19> bit(tmp);
    int bit1 = bit.count();
    if (bit1 != N) continue;
    vector<int> A;
    int p =1;
    for (int i =N+M-2; i>=0; i--) {
      if (bit.test(i)) {
        A.push_back(p);
      } else {
        p++;
      }
    }
    int ansD =0;
    for (int i =0; i<Q; i++) {
      int a,b,c,d;
      tie(a,b,c,d) = mat.at(i);
      if (A.at(b-1) - A.at(a-1) == c) ansD += d;
    }
    ans = max(ansD,ans);
  }
  cout << ans << endl; 
}
  

Measured memory_bytes: 3568
#include <iostream>
#include <vector>

using namespace std;

vector<string> bs;
void init() {
    bs.push_back("");
    bs.push_back("',.!?");
    bs.push_back("abcABC");
    bs.push_back("defDEF");
    bs.push_back("ghiGHI");
    bs.push_back("jklJKL");
    bs.push_back("mnoMNO");
    bs.push_back("pqrsPQRS");
    bs.push_back("tuvTUV");
    bs.push_back("wxyzWXYZ");
}

string F(char c, int n) {
//    cout << c << ' ' << n << endl;
    if (c == '0') {
        if (n == 0) return "";
        string t = "";
        for (int i = 0; i < n-1; i++) t.push_back(' ');
        return t;
    }
    return string("") + bs[c-'0'][(n-1) % bs[c-'0'].size()];
}

int main() {
    init();
    string s;
    while (cin >> s) {
        char c = '0';
        int n = 0;
        for (int i = 0; i < s.size(); i++) {
            if (c != s[i]) {
                cout << F(c, n);
                c = s[i];
                n = 1;
            } else {
                n++;
            }
        }
        cout << F(c, n);
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String[] temp = sc.nextLine().split(" ");
		int[] list = new int[n];
		int ans = 0;

		list[0] = Integer.parseInt(temp[0]);
		for(int i = 1; i < n; i++) {

			list[i] = list[i - 1] + Integer.parseInt(temp[i]);
		}

		ans = list[n - 1];
		for(int i = 1; i < n - 1; i++) {

			ans = Math.min(ans, Math.abs((list[n - 1] - list[i]) - list[i]));

		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <ctype.h>
   
int par[100000];
   
void init(int);
int dep(int);
int inp(void);
  
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
  
int main(){
  int n,i,j,id,k,c;
  
  fread(in,sizeof(in),1,stdin);  
  p = in;
  
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
   
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
      
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
  
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
  
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
  
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
  
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}

Measured memory_bytes: 2892
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void)
{
	int N, K,count=0;
	int h[100010];
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%d", &h[i]);
		if (h[i] >= K) {
			count++;
		}
	}
	printf("%d", count);

	return 0;
}


Measured memory_bytes: 512
def search(idx, a, b, c):
    if idx == N:
        if min(a, b, c) > 0:
            return abs(A-a) + abs(B-b) + abs(C-c) - 30
        else:
            return 10**20
            
    n0 = search(idx+1, a, b, c)
    n1 = search(idx+1, a+l[idx], b, c) + 10
    n2 = search(idx+1, a, b+l[idx], c) + 10
    n3 = search(idx+1, a, b, c+l[idx]) + 10
    
    return min(n0, n1, n2, n3)
    
N, A, B, C = list(map(int, input().split()))
l = [int(input()) for i in range(N)]

print(search(0, 0, 0, 0))

Measured memory_bytes: 3064
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <climits>
#include <deque>
#include <map>
#include <deque>
#include <iomanip>
#include <cmath>
#include <functional>
#include <set>
#include <list>
#include <bitset>
#include <stack>
#include <stdio.h>
#define endl '\n'
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
typedef pair<ll,ll> pll;
int main()
{
    /*
for reading from input.txt and writing on output.txt
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/
    cin.sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n;cin>>n;
    if(n&1)
    {
        cout<<0<<endl;
        return 0;
    }
    else
    {
        ll ans=0;
        ll d=10;
        while(n/d)
        {
            ans+=n/d;
            d=d*5;
        }
        cout<<ans<<endl;
    }
}


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


int main() {

    int a, b;
    cin >> a >> b;
    int  ans = 0;
    for (int i = a; i <= b; ++i) {
        int a = i / 10000, b = i % 10;
        int c = i / 1000 % 10, d = i % 100 / 10;
        if (a == b && c == d) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
A
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	string s;
	cin>>s;
	if(s[0]=='A') cout<<'T';
	else if(s[0]=='T') cout<<'A';
	else if(s[0]=='G') cout<<'C';
	else cout<<'G';
	return 0;
}


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

int main(){
    int_fast64_t N, C;
    scanf("%lld%lld", &N, &C);
    vector<pair<int_fast64_t, int_fast64_t>> cw(N + 1), ucw(N + 1);
    vector<pair<int_fast64_t, int_fast64_t>> sushi(N + 1);
    for(uint_fast64_t i = 0; i < N; ++i)scanf("%lld%lld", &sushi[i].first, &sushi[i].second);
    cw[0] = make_pair(0, 0);
    cw[1] = make_pair(sushi[0].second - sushi[0].first, sushi[0].first);
    for(uint_fast64_t i = 2; i <= N; ++i){
        cw[i] = make_pair(cw[i - 1].first + sushi[i - 1].second + sushi[i - 2].first - sushi[i - 1].first, sushi[i - 1].first);
    }
    ucw[0] = make_pair(0, 0);
    ucw[1] = make_pair(sushi[N - 1].second - C + sushi[N - 1].first, C - sushi[N - 1].first);
    for(uint_fast64_t i = 2; i <= N; ++i){
        ucw[i] = make_pair(ucw[i - 1].first + sushi[N - i].second + sushi[N - i].first - sushi[N - i + 1].first, C - sushi[N - i].first);
    }
    partial_sum(cw.begin(), cw.end(), cw.begin(), [](pair<int_fast64_t, int_fast64_t> a, pair<int_fast64_t, int_fast64_t> b){return max(a, b);});
    partial_sum(ucw.begin(), ucw.end(), ucw.begin(), [](pair<int_fast64_t, int_fast64_t> a, pair<int_fast64_t, int_fast64_t> b){return max(a, b);});
    int_fast64_t ans(numeric_limits<int_fast64_t>::min());
    for(uint_fast64_t i = 0; i <= N; ++i){
        ans = max({ans, cw[i].first, ucw[N - i].first, cw[i].first + ucw[N - i].first - min(cw[i].second, ucw[N - i].second)});
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    rep(i,n-2){
        string q = "ABC";
        if(s.substr(i,3)==q){
            ++cnt;
        }
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
#define llong long long

int main(){
  int N; cin >> N;
  int A[N][10], B[N][11], C[N];
  for (int i=0; i<N; i++){
    for (int j=0; j<10; j++){
      cin >> A[i][j];
    }
  }
  for (int i=0; i<N; i++){
    for (int j=0; j<=10; j++){
      cin >> B[i][j];
    }
  }
  llong ans = -(1<<30);
  for (int bit = 1; bit < (1<<10); bit++){
    llong x = 0;
    for (int i=0; i<N; i++){
      int cnt=0;
      for (int j=0; j<10; j++){
        if((bit>>j&1) && A[i][j]) cnt++;
      }
      x += B[i][cnt];
    }
    if(ans<x) ans = x;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {
    static Stack<Integer> stack = new Stack<>();
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] split = sc.nextLine().trim().split(" ");
        for (int i = 0; i < split.length; i++) {
            if (split[i].equals("+")) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                int i1 =pop1 +pop2;
                stack.push(i1);
            }
            else if (split[i].equals("-")) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                int i1 =pop2 -pop1;
                stack.push(i1);
            }
           else if (split[i].equals("*")) {
                Integer pop1 = stack.pop();
                Integer pop2 = stack.pop();
                int i1 =pop1 *pop2;
                stack.push(i1);
            }else {
                stack.push(Integer.parseInt(split[i]));
            }
        }
        System.out.println(stack.pop());
    }

}


Measured memory_bytes: 26064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

void solve() {
    int n;
    cin >> n;

    vector<ii> v(n);
    fori (i, 0, n) {
        cin >> v[i].first >> v[i].second;
    }

    sort(begin(v), end(v));

    int ans = 0;

    set<int> less, more;
    less.insert(v.back().second - v.back().first);
    more.insert(v.back().second + v.back().first);

    ford (i, n - 2, 0) {
        int x, y;
        tie(x, y) = v[i];

        int a = abs(y - (*less.begin() + x));
        int b = abs(y - (*more.rbegin() - x));

        ans = max(ans, a);
        ans = max(ans, b);

        less.emplace(y - x);
        more.emplace(y + x);
    }

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 23520
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define ufor(i,l,r) for (int i=l;i<=r;i++)
#define MAXN 2050
int a[MAXN],d[MAXN][MAXN];
int n;


int main()
{
	int X,Y;
	scanf("%d%d%d",&n,&X,&Y);
	ufor (i,1,n)
	ufor (j,1,n) d[i][j]=abs(i-j);
	d[X][Y]=d[Y][X]=1;
	
	bool flag=true;
	while (flag)
	{
		flag=false;
		ufor (i,1,n)
		ufor (j,1,n)
		{
			int x=min(d[i][X]+d[X][j],d[i][Y]+d[Y][j]);	
			if (x<d[i][j]) d[i][j]=x,flag=true;
		}
	}

	ufor (i,1,n-1)
	ufor (j,i+1,n) a[d[i][j]]++;
	
	ufor (i,1,n-1)
	printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 19760
<?php
	$nums = explode( " ", trim( fgets( STDIN ) ) );	
	for( $i=0; $i<2; $i++ ) {
		for( $j=$i+1; $j<3; $j++ ) {
			if( $nums[$j] < $nums[$i] ) {
				$t = $nums[$i];
				$nums[$i] = $nums[$j];
				$nums[$j] = $t;
			}
		}
	}
	print "$nums[0] $nums[1] $nums[2]";
?>

Measured memory_bytes: 6580
H, W, N = gets.split.map(&:to_i)
bs = {}
N.times.each do
  x, y = gets.split.map(&:to_i)
  (([1, (x-2)].max)..([x, H-2].min)).map do |xx|
    (([1, y-2].max)..([y, W-2].min)).map do |yy|
      bs[xx] ||= {}
      bs[xx][yy] ||= 0
      bs[xx][yy] += 1
    end
  end
end
result = bs.values.flat_map(&:values)
p (H-2) * (W-2) - result.count
(1..9).each do |i|
  p result.count(i)
end


Measured memory_bytes: 121084
n = int(input())
ans = 0
nex = 0
for i in range(n):
    now = int(input())
    if nex == 1 and now > 0:
        now -= 1
        nex = 0
        ans += 1
    elif nex == 1 and now == 0:
        nex = 0 
    ans += now//2
    if now % 2 == 1:
        nex = 1
print(ans)

Measured memory_bytes: 3060
let partition a p r =
  let x = a.(r) in
  let swap i j = let t = a.(i) in a.(i) <- a.(j); a.(j) <- t
  in
  let rec doit i j =
    if j >= r then i
    else begin
      if a.(j) <= x then (swap (i + 1) j; doit (i + 1) (j + 1))
      else doit i (j + 1)
    end
  in
  let i = doit (p - 1) p in
  swap (i + 1) r;
  i + 1

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let k = partition a 0 (n - 1) in
  Array.iteri (fun i e ->
    Printf.printf (if i = 0 then "%d" else if i = k then " [%d]" else " %d") e) a;
  print_newline ()

Measured memory_bytes: 5388
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    deque<ll> deq;
    ll ans = 1;
    deq.push_back(v[0]);
    for(int i = 1; i < n; i++){
        int id = lower_bound(deq.begin(), deq.end(), v[i]) - deq.begin();
        if(id == 0){
            //cout << "Yes" << endl;
            deq.push_front(v[i]);
        }
        else deq[id-1] = v[i];
        //cout << id << endl;
    }
    cout << (int)deq.size() << endl;
    return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  vector<ll> B(N);
  rep(i,N){
    ll x;
    cin >> x;
    B[i] = x - i - 1;
  }

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

  ll base =  B[N/2];

  //rep(i,N) cout << B[i] << endl;

  ll ans = 0;

  rep(i, N) ans += abs(B[i]-base);

  cout << ans << endl;



}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    int n,k;
	    cin >> n >> k;
	    ll dp[n+1]={};
	    ll arr[n+1];
	    dp[1]=0;
	    for(int i=1 ; i<=n ; i++){
	        cin >> arr[i];
	    }
	    for(int i=2 ; i<=(k+1) && i<=n ; i++){
	        ll temp=1000000000000000000;
	        for(int j=(i-1) ; j>=1 ; j--){
	            temp=min(temp,dp[j]+abs(arr[j]-arr[i]));
	        }
	        dp[i]=temp;
	    }
	    for(int i=(k+2) ; i<=n ; i++){
	        ll temp=1000000000000000000;
	        for(int j=(i-1) ; j>=(i-k) ; j--){
	            temp=min(temp,dp[j]+abs(arr[j]-arr[i]));
	        }
	        dp[i]=temp;
	    }
	    cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 5204
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//sin(x*pi/180)
//be careful from the multiplication while using this define 
//alot of memset may couse TLE
#define TC int t;cin>>t;while(t--)
//</DEFINE>
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
int n, k;
vector<int>v;
int res[100001][2];
//<FUNCTIONS>
bool solve(int rem, bool state) {
	int& ans = res[rem][state];
	if (~ans)return ans;
	if (state) {
		ans = 0;
		for (int i = 0; i < n; i++)
			if (rem - v[i] >= 0)ans |= solve(rem - v[i], 0);
		return ans;
	}
	else {
		ans = 1;
		for (int i = 0; i < n; i++)
			if (rem - v[i] >= 0)ans &= solve(rem - v[i], 1);
		return ans;
	}
}
//</FUNCTIONS>	
int main() {
	Fast(), File();
	memset(res, -1, sizeof(res));
	cin >> n >> k;
	v.resize(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	cout << (solve(k, 1) ? "First" : "Second");
}

Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    if(N==M){
        ll ans=2;
        rep2(i,N){
            ans=(ans*i)%mod;
        }
        rep2(i,M){
            ans=(ans*i)%mod;
        }
        cout<<ans<<endl;
    }else if(abs(N-M)==1){
        ll ans=1;
        rep2(i,N){
            ans=(ans*i)%mod;
        }
        rep2(i,M){
            ans=(ans*i)%mod;
        }
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3628
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    qs = [tuple(input().split()) for _ in range(q)]
    flag = 1
    for qse in qs:
        if qse[0] == '1':
            flag ^= 1
        else:
            f = int(qse[1]) - 1
            f ^= flag
            if f:
                s.appendleft(qse[2])
            else:
                s.append(qse[2])
    if flag:
        print("".join(s))
    else:
        ss = list(s)
        print("".join(ss[::-1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 30016
#include<bits/stdc++.h>
const int N = 100010;

char s[N];

int main()
{
    scanf("%s", s);
    int cnt = 0, len = strlen(s);
    for (int i = 1; i < len; i++)
        if (s[i] != s[i - 1])
            cnt ++;
    printf("%d\n", cnt);
    return 0;
}

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

using namespace std;

int64_t modpow(int64_t a, int64_t b, int64_t MOD) {
	int64_t ret = 1;
	while (b > 0) {
		if (b & 1) { (ret *= a) %= MOD; }
		(a *= a) %= MOD;
		b >>= 1;
	}
	return ret % MOD;
}

int main() {
	Int N, P;
	cin >> N >> P;
	string s;
	cin >> s;

	if (P == 2 || P == 5) {
		vector<Int> curr(P, 0);
		curr[(int)(s[0] - '0') % P] = 1;
		Int ans = curr[0];
		for (int i = 1; i < N; ++i) {
			vector<Int> nxt(P, 0);
			int x = s[i] - '0';
			nxt[x % P] += 1;
			for (int j = 0; j < P; ++j) {
				nxt[(j * 10 + x) % P] += curr[j];
			}
			ans += nxt[0];
			curr = nxt;
		}
		cout << ans << endl;

		return 0;
	}

	Int x = 0, y = 1;
	vector<Int> cnt(P, 0);
	cnt[0] = 1;
	Int ans = 0;
	for (int i = 0; i < N; ++i) {
		(x = x * 10 + (s[i] - '0')) %= P;
		Int z = x * modpow(y, P - 2, P) % P;
		ans += cnt[z];
		++cnt[z];
		y = y * 10 % P;
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(a.begin(),a.end());

    bool es;
    for(int i=0;i<n-1;i++){
        if(a.at(i)==a.at(i+1)){
            es=false;
            break;
        }
        else es=true;
    }
    if(es) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
manzoku = 0
prev = 0
 
for a in A:
  manzoku += B[a-1]
  if prev+1 == a and prev != 0:
    manzoku += C[prev-1]
  prev = a
print(manzoku)

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define P pair<LL,LL>
#define INF 0x3f3f3f3f
const int Mod = 998244353;
const int N = 1e5 + 10;
LL a[N];
int main()
{

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

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

    LL ans = INF;
    for (int i = k; i <= n; i++)
        ans = min(ans, min(abs(a[i - k + 1]), abs(a[i])) + a[i] - a[i - k + 1]);
    cout << ans << endl;
    return 0;

}
/*
2
3
-3 0
1 0
3 2
3
-4 2
-4 -3
1 0
*/


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long N,M,X,max=0,cnt=0;
    cin >> N;
    N = N%10;
    if(N ==3){
        cout << "bon";
    }else if(N == 0 || N==1 || N==6 || N == 8){
        cout <<"pon";
    }else{
        cout << "hon";
    }
}

Measured memory_bytes: 3608
#include<stdio.h>
 
int main(){
  int a;
  int b;
  
  scanf("%d %d", &a, &b);
 
  int menseki;
  menseki = a * b;
  int nagasa;
  nagasa = 2 * (a + b);
 
  printf("%d %d\n" ,menseki, nagasa);
 
  return 0;
}


Measured memory_bytes: 1988
#include<stdio.h>
int main()
{
    int a;
    int b;
    int h;
    int area = 0;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &h);

    area = (a + b) * h / 2;
    printf("%d\n", area);

    return 0;
}

Measured memory_bytes: 128
import sys


def resolve():
    readline = sys.stdin.readline

    X = int(readline())
    
    if 400 <= X <= 599:
        print(8)
    elif 600 <= X <= 799:
        print(7)
    elif 800 <= X <= 999:
        print(6)
    elif 1000 <= X <= 1199:
        print(5)
    elif 1200 <= X <= 1399:
        print(4)
    elif 1400 <= X <= 1599:
        print(3)
    elif 1600 <= X <= 1799:
        print(2)
    elif 1800 <= X <= 1999:
        print(1)

resolve()


Measured memory_bytes: 9172
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<cmath>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;

inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
}

const int N = 505;
char a[N][N], b[N][N], c[N][N];

int main() { 
//	freopen("in.txt","r",stdin);
	int n = read(), m = read();
	rep(i,1,n) scanf("%s",c[i]+1);
	rep(i,1,n) { 
		a[i][1] = '#', a[i][m] = '.';
		b[i][m] = '#', b[i][1] = '.';
		if( i & 1 ) { 
			rep(j,2,m-1) a[i][j] = '#', b[i][j] = '.';
		} else { 
			rep(j,2,m-1) a[i][j] = '.', b[i][j] = '#';
		}
	}
	rep(i,1,n) { 
		rep(j,1,m) if( c[i][j] == '#' ) a[i][j] = b[i][j] = '#';
	}
	rep(i,1,n) { 
		printf("%s\n", a[i]+1);
	}
	puts("");
	rep(i,1,n) { 
		printf("%s\n", b[i]+1);
	}
	return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split();
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int ans = -1;
        for (int i = (A - 1) * 25 / 2; i < (A + 1) * 25 / 2; i++)
        {
            if (ans==-1&&Math.Floor((double)(i / 10)) == B&& Math.Floor((double)(i * 8 / 100))==A) { ans = i; }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140