akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
 
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; }

const int MAX_E=2000;

const int MAX_V=1000;

struct edge {int from, to; ll cost;};
edge es[MAX_E];
ll d[MAX_V];
int V, E;
const ll INF =1LL << 50;

bool bellmanford(int s)
{
    rep(i, V)
        d[i]=INF;
    
    d[s]=0;
    
    for(int j=0; j<2*V; j++)
    {
        for(int i=0; i<E; i++)
        {
            edge e = es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
                if(j>=V-1 && e.to==V-1) 
                {
                    return true;
                }
            }
        }
    }
    return false;
}

bool findNegativeLoop()
{
    FILL0(d);
    for(int i=0; i<V; i++)//あくまで回数
    {
        for(int j=0; j<E; j++)
        {
            edge e = es[j];
            if(d[e.to] > d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
                if(i==V-1)
                {
                    return true;
                }
            }
        }
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    cin >> V >> E;

    rep(i, E)
    {
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].from--;
        es[i].to--;
        es[i].cost = -1*es[i].cost;
    }

    if(bellmanford(0))
    {
        cout << "inf" << endl;
        return 0;
    }
  

    cout << -1*d[V-1] << endl;

 
    return 0;
}
 

Measured memory_bytes: 384
import sys


class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None

    def preorder(self):
        nodeList = [self.key]
        if self.left:
            nodeList += self.left.preorder()
        if self.right:
            nodeList += self.right.preorder()
        return nodeList

    def inorder(self):
        nodeList = []
        if self.left:
            nodeList += self.left.inorder()
        nodeList += [self.key]
        if self.right:
            nodeList += self.right.inorder()
        return nodeList


class BinaryTree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        z = Node(key)
        y = None
        x = self.root
        while x:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.parent = y

        if y is None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

    def find(self, key):
        x = self.root
        while x is not None and key != x.key:
            if key < x.key:
                x = x.left
            else:
                x = x.right
        return x

    def print(self):
        print(" " + " ".join(map(str, self.root.inorder())))
        print(" " + " ".join(map(str, self.root.preorder())))


if __name__ == "__main__":
    tree = BinaryTree()
    n = int(sys.stdin.readline())
    for inp in sys.stdin.readlines():
        inp = inp.split()
        if inp[0] == "insert":
            tree.insert(int(inp[1]))
        elif inp[0] == "find":
            if tree.find(int(inp[1])) is None:
                print("no")
            else:
                print("yes")
        else:
            tree.print()

Measured memory_bytes: 194356
n=int(input())
s=input()

#r=s.count('R')
#g=s.count('G')
#b=s.count('B')

r,g,b=0,0,0

for i in range(0,n):
  if s[i]=='R':
    r+=1
  elif s[i]=='G':
    g+=1
  else:
    b+=1

ng=0

all=r*g*b

#NGパターン数の洗い出し
for i in range(0,n-2):
  for j in range(i,n-1):
    if s[i]==s[j]:
      continue
    else:
      if j*2-i<=n-1:
#        print(i,j,j*2-i)
        if s[j]!=s[j*2-i] and s[j*2-i]!=s[i]:
          ng+=1
print(all-ng)

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


class Prime(object):
    '''Represents a snippet for prime numbers.
    '''

    def __init__(self, number):
        self.number = number
        self._values = []

    def is_included(self) -> bool:
        '''Determine whether it is a prime number.
        Args:
            number: Int of number (greater than 0).
        Returns:
            True if the input number was prime.
            False if the input number was not prime.
        See:
            https://qiita.com/srtk86/items/874639e361917e5016d4
            https://docs.python.org/ja/3/library/2to3.html?highlight=isinstance#2to3fixer-isinstance
        '''

        from math import sqrt

        if (self.number <= 1) or (isinstance(self.number, float)):
            return False

        for i in range(2, int(sqrt(self.number)) + 1):
            if self.number % i == 0:
                return False

        return True

    def generate(self) -> list:
        '''Generate a list of prime numbers using sieve of Eratosthenes.
        Returns:
            A list of prime numbers that is eqaul to or less than the input
            number.
        Landau notation: O(n log log n)
        See:
            https://beta.atcoder.jp/contests/abc110/submissions/3254947
        '''

        if self._values:
            return self._values

        is_met = [True for _ in range(self.number + 1)]
        is_met[0] = False
        is_met[1] = False

        for i in range(2, self.number + 1):
            if is_met[i]:
                self._values.append(i)

                for j in range(2 * i, self.number + 1, i):
                    is_met[j] = False
        return self._values


def main():
    a, b = map(int, input().split())
    set_a = set()
    set_b = set()

    # a, bの約数を計算
    for i in range(1, int(a ** 0.5) + 1):
        if a % i == 0:
            set_a.add(i)
            set_a.add(a // i)

    for i in range(1, int(b ** 0.5) + 1):
        if b % i == 0:
            set_b.add(i)
            set_b.add(b // i)

    # aとbの公約数を求める
    set_ab = set_a & set_b
    count = 1

    # 素数を計算
    for s in set_ab:
        p = Prime(s)

        if p.is_included():
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5116
#include<stdio.h>

main(){
  int a, b, c, d, n, sum, count;

  while(scanf("%d", &n) != EOF){
    count = 0;
    for(a=0; a<10; a++){
      for(b=0; b<10; b++){
	for(c=0; c<10; c++){
	  for(d=0; d<10; d++){
	    sum = a + b + c + d;
	    if(n == sum)
	      count++;
	  }
	}
      }
    }
  printf("%d\n", count);
  }
  return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= b; i++) {
    if (i < a + k || i >= b - k + 1) {
      cout << i << endl;
    }
  }
  return 0;
}

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


int main() {
  int N, num, min;
  cin >> N;
  vector <int> A(N);
  num = 0, min = 100000000000;
  
  for (int i=0; i<N; i++) {
    cin >> A[i];
    
    while (A[i]%2==0){
      A[i] /=2;
      num ++;
    }
    if (num < min){
      min = num;
    }
    num = 0;
  }

      cout << min << endl;

  
  
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(n, vi(n));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        d[a][b] = d[b][a] = 1;
    }
    vector<int> id(n);
    rep(i, n) id[i] = i;

    int ans = 0;
    do {
        bool f = id[0] == 0;
        rep(i, n-1) f &= d[id[i]][id[i+1]];
        if(f) ++ans;
    }while(next_permutation(all(id)));

    cout << ans << endl;

    return 0;
}

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

int main()
{ 
  int n, ans = 0;
  vector<vector<int>> abc(3, vector<int>(20));

  cin >> n;
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (i != 2 || j != n - 1)
        cin >> abc[i][j];
    }
  }
  for (int i = 0; i < n; i++)
  {
    ans += abc[1][abc[0][i] - 1];
    if (i != n - 1)
    {
      if (abc[0][i + 1] == abc[0][i] + 1)
        ans += abc[2][abc[0][i] - 1];
    }
  }
  cout << ans << endl;
}

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

int main(){
    int a,b,c;
    scanf("%d%d%d", &a, &b, &c);
    if(a+b==c || a+c==b || b+c==a)
        printf("Yes");
    else
        printf("No");
return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y, h;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++)
		sum *= (x--);
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, a, b, c = 0, d = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a > c) {
			c = a, d = a + b;
		}
	}
	cout << d << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]

count = 0
for i in range(N):
    tmp = (L[N-i-1][0] + count) // L[N-i-1][1]
    if (L[N-i-1][0] + count)%L[N-i-1][1] != 0:
        count +=  ((tmp + 1) * L[N-i-1][1]) - (L[N-i-1][0] + count)
    else:
        count += (tmp * L[N-i-1][1]) - (L[N-i-1][0] + count)

print(count)

Measured memory_bytes: 27380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  int X;
  cin >> X;

  int ans[100001]; // store 1 or 0;

  // store initial conditions
  for(int i=0; i<=99; i++)
    ans[i] = 0;
  for(int i=100; i<=105; i++)
    ans[i] = 1;

  for(int i=106; i<=X; i++) {
    if ( (ans[i-100] == 1) ||
         (ans[i-101] == 1) ||
         (ans[i-102] == 1) ||
         (ans[i-103] == 1) ||
         (ans[i-104] == 1) ||
         (ans[i-105] == 1) ) {
      ans[i] = 1;
    }
    else {
      ans[i] = 0;
    }
  }

  cout << ans[X] << endl;

  return 0;
}



Measured memory_bytes: 640
//***___*********___*****___****___***___*********//
/*  |   \  |   | |   |   |   \  |     |     |   |  **
/*  |   |  |   | |___|   |   _  |__   |___  |___|  **
/*  |   |  |   | |   \   |  | | |         | |   |  **
/*  |___/  |___| |    \  |__| | |___  ____| |   |  **
//*************************************************/
#include <iostream>
#include <bits/stdc++.h>
#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 <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ff double
#define endl "\n"
#define M 1000000007
#define forever while(1)
#define ll long long
#define pb push_back
#define vi vector<long long>
#define mii map<int,int>
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');
using namespace std;
void fastscan(int &x)
{
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
}
int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    REP(i,n)
    cin>>arr[i];
    ll ans=0;
    sort(arr+0,arr+n);
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((arr[k]<arr[j]+arr[i]))
                    ans++;
                    else
                        break;
            }
        }
    }
    cout<<ans<<endl;

     return 0;


}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a = int(input())
b = input()

s = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

out = ""

for i in range(len(b)):
    index = s.index(b[i])
    out += s[(index+a) % 26]

print(out)

Measured memory_bytes: 3064
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

struct LzyST {
  ll n;
  vll dat, laz;
  LzyST() {}
  LzyST(ll n_) { init(n_); }
  void init(ll n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.clear();
    dat.resize(2 * n - 1, 0);
    laz.clear();
    laz.resize(2 * n - 1, 0);
  }

  inline void eval(ll k) {
    if (laz[k] == 0) return;
    if (k * 2 + 1 < n * 2 - 1) {
      laz[k * 2 + 1] += laz[k];
      laz[k * 2 + 2] += laz[k];
    }
    dat[k] += laz[k];
    laz[k] = 0;
  }
  void add(ll a, ll b, ll x, ll k, ll l, ll r) {
    eval(k);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      laz[k] = x;
      eval(k);
      return;
    }
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    dat[k] = min(dat[2*k+1], dat[2*k+2]);
    return;
  }
  ll find(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a || b <= l) return INF;
    eval(k);    
    if (a <= l && r <= b) return dat[k];
    ll vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
  void add(ll a, ll b, ll x) { add(a, b + 1, x, 0, 0, n); }
  ll find(ll a, ll b) { return find(a, b + 1, 0, 0, n); }
};

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, q;
  cin >> n >> q;
  LzyST lst(n);
  for (ll i = 0; i < q; i++) {
    ll c;
    cin >> c;
    if (c == 0) {
      ll s, t, x;
      cin >> s >> t >> x;
      lst.add(s, t, x);
    } else {
      ll s, t;
      cin >> s >> t;
      cout << lst.find(s, t) << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 7016
S_= list(input())
T = list(input())
n,m = len(S_),len(T)

#S_をｍ文字ずつ切ってTに一致させられるものがあるかを確認
#なるべく後ろの?でTに一致させたい ->　反転させたものを使う,前の?にaを入れる方が辞書的に早いので
#(ex)
#?tc???? -> ????ct?
#coder -> redoc
#にして,前から調べて一致させることができたら,残りの?をaにしてreverse(元に戻す）
S_.reverse(),T.reverse()
key_index = -1 #-1:なし,x:一致させることができた場合の最初のindex
judge = 0 #0:なし,1:あり
for i in range(n):
  if((S_[i] == '?')or(S_[i] == T[0])):
    if(i+m-1 <= n-1): 
     tmp = S_[i:i+m]
     judge = 1
     for j in range(m):
        if((tmp[j] == T[j])or(tmp[j] == '?')):
          continue
        else:
          judge = 0
          break
  if(judge == 1):
    key_index = i
    break
 
if(judge == 0):
  print('UNRESTORABLE')
else:
  j = 0
  for i in range(n):
    if(key_index <= i <= key_index+m-1):
      S_[i] = T[j]
      j += 1
    elif(S_[i] == '?'):
      S_[i] = 'a'
  S_.reverse()
  ans = ''.join(S_)
  print(ans)

Measured memory_bytes: 3064
n = int(input())
ca, cb = 0, 0
for i in range(n):
    a, b = map(int,input().split())
    x, y = 1, 1
    if ca > a:
        x = ca // a
        if ca % a:
            x += 1
    if cb > b:
        y = cb // b
        if cb % b:
            y += 1
    x = max(x, y)
    ca = a * x
    cb = b * x
print(ca + cb)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;


signed main(){
	//cout << fixed << setprecision(10);
	ll n; cin >> n;
	ll sum_gcd;
	ll m = 0;
	map<ll,ll> mp;
	bool ans = 1;
	vector<bool> vec(1001000,false);
	rep(i,0,n){
		ll a; cin >> a;
		if(mp[a] > 0 && a != 1){
			ans = 0;
		}
		mp[a]++;
		vec[a] = 1;
		if(i == 0)sum_gcd = a;
		else sum_gcd = __gcd(a,sum_gcd);
		chmax(m,a);
	}
	for(ll i = 2;i <= m;i++){
		ll cnt = 0;
		ll j = i;
		bool ok = true;
		while(j <= m){
			if(vec[j])cnt++;
			if(cnt > 1){
				ok = 0;
				break;
			}
			j += i;
		}
		if(!ok){
			ans = 0;
			break;
		}
	}
//	cout << sum_gcd << endl;
	if(ans)cout << "pairwise coprime" << endl;
	else if(sum_gcd == 1)cout << "setwise coprime" << endl;
	else cout << "not coprime" <<endl;


	return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    string s,t;
    cin>>s>>t;
    int slen=s.size(),tlen=t.size();
    vector<vector<int>> dp(slen+1,vector<int>(tlen+1));
    rep(i,0,slen){
        rep(j,0,tlen){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    /*
    rep(i,0,slen+1){
        rep(j,0,tlen+1)cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    */
    string ans="";
    int i=s.size(),j=t.size();
    while(i>0&&j>0){
        if(dp[i][j]==dp[i-1][j])i--;
        else if(dp[i][j]==dp[i][j-1])j--;
        else{
            ans=s[i-1]+ans;
            i--;j--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    string S,T;
    cin>>S;
    cin>>T;
    ll ans=0;
    rep(0,i,3)if(S.substr(i,1)==T.substr(i,1))++ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const long long INF = LLONG_MAX / 4;

void shortestPath(vector<vector<long long> >& dist)
{
    int n = dist.size();
    for(int k=0; k<n; ++k){
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

class Data
{
public:
    int l, r, index;
    bool operator<(const Data& d) const{
        return r < d.r;
    }
};

int main()
{
    int n, start;
    cin >> n >> start;

    ++ n;
    vector<Data> d(n);
    d[0].l = d[0].r = d[0].index = 0;
    for(int i=1; i<n; ++i){
        cin >> d[i].l >> d[i].r;
        d[i].index = i;
    }
    sort(d.begin(), d.end());

    vector<vector<long long> > dist(n, vector<long long>(n, INF));
    dist[0][start] = 0;
    for(int i=1; i<n; ++i){
        for(int j=1; j<n; ++j){
            cin >> dist[i][j];
        }
    }
    shortestPath(dist);

    vector<long long> t(n, -1);
    t[0] = 0;
    for(int i=0; i<n; ++i){
        int y = d[i].index;
        for(int j=0; j<i; ++j){
            int x = d[j].index;
            if(t[x] == -1)
                continue;

            if(d[j].r + dist[x][y] < d[i].r){
                t[y] = max(t[y], t[x] + d[i].r - max((long long)d[i].l, d[j].r + dist[x][y]));
            }
        }
    }

    long long ret = *max_element(t.begin(), t.end());
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;

class Dice1{
	private int[] number = new int[6]; //Diceの方向には何の数字かを示す
										//初期値の順番と一緒：上面①、その下②、その右③、その左④、その上⑤、その反面⑥（Indexと一個違い）

	//コンストラクタ
	public Dice1(int[] n) {
		for (int i=0; i< 6; i++)number[i] = n[i];
	}

	public int getDice(int no) {
		return number[no];
	}

	public void roll(String target) {
		int [] w = new int[6];  //仮のway
		int a = target.length();
		for (int i=0; i<a; i++) {
			for (int j=0; j< 6; j++) w[j] = number[j];  //コピーする
			String t = target.substring(i, i+1);
			switch(t) {
			case "N":
				number[4] = w[0];
				number[0] = w[1];
				number[1] = w[5];
				number[5] = w[4];
				break;
			case "E":
				number[2] = w[0];
				number[0] = w[3];
				number[3] = w[5];
				number[5] = w[2];
				break;
			case "S":
				number[4] = w[5];
				number[0] = w[4];
				number[1] = w[0];
				number[5] = w[1];
				break;
			case "W":
				number[2] = w[5];
				number[0] = w[2];
				number[3] = w[0];
				number[5] = w[3];
				break;
			}
		}
	}
}

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int [] n = new int[6];
			for (int i=0; i<6; i++) n[i] = sc.nextInt(); //diceの数字を取得
			Dice1 dice1 = new Dice1(n);
			String target = sc.next();
			dice1.roll(target);
			System.out.println(dice1.getDice(0));  //上面を出力
		}
	}
}



Measured memory_bytes: 26364
num = int(input())
kabu = [int(x) for x in input().split()]
kabu.append(-1)
mkabu = 0
max = 0
money = 1000
MAX = 0

for i in range(num):
    if MAX < kabu[i]:
        MAX = kabu[i]


for i in range(num):
    if kabu[i] == -1:
        bleak
    if 0 < mkabu: #売る
        money = money + kabu[i] * mkabu
        mkabu = 0
#        print("売る", money)
#    print("MAX", max)
    if kabu[i] < kabu[i+1]: #買う
        mkabu = money // kabu[i]
        money = money % kabu[i]
#        print("買う", money)
if 0 < mkabu:
    money = money + kabu[-1] * mkabu

print(money)


Measured memory_bytes: 9208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int start = sc.nextInt();
        int end = sc.nextInt();
        int[] startCosts = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            if (i == start) {
                continue;
            }
            startCosts[i] = getValue(start, i, sc);
        }
        int[] endCosts = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            if (i == end) {
                continue;
            }
            endCosts[i] = getValue(end, i, sc);
        }
        ArrayList<Path> org = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if (startCosts[i] + endCosts[i] == startCosts[end]) {
                org.add(new Path(i, startCosts[i]));
            }
        }
        Collections.sort(org);
        Path prev = org.get(0);
        ArrayList<Integer> list = new ArrayList<>();
        list.add(start);
        for (int i = 1; i < org.size(); i++) {
            Path next = org.get(i);
            int value = getValue(prev.idx, next.idx, sc);
            if (value == startCosts[next.idx] - startCosts[prev.idx]) {
                list.add(next.idx);
                prev = next;
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append("!");
        for (int x : list) {
            sb.append(" ").append(x);
        }
        System.out.println(sb);
        System.out.flush();
    }
    
    static int getValue(int from, int to, Scanner sc) {
        StringBuilder sb = new StringBuilder();
        sb.append("? ").append(from).append(" ").append(to);
        System.out.println(sb);
        System.out.flush();
        int x = sc.nextInt();
        if (x == -1) {
            System.exit(0);
        }
        return x;
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        
        public Path(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}



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

int	main()
{
  int		n, t, a, h, i, index = 1;
  double	diff;
  
  cin >> n >> t >> a;
  cin >> h;
  diff = abs((t - h * 0.006) - a);
  for (i = 1; i < n; i++)
  {
    cin >> h;
    if (abs((t - h * 0.006) - a) < diff)
    {
      diff = abs((t - h * 0.006) - a);
      index = i + 1;
    }
  }
  cout << index << endl;
  return (0);
}

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

int main() {
    
	int x,ans(0);
  	cin >>x;
  	for(int i = 1;i <= 360;i++){
      ans++;
      if((i*x) % 360 == 0){
        cout << ans;
        return 0;
      }
    }
    
}


Measured memory_bytes: 3624
//This sourcecode is under GPLv3
//yeguanghao
#include <bits/stdc++.h>
#define rep(name,start,end,step) for(int name=start;name<=end;name+=step)
using namespace std;
#define Pn(x) printf("%d\n",x)
#define Ps(x) printf("%d ",x)
#ifdef _WIN32
#define Pln(x) printf("%I64d\n",x)
#define Pls(x) printf("%I6d ",x)
#else
#define Pln(x) printf("%lld\n",x)
#define Pls(x) printf("%lld ",x)
#endif
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PROB
inline void R(int &x) {
	x=0; int f=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
 
void Redirect() {
#ifndef DEBUG
	freopen(PROB".in","r",stdin);
	freopen(PROB".out","w",stdout);
#endif
}
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
int main() {
	ull x,y;
	cin>>x>>y;
	int ans=1;
	for(int i=1;x+x<=y;++i) {
		x<<=1;
		ans++;
	}
	Pn(ans);
}
 


Measured memory_bytes: 256
/*
 * AIZU ALDS1_1_B - Greatest Common Divisor
 *
 * Time:
 * Memory:
 *
 * Author: DragonLee
 */

#include <cstdio>
using namespace std;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", gcd(a, b));
    return 0;
}


Measured memory_bytes: 2692
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string S;
    cin >> S;
    S[1] = S[1] ^ 'R' ^ 'B';
    puts(S.c_str());
    return 0;
}

Measured memory_bytes: 3556
<?php

fscanf(STDIN, '%d', $N);
fscanf(STDIN, '%s', $S);
fscanf(STDIN, '%s', $T);
$result = 2 * $N;
for ($i = 0; $i < $N; $i++) {
	$str = substr($S, $i);
	$str2 = substr($T, 0, $N - $i);
	if ($str === $str2) {
		$result = (2 * $N) - ($N - $i);
		break;
	}
}
echo $result . PHP_EOL;


Measured memory_bytes: 3832
function main(input) {
  input = input.trim().split("\n");
  const [n, m] = input[0].split(" ").map(a => Number(a));
  const pys = input.slice(1).map(a => a.split(" ").map(b => Number(b)));
  const originalPys = pys.slice();
  pys.sort((a, b) => {
    const [ap, ay] = a;
    const [bp, by] = b;
    if (ap === bp) return ay-by;
    return ap-bp;
  });
  const map = {};
  let prevNo;
  for(let i = 0; i < m; i++) {
    const [p, y] = pys[i];
    const pDigit = ("" + p).length;
    const pStr = Array(6-pDigit).fill(0).join("") + p;
    const no = (() => {
      if (i === 0) return 1;
      if (pys[i-1][0] === p) return prevNo + 1;
      return 1;
    })();
    const noDigit = ("" + no).length;
    const noStr = Array(6-noDigit).fill(0).join("") + no;
    map[p + "-" + y] = pStr + noStr;
    prevNo = no;
  }
  for(const py of originalPys) {
    const [p, y] = py;
    console.log(map[p + "-" + y]);
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 89064
while True:
    s = input().split()
    H = int(s[0])
    W = int(s[1])
    if H==0 and W==0:
        break
    
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#",sep="",end="")
            else:
                print(".",sep="",end="")
        print()
    print()
            



Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    char a;
    cin>>a;
    if ('a' <= a && a <= 'z'){
        cout << "a" << endl;
    }else{
        cout << "A" << endl;
    }
}

Measured memory_bytes: 3548
//プライオリティーキュー
#include "bits/stdc++.h"
#include <queue>
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける


ll n;

//2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort2(vi &a,vi &b,ll flag){
  if (a.size()>0){
    vector<pair<ll, ll>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second=b[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second;
    }
  }
  return;
}




int main()
{
  //ll ans=0;

  ll t;
  cin>>t;
  vi ans(t);
  for(ll tt=0;tt<t;tt++){
    

    priority_queue<
      ll,                // 要素の型はint
      vector<ll>,   // 内部コンテナはstd::vector (デフォルトのまま)
      greater<ll>   // 昇順 (デフォルトはstd::less<T>)
    > que;

    priority_queue<
      ll,                // 要素の型はint
      vector<ll>,   // 内部コンテナはstd::vector (デフォルトのまま)
      greater<ll>   // 昇順 (デフォルトはstd::less<T>)
    > que2;




  cin >> n;
  vi K(n),L(n),R(n);
  ll lnum=0;
  ll rnum=0;
  vi lp,rp;
  vi lk,rk;
  REP(i,n){
    cin>>K[i]>>L[i]>>R[i];
    if (L[i]<R[i]){
      rnum++;
      ll tmp=(R[i]-L[i])*1000000001LL;
      rp.push_back(R[i]+tmp);
      rk.push_back(K[i]);
    }else{
      lnum++;
      ll tmp=(L[i]-R[i])*1000000001LL;
      lp.push_back(L[i]+tmp);
      lk.push_back(K[i]);
    }
  }

  ll phnum=0;
  if (lnum!=0)
    mysort2(lk,lp,0);

  for(ll i=0;i<lnum;i++){
    if (phnum<lk[i]){
      ans[tt]+=lp[i]%1000000001LL;
      que.push(lp[i]/1000000001LL);
      phnum++;
    }else{
      ll tmp=lp[i]/1000000001LL;
      if (que.top()<tmp){
        ans[tt]-=que.top();
        ans[tt]+=lp[i]%1000000001LL;
        que.pop();
        que.push(tmp);
      }else{
        ans[tt]+=(lp[i]%1000000001LL)-lp[i]/1000000001LL;
      }
    }
  }

  
  //que.clear();
  if (rnum!=0)
    mysort2(rk,rp,1);
  phnum=0;
  for(ll i=0;i<rnum;i++){
    if (phnum<n-rk[i]){
      ans[tt]+=rp[i]%1000000001LL;
      que2.push(rp[i]/1000000001LL);
      phnum++;
    }else{
      ll tmp=rp[i]/1000000001LL;
      if (que2.empty()){
        ans[tt]+=(rp[i]%1000000001LL)-rp[i]/1000000001LL;
      }else{
        if (que2.top()<tmp){
          ans[tt]-=que2.top();
          ans[tt]+=rp[i]%1000000001LL;
          que2.pop();
          que2.push(tmp);
        }else{
          ans[tt]+=(rp[i]%1000000001LL)-rp[i]/1000000001LL;
        }
      }
    }
  }




  
  
  }



  for(ll i=0;i<t;i++){
    cout<<ans[i]<<endl;
  }

}

/*
1
4
1 4 10
2 4 10
3 4 10
4 5 10
*/

Measured memory_bytes: 14392
#include <stdio.h>

int main(void){
	int A,B;
	scanf("%d",&A);
	scanf("%d",&B);
	int wa,sa,kake;
	wa = A+B;
	sa = A-B;
	kake = A*B;
	if(wa >=sa && wa >= kake){
		printf("%d",wa);
	}else if(sa >=wa && sa >= kake){
		printf("%d",sa);
	}else if(kake >=sa && kake >= wa){
		printf("%d",kake);
	}
	
	return 0;}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define mod 1000000007
using ll = long long;
using namespace std;
int check(int n){
  while(n >= 10){
    n /= 10;
  }
  return n;
}
int main(){
  int n;
  cin >> n;
  vvi cnt(9, vi(9, 0));
  for(int i = 1; i <= n; i++){
    if(i % 10 == 0) continue;
    int first = i % 10;
    int last = check(i);
    cnt[first - 1][last - 1]++;
  }
  int ans = 0;
  rep(i, 9){
    rep(j, 9){
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <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 <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#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";}}

#define EPS 1e-8
#define EQ(a, b) (abs((a)-(b)) < EPS)

inline int signum(double x) { return (abs(x) < EPS) ? 0 : (x > 0) ? 1 : -1; }

typedef complex<double> P;

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    int sign = signum(cross(b, c));
    if (sign != 0) return sign;
    if (signum(dot(b, c)) == -1) return 2;
    if (abs(b) < abs(c)) return -2;
    return 0;
}

double dis_p_li(P a, P b, P c) {
    b -= a;
    c -= a;
    return abs(cross(b, c)) / abs(b);
}

double dis_p_li_ss(P a, P b, P c) {
    P x1 = b - a;
    P y1 = c - a;
    P x2 = a - b;
    P y2 = c - b;
    if (signum(dot(x1, y1)) < 0) return abs(y1);
    if (signum(dot(x2, y2)) < 0) return abs(y2);
    return dis_p_li(a, b, c);
}

bool is_intersected_li_ss(P a1, P a2, P b1, P b2) {
    return (ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0) &&
           (ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0);
}

double dis_li_s_li_s(P a1, P a2, P b1, P b2) {
    if (is_intersected_li_ss(a1, a2, b1, b2)) return 0.0;
    return min({
                       dis_p_li_ss(a1, a2, b1),
                       dis_p_li_ss(a1, a2, b2),
                       dis_p_li_ss(b1, b2, a1),
                       dis_p_li_ss(b1, b2, a2)
               });
}

int main() {

    int Q;
    cin >> Q;

    while (Q--) {

        vector<P> p(4);
        for (int i = 0; i < 4; i++) {
            double x, y;
            cin >> x >> y;
            p[i] = P(x, y);
        }
        double ans = dis_li_s_li_s(p[0], p[1], p[2], p[3]);
        cout << fixed << setprecision(10) << ans << endl;
    }

}














































Measured memory_bytes: 3344
N, Q = map(int, input().split())
s = input()
t = []
d = []
for i in range(Q):
    j, k = input().split()
    t.append(j)
    d.append(k)
l = 0
r = N - 1
for i in range(Q):
    if d[-i-1] == 'L':
        if s[l] == t[-i-1]:
            l += 1
        if r < N - 1 and s[r + 1] == t[-i-1]:
            r += 1
    if d[-i-1] == 'R':
        if s[r] == t[-i-1]:
            r -= 1
        if l > 0 and s[l - 1] == t[-i-1]:
            l -= 1
    if l > r:
        break
print(max(0, r - l + 1))

Measured memory_bytes: 6680
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  // 入力
  int a, p;
  cin >> a >> p;
  
  // 出力
  int ans = (3 * a + p) / 2;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
title:

url:

intとdoubleのキャストに要注意
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int water[2], sugar[2];
    int can_dis, can_in;
    rep(i, 2)
    {
        cin >> water[i];
    }
    rep(i, 2)
    {
        cin >> sugar[i];
    }
    cin >> can_dis >> can_in;

    vector<int> ans(2, 0);
    for (int i = 0; i * water[0] * 100 <= can_in; i++)
    {
        for (int j = 0; i * water[0] * 100 + j * water[1] * 100 <= can_in; j++)
        {
            int max_sugar = min(can_in - (i * water[0] * 100 + j * water[1] * 100), (i * water[0] + j * water[1]) * can_dis);
            for (int k = 0; k * sugar[0] <= max_sugar; k++)
            {
                for (int l = 0; k * sugar[0] + l * sugar[1] <= max_sugar; l++)
                {
                    int tmp_all = i * water[0] * 100 + j * water[1] * 100 + k * sugar[0] + l * sugar[1];
                    int tmp_sugar = k * sugar[0] + l * sugar[1];
                    if (tmp_all * ans[1] <= tmp_sugar * ans[0])
                    {
                        ans[0] = (int)tmp_all;
                        ans[1] = (int)tmp_sugar;
                    }
                }
            }
        }
    }
    cout << ans[0] << " " << ans[1] << endl;
}

Measured memory_bytes: 256
class Price:
    ALL_DIGITS = set(list(map(str, range(10))))

    def __init__(self, required_price, disabled_digits):
        self.required_price = '0' + str(required_price)
        self.disabled_digits = set(disabled_digits)
        self.available_digits = sorted(
            list(self.ALL_DIGITS - self.disabled_digits))
        self.payed_price = required_price

    def get_greater_digit(self, digit):
        candidates = [d for d in self.available_digits if d >= digit]
        if len(candidates) == 0:
            raise ValueError
        return min(candidates)

    def get_lower_digit(self, digit):
        candidates = [d for d in self.available_digits if d <= digit]
        if len(candidates) == 0:
            raise ValueError
        return max(candidates)

    def _from_right(self):
        reversed_price = list(reversed(self.required_price))
        length = len(reversed_price)
        for i in range(length - 1):
            r = reversed_price[i]
            if r not in self.available_digits:
                try:
                    reversed_price[i] = self.get_greater_digit(r)
                except ValueError:
                    reversed_price[i] = min(self.available_digits)
                    r_next = reversed_price[i + 1]
                    reversed_price[i + 1] = chr(ord(r_next) + 1)

        r = reversed_price[-1]
        if r not in self.available_digits and r != '0':
            reversed_price[-1] = self.get_greater_digit(r)

        self.payed_price = ''.join(reversed(reversed_price))

    def _from_left(self):
        carry = False
        i = 0
        pay = list(self.payed_price)
        while i < len(pay):
            if carry:
                pay[i] = min(self.available_digits)
            else:
                carry = pay[i] > self.required_price[i]
            i += 1
        self.payed_price = ''.join(pay)

    def calculate(self):
        self._from_right()
        self._from_left()

    def get_payed_price(self):
        return int(self.payed_price)


def check(price, disabled_digits):
    p = Price(required_price=price, disabled_digits=disabled_digits)
    p.calculate()
    return p.get_payed_price()


def main():
    price, k = input().split()
    disabled_digits = input().split()
    print(check(price, disabled_digits))


if __name__ == '__main__':
    main()


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

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


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

int cnt;

void insertionSort(int A[], int n, int g) {
  for(int i = g; i <= n-1; ++i) {
    int v = A[i];
    int j = i - g;
    while(j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  cnt = 0;
  //int g[] = {797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1};
  int g[] = {531441, 177147, 59049, 19683, 6561, 2187, 729, 243, 81, 27, 9, 3, 1};
  int M = sizeof(g)/sizeof(int);
  vector<int> G;
  for(int i = M-1; i >= 0; --i) G.push_back(g[i]);
  int m = 0;
  while(m < M && G[m] <= n) ++m;
  G.resize(m);
  reverse(G.begin(), G.end());


  printf("%d\n", m);
  for(int i = 0; i < m; ++i) {
    if(i) printf(" ");
    printf("%d", G[i]);
  }
  printf("\n");

  for(int i = 0; i <= m-1; ++i) {
    insertionSort(A, n, G[i]);
  }
  printf("%d\n", cnt);
  for(int i = 0; i < n; ++i) {
    printf("%d\n", A[i]);
  }
}

int n;
int A[1000000];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) cin >> A[i];
  shellSort(A, n);
  return 0;
}

Measured memory_bytes: 5156
#include<stdio.h>

long long int absll(long long int a, long long int b){
  if(a>b)
    return a-b;
  else
    return b-a;
}

int main(){
  int i,j,k;
  long long int x,y,z,K;
  scanf("%lld %lld %lld %lld",&x,&y,&z,&K);
  
  if(absll(x,y) > 10e+18){
    puts("Unfair");
    return 0;
  }
  
  if((K%2) == 1){
    printf("%lld\n",y-x);
  }
  else
    printf("%lld\n",x-y);
  return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<stack>
#include<string>
#include<typeinfo>
using namespace std;
int main(void){
    string num;
    int a,b;
    stack<int> st;
    while(cin >> num){
        if(num=="+"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a+b);
        }else if(num=="-"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(b-a);
        }else if(num=="*"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a*b);
        }else{
            st.push(stoi(num));
        }
    }
    cout << st.top() << endl;
    return 0;
}


Measured memory_bytes: 3180