akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    s = input()
    # Positions for each character.
    r = set()
    g = set()
    r_add = r.add
    g_add = g.add
    for ind, c in enumerate(s):
        if c == 'R':
            r_add(ind)
        elif c == 'G':
            g_add(ind)
    b = set(range(n)) - r - g

    ans = 0
    for i in r:
        for j in g:
            p, q = min(i, j), max(i, j)
            if (q - p) % 2 == 0 and (p + q) // 2 in b:
                ans -= 1
            if (q + (q - p)) in b:
                ans -= 1
            if (p - (q - p)) in b:
                ans -= 1
            ans += len(b)
    return ans


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


Measured memory_bytes: 9568
using System;

namespace AOJ.Volume3
{
    public class YuekisAudioRoom
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                int r = int.Parse(input[0]);
                int t = int.Parse(input[1]);

                if (r % 100 == 0 && t % 30 == 0)
                {
                    // 測定点にいる場合
                    // 距離100の測定点は(t / 30) * 5 + 1
                    // その測定点から100離れる毎に番号が1増える
                    // 増える番号は(r / 100) - 1(距離100は増やす必要がない)
                    // まとめると((t / 30) * 5) + (r / 100)
                    Console.WriteLine((t / 30) * 5 + (r / 100));
                }
                else if (r % 100 == 0)
                {
                    // 円弧上にいる場合
                    int t1 = (int)Math.Floor((decimal)t / 30);
                    int t2 = (int)Math.Ceiling((decimal)t / 30);

                    int ans1 = t1 * 5 + (r / 100);
                    int ans2 = t2 * 5 + (r / 100);

                    Console.WriteLine("{0} {1}", ans1, ans2);
                }
                else if (t % 30 == 0)
                {
                    // 直線上にいる場合
                    int r1 = (int)Math.Floor((decimal)r / 100);
                    int r2 = (int)Math.Ceiling((decimal)r / 100);

                    int ans1 = (t / 30) * 5 + r1;
                    int ans2 = (t / 30) * 5 + r2;

                    Console.WriteLine("{0} {1}", ans1, ans2);
                }
                else
                {
                    // 扇形の中にいる場合
                    int t1 = (int)Math.Floor((decimal)t / 30) * 5;
                    int t2 = (int)Math.Ceiling((decimal)t / 30) * 5;
                    int r1 = (int)Math.Floor((decimal)r / 100);
                    int r2 = (int)Math.Ceiling((decimal)r / 100);

                    int ans1 = t1 + r1;
                    int ans2 = t1 + r2;
                    int ans3 = t2 + r1;
                    int ans4 = t2 + r2;

                    Console.WriteLine("{0} {1} {2} {3}", ans1, ans2, ans3, ans4);
                }
            }

            return 0;
        }
    }
}

Measured memory_bytes: 9300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> v,v1;
    v.push_back(0);
    v1.push_back(0);
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;

        v.push_back(x);
    }
    for(int i=0;i<m;i++)
    {
        ll x;
        cin>>x;

        v1.push_back(x);
    }
    for(int i=1;i<v.size();i++)
    {
        v[i] +=v[i-1];
    }
    /*for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;*/
    for(int i=1;i<v1.size();i++)
    {
        v1[i] +=v1[i-1];
    }
  /*  for(int i=0;i<v1.size();i++)
    {
        cout<<v1[i]<<" ";
    }
    cout<<endl;*/
    ll ans = 0;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]<=k)
        {  // cout<<v[i]<<endl;
            ll temp = k-v[i];
           // cout<<temp<<endl;
            ll pos = upper_bound(v1.begin(),v1.end(),temp) - v1.begin();
           // cout<<pos<<endl;
            ans = max(ans,pos+i-1);
            continue;
        }
        break;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(void){
  
  int A,B,T;
  int s;
  cin>>A;
  cin>>B;
  cin>>T;
  
 for(int i=A; i<T+0.5;i=i+A){
   s+=B;
 }
  
  cout <<s<<endl;
  
  
}

Measured memory_bytes: 256
// C - Typical Stairs

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const int MOD = 1e9 + 7;

ll dp[100001];

int main(){
	int N, M;
	cin >> N >> M;

	int a;
	for (int i=0; i<M; i++) {
		cin >> a;
		dp[a] = -1;
	}

	dp[0] = 1;

	if (dp[1] == -1) {
		dp[1] = 0;
	} else {
		dp[1] = 1;
	}


	for (int i=2; i<=N; i++) {
		if (dp[i] == -1) {
			dp[i] = 0;
		} else {
			dp[i] = (dp[i-1] + dp[i-2]) % MOD;
		}
	}

	cout << dp[N] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int x; cin>>x;
	cout<<(x >= 30 ? "Yes" : "No");
}

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

long long n;
vector<int> c, a, b;
vector<long long> res;
vector<int> x;
vector<int> n_descendents;
vector< vector<int> > neighbors;

void dfs(int i, int p) {
    n_descendents[i] = 0;
    int next_x = x[c[i]];
    for(int j=0; j<neighbors[i].size(); j++) {
        int neighbor = neighbors[i][j];
        if (neighbor == p) continue;
        int before = x[c[i]];
        dfs(neighbor, i);
        int after = x[c[i]];
        int s = 1 + n_descendents[neighbor];
        long long m = s - after + before;
        n_descendents[i] += s;
        res[c[i]] -= m * (m-1) / 2;
    }
    next_x += 1 + n_descendents[i];
    x[c[i]] = next_x;
}


vector<long long> solve(long long n, vector<int> c, vector<int> a, vector<int> b) {
    neighbors.resize(n);
    for(int i=0; i < n-1; i++) {
        neighbors[a[i]].push_back(b[i]);
        neighbors[b[i]].push_back(a[i]);
    }
    res.resize(n, 0);
    x.resize(n, 0);
    n_descendents.resize(n, 0);

    int root = 0;
    dfs(root, -1);

    set<int> present_colors;
    for(int i=0; i<n ; i++)
        present_colors.insert(c[i]);
    set<int>::iterator it;
    for(it=present_colors.begin(); it !=present_colors.end(); it++) {
        if (*it == c[root]) continue;
        long long m = n - x[*it];
        res[*it] -= m * (m-1) / 2;
    }
    for(it=present_colors.begin(); it !=present_colors.end(); it++) {
        res[*it] += n * (n-1) / 2;
    }
    for(int j=0; j <n ; j++){
        int i = c[j];
        res[i] += 1;
    }
    return res;
}


int main() {
    cin >> n;
    c.resize(n, 0);
    a.resize(n - 1, 0);
    b.resize(n - 1, 0);
    for(int i=0; i<n; i++) {
        cin >> c[i];
        c[i]--;
    }
    for(int i=0; i<n-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    res = solve(n, c, a, b);
    for(int i=0; i<n; i++)
        cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 48248
n = int(input())
a = 0
b = 0
c = 0
total = 0
for _ in range(n):
    s = input()
    total += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        c+=1
    elif s[-1] == 'A':
        a+=1
    elif s[0] == 'B':
        b+=1

if a+b == 0:
    print(total + max(0, c - 1))
else:
    print(total + min(a, b) + c)




Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
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 const INF = 1 << 30;


int main()
{
    int w,b;
    cin >> w >> b;
    w--; b--;

    //Background: L -> '#', R -> ' .'
    vector<vector<char>> L(100,vector<char>(50,'#'));
    vector<vector<char>> R(100,vector<char>(50,'.'));

    rep(i,50) {
        rep(j,10) {
            if(10*i + j < w) L[i*2][j*2] = '.';
            if(10*i + j < b) R[i*2][49-j*2] = '#';
        }
    }

    cout << 100 << ' ' << 100 << endl;
    rep(i,100) {
        rep(j,100) {
            if(j < 50) cout << L[i][j];
            else cout << R[i][j-50];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int MAX = 100;
static int INFTY = 10000000;
static int WHITE = 0;
static int GRAY = 1;
static int BLACK = 2;

int n, A[100][100];

int prim(){
  int u,minv,i,sum = 0,v;
  int d[MAX],p[MAX],color[MAX];
  for(i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0;i < n;i++){
      if(minv > d[i] && color[i] != BLACK){
 u = i;
 minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(v = 0;v < n;v++){
      if(color[v] != BLACK && A[u][v] != INFTY){
 if(d[v] > A[u][v]){
   d[v] = A[u][v];
   p[v] = u;
   color[v] = GRAY;
 }
      }
    }
  }
  for(i = 0;i < n; i++)
    if(p[i] != -1)sum += A[i][p[i]];
  
  return sum;
}

int main(){
	int i,j,e,sum;
  	scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&e);
      A[i][j] = (e == -1) ? INFTY : e;
    }
  }
  sum = prim();
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    
    X = ' ' + X; //insert a space to X[0]
    Y = ' ' + Y; //insert a space to Y[0]
    
    for(int i = 0; i <= m; i++) c[i][0] = 0;
    for(int j = 1; j <= n; j++) c[0][j] = 0;
    
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            if(X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            }else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    string s1, s2;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7044
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    s = input()
    x = 0
    maxx = 0
    for i in s:
        if i == 'D':
            x -= 1
        if i == 'I':
            x += 1
        
        maxx = max(maxx, x)
    
    print(maxx)

solve()


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;

void solve() {
    int s = 0;
    int i = 1;
    while (s < n) {
        s += i;
        i++;
    }
    int v = s - n;
    for (int j = 1; j < i; j++) {
        if (j != v)
            cout << j << endl;
    }
}

void input() {
    cin >> n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    string S;
	cin >> S;
    int N = S.size();
    vector<int> v(N);
    rep(i,N) v.at(i) = stoi(S.substr(i,1));

    for(int bit=0; bit < (1<<(N-1)); bit++){
        int tmp = v.at(0);
        for(int i=0;i<N-1;i++){
            if(bit & (1<<i)) tmp += v.at(i+1);
            else tmp -= v.at(i+1);
        }
        if(tmp == 7){
            cout << v.at(0);
            for(int i=0;i<N-1;i++){
                if(bit & (1<<i)) cout << "+";
                else cout << "-";
                cout << v.at(i+1);
                if(i==N-2) cout << "=7" << endl;
            }
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	cout<<c*60+d-a*60-b-e<<endl; 
	return 0;
}



Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define inf 10000000
using namespace std;

int main(){
    int D;
    cin >> D;

    if(D == 25){
        cout << "Christmas" << endl;
    }else if(D == 24){
        cout << "Christmas Eve" << endl;
    }else if(D == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(D == 22){
        cout << "Christmas Eve Eve Eve" <<endl;
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int N;
int A, B;
vector<vector<int> >G(100010);
int K;
int V[100010], P[100010];
int vl[100010], vr[100010];
queue<int> q;

int solve()
{
	int i;
	for(i=0; i<K; i++){
		q.push(V[i]);
	}
	int u, v;
	int l, r;
	while(!q.empty() ){
		u = q.front();
		q.pop();
		for(i=0; i<G[u].size(); i++){
			v = G[u][i];
			if(vl[u]-1>vr[v] || vl[v]>vr[u]+1)
				return 0;
			l = vl[u]-1;
			if(l < vl[v])
				l = vl[v];
			r = vr[u]+1;
			if(r > vr[v])
				r = vr[v];
			if(r-l==1)
				return 0;
			if(l!=vl[v] || r!=vr[v]){
				vl[v] = l;
				vr[v] = r;
				q.push(v); 
			}
		}
	}
	return 1;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	scanf("%d", &N);
	for(i=0; i<N-1; i++){
		scanf("%d %d", &A, &B);
		A--, B--;
		G[A].push_back(B);
		G[B].push_back(A);
	}
	scanf("%d", &K);
	for(i=0; i<N; i++){
		vl[i] = -10000000;
		vr[i] = 10000000;
	}
	for(i=0; i<K; i++){
		scanf("%d%d", &V[i], &P[i]);
		V[i] --;
		vl[V[i]] = vr[V[i]] = P[i];
	}
	if(solve() ){
		printf("Yes\n");
		for(i=0; i<N; i++){
			printf("%d\n", vl[i]);
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

int main() {
  char c,a,i,u,e,o;
  cin >> c;
  a = 'a';
  i = 'i';
  u = 'u';
  e = 'e';
  o = 'o';
    
  if (c==a || c==i || c==u || c==e || c==o){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
       
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(c-(a-b) <0) cout << 0 << endl; 
  else cout << c-(a-b) << endl;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read

N, M = map(int, input().split())
if M != 0:
    AB = list(map(int, read().split()))
else:
    print(-1)
    exit()

graph = [[] for _ in range(N + 1)]
A = AB[::2]
B = AB[1::2]
A_s = set(A)
# 出次数が0の頂点はいらない。
needless = set(range(1, N + 1)) - A_s

for i, j in zip(A, B):
    if j not in needless:
        graph[i].append(j)


# cycleを少なくとも一つ検出する
def dfs(original_stack):
    checked = [False] * (N + 1)
    while original_stack:
        start = original_stack.pop()
        if checked[start]:
            continue
        checked[start] = True
        stack = [(start, [start])]
        while stack:
            v, route = stack.pop()
            for i in graph[v]:
                if i in route:
                    return route[route.index(i):]
                else:
                    stack.append((i, route + [i]))
                    checked[i] = True


v = dfs([i for i in range(1, N + 1) if graph[i]])
if not v:
    print(-1)
    exit()

while True:
    v_s = set(v)
    length = len(v)
    for i, (v_i, v_j) in enumerate(zip(v, v[1:] + [v[0]])):
        for j in graph[v_i]:
            if j != v_j and j in v_s:
                idx = v.index(j)
                if i < idx:
                    v = v[:i + 1] + v[idx:]
                else:
                    v = v[idx:i + 1]
                break
        else:
            continue
        break
    else:
        print(len(v))
        print('\n'.join(map(str, v)))
        exit()


Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<int,string>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<P> fst,lst;
    rep(i,n){
        string s,t;
        cin>>s;
        int ls=s.size();
        stack<char> st;
        rep(j,ls){
            if(st.empty()){
                st.push(s[j]);
            }else{
                if(st.top()=='('&&s[j]==')') st.pop();
                else st.push(s[j]);
            }
            
        }
        int l=0,r=0;
        while(!st.empty()){
            char c=st.top();
            st.pop();
            if(c=='(') l++;
            else r++;
            t+=c;
        }
        reverse(all(t));
        if(l-r>=0){
            fst.emplace_back(r,t);
        }else{
            lst.emplace_back(l,t);
        }
    }
    sort(all(fst));
    sort(all(lst),greater<P>());
    string check="";
    
    for(auto cur:fst) check+=cur.sc;
    for(auto cur:lst) check+=cur.sc;
    stack<char> ss;
    bool ok=1;
    for(char c:check){
        if(ss.empty()){
            ss.push(c);
        }else{
            if(ss.top()=='('&&c==')') ss.pop();
            else ss.push(c);
        }
    }
    if(ss.empty()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint 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;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> a >> b;
    if(a>=1 && a<= 9 && b >= 1 && b <= 9)
    {
        cout << a * b << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    int n, m, in;
    string key;
    set<int> A;
    set<int> B;
    vector<int> result;
    cin >> n;
    rep(i, n)
    {
        cin >> in;
        A.insert(in);
    }
    cin >> m;
    rep(i, m)
    {
        cin >> in;
        B.insert(in);
    }
    set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(result, result.end()));
    
    rep(i, result.size())
    {
        cout << result[i] << endl;
    }
}



Measured memory_bytes: 23652
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>


int main() {
	
	int R;
	scanf("%d",&R);
	
	float answer = R*2*3.141592;
	
	printf("%f",answer);
	
	return 0;
}

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

int main(){
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(int i=0; i<n; ++i)cin>>a[i];

  bool dp[100010]={false};

  dp[0]=false;
  for(int i=0; i<=k; ++i){
    for(int j=0; j<n; ++j){
      if(i-a[j]>=0)dp[i] |=!dp[i-a[j]];
    }
  }

  if(dp[k])cout<<"First"<<endl;
  else cout<<"Second"<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int solve(int,int);

int n,A[2000];

int main(){

  int i,q,judge,m[2000];


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

    scanf("%d",&A[i]);

  }
  scanf("%d",&q);

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

      scanf("%d",&m[i]);

    }
    for(i=0;i<q;i++){
      judge=0;
      judge=solve(0,m[i]);
      if(judge==1)printf("yes\n");
      else printf("no\n");
      
 
    }

  return 0;
}

int solve(int i,int m){

  int res;
  
  if(m == 0)return 1;
  if(i>=n)return 0;
  res =solve(i+1,m) || solve(i+1,m-A[i]);
    return res;





}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  s = "00" + s, n += 2;
  V<> iz(n);
  int t = 0;
  for (int i = 0; i < n; i++) if (s[i] == '0') t = 0;
  else iz[i] = ++t;
  V<> dp(n + 1);
  for (int i = 2; i < n; i++) {
    dp[i + 1] = dp[i];
    if (s.substr(i - 2, 3) == "101") dp[i + 1] = max({dp[i + 1], dp[i - iz[i - 2] - 1] + iz[i - 2], dp[i - iz[i - 2]] + iz[i - 2] - 1});
    if (s.substr(i - 1, 2) == "11" and s.substr(i - iz[i] - 1, 2) == "10") dp[i + 1] = max(dp[i + 1], dp[i - iz[i] - 1] + iz[i]);
  }
  cout << dp[n] << '\n';
}

Measured memory_bytes: 4784
/**
 *   created: 22 May 2019  22:00:21
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vi v(n);
		rep(i,0,n)
			cin>>v[i];
		vector< vi > mem(n,vi(2,0));
		mem[1][0] = abs(v[0]-v[1]);
		mem[1][1] = INF;
		rep(i,2,n){
			mem[i][0] = min(mem[i-1][0],mem[i-1][1]) + abs(v[i]-v[i-1]);
			mem[i][1] = min(mem[i-2][0],mem[i-2][1]) + abs(v[i]-v[i-2]);
			// trace2(mem[i][0],mem[i][1]);
		}
		cout<<min(mem[n-1][0],mem[n-1][1]);
	}
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

std::vector<ll> ABC(3);
std::vector<ll> L;

ll recursion(ui n, ll a, ll b, ll c)
{
  if(!n)
  {
    return std::min({a, b, c}) > 0
      ? std::abs(a - ABC[0]) + std::abs(b - ABC[1]) + std::abs(c - ABC[2]) - 30
      : std::numeric_limits<ll>::max() / 2;
  }

  return std::min({
    recursion(n - 1, a, b, c),
    recursion(n - 1, a + L[n - 1], b, c) + 10,
    recursion(n - 1, a, b + L[n - 1], c) + 10,
    recursion(n - 1, a, b, c + L[n - 1]) + 10});
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}; std::cin >> N;
  rep(0, ABC.size()) cin >> ABC[i];
  L.resize(N);
  rep(0, L.size()) cin >> L[i];

  cout << recursion(N, 0, 0, 0) << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)

using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

char maze[1010][1010];
bool checked[1010][1010]={};
int main(){

int h,w;
cin>>h>>w;

vector<queue<int>>q(2500);
rep2(i,h){
    rep2(k,w){
        cin>>maze[i][k];//maze[y][x]
        if(maze[i][k]=='#'){
            q[0].push(k);
            q[0].push(i);
            checked[i][k]=true;
        }
    }
}

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int p=0;
while(1){
    bool finish=true;
    while(!q[p].empty()){
        int x=q[p].front();q[p].pop();
        int y=q[p].front();q[p].pop();
        rep(i,4){
            int nowx=x+dx[i];
            int nowy=y+dy[i];
            if(nowx>=1 && nowx<=w && nowy>=1 && nowy<=h){
                if(checked[nowy][nowx])continue;
                q[p+1].push(nowx);
                q[p+1].push(nowy);
                checked[nowy][nowx]=true;
                finish=false;
            }
        }
        
    }
    
    if(finish)break;
    p++;
}

cout<<p<<endl;;
 return 0;
}
/*

by my self
first 23m 43s

3 3
...
.#.
...

2


6 6
..#..#
......
#..#..
......
.#....
....#.

3
*/

Measured memory_bytes: 12048
a,b,c,x=[int(input()) for i in range(4)]
count=0
for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if  500*i+100*j+50*k==x:
                count=count+1
print(count)
          

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

ll memo[3003][3003];

int main() {
    string a, b;
    cin >> a >> b;
    for(int i = 0; i <= a.size(); i++)
        memo[i][0] = 0;
    for(int j = 0; j <= b.size(); j++)
        memo[0][j] = 0;
    for(int i = 1; i <= a.size(); i++) {
        for(int j = 1; j <= b.size(); j++) {
            if (a[i-1] == b[j-1]) memo[i][j] = memo[i-1][j-1] + 1;
            else memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
        }
    }
    string res;
    int i = a.size(), j = b.size();
    while (i > 0 && j > 0) {
        if (a[i-1] == b[j-1]) {
            res += a[i-1];
            i--;
            j--;
        } else if (memo[i-1][j] > memo[i][j-1]) i--;
        else j--;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 70656
import Data.List
import Data.Maybe

solve n ps qs =
    abs (pi-qi)
    where 
        xs = sort $ permutations $ concatMap show [1..n]
        pi = fromJust $ elemIndex ps xs
        qi = fromJust $ elemIndex qs xs

main = do
    n <- readLn :: IO Int
    ps <- concat . words <$> getLine :: IO String
    qs <- concat . words <$> getLine :: IO String
    print $ solve n ps qs

Measured memory_bytes: 21116
import sys
from fractions import gcd


def main():
    n, k = map(int, input().split())

    ans = 0

    if k % 2 == 1:
        ans = (n // k)**3
    else:
        ans = (n // k)**3 + ((n + k // 2) // k)**3
    
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5432
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <utility>
#include <vector>
#include <math.h>

#define rep(i, n) for (auto i = 0; i < (n); i++)
#define MOD 1e9 + 7
typedef long long ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  rep(i, n) {
    string r;
    cin >> r;
    if (r == "AC")
      ac++;
    else if (r == "WA")
      wa++;
    else if (r == "TLE")
      tle++;
    else if (r == "RE")
      re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}



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

	#define mainspring cout<<"mainspring\n";
	#define barrel cout<<"barrel\n";
	#define escapement cout<<"escapement\n";

	#define pb push_back
	#define eb emplace_back
	#define all(v) (v).begin(), (v).end() 
	#define sz(v) (int)((v).size())
	#define fs first
	#define sd second
	#define tik(i,a,b) for(int i = a; i < b; i++)
	#define tok(i,a,b) for(int i = a; i >= b; i--)
	#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

	typedef long long ll;
	typedef unsigned long long ull;

	#define int ll 

	typedef pair < int, int > pi;
	typedef pair < pi, int > ppi;

	typedef vector < int > vi;
	typedef vector < vector < int > > vvi;
	typedef vector < pi > vpi;
	typedef vector < vpi > vvpi;
	typedef vector < ppi > vppi;

	void fast() {
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	}

	void err(istream_iterator<string> it) {cout << endl;}
	template<typename T, typename... Args>
	void err(istream_iterator<string> it, T a, Args... args) {
	    cerr << *it << " = " << a << " ";
	    err(++it, args...);
	}

	ll pow(ll x, ll y) {
		if(y == 0)
		return 1;
		ll temp = pow(x, y/2);
		temp = (temp*temp);
		if(y%2 == 1)
			temp *= x;
		return temp;
	}

	int32_t main() {
		string s;
		cin >> s;
		if(s[2] == s[3] && s[4] == s[5])
			cout << "Yes";
		else
			cout << "No";

	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    string S = in<string>();
    int count = 0;
    char OK = 'D';
    REP(i,N){
        if(S[i] == 'A'){
            OK = 'A';
        }else if(S[i] == 'B' && OK == 'A'){
            OK = 'B';
        }else if(S[i] == 'C' && OK == 'B'){
            count++;
            OK = 'D';
        }else{
            OK = 'D';
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int max = 0;
  for(int i = 0; i < N-1; ++i){
    int count = 0;
    for(char c = 'a'; c <= 'z'; c++){
      bool left = false;
      bool right = false;
      for(int j = 0; j <= i; ++j){
        if(S[j] == c) left = true;
      }
      for(int k = i+1; k < N; ++k){
        if(S[k] == c) right = true;
      }
      if(left && right) ++count;
    }
    if(count > max) max = count;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
a, b = [0], [0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])
for i in range(n+1):
    if a[i] > k:
        break
    while b[m] > k - a[i]:
        m -= 1
    ans = max(ans, i + m)
print(ans)


Measured memory_bytes: 47320
#include <iostream>

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

using namespace std;

int main(){
  int N, P;
  cin >> N >> P;
  int A[N];
  rep(i, N)
    cin >> A[i];
  //入力終了

  //偶数と奇数の数
  int eve_n = 0, odd_n = 0;
  rep(i, N)
    if(A[i]&1)
      odd_n++;
    else
      eve_n++;

  //偶数しかないとき
  if(odd_n==0){
    //P=0なら，全ての袋を選ぶか選ばないかで，2^N通り
    if(P == 0){
      long long ans = 1;
      for(int i=0; i<N; i++)
	ans *= 2;
      cout << ans << endl;
    }
    //P=1は無理
    else
      cout << 0 << endl;
    return 0;
  }
  
  //2^(N-1)が答え
  long long ans = 1;
  rep(i, N-1)
    ans *= 2;
  cout << ans << endl;
  
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; ++i)
    {
        int num = 0;
        int a = i;
        while (a != 0)
        {
            num++;
            a = a / 10;
        }
        if (num % 2 == 1)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace::std;

int cal_max(int N, int A, int B) {

	int N_p = max(A, B);
	int z;

	z = (A + B) - N_p;

	return z;
}

int cal_min(int N, int A, int B) {

	int N_p = N;
	int z;

	z = (A + B) - N_p;

	if (z < 0) z = 0;

	return z;
}


int main(void)
{

	int N, A, B;
	int z_max, z_min;

	cin >> N;
	cin >> A;
	cin >> B;


	z_max = cal_max(N, A, B);
	z_min = cal_min(N, A, B);

	cout << z_max << " " << z_min << endl;

	return 0;
}

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

int main()
{
    long long h;
    cin >> h;
    int count = 0;
    long long p = h;
    while(h!=0){
        h /= 2;
        count++;
    }
    long long ans = 1;
    while(count--){
        ans *= 2;
    }
    cout << ans -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#define ll long long
using namespace std;

ll a[200010], sum[200010];

int main() {
	ll N, K;
	cin >> N >> K;
	for(ll i=0; i<N; ++i){
		cin >> a[i];
		sum[i+1]=sum[i]+a[i]-1;
	}
	ll ans=0;
	map<ll, ll> mp;
	for(ll i=0; i<=N; ++i){
		ans += mp[sum[i]%K];
		++mp[sum[i]%K];
		if(K<=i+1) --mp[sum[i+1-K]%K];
	}
	cout << ans << endl;
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll sumOfDigits(ll n){
  ll sum = 0;
  while(n != 0){
    ll r = n % 10;
    n = (n-r) / 10;
    sum += r;
  }
    
  return sum;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, a, b;
  cin >> n >> a >> b;
  
  ll sum = 0;
  REP(i, n){
    if(a <= sumOfDigits(i+1) && sumOfDigits(i+1) <= b)
      sum += i+1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void dfs(int v,vector<bool>& visited,vector<vector<int>>& adj)
{
    visited[v]=true;
    for(auto const&e:adj[v])
    {
        if(!visited[e])
        {
            dfs(e,visited,adj);
        }
    }
    return;
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n);
    for(int i=0;i<m;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans=0;
    vector<bool> visited(n,false);
    for(int i=0;i<n;i++)
    {
        if(!visited[i])
        {
            ans++;
            dfs(i,visited,adj);
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 13464
n,m = map(int,input().split())

stu = [list(map(int,input().split())) for i in range(n)]

check = [list(map(int,input().split())) for i in range(m)]

mini = [3*10**8]*n
index = [0]*n

for i in range(n):
    for j in range(m):
        dist = abs(stu[i][0]-check[j][0]) + abs(stu[i][1]-check[j][1])
        if dist < mini[i]:
            mini[i] = dist
            index[i] = j+1
    
    
            
for i in index:
    print(i)

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

using namespace std;

template<typename T>
void myswap(T &a, T &b) {
	T t = a;
	a = b;
	b = t;
}

template<typename T>
int partition(vector<T> &A, int p, int r) {
	int i = p;
	for (int j = p; j < r; j++) {
		if (A[j] <= A[r]) {
			myswap(A[i], A[j]);
			i++;
		}
	}
	myswap(A[i], A[r]);
	return i;
}

template <typename T>
void quick_sort(vector<T> &A, int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quick_sort(A, p, q - 1);
		quick_sort(A, q + 1, r);
	}
	else
		return;
}

struct card {
	int number;
	char suit;
};
bool operator < (const card& lhs, const card& rhs) {
	return lhs.number < rhs.number;
}

bool operator > (const card& lhs, const card& rhs) {
	return  rhs < lhs;
}
bool operator <= (const card& lhs, const card& rhs) {
	return !(lhs > rhs);
}
bool operator >= (const card& lhs, const card& rhs) {
	return !(lhs < rhs);
}
bool operator == (const card& lhs, const card& rhs) {
	return (lhs.suit == rhs.suit && lhs.number == rhs.number);
}
bool operator != (const card& lhs, const card& rhs) {
	return !(lhs == rhs);
}


int main() {
	int n = 0;
	cin >> n;
	vector<card> v,v2;
	v.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> v[i].suit >> v[i].number;
	}
	v2 = v;
	
	quick_sort(v, 0, n - 1);
	stable_sort(v2.begin(), v2.end());
	
	bool is_stable = true;
	for (int i = 0; i < n; i++) {
		if (v[i] != v2[i]) {
			is_stable = false;
			break;
		}
	}
	if (is_stable)
		cout << "Stable\n";
	else
		cout << "Not stable\n";


	for (int i = 0; i < n; i++) {
		cout << v[i].suit << " " << v[i].number << "\n";
	}
	
	return 0;

}

Measured memory_bytes: 4608
#include<iostream>

using namespace std;

int main(){
    long long s,c,sum = 0;

    cin >> s >> c;

    if(s*2 <= c){
        c -= s*2;
        sum = c/4 + s;
    }else{
        sum = c/2;
    }

    cout << sum << endl;
    
    return 0;
}

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

int main(){
    string str;
    cin >> str;
    int i = str.size();
    if ( str.at(i-1) == 's'){
        cout << str << "es" <<endl;
    }else{
        cout << str << "s" << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)

int_fast32_t nn,n,sqrtN;
int_fast64_t ans,d;
char c;
char wr[15];
char *w = wr;
main() {
    char c;
    while(1) {
        c = getwchar_unlocked();
        if(c!='\n')
            nn = nn * 10 + c - '0';
        else
            break;
    }
    const int_least32_t n = nn;
    const int_fast32_t sqrtN = sqrt(n);
    ans = -(int_fast64_t)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    rep2(i, 1, sqrtN) { ans += (i * (i + (n / i)) * ((n / i) + 1 - i)); }
    while(ans) {
        *w = ans % 10 + '0';
        ans /= 10;
        w++;
    }
    while(1) {
        w--;
        putwchar_unlocked(*w);
        if(w == wr) break;
    }
}

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

int main() {
    int x, y; cin >> x >> y;

    for(int i = 1; i <= x; i++) {
        if(i * 2 + (x - i) * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        } 
        if (i * 4 + (x - i) * 2 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;

    vector<int64_t> A(N);
    for(int i=0;i<N;i++)    cin >> A[i];

    int64_t ans = A[0];
    for(int i=0;i<N;i++){
        ans = __gcd(ans, A[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
  long long i, n, now = 1;
  scanf("%lld", &n);
  if(!n) {
    printf("0\n");
    return 0;
  }
  for(i = 1; ; ++i) {
    now *= 2;
    if(now > n) break;
  }
  printf("%lld\n", i);
  return 0;
}


Measured memory_bytes: 2752
function main(input) {
    const args = input.split('\n');
    const N = args[0];
    const H = args[1].split(' ');
    var flag = 'Yes';
    var jadge = false;
    var array = [];

    for (var k=0; k < N ; k++) {
        array.push(parseInt(H[k], 10));
    }

    if(array[0] > 0) {
        array[0] = array[0] - 1;
    }

    for(var i = 1; i < N ; i++) {

        if( array[i-1] < array[i] ){
            flag = 'Yes';
            array[i] = array[i] - 1;
        } else if (array[i-1] === array[i]) {
            flag = 'Yes';
        } else {
            flag= 'No'
        }
        if (flag === 'No' ) break;
    }
    console.log(flag);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28212