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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  int A, B, K;
  cin >> A >> B;
    K = A+B;
  
  if(K%2==0) {
    cout << K/2 << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
    


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		IrohaGrid iroha = new IrohaGrid();
		iroha.run();
	}
}

class IrohaGrid {
	
	int H;
	int W;
	int A;
	int B;
	
	IrohaGrid() {
		//MARK Input
		Scanner cin = new Scanner(System.in);
		this.H = cin.nextInt();
		this.W = cin.nextInt();
		this.A = cin.nextInt();
		this.B = cin.nextInt();
	}
	
	void run() {
		long mod = (long) Math.pow(10, 9) + 7;
		FermatCombination com = new FermatCombination(H + W, mod);
		
		long ans = 0;
		long n, k = 0; //nCk
		for (int i = B; i < W; i++) { // B <= i <= W -1;
			
			n = H - A - 1 + i;
			k = i;
			long tmp1 = com.combine(n, k);
			
			n = A - 1 + W - i - 1;
			k = A - 1;
			long tmp2 = com.combine(n, k);
			
			ans += tmp1 * tmp2;
			ans %= mod;
		}
		System.out.println(ans);
	}
	
	class FermatCombination {
		
		long[] factrial;
		long[] inverse;
		long MOD;
		
		FermatCombination(long size, long mod) {
			
			this.factrial = new long[(int) size + 1];
			this.inverse = new long[(int) size + 1];
			this.MOD = mod;
			
			this.factrial[0] = 1;
			this.inverse[0] = 1;
			
			for (int i = 1; i <= size; i++) {
				factrial[i] = factrial[i - 1] * i % MOD;
				inverse[i] = pow(factrial[i], (int) MOD - 2) % MOD; //フェルマーの小定理
			}
		}
		
		long combine(long n, long k) {
			return factrial[(int) n] * inverse[(int) k] % MOD * inverse[(int)n - (int)k] % MOD;
		}
		
		long pow(long x, int n) {
			long ans = 1;
			while (n > 0) {
				if ((n & 1) == 1) {
					ans = ans * x % MOD;
				}
				x = x * x % MOD;
				n >>= 1;
			}
			return ans;
		}
	}
	
}


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

int N, M;
vector<string> elms;
string text;
vector<vector<int>> cors;
bool memo[5010][1<<12];

bool dfs(int si, int s, int l){
    if(s == (1<<N)-1) return true;
    if(memo[si][s]) return false;
    
    for(int i=0; i<N; i++) if((s>>i&1) == 0){
        if(binary_search(cors[i].begin(), cors[i].end(), si))
            if(dfs(si+(int)elms[i].size(), s|(1<<i), l+(int)elms[i].size()))
                return true;
    }
    memo[si][s] = true;
    return false;
}

void solve(){
    cors.clear(); cors.resize(N);
    memset(memo, 0, sizeof(memo));
    for(int i=0; i<N; i++){
        string elm = elms[i];
        for(int j=0; j<text.size(); j++){
            if(text.substr(j, elm.size()) == elm)
                cors[i].push_back(j);
        }
    }
    int ans = 0;
    for(int i=0; i<text.size(); i++){
        ans += dfs(i, 0, 0);
    }
    cout << ans << endl;
}

int main(){
    while(cin>>N>>M, N|M){
        elms.resize(N);
        for(auto &s: elms) cin >> s;
        text = "";
        for(int i=0; i<M; i++){
            string t; cin >> t;
            text += t;
        }
        solve();
    }
    
    return 0;
}

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

typedef long long ll;
#define rep(n, i) for(int i = 0; i < n; ++i)

void solve(void) {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll res = 0;
  
  if (K <= A) {
    res = K;
  } else if ( K <= A + B ) {
    res = A;
  } else {
    res = A - (K - A - B);
  }

  cout << res << endl;
}
int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,a[27],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=2;i<n;i++){
		if((a[i]>=a[i+1]&&a[i]<a[i-1])||(a[i]>=a[i-1]&&a[i]<a[i+1]))ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main () {
    int N, M;
    cin >> N >> M;
    vector<int> tosia(M);
    vector<int> tosib(M);
    for (int i = 0; i < M; i++) {
        cin >> tosia.at(i) >> tosib.at(i);
    }
    int sum = 0;
    for (int  i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (i + 1 == tosia.at(j) || i + 1 == tosib.at(j)) {
                sum++;
            }
        }
        cout << sum << endl;
        sum = 0;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll t[1000000];
string s[10000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	ll a[4];
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	sort(a,a+4);
	if(a[0]==a[1] && a[2]==a[3]){
		cout<<"yes"<<endl;
	}else{
		cout<<"no"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    cin >>n;
    vector<int> p(n);
    rep(i,n) cin >>p[i];

    int ans = 0;
    while(1)
    {
        int ct = 0;
        rep(i,n) ct += (p[i]>=ans+1);

        if(ct>=ans+1) ++ans;
        else break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>

int main(void)
{
  int a[200010]={0};
  int A[200010]={0};
  int n;
  
  scanf("%d", &n);
  for(int i=2;i<=n;i++)
    scanf("%d", &a[i]);
  for(int i=2;i<=n;i++)
    A[a[i]]++;
  for(int i=1;i<=n;i++)
    printf("%d\n",A[i]);
  
  return 0;
}
  

Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;

void solve(int N) {
  string ans;
  switch (N % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    ans = "hon";
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    ans = "pon";
    break;
  case 3:
    ans = "bon";
    break;      
  }
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  solve(N);

  return 0;
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 04:40:02 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  AB = [tuple(map(int, input().split())) for _ in range(N)]

  AB = sorted(AB, key=lambda x: x[1])
  time = 0
  for a, b in AB:
    time += a
    if time > b:
      print('No')
      return
  print('Yes')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 108796
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    vector<vector<char> > G(80, vector<char>(80, '.'));
    for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 80; j++) {
            G[i][j] = '#';
        }
    }
    for (int i = 0; i < A-1; i++) {
        G[i/40*2][i%40*2] = '.';
    }
    for (int i = 0; i < B-1; i++) {
        G[41+i/40*2][i%40*2] = '#';
    }
    puts("80 80");
    for (int i = 0; i<80; i++) {
        for (int j = 0; j<80; j++) {
            putchar(G[i][j]);
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int gcd(int a, int b){
      if(b != 0){
        return gcd(b, a%b);
      }
      return a;
    }
     
    int main(){
      int N, p = 0;
      cin >> N;
      
      vector<int> A(N), right(N), left(N);
      for (int i = 0; i < N; i++){
        cin >> A.at(i);
      }
      
      right.at(N - 1) = A.at(N - 1);
      left.at(0) = A.at(0);
      for(int i = 1; i < N; i++){
        left.at(i) = gcd(A.at(i - 1), left.at(i - 1));
      }
      for(int i = N - 2; i >= 0; i--){
        right.at(i) = gcd(A.at(i + 1), right.at(i + 1));
      }
      
      right.at(N - 1) = left.at(0) = 0;
      int c, ma = max(right.at(0), left.at(N - 1));
      for(int i = 0; i < N; i++){
        c = gcd(right.at(i), left.at(i));
        if(c > ma){
          ma = c;
        }
      }
        
      cout << ma << endl;
      return 0;
    }

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string a,b;
cin>>a>>b;
a+=b;
int x = stoi(a);
for(int i =1;i<=10000;i++)
{
    if(i*i==x)
    {
        cout<<"Yes";
        return 0;
    }
}
cout<<"No";
return 0;
}


Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  ll ans = true;
  rep(i, n) {
    string s; cin >> s;
    ans = (!ans || (s == "T"));
  }
  if (ans) cout << "T" << endl;
  else cout << "F" << endl;
}



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

int main() {
  
  int n,m;
  double x;
  cin >> n >> m;
  x = (4*(double)n-m)/2;
  if((x == int(x))&&(x >= 0)&&(x <= n)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main () {
	int a, b;
	cin >> a >> b;
	// a > b, a == b, a < b
	// a > b => a-1
	// a == b => a
	// a < b => a
	cout << (a > b ? a-1 : a) << endl;
	return 0;
}



Measured memory_bytes: 256
S = int(input())
numbers = str(S)
L = len(numbers)
prev = 0
for bit in range(1<<L-1):
    now = int(numbers[0])
    for i in range(L-1):
        if bit & (1<<i):
            prev += now
            now = int(numbers[i+1])
        else:
            now = now * 10 + int(numbers[i+1])
    prev += now
print(prev)

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
import math

def solve(H: int, W: int, N: int):
    print(-(-N//max(H,W)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(H, W, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main( String[] args ){

        Scanner in = new Scanner(System.in);

        String[] firstParams = in.nextLine().split(" ");
        int p = Integer.parseInt(firstParams[0]);
        int q = Integer.parseInt(firstParams[1]);
        int r = Integer.parseInt(firstParams[2]);

        int max = p;
        if( max < q )max = q;
        if( max < r )max = r;

        System.out.println(p + q + r - max );

    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int s,a,b,c,s1=0;
    scanf("%d%d%d",&a,&b,&c);
    s=b-(a-c);
    if(s<=0)
        printf("%d",s1);
    else
    printf("%d",s);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  string s; cin >> s;
  int L = LEN(s);

  stack<int> p;
  int ans = 0;
  for (int i = 0; i < L; ++i) {
    char c = s[i];
    if (p.empty()) {
      p.push(c);
    } else if (p.top() != c) {
      p.pop();
      ans += 2;
    } else {
      p.push(c);
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,m; cin >> n >>m;
    vector<vector<int>> v(m);
    vector<int> p(m);
    rep(i,m){
        int k; cin >> k;
        rep(j,k){ 
            int t; cin >> t;
            v[i].push_back(t);
        }
    }
    rep(i,m) cin >> p[i];
    int ans = 0;
    rep(i, 1<<n){
        bool flag = true;
        rep(j,m){
            int t=0;
            for(auto x: v[j]) if( ((1<<(x-1))&i) == (1<<(x-1))) t++;
            flag = flag && (p[j] == (t%2));
        }
        if(flag) ans++;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[200009];
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    FAST
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n,greater<ll> ());
    for(i=1;i<n;i++)
    {
        x+= a[i/2];
    }
    cout<<x<<endl;

    return 0;
}



Measured memory_bytes: 5140
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
using namespace std;

int main() {
	string s;
	cin >> s;
	bool used[4];
	fill(used, used + 4, false);
	for (int i = 0; i < s.size(); i++) {
		switch (s[i]) {
		case 'N':
			used[0] = true;
			break;
		case 'S':
			used[1] = true;
			break;
		case 'W':
			used[2] = true;
			break;
		case 'E':
			used[3] = true;
			break;
		}
		if (used[0] && used[1] && used[2] && used[3]) break;
	}
	if (!(used[0] ^ used[1]) && !(used[2] ^ used[3]))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
solve :: Int -> Int -> Int -> Bool
solve a b k
    | a == b && (b `mod` k == 0) = True
    | a == b = False
    | otherwise = (a `mod` k == 0) || solve (a+1) b k

main = do
    k <- readLn
    [a,b] <- map read . words <$> getLine
    putStrLn $ if solve a b k then "OK" else "NG"


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, a, b;
  std::cin >> n >> a >> b;
  std::cout << std::min(n * a, b) << std::endl;
  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
long long int n,m,i,j=1,t;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1,};
 
std::vector<P> tree[100010];
long long int dp[100005];
bool used[100005];
char s[100005];
ll ans=0;





int main(){
	cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		if(i%2==0 && s[i]=='p')ans--;
		if(i%2!=0 && s[i]=='g')ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
N = int(input()) 

ans=0
d = [10*[0] for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    if s[0]=="0" or s[-1]=="0":
        continue
    d[int(s[0])][int(s[-1])]+=1
    
for i in range(10):
    for j in range(10):
        ans+=d[i][j]*d[j][i]
print(ans)


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }

int solve(int N, int M, vi& s, vi& p) {
    int P=1<<N, ans=0;
    rep(j,P){
        int cnt = 0;
        rep(i,M){
            int n = __builtin_popcount(s[i] & j);
            if (n%2 == p[i]) ++cnt;
        }
        if (cnt == M) ++ans;
    }
    return ans;
}

int main() {
    int N,M; cin >> N >> M;
    vi s(M,0);
    vi p(M);
    rep(i,M){
        int k; cin >> k;
        rep(j,k) {
            int sw; cin >> sw; --sw;
            s[i] |= (1 << sw);
        }
    }
    rep(i,M) cin >> p[i];
    cout << solve(N,M,s,p) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 101
#define INF 10000000
#define NIL -1

#define WHITE 0
#define BLACK 1 

int n;
int Graph[MAX][MAX];

int prim(void);

int main(){

  int i, j, ans;

  scanf("%d", &n);

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

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

      scanf("%d", &Graph[i][j]);
      
      if(Graph[i][j] == NIL)
	Graph[i][j] = INF;

    }

  }

  ans = prim();

  printf("%d\n", ans);

  return 0;

}

int prim(){

  int u, v, mincost, i, sum;
  int d[MAX];
  int pi[MAX];
  int color[MAX];

  sum = 0;

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

    d[u] = INF;
    
    pi[u] = NIL;

    color[u] = WHITE;

  }

  d[0] = 0;

  while(1){

    mincost = INF;

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

      if((color[i] != BLACK) && (d[i] < mincost)){

	mincost = d[i];

	u = i;

      }

    }

    if(mincost == INF)
      break;

    color[u] = BLACK;

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

      if(Graph[u][v] != INF){

	if((color[v] != BLACK) && (Graph[u][v] < d[v])){

	  pi[v] = u;

	  d[v] = Graph[u][v];

	}

      }

    }

  }

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

    if(pi[i] != NIL)
      sum += Graph[i][pi[i]];

  }
  
  return sum;

}

Measured memory_bytes: 640
while True:
	s = list(input().split())
	s[0] = int(s[0])
	s[2] = int(s[2])
	op = s[1]
	if op == '?':
		exit()
	if op == '+':
		print(s[0]+s[2])
	elif op == '-':
		print(s[0]-s[2])
	elif op == '*':
		print(s[0]*s[2])
	elif op == '/':
		print(s[0]//s[2])


Measured memory_bytes: 5596
N = int(input())
dist = []
neighbours = [[] for i in range(N)]
for i in range(N):
    line = list(input())
    dist.append([1 if c == '1' else float('inf') for c in line ])
    for j, char in enumerate(line):
        if char == '1': neighbours[i].append(j)

for i in range(N): dist[i][i] = 0
# Find diameter
for k in range(N):
    for i in range(N):
        for j in range(N):
            if dist[i][k] + dist[k][j] < dist[i][j]:
                dist[i][j] = dist[i][k] + dist[k][j]

startVertex = 0
startDiam = 0
for i in range(N):
    for j in range(N):
        if dist[i][j] > startDiam:
            startDiam = dist[i][j]
            startVertex = i
            
isPossible = True

# Dijkstra
distances = [float('inf') for i in range(N)]
visited = [False for i in range(N)]

distances[startVertex] = 0

while True:
    curNode = min(range(N), key=lambda n:(visited[n], distances[n]))

    if visited[curNode]:
        break
    visited[curNode] = True

    for neighbour in neighbours[curNode]:
        if distances[neighbour] == float('inf'):
            distances[neighbour] = distances[curNode] + 1
        else:
            if abs(distances[neighbour] - distances[curNode]) != 1:
                isPossible = False

if not isPossible:
    print(-1)
else:
    total = len(set(distances))
    print(total)


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 100100;

bool a[M];

bool ask(int i) {
  cout << i << endl;
  string res;
  cin >> res;
  if (res == "Vacant") {
    exit(0);
  }
  if (res == "Male") {
    return a[i] = true;
  } else {
    return a[i] = false;
  }
}

bool good(int l, int r) {
  if ((r - l) % 2 == 0)
    return a[l] != a[r];
  else
    return a[l] == a[r];
}

int main() {
#ifdef LOCAL
  //assert(freopen("c.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  int l = 0, r = n - 1;

  ask(l);
  ask(r);

  while (true) {
    assert(good(l, r));
    int m = (l + r) / 2;
    ask(m);
    if (good(l, m))
      r = m;
    else
      l = m;
  }
}



Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const ll mod = 1e9 + 7;
ll t[100010], a[100010];
ll dp[100010];
int main(void){
	int n; cin >> n;
	t[0] = a[0] = 0;
	t[n + 1] = a[n + 1] = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> t[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}

	dp[0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		if(t[i - 1] < t[i]){
			if(t[i] <= a[i]){
				dp[i] = dp[i - 1];
				dp[i] %= mod;
			}else{
				printf("0\n");
				return 0;
			}
		}else{
			if(a[i] > a[i + 1]){
				dp[i] = dp[i - 1];
				dp[i] %= mod;
			}else{
				dp[i] = dp[i - 1] * min(a[i], t[i]);
				dp[i] %= mod;
			}
		}
	}
	printf("%lld\n", dp[n] % mod);
	return 0;
}

Measured memory_bytes: 2560
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define int ll
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int32_t main() {
   
 	int n,k;
 	cin>>n>>k;
 	vi a(n);
 	forr(i,n){
 		cin>>a[i];
 	}   
 	sort(a.begin(),a.end());
 	int t1 = lower_bound(a.begin(),a.end(),k)-a.begin();
 	cout<<n-t1;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,j,a,b;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int p[10000]={0},f[10000]={0},o[10000]={0};
inline int X(int x){
int e,z,u,t=0,k,g=0,w;
for(e=0;e<x;e++){
	u=0;
	w=0;
	if(o[e]!=0){
		for(z=e;z<x;z++){
				if(o[e]==o[z])u++;
				else if(o[z]==0)w++;
				else break;
		}
		if(u>=4){
			t=1;
			for(k=0;k<w+u;k++)o[e+k]=0;
		}
	}
	if(o[e]!=0)g++;
}
if(t==1)return X(x);
return g;
}
int main(){
//int a[1000],b=0;
while(1){
	int n,i,j,m,l;
	cin>>n;
	if(n==0)break;
	memset(f,0,sizeof(f));
	for(i=0;i<n;i++)cin>>p[i];
	for(i=0;i<n;i++){
		if(p[i]==p[i-1]&&i!=0)f[i]=f[i-1];
		else{
			for(j=i;j<n;j++){
				if(p[i]==p[j])f[i]++;
				else break;
			}
		}
	}
	m=n;
	for(i=0;i<n;i++){
		if( (i!=n-1&&p[i]!=p[i+1]&&1+f[i+1]>=4) || i!=0&&p[i]!=p[i-1]&&1+f[i-1]>=4||p[i+1]==p[i-1]&&i!=0&&i!=n-1&&f[i]+f[i+1]+f[i-1]>=4&&f[i]==1){
			for(j=1;j<=3;j++){
				for(l=0;l<n;l++)o[l]=p[l];
				if(o[i]!=j){
					o[i]=j;
					m=min(m,X(n));
				}
			}
		}
	}
	/*a[b]=m;
	b++;*/
	cout<<m<<endl;
}
//for(int r=0;r<b;r++)cout<<a[r]<<endl;
return 0;
}
		

Measured memory_bytes: 3092
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e18
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

// -----------> copied code <------------

const ll is_query = -(1LL<<62);

struct Line {
	ll m, b;
	mutable function<const Line*()> succ;
	bool operator<(const Line& rhs) const {
		if (rhs.b != is_query) return m < rhs.m;
		const Line* s = succ();
		if (!s) return 0;
		ll x = rhs.m;
		return b - s->b < (s->m - m) * x;
	}
};

struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->m == z->m && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->m == x->m && y->b <= x->b;
		return (double)(x->b - y->b)*(z->m - y->m) >= (double)(y->b - z->b)*(y->m - x->m);
	}
	void insert_line(ll m, ll b) {
		auto y = insert({ m, b });
		y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
		if (bad(y)) { erase(y); return; }
		while (next(y) != end() && bad(next(y))) erase(next(y));
		while (y != begin() && bad(prev(y))) erase(prev(y));
	}
	ll eval(ll x) {
		auto l = *lower_bound((Line) { x, is_query });
		return l.m * x + l.b;
	}
};

// -----------> end of copied code <------------

ll n, c;
ll h[223456];

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> c;
	for(int i=0; i<n; i++) cin >> h[i];
	ll res = (h[1] - h[0])*(h[1] - h[0])+c;
	if(n == 2) {
		cout << res << endl;
		return 0;
	}
	HullDynamic cht;
	cht.insert_line(2*h[0], -(c + h[0]*h[0]));
	cht.insert_line(2*h[1], -(res + c + h[1]*h[1]));
	for(int i=2; i<n; i++) {
		res = h[i] * h[i] - cht.eval(h[i]);
		cht.insert_line(2*h[i], -(res + c + h[i]*h[i]));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<vector<int > > vec2int;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n;
  cin >> n;
  string s; cin >> s;
  vecint x(n + 1,0); // num of 'W' 
  vecint y(n + 1,0);
  REP(i,n){
    if(s[i] == 'W'){
      x[i + 1] = x[i] + 1;
    }else{
      x[i + 1] = x[i];
    }
  }
  REP(i,n + 1){
    y[i] = i - x[i];
  }

  int ans = 1e9;
  int tmp = 0;
  // REP(i,n + 1){
  //   cout << i;
  // }
  // cout << endl;
  // REP(i,n + 1){
  //   cout << x[i];
  // }
  // cout << endl;
  // REP(i,n + 1){
  //   cout << y[i];
  // }
  // cout << endl;
  REP(i,n){
    tmp = x[i];
    tmp += y[n] - y[i + 1];
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}



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

int main() {
  vector<int> dice(6);
  vector<int> copy(6);
  rep(i,6) cin >> dice[i];
  copy = dice;
  string order;
  cin >> order;
  for(int i = 0; i < sz(order); i++) {
    copy = dice;
    if(order[i] == 'N') {
      copy[0] = dice[1];
      copy[1] = dice[5];
      copy[4] = dice[0];
      copy[5] = dice[4];
      dice = copy;
    }
    if(order[i] == 'E') {
      copy[0] = dice[3];
      copy[2] = dice[0];
      copy[5] = dice[2];
      copy[3] = dice[5];
      dice = copy;
    }
    if(order[i] == 'W') {
      copy[0] = dice[2];
      copy[2] = dice[5];
      copy[5] = dice[3];
      copy[3] = dice[0];
      dice = copy;
    }
    if(order[i] == 'S') {
      copy[0] = dice[4];
      copy[1] = dice[0];
      copy[4] = dice[5];
      copy[5] = dice[1];
      dice = copy;
    }
  }
  cout << dice[0] << endl;
  return 0;
}


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


void rem(vector<string> &msg,int idx){
	vector<string> r;
	for(int i = 0 ; i < msg.size() ; i++)
		if( i != idx ) r.push_back(msg[i]);
	msg = r;
}

void rem(string &msg,int idx){
	string r;
	for(int i = 0 ; i < msg.size() ; i++)
		if( i != idx ) r += msg[i];
	msg = r;
}

vector<string> msg;
string buf = "";
int x,y;


int main(){
	string tmp;
	while(getline(cin,tmp)){
		if( tmp[tmp.size()-1] == '\r' ) tmp = tmp.substr(0,tmp.size()-1);
		if( tmp == "END_OF_TEXT" ) break;
		msg.push_back(tmp);
	}
	while( cin >> tmp && tmp != "-"){
		if( tmp == "a" ){
			x = 0;
		}
		if( tmp == "e" ){
			x = msg[y].size();
		}
		if( tmp == "p" ){
			x = 0;
			if(y)y--;
		}
		if( tmp == "n") {
			x = 0;
			if(y+1<msg.size())y++;
		}
		if( tmp == "f" ){
			if( x != msg[y].size() ){
				x++;
			}else if( x == msg[y].size() && y + 1 < msg.size() ){
				y++;
				x=0;
			}
		}
		if( tmp == "b" ){
			if( x != 0 ) x--;
			else if( x == 0 && y ){
				y--;
				x = msg[y].size();
			}
		}
		if( tmp == "d" ){
			if( x < msg[y].size() ){
				rem(msg[y],x);
			}else if( x == msg[y].size() && y+1 < msg.size() ){
				msg[y] += msg[y+1];
				rem(msg,y+1);
			}
		}

		if( tmp == "k" ){
			if( x == msg[y].size() && y+1 < msg.size() ){ // ここ日本語怪しいからチェック
				msg[y] += msg[y+1];
				rem(msg,y+1);
				buf = "\n";
			}else if( x != msg[y].size() ){
				buf = msg[y].substr(x);
				msg[y] = msg[y].substr(0,x);
			}//else buf = "\n";
		}
		if( tmp == "y" ){
			if( buf == "" ){
			}else if( buf == "\n" ){
				vector<string> a;
				for(int k = 0 ; k < y ; k++)
					a.push_back(msg[k]);
				a.push_back(msg[y].substr(0,x));
				a.push_back(msg[y].substr(x));
				for(int k = y+1 ; k < msg.size() ; k++)
					a.push_back(msg[k]);
				msg = a;
				y++;
				x = 0;
			}else{
				msg[y] = msg[y].substr(0,x) + buf + msg[y].substr(x);
				x += buf.size();
			}
		}
	}
	for(int i = 0 ; i < msg.size() ; i++)
		cout << msg[i] << endl;
}

Measured memory_bytes: 1212
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> Q;


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

const int inf = 1<<30;

int main(void){
    int n,m;
    string s;
    cin>>n>>m>>s;
    vector<int>dp(n+1,inf);
    dp[n]=0;
    queue<int>q;
    q.push(0);
    for(int i=n-1;i>=0;--i){
        while(1){
            if(q.size()==0){
                cout<<"-1"<<endl;
                return 0;
            }
            if(q.front() != inf && q.size()<=m)break;
            q.pop();
        }
        if(s[i]=='0')dp[i]=q.front()+1;
        q.push(dp[i]);
    }
    vector<int>ans;
    int x = 0;
    int rest = dp[0];
    while(x<n){
        --rest;
        int i=1;
        while(dp[x+i]!=rest)++i;
        ans.push_back(i);
        x += i;
    }
    for(int i=0;i<ans.size();i++){
        if(i==ans.size()-1)cout<<ans[i]<<endl;
        else cout<<ans[i]<<" ";
    }
    return 0;
}

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

typedef vector<int> vi;

string parse(string x, int &i)
{
	if (x.length() == i) return "";

	if ('A' <= x[i] && x[i] <= 'Z')
	{
		char c = x[i];
		i++;
		return c + parse(x, i);
	}
	else if (x[i] == ']')
	{
		i++;
		return "";
	}

	i++;
	string s = parse(x, i);
	reverse(s.begin(), s.end());

	return s + parse(x, i);
}

string pre(string x)
{
	int d = 0;
	string ret = "";
	rep(i, 0, x.length())
	{
		if ('A' <= x[i] && x[i] <= 'Z')
		{
			int j = x[i] - 'A';
			while (d < 0) d += 26;
			j = (j + d) % 26;
			ret += char('A' + j);
			d = 0;
		}
		else if (x[i] == '?')
		{
			d = 0;
			ret += "A";
		}
		else if (x[i] == '+')
			d++;
		else if (x[i] == '-')
			d--;
		else
			ret += x[i];
	}
	return ret;
}

int main()
{
	while (1)
	{
		string s; cin >> s;
		if (s[0] == '.') return 0;

		int i = 0;
		string ans = parse(pre(s), i);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
int main()
{
       ll n;
       cin>>n;
       ll ans = (n*(n+1))/2;
       ll xx = n/3;
       xx = (xx*(xx+1))/2;
       xx *= 3;
       ans -= xx;
       xx = n/5;
       xx = (xx*(xx+1))/2;
       xx *= 5;
       ans -= xx;
       xx = n/15;
       xx = (xx*(xx+1))/2;
       xx *= 15;
       ans += xx;
       cout<<ans<<endl;
}


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

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

	int res = 0;
	for (int i = 0; i < s.size(); ++i)
		res += (s[i] != t[i]);
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3844
#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>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define 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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
const ll INF=10e9;

signed main(){
	int n,m; cin>>n>>m;
	vector<pl> p(n);
	vector<pl> q(m);
	vl ans(n);
	rep(i,0,n){
		ll a,b; cin>>a>>b;
		p[i].first=a;
		p[i].second=b;
	}
	rep(i,0,m){
		ll a,b; cin>>a>>b;
		q[i].first=a;
		q[i].second=b;
	}
	rep(i,0,n){
		ll cnt=abs(p[i].first-q[0].first)+abs(p[i].second-q[0].second);
		//cout<<cnt;
		ll cnj=0;
		ll a=p[i].first;
		ll b=p[i].second;
		rep(j,1,m){
			ll c=q[j].first;
			ll d=q[j].second;
			ll cnt2=abs(a-c)+abs(b-d);
			//cout<<" "<<min(cnt,cnt2);
			//cout<<" "<<cnt2<<endl;
			if(cnt==cnt2) continue;
			//cout<<"apple";
			if(cnt>cnt2){
				cnt=cnt2;
				cnj=j;
				//cout<<"aho";
			}
		}
		ans[i]=cnj;
	}
	rep(i,0,n) cout<<ans[i]+1<<endl;
	return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


vector<pair<long long, long long> > prime_factorize(long long n) { //素因数分解、pairのfirstに底、secondに底の何乗
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    string s;
    cin >> n >> s;
    ll r = 0;
    rep(i, sz(s)){
        if(s[i] == 'R') r++;
    }
    string t;
    rep(i, sz(s)){
        if(i + 1 > r) t.push_back('W');
        else t.push_back('R');
    }
    ll ans = 0;
    rep(i, sz(s)){
        if(t[i] == 'R' && t[i] != s[i]) ans++;
    }
    print(ans);
    


    

}



Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e18;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    vl x(5);
    ll ans;
    rep(i, 5){
      cin >> x[i];
      if(x[i]==0)ans = i + 1;
    }
    print(ans);
}

Measured memory_bytes: 3624
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String m[] = s.split("");
    int ans = 0;
    for (int i = 0; i < s.length(); i++){
      if (m[i].equals("+")){
        ans++;
      }else{
        ans--;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35600