akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> f(n+1, -1*INF);
    vector<P> sushi;
    rep(i, n) {
        ll t, d;
        cin >> t >> d;
        sushi.push_back(make_pair(d, t)); // 美味しさ先にする
    }
    sort(ALL(sushi), greater<P>());

    // 初期状態を作る
    // pqmaxは絶対解に必要, pqminは2番手以降なので抜いてもOK
    priority_queue<ll, vector<ll>, greater<ll>> pqmax, pqmin;
    ll sum = 0;
    set<ll> var; // どの寿司が含まれてるか
    rep(i, k) {
        sum += sushi[i].first;
        // 始めて来た寿司
        if(!var.count(sushi[i].second)) {
            var.insert(sushi[i].second);
            pqmax.push(sushi[i].first);
        }
        // 2番手以降の寿司
        else {
            pqmin.push(sushi[i].first);
        }
    }
    f[var.size()] = sum;

    frep(i, k, n-1) {
        // 始めて来た寿司に対してのみ操作をする
        if(!var.count(sushi[i].second) && pqmin.size() != 0) {
            // 最小値取り出し
            ll tp = pqmin.top();
            pqmin.pop();
            sum -= tp;
            // 新種を挿入
            sum += sushi[i].first;
            pqmax.push(sushi[i].first);
            var.insert(sushi[i].second);
            f[var.size()] = sum;
        }
    }

    ll ans = -1*INF;
    frep(i, 1, n) {
        if(f[i]+i*i > ans) ans = f[i]+i*i;
    }
    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 9480
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String b = sc.next();

		if (b.equals("A"))
			System.out.println("T");
		else if (b.equals("C"))
			System.out.println("G");
		else if (b.equals("G"))
			System.out.println("C");
		else if (b.equals("T"))
			System.out.println("A");
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 20052
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void insertionSort(int A[], int N) {
	int i;
	int v;
	int j;

	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (0 <= j && v < A[j]) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
}

void getAns(int n, int A[], int Ans[], int Ans2[]) {
	Ans[0] = 1;
	int i, j;
	for (j = 0; j < n; ++j) {
		for (i = 0; i < 2001; ++i) {
			if (Ans[i] == 1) {
				if (i + A[j] <= 2000) {
					Ans2[i + A[j]] = 1;
				}
			}
		}
		for (i = 0; i < 2001; ++i) {
			if (Ans2[i] == 1) {
				Ans[i] = 1;
			}
		}
	}
}

int main() {
	int n;
	int A[20];
	int Ans[2001];
	int Ans2[2001];
	int q;
	int m;
	int i;

	for (i = 0; i < 2001; ++i) {
		Ans[i] = 0;
		Ans2[i] = 0;
	}

	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%d", A + i);
	}
	insertionSort(A, n);

	getAns(n, A, Ans, Ans2);

	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &m);
		if (Ans[m]) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}


	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
int main(void){
    int i,N,p[10];
    int sum=0,min=100;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&p[i]);
    }
    for(i=0;i<N;i++){
        if(min<p[i]){
            min=p[i];
        }
    }
    for(i=0;i<N;i++){
        sum=sum+p[i];
    }
    printf("%d",sum-min/2);
    return 0; 
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back

typedef long long ll;

int main() {
    int n; cin >> n;
    double p[n];
    fore(i, 0, n) cin >> p[i];

    double dp[n + 1][n + 1];

    dp[0][0] = 1;

    fore(i, 1, n + 1) {
        dp[i][0] = dp[i - 1][0] * p[i - 1];
    }
    fore(j, 1, n + 1) {
        dp[0][j] = dp[0][j - 1] * (1 - p[j - 1]);
    }
    fore(i, 1, n + 1) {
        fore(j, 1, n + 1) {
            if(i + j == n + 1) break;
            dp[i][j] = dp[i - 1][j] * p[i + j - 1] + dp[i][j - 1] * (1 - p[i + j - 1]);
        }
    }
    double res = 0;
    fore(i, 0, n + 1) {
        fore(j, 0, n + 1) {
            if(i > j && i + j == n) res += dp[i][j];
        }
    }
    cout.precision(20);
    cout << res << endl;
}

Measured memory_bytes: 70400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
using M = map<int, int>;

int main()
{
  double a, b;
  cin >> a >> b;
  int ans = -1;
  rep(i, 100000){
    
    if((int)(i * 0.08) == a && b == (int)(i * 0.1)){
      ans = i;
      break;
    }
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define FOR(v1, v2) for (v1 = 0; v1 < v2; ++v1)

int bingo_mat[3][3];
bool is_num[100];
int b[10];

bool check_row(int i) {
  int j;
  FOR(j, 3) {
     if (!is_num[bingo_mat[i][j]])
       return false;
  }
  return true;
}

bool check_col(int j) {
  int i;
  FOR(i, 3) {
     if (!is_num[bingo_mat[i][j]])
       return false;
  }
  return true;
}

bool check_diag1() {
  if (!is_num[bingo_mat[0][0]])
    return false;

  if (!is_num[bingo_mat[1][1]])
    return false;

  if (!is_num[bingo_mat[2][2]])
    return false;

  return true;
}

bool check_diag2() {
  if (!is_num[bingo_mat[0][2]])
    return false;

  if (!is_num[bingo_mat[1][1]])
    return false;

  if (!is_num[bingo_mat[2][0]])
    return false;

  return true;
}

                                                                                                                                                           
int main () {
  int i, j;
  FOR(i, 3) {
    FOR(j, 3) {
      cin >> bingo_mat[i][j];
      --bingo_mat[i][j];
    }   
  }
  int n;
  cin >> n;
  FOR(i, n) {
    cin >> b[i];
    --b[i];
    is_num[b[i]] = true;
  }

  FOR(i, 3) {
    if(check_row(i) || check_col(i))  {
      cout << "Yes" << endl;
      return 0;
    }   
  }
  if (check_diag1() || check_diag2()) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var k = o.a();
  if(k === 1)return 0;
  return n-k;
}

Measured memory_bytes: 22964
let () =
  let v = Scanf.scanf "%d" (fun v->v) in
  let rec loop l n =
    if n = 0 then l else loop (n mod 10 :: l) (n/10)
  in
  let l = loop [] v in
  let l = List.fold_left (fun l d ->
    match l with
    | [] -> [0,d]
    | l -> List.fold_left (fun l (sum, x) ->
             (sum + x, d)::(sum, 10 * x + d)::l
           ) [] l
  ) [] l in
  let r = List.fold_left (fun r (sum, x) -> r + sum + x) 0 l in
  Printf.printf "%d\n" r


Measured memory_bytes: 512
#include <bits/stdc++.h>
   using namespace std;
   using pii = pair<int, int>;
   using ll = long long;
   #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
   const ll MOD = 1000000007;
   const ll INFL = (1LL << 60);
   const int INFI = (1 << 30);

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

     if (S.length() <= K) cout << S << endl;
     else cout << S.substr(0, K) << "..." << endl;
   }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c; cin >> a >> b >> c;
    bool ans = false;
    for(int i = b; i <= c;i++){
        if(i%a == 0){
            ans = true;
            break;
        }
    }

    if(ans) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import sys
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X, Y, N, M, L = MAP()
A = LIST()
B = LIST()
C = LIST()

A.sort(reverse=1)
B.sort(reverse=1)

que = []
que += A[:X]
que += B[:Y]
heapify(que)

for c in C:
    if c > que[0]:
        heappop(que)
        heappush(que, c)
ans = sum(que)
print(ans)


Measured memory_bytes: 96424
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    vector<vector<long long>> abc(N, vector<long long>(3));
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) cin >> abc[i][j];

    vector<vector<long long>> dp(N, vector<long long>(3, 0));
    for (int i = 0; i < 3; i++) dp[0][i] = abc[0][i];

    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i + 1][k]);
                }
            }
        }
    }

    long long ans = *max_element(dp[N - 1].begin(), dp[N - 1].end());

    cout << ans << endl;

    return 0;
}
















































Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define MAXN 50
using namespace std;
int n;
int a[MAXN+1],b[MAXN+1];
bool solve[MAXN+1][MAXN+1][MAXN+1];
bool dp[MAXN+1][MAXN+1];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    memset(solve,false,sizeof(solve));
    memset(dp,false,sizeof(dp));
    for(int i=0;i<=MAXN;i++)
    {
        dp[i][i]=true;
        solve[0][i][i]=true;
    }
    for(int i=1;i<=MAXN;i++)
    {
        for(int j=0;j<=MAXN;j++)
        {
            for(int k=0;k<=MAXN;k++)
            {
                solve[i][j][k]=solve[i-1][j][k];
            }
        }
        for(int j=0;j<=MAXN;j++)
        {
            for(int k=0;k<=MAXN;k++)
            {
                if(solve[i][j%i][k])
                {
                    solve[i][j][k]=true;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!solve[MAXN][a[i]][b[i]])
        {
            printf("%d\n",-1);
            return 0;
        }
    }
    long long ans=0;
    for(int i=MAXN;i>=1;i--)
    {
        int j,k;
        for(j=1;j<=n;j++)
        {
            for(k=0;k<=MAXN;k++)
            {
                if(dp[a[j]][k])
                {
                    if(solve[i-1][k][b[j]])
                    {
                       // printf("ss\n");
                        break;
                    }
                }
            }
            //每一个都没走完n个 就continue
            //有一个走完了n个 就不continue
            if(k>MAXN)
            {
             //   printf("A %d\n",j);
                break;
            }
        }
        if(j==n+1)
        {
            continue;
        }
        ans+=1ll<<i;
      //  printf("%d\n",i);
        for(j=1;j<=MAXN;j++)
        {
            for(k=1;k<=MAXN;k++)
            {
                if(dp[j][k])
                {
                    dp[j][k%i]=true;
                }
            }
        }
    }
    printf("%lld\n",ans);
}


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

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[100];

void solve(int x, int y, int s)
{
  REP(i,10) REP(j,10)
  {
    if(s == 3 && abs(x-i)+abs(y-j)<=2) a[i+j*10]++;
    if(s == 2 && abs(x-i)<=1 && abs(y-j)<=1) a[i+j*10]++;
    if(s == 1 && abs(x-i)+abs(y-j)<=1) a[i+j*10]++;
  }
}

int main()
{
  fill_n(a,100,0);
  int x, y, s;
  while(~scanf("%d,%d,%d",&x,&y,&s))
    solve(x,y,s);
  int ans1 = 0, ans2 = -1;
  REP(i,100)
  {
    if(a[i] == 0) ans1++;
    ans2 = max(ans2, a[i]);
  }
  printf("%d\n%d\n",ans1,ans2);
  return 0;
}

Measured memory_bytes: 3204
#include <iostream>

using namespace std;

int main(void){
  string S;
  cin>>S;
  int cnt=0;
  for(int i=0;i<3;i++){
    if(S[i] == 'R'){
      cnt++;
      if(S[i+1] =='R' && i+1<3){
        cnt++;
        if(S[i+2] =='R' && i+2<3) cnt++; 
      }
      break;
    }
  }
  cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   string a,b;
    cin>>a;
    b=a;
    reverse(all(b));
    w(q)
    {
        cin>>x;
        if(x==1)
        {
            swap(a,b);
        }
        else
        {   char c;
            cin>>x>>c;
            if(x==1){a.insert(a.begin(),c);b.pb(c);}
            else {a.pb(c);b.insert(b.begin(),c);}
        }
        
    }
    
    
    cout<< a<<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 4124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int n;
	cin >> n;
	cout << (n + 1) / 2;*/


	/*int a[3][3];
	rep(i, 3)rep(j, 3) {
		cin >> a[i][j];
	}
	int n;
	cin >> n;
	int b;
	vector<vector<int>>c(3, vector<int>(3));
	rep(i, n) {
		cin >> b;

		rep(j, 3) {
			rep(k, 3) {
				if (b == a[j][k])c[j][k] = 1;
			}
		}
	}
	bool ok = false;
	int x = 0, y = 0;

	rep(i, 3) {
		x = 0;
		y = 0;
		rep(j, 3) {
			x += c[i][j];
			y += c[j][i];
		}
		if (x == 3 || y == 3)ok = true;
	}
	int z = 0, z2 = 0;
	z = c[0][0] + c[1][1] + c[2][2];
	z2 = c[2][0] + c[1][1] + c[0][2];
	if (z == 3 || z2 == 3)ok = true;

	if (ok)puts("Yes");
	else puts("No");*/


	int n, m;
	cin >> n >> m;
	vector<int>used(n), ans(n);
	int s, c;
	bool ok = true;
	rep(i, m) {
		cin >> s >> c;
		s--;
		if (used[s] && c != ans[s])ok = false;

		used[s] = 1;
		ans[s] = c;
	}
	if (n != 1 && used[0] && ans[0] == 0)ok = false;
	if (ok) {
		if (ans[0] == 0) {
			ans[0] = 1;
			if (n == 1)ans[0] = 0;
		}
		rep(i, n)cout << ans[i];
	} else cout << -1;



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
  int N,Q;
  cin >> N >> Q;
  char S[100000];
  int ans = 0;
  int lr[100000];
  cin >> S;

  int p = 0;
  lr[0] = 0;
  for(int i = 1;i <= N; i++){
    if(S[i-1] == 'A' && S[i] == 'C'){
         p++;
      }
    lr[i+1] = p;
  }

  for(int i = 0;i < Q; i++){
    int l,r;
      cin >> l >> r;
     cout << lr[r] -  lr[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}




// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    ll r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    combination c(1e7);
    mint ans = 0;
    ans += c(r2+c2+2,c2+1);
    ans -= c(r2+c1+1,c1);
    ans -= c(r1+c2+1,c2+1);
    ans += c(r1+c1,c1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 156544
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    fr(i,n-k) puts(a[i]<a[i+k]?"Yes":"No");
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

// w = lca(u, v)
// Q(u, v) = Q(w, u) + Q(w, v) = Q(root, u) + Q(root, v) - 2 * Q(root, w)
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> cnt(n, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    cnt[a - 1]++;
    cnt[b - 1]++;
  }
  bool f = true;
  rep(i, n) if (cnt[i] % 2) f = false;
  cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int left = int.MinValue,
            right = int.MaxValue;
        for (int i = 0; i < m; i++)
        {
            int[] lr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            left = Math.Max(left, lr[0]);
            right = Math.Min(right, lr[1]);
        }
        Console.WriteLine(right - left >= 0 ? right - left + 1 : 0);
    }
}

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

using namespace std;

typedef long long ll;
const ll maxn = 100010;
ll n,q,top,tn;
ll a[maxn],S[maxn],tong[maxn],ci[maxn],sum[maxn];
vector <pair<ll,ll> >V[maxn];

ll find(ll x)
{
    ll l = 1,r = top,res = 1;
    while (l <= r)
    {
        ll mid = (l + r) >> 1;
        if (S[mid] <= x)
        {
            res = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
    return res;
}

int main()
{
    scanf("%lld%lld",&n,&q);
    tn = n;
    for (ll i = 1; i <= q; i++)
        scanf("%lld",&a[i]);
    S[++top] = n;
    for (ll i = 1; i <= q; i++)
    {
        while (top && S[top] >= a[i])
            top--;
        S[++top] = a[i];
    }
    n = S[1];
    V[1].push_back(make_pair(-n,1));
    for (ll i = 2; i <= top; i++)
    {
        ll x = S[i];
        ll cur = i - 1;
        while (x > n)
        {
            ll temp = x / S[cur];
            V[i].push_back(make_pair(cur,temp));
            x %= S[cur];
            cur = find(x);
        }
        if (x > 0 && x <= n)
            V[i].push_back(make_pair(-x,1));
    }
    ci[top] = 1;
    for (ll i = top; i >= 1; i--)
        for (ll j = 0; j < V[i].size(); j++)
        {
            ll u = V[i][j].first,v = V[i][j].second;
            if (u < 0)
                tong[-u] += v * ci[i];
            else
                ci[u] += v * ci[i];
        }
    for (ll i = 1; i <= n; i++)
        if (tong[i])
        {
            sum[1] += tong[i];
            sum[i + 1] -= tong[i];
        }
    for (ll i = 1; i <= n; i++)
        sum[i] += sum[i - 1];
    for (ll i = 1; i <= n; i++)
        printf("%lld\n",sum[i]);
    for (ll i = n + 1; i <= tn; i++)
        puts("0");

    return 0;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

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<(int)(n); i++)

int main() {
    

    
    double r, g;
    cin>>r>>g;
    cout<<2*g-r<<endl;
    
}


Measured memory_bytes: 256
#include <atcoder/scc>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
int m, n, a, b, city[100];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m;
  scc_graph g(n);

  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    g.add_edge(a - 1, b - 1);
    g.add_edge(b - 1, a - 1);
  }

  auto s = g.scc();
  cout << s.size() - 1;

  //  for (auto x : s) {
  //  cout << "\n";
  // for (auto q : x) {
  // cout << q << " ";
  //}
  //}
  return 0;
}


Measured memory_bytes: 11112
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
const int maxn=1e9+1;
int main()
{
	int n,a[100010];
	int ans=maxn;
	int ant=0;
	int ast=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	ans=a[0];
	for(int i=1;i<n;i++)
	{
		if(a[i]<=ans)
		{
			ans=a[i];
			ast++;
		}
		else
		{
			ans=a[i];
//			printf("ast :%d\n",ast);
			ant=max(ant,ast);
			ast=0;
		}
	}
	ant=max(ant,ast);
	printf("%d\n",ant);
	return 0;
}

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


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

//INSERT ABOVE HERE
signed main(){
  Int n,x,d;
  cin>>n>>x>>d;
  vector<Int> m(n);
  vector<vector<Int> > G(n);
  cin>>m[0];
  for(Int i=1;i<n;i++){
    Int p;
    cin>>m[i]>>p;
    G[--p].emplace_back(i);
  }
  
  vector<Int> v(n),w(n);
  function<void(Int)> dfs=[&](Int x){
    v[x]=1;w[x]=m[x];
    for(Int y:G[x]){
      dfs(y);
      v[x]+=v[y];
      w[x]+=w[y];
    }
  };
  dfs(0);

  const Int INF = x+1;
  vector<Int> dp(n*n*n+1,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++){
    Int c=min(n,d);
    for(Int k=1;c;k<<=1){
      chmin(k,c);
      c-=k;
      for(Int j=n*n*n;j>=0;j--)
	if(j+k*v[i]<=n*n*n)
	  chmin(dp[j+k*v[i]],dp[j]+k*w[i]);
    }
  }
  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),
       [&](Int a,Int b){return v[a]*w[b]>v[b]*w[a];});

  Int ans=0;
  for(Int i=0;i<=n*n*n;i++){
    if(dp[i]>x) continue;
    Int res=i,val=x-dp[i];
    Int c=d-min(n,d);
    for(Int j=0;j<n;j++){
      Int x=min(ord[j]?c:val,val/w[ord[j]]);
      res+=x*v[ord[j]];
      val-=x*w[ord[j]];
    }
    //cout<<i<<":"<<dp[i]<<" "<<res<<endl;
    chmax(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1280
#define George_Plover
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 111
#define LL long long
#define INF (-1)
using namespace std;
int n;
struct POINT{
    int x,y;
    LL h;
}p[MAXN];
bool cmp(POINT x,POINT y)
{
    return x.h>y.h;
}
int dis(POINT x,POINT y)
{
    return abs(x.x-y.x)+abs(x.y-y.y);
}
LL check(POINT & aim)
{
    LL std=p[1].h+dis(aim,p[1]);
    for(int i=2;i<=n;i++)
    {
        
        if(p[i].h+dis(p[i],aim)!=std &&!(p[i].h==0 && p[i].h+dis(p[i],aim)>std))
            return 0;
    }
    return std;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%lld",&p[i].x,&p[i].y,&p[i].h);
    }
    sort(p+1,p+n+1,cmp);
    POINT aim;
    
    for(aim.x=0;aim.x<=100;aim.x++)
        for(aim.y=0;aim.y<=100;aim.y++)
        {
            if(check(aim))
            {
                printf("%d %d %lld\n",aim.x,aim.y,check(aim));
                return 0;
            }
        }
    
    
    return 0;
}


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

int main(void){
    int a,b,k;
    scanf("%d%d",&a,&b);
    if(a==b){
        printf("%d",0);
    }else if((a-b)%2==0){
        printf("%d",abs((a+b)/2));
    }else{
        printf("IMPOSSIBLE");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int a, b;

	std::cin >> a >> b;

	std::cout << a * a - b << std::endl;
	return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(void){
  int i,j,tmp,n,count=0,flag=1,data[N];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&data[i]);

  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(data[j]<data[j-1]){
        tmp=data[j];
        data[j]=data[j-1];
        data[j-1]=tmp;
        count++;
        flag=1;
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d",data[i]);
    if(i!=n-1) printf(" ");
  }

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

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll now = 100;
    ll ans = 0;
    while(now < x) {
        now = (ll)(now * 1.01);
        ans++;
    }
    print(ans);
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;

char change(char s, ll i){
    int a = s -'A';
    if(a+i>25){
        i=a+i-26;
        s = 'A';
        }
    char num = s+i;
    return num;
    }

int main(){
    ll n;
    cin >> n;
    string S;
    cin >> S;
    for(ll i=0; i<S.size(); i++){
        cout << change(S[i], n);
        }

}

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

int main(){
  string S;
  int i;
  bool B = true;
  cin >> S;

  for(i=0;i<3;i++){
    if(S.at(i)==S.at(i+1))
    B = false;
  }
  if(B==false)
  cout << "Bad" << endl;
  else
  cout << "Good" << endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)

ans = [0] * N

index = 0
lcount = 0
rcount = 0
for i in range(N):
    if S[i] == 'R' and S[i + 1] == 'R':
        rcount += 1
    if S[i] == 'L' and S[i - 1] == 'L':
        lcount += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        if lcount != 0:
            ans[index] += lcount // 2 + lcount % 2
            ans[index + 1] += lcount // 2
            lcount = 0
        index = i
        ans[i] = 1
        ans[i + 1] = 1
        if rcount != 0:
            ans[i] += rcount // 2
            ans[i + 1] += rcount // 2 + rcount % 2
            rcount = 0
        i += 1
if lcount != 0:
    ans[index] += lcount // 2 + lcount % 2
    ans[index + 1] += lcount // 2
    lcount = 0

for i in range(N):
    print(ans[i], end=" ")



Measured memory_bytes: 4980
a, b, k = map(int, input().split())
for i in range(k//2):
 if a % 2 == 1:
  a -= 1
 a = a / 2
 b += a
 if b % 2 == 1:
  b -= 1
 b = b/2
 a += b
if k % 2 == 1:
 if a % 2 == 1:
  a -= 1
 a = a / 2
 b += a
print(int(a),int(b))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

long table[3][100000];
std::vector<long> result(3);
long N;
long a[100000],b[100000],c[100000];

long solve(long days, long activity)
{
    if(table[activity][days]<0){
        if(days==0){
            table[0][0]=a[0];
            table[1][0]=b[0];
            table[2][0]=c[0];
        }else{
            if(activity==0){
                table[0][days]=std::max(solve(days-1,1),solve(days-1,2))+a[days];
            }else if(activity==1){
                table[1][days]=std::max(solve(days-1,0),solve(days-1,2))+b[days];
            }else if(activity==2){
                table[2][days]=std::max(solve(days-1,0),solve(days-1,1))+c[days];
            } 
        }
    }
    return table[activity][days];
}

void init()
{
    for(long i=0; i<3; i++){
        for(long j=0; j<100000; j++){
            table[i][j]=-1;
        }
    }
}

int main()
{   
    std::cin >> N;
    for(long i=0; i<N; i++){
        std::cin >> a[i] >> b[i] >> c[i];
    }
    for(long i=0; i<3; i++){
        init();
        result[i]=solve(N-1,i);
    }
    std::sort(result.begin(),result.end());
    std::cout << result[2] << std::endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a = n % 10;
  if(a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
  else if(a == 3) cout << "bon" << endl;
  else cout << "hon" << endl;
}

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

using namespace std;
typedef long long ll;


int main()
{
    int n, m, q_num;
    cin >> n >> m >> q_num;

    vector<vector<int>> cnt(n, vector<int>(n));

    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        for (int j = r; j < n; j++) {
            cnt[l][j]++;
        }
    }

    for (int i = 0; i < q_num; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        int ans = 0;
        for (int j = p; j <= q; j++) {
            ans += cnt[j][q];
        }

        cout << ans << endl;
    }

}  



Measured memory_bytes: 1920
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n, l[100], ans = 0, maxi;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        maxi = max(l[i], l[j]);
        maxi = max(maxi, l[k]);
        if (maxi < l[i] + l[j] + l[k] - maxi && l[i] != l[j] && l[j] != l[k] &&
            l[i] != l[k]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int n, q;
vi par;
vector<char> t;
vi v;
vi cnt;

int lma(int x) {
    if (cnt[x]) return x;
    return par[x] = lma(par[x]);
}

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

    while (cin >> n >> q, n) {
        par.assign(n, -1);
        rep2(i, 1, n) {
            int p;
            cin >> p;
            p--;
            par[i] = p;
        }

        t.clear(); t.resize(n);
        v.clear(); v.resize(n);
        cnt.assign(n, 0);
        cnt[0] = 1;
        rep(i, q) {
            cin >> t[i] >> v[i];
            v[i]--;
            if (t[i] == 'M') {
                cnt[v[i]]++;
            }
        }

        int ans = 0;
        rrep(i, q) {
            if (t[i] == 'M') {
                cnt[v[i]]--;
            }
            else {
                ans += lma(v[i]) + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 5436
#include <stdio.h>
#include <math.h>

int main()
{
  int n,d;
  scanf("%d %d",&n,&d);
  int x[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      scanf("%d",&x[i][j]);
    }
  }
  double s;
  double q;
  int a=0;
  for(int k=0;k<n;k++){
    for(int l=k+1;l<n;l++){
        s=0;
        for(int m=0;m<d;m++){
           s=s+(x[l][m]-x[k][m])*(x[l][m]-x[k][m]);
  }
  q=sqrt(s);
  if(ceil(q)==floor(q)) a=a+1;
}}
printf("%d\n",a);
return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n , k , x ;
    while(cin>>n>>k)
    {
        int mx = 0 , g = 0;
        for(int i = 0; i < n; i++)
        {
            cin>>x;
            g = __gcd(g,x);
            mx = max(mx,x);
        }
        if( k <= mx && k % g == 0 ) 
        {
            cout<<"POSSIBLE"<<endl;
        }
        else
        {
            cout<<"IMPOSSIBLE"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

N, K, C = map(int, input().split())
S = input()

last = deque()
pre = -C - 1
for i, s in enumerate(reversed(S)):
  if i > pre + C and s == 'o':
    last.appendleft(N - 1 - i)
    pre = i
    if len(last) == K:
      break

count = 0
pre = -C - 1
x = last.popleft()
for i, s in enumerate(S):
  if i > pre + C and s == 'o':
    count += 1
    while x < i:
      x = last.popleft()
    if x == i and count + len(last) == K:
      print(i + 1)
    pre = i
    if count == K:
      break

Measured memory_bytes: 11876
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main(){
    ll N,K;
    cin >> N >> K;
    pair<ll , ll> p[N];
    ll a,b,i;
    for(i=0;i<N;i++){
        cin >> a >> b;
        p[i]=make_pair(a,b);
    }
    sort(p,p+N);
    ll t=0;
    for(i=0;i<N;i++){
        t+=p[i].second;
        if(t>=K){
            cout << p[i].first;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
from operator import itemgetter
N,M=map(int,input().split())
islands=[list(map(int,input().split())) for _ in range(M)]
islands.sort(key=itemgetter(1))

i=0
cnt=0
while i<M:
    j=0
    while i+j<M and islands[i+j][0]<islands[i][1]:
        j+=1
    i+=j
    cnt+=1
print(cnt)

Measured memory_bytes: 28584
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main(){
	
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
	
		ll a;
		
		char s[10];
		
		cin >> a >> s;
		
		if(a>=3200){
			cout << s << endl;
		}else{
			cout << "red" << endl;
		} 
	
return 0;
}


Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int n;cin>>n;
	VI a(n);
	rep(i,n){
		cin>>a[i];
	}
	sort(all(a));
	rep(i,n-1){
		if(a[i]==a[i+1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
a_list = list(map(int,input().split()))

processing = True
result = 0
while processing:
    processing = False
    for i in range(0,N):
        if a_list[i] % 2 == 0:
            a_list[i] = a_list[i] // 2
            processing = True
            result += 1

print(result)

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 123;
int a[N];

void solve() {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", a+i);
	printf("%d", *max_element(a, a+n)-*min_element(a, a+n));
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256