akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//map<pair<long long int,long long int>,long long int>mapa;
//pair<ll,ll>v[200005];
map<ll,ll>mp,mpp;
//priority_queue<ll>pq;
class Myfirst{
private:
    string *name;       ll *age;
    public:
        ll gcd(ll a ,ll b)
        {   if(b==0) return a;  a%=b;   return gcd(b,a);    }
        ll exte_gcd(ll a,ll b,ll& x,ll& y)
        {
            if(b==0)
            {   x=1; y=0;   return a;   }
            ll x1,y1;             ll d=exte_gcd(b,a%b,x1,y1);
            x=y1;                 y=x1-y1*(a/b);  return d;
        }
        ll powe(ll d,ll s)
        {
            if(s==1) return d;      else if(s==0) return 1;
            else
            {   ll u,v=d;            for(u=1;u<s;u++)    d=d*v;
                return d;
            }
        }
        ll count_divisors(ll b)
        {
                ll i,count=0,n=1;
                for(i=2;i*i<=b;i++)
                {
                    count=0;
                    if(b%i==0)
                    {
                        while(b%i==0)
                        {
                            b=b/i;      count++;
                        }
                        n=n*(count+1);
                    }
                }
                if(b>1) n=2*n;
            return n;
        }
        ll bigmod(ll a,ll b, ll mod)
        {
            if(b==0)
                return 1;
            ll x=bigmod(a,b/2,mod);         x=(x*x)%mod;
            if(b%2) x=(x*a)%mod;
                return x;
        }
        ll phi(ll n)
        {
            double result=n;
            for (ll p=2;p*p<=n;++p){
                if (n%p==0){
                    while(n%p==0)       n/=p;
                    result*=(1.0-(1.0/(double)p));
                }
            }
            if(n>1)
                result*=(1.0-(1.0/(double)n));
            return (ll)result;
        }

        void solve()
        {
            ll n,i,mx=0,j,x;
            cin>>n;
            ll a[n+5];
            for(i=1;i<=n;i++) scanf("%lld", &a[i]);
            for(i=1;i<=n;i++)
            {
                x=a[i];
                for(j=2;j*j<=x;j++)
                {
                    if(x%j==0)
                    {
                        while(x%j==0)
                        {
                            x=x/j;
                        }
                        mp[j]++;
                        mx=max(mp[j],mx);
                    }
                }
                if(x>1) mp[x]++;
                mx=max(mx,mp[x]);
                //cout<<mx<<endl;
            }
            if(mx==1) cout<<"pairwise coprime";
            else if(mx==0) cout<<"pairwise coprime";
            else if(mx<n) cout<<"setwise coprime";
            else cout<<"not coprime";



        }



};
int main()
{
    Myfirst *prg = new Myfirst();
    prg->solve();
}



Measured memory_bytes: 16316
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define int long long
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;


signed main(){
	
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(b,c)<<" ";
	if(a>=b+c)cout<<0<<endl;
	else cout<<b+c-a<<endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define BALL 1

int main(void)
{
	char cup_l = '0';
	char cup_r = '0';
	int a = BALL;
	int b = 0; 
	int c = 0; 
	int m = 0;/*入れ替えるときに一時的に退避する変数*/


	while(scanf("%c,%c", &cup_l, &cup_r) != EOF)
	{
		if(cup_l == 'A' && cup_r =='B')
		{
			m = a;
			a = b;
			b = m;
		}
		else if(cup_l == 'A' && cup_r == 'C')
		{
			m = a;
			a = c;
			c = m;
		}
		else if(cup_l == 'B'  && cup_r == 'C')
		{
			m = b;
			b = c;
			c = m;
		}
		else if(cup_l == 'B'  && cup_r == 'A')
		{
			m = b;
			b = a;
			a = m;
		}
		else if(cup_l == 'C'  && cup_r == 'A')
		{
			m = c;
			c = a;
			a = m;
		}
		else if(cup_l == 'C'  && cup_r == 'B')
		{
			m = c;
			c = b;
			b = m;
		}
	}
	if(a == BALL)
	{
		printf("A\n");
	}
	else if(b == BALL)
	{
		printf("B\n");
	}
	else if(c == BALL)
	{
		printf("C\n");
	}

	return 0;
}

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

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

    vector<int> minCost(n);
    for (int i = 1; i < n; i++) {
        if (i == 1)
            minCost[i] = abs(height[i] - height[i - 1]);
        else {
            int firstStone = abs(height[i] - height[i - 1]) + minCost [i - 1];
            int secondStone = abs(height[i] - height[i - 2]) + minCost[i - 2];
            minCost[i] = min(firstStone, secondStone);
        }
    }

    cout << minCost.back();
    return 0;
}

Measured memory_bytes: 3640
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

int main(){
  int N, i;
  cin >> N >> i;
  int ans = N + 1 - i;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static Scanner scn=new Scanner (System.in);
    public static void main(String []args){
        ans();
    }
    public static void ans(){
        String str=scn.nextLine();
        if(str.length()<6)
        System.out.print("No");
        else{
            char ch1=str.charAt(2);
            char ch2=str.charAt(3);
            char ch3=str.charAt(4);
            char ch4=str.charAt(5);
            if(ch1==ch2 && ch3==ch4)
            System.out.print("Yes");
            else 
            System.out.print("No");
        }
    }
}
  

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

int main(){
    int X;
    cin>>X;
    if (X>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    int n,k;
    long long temp;
    long long ans;

    vector<long long> num;

    cin >> n >> k;
    while(n!=0 && k!=0) {
        for(int i=0; i<n; ++i) {
            cin >> temp;
            num.push_back(temp);
        }

        ans=0;

        for(int i=0; i<k; ++i) {
            ans+=num[i];
        }

        temp=ans;

        if(k!=n) {
            for(int i=k; i<n; ++i) {
                temp=temp+num[i]-num[i-k];
                ans=MAX(ans,temp);
            }
        }

        cout << ans << endl;
        num.clear();
        cin >> n >> k;
    }
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MN = 2e5;
vector<ll> v[MN];
ll color[MN];
ll ok = 1;
void f(ll x, ll c) {
	if(color[x]) {
		if(color[x] != c) ok = 0;
		return;
	}
	color[x] = c;
	ll d = 1;
	if(c == 1) d = 2;
	for(auto y: v[x]) {
		f(y, d);
	}
}
int main() {
	ll n,m;
	cin>>n>>m;
	for(ll i = 0; i < m; ++i) {
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	f(1, 1);
	if(!ok) {
		cout<<(n*(n-1))/2 - m<<endl;
	}
	else {
		ll q = 0;
		for(int i = 1; i <= n; ++i) {
			if(color[i] == 1) ++q;
		}
		ll sum = 0;
		for(int i = 1; i <= n; ++i) {
			if(color[i] == 1) {
				sum += (n-q);
			}
			else {
				sum += q;
			}
		}
		cout<<sum/2-m<<endl;
	}
}


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

int main(){
	unsigned long int a,b,x,ans;
  	cin>>a>>b>>x;
  	
    if(a!=0){
  		ans=b/x-(a-1)/x;
    }else{
    	ans=b/x+1;
    }
  	cout<<ans<<endl;
}    

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	h := scanInt()
	w := scanInt()
	d := scanInt()

	a := make([]grid, h*w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			a[scanInt()-1] = grid{i,j}
		}
	}

	sum := make([]int, h*w-d+1)

	for i := 0; i < w*h-d; i++ {
		sum[i+1] = abs(a[i+d].x-a[i].x)+abs(a[i+d].y-a[i].y)
		if i+1-d >= 0 {
			sum[i+1] += sum[i+1-d]
		}
	}

	// fmt.Println(sum)

	q := scanInt()
	for j := 0; j < q; j++ {
		r,l := scanInt()-d,scanInt()-d
		if r < 0 {
			r = 0
		}
		if l < 0 {
			l = 0
		}

		fmt.Fprintln(wr,sum[l]-sum[r])
	}

	wr.Flush()

}

type grid struct {
	x int
	y int
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{


    ll n, ans = 0;
    cin >> n;
    vector<ll> v;
    for(ll i = 0; i < n; i++)
    {

        ll x;
        cin >> x;
        v.pb(x);
    }
    ll sz = v.size()-1;
    sort(v.begin(), v.end());
    cout << v[n/2]-v[n/2-1];
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 a,b,k;
    cin >> a >> b >> k;
    int64 eat = min(a,k);
    a -= eat;
    k -= eat;
    b = max<int64>(0, b - k);
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
s = input()

a = 0
b = 0
for si in s:
    if si == 'a' and a+b < A+B:
        a += 1
        print('Yes')
    elif si == 'b' and a+b < A+B and b < B:
        b += 1
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 4016
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=200005;
inline int read(){
	int u=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){u=u*10+c-'0';c=getchar();}
	return u*f;
}

int r,c;
struct P{
	int pos,x;
}p[4][maxn];
int cnt[4];
int is_bod(int x,int y){
	if(x==0)return 0;
	if(y==c)return 1;
	if(x==r)return 2;
	if(y==0)return 3;
	return -1; 
}
bool cmp1(P x,P y){
	return x.pos<y.pos;
}
bool cmp2(P x,P y){
	return x.pos>y.pos;
}
int sta[maxn];
int top=0,n;
int main(){
	r=read();c=read();n=read();
	for(int i=1;i<=n;i++){
		int x[2],y[2];
		scanf("%d%d%d%d",&x[0],&y[0],&x[1],&y[1]);
		bool flag=1;
		for(int j=0;j<2;j++){
			if(x[j]%r&&y[j]%c)flag=0;
		}
		if(flag){
			for(int j=0;j<2;j++){
				int xx=is_bod(x[j],y[j]);
				cnt[xx]++;p[xx][cnt[xx]].x=i;
				p[xx][cnt[xx]].pos=(xx%2?x[j]:y[j]);
			}
		}
		
	}
	for(int i=0;i<4;i++){
		if(i<2)sort(p[i]+1,p[i]+cnt[i]+1,cmp1);
		else sort(p[i]+1,p[i]+cnt[i]+1,cmp2);
		for(int j=1;j<=cnt[i];j++){
			if(sta[top]==p[i][j].x&&top)top--;
			else top++,sta[top]=p[i][j].x;
		}
	}
	if(top!=0)puts("NO");
	else puts("YES");
	return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  string str;
  cin>>str;
  if(str=="SUN"){
    a=7;
  }
  if(str=="MON"){
    a=6;
  }
  if(str=="TUE"){
    a=5;
  }
  if(str=="WED"){
    a=4;
  }
  if(str=="THU"){
    a=3;
  }
  if(str=="FRI"){
    a=2;
  }
  if(str=="SAT"){
    a=1;
  }
  cout<<a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,x,y,i,r=0,c;
    string a;
    cin>>a;
    n = a.length();
    for(i=0;i<n;i++)
    {
        if(a[i]!='0')
        {
          for(c=i+1;c<n;c++)
          {
               if(a[i]==a[c])
               {
                   r++;
                   a[c] = '0';
               }
          }
        }

    }
     if(r==0)
        cout<<"yes"<<endl;
     else
        cout<<"no"<<endl;
    return 0;
}


Measured memory_bytes: 384
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-28 21:06:14
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int m = 0;
    for (int i = 0; i < n-1; i++) {
        int dist = a[i+1] - a[i];
        if (m < dist) m = dist;
    }
    if (m < a[0] + k - a[n-1]) m = a[0] + k - a[n-1];

    int ans = k - m;
    cout << ans << endl;

    return 0;
}


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

int main() {
  int n; cin >> n;
  int a[210];
  for(int i=0; i<n; i++) {
    cin >> a[i];
  };

  sort(a, a+n, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for(int i=0; i<n; i++) {
    if (i%2 == 0) Alice += a[i];
    else Bob += a[i];
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)

using namespace std;

int main() {
  int A, B;
  
  scanf("%d %d", &A, &B);
  
  printf("%d\n", B % A == 0 ? A+B : B-A);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  int R;
  cin >> R;
  if(R < 1200)
    cout << "ABC" << endl;
  else if(R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}

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


int main() {
  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(10));
  for(int i= 0;i<N;i++){
    for(int j = 0;j<10;j++){
      cin >> F[i][j];
    }
  }
  
  vector<vector<ll>> P(N, vector<ll>(11));
  for(int i= 0;i<N;i++){
    for(int j = 0;j<11;j++){
      cin >> P[i][j];
    }
  }
  ll ans = -1000000000;
  for(int bit = 1;bit < (1<<10);bit++){//10桁のbitは姉の店が開いている時間帯を表す
    ll x  = 0; 
    for(int i= 0;i<N;i++){
      int biti = 0;//各店iについて開いている時間帯の情報をbitiに保存
      for(int j = 0;j<10;j++){
        if(F[i][j] == 1){
          biti |= (1<<j);
        }
      }
      
        int bitk = (bit&biti);/*店iについていつ開いていているかをbitiに保存したら、
        bitiとbitのandを取り、1の個数（姉の店と店iが共に営業している時間帯の数cを求める*/
        int c = __builtin_popcount(bitk);
        x += P[i][c];//ｘにその時の利益を足す
    }
    ans = max(ans,x);
  }
  
  cout << ans << endl;

    
}


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

#define MAXN 2000
struct Edge{
    int v,u;
}E[MAXN+5];
int N,K;
vector<int> G[MAXN+5];

int dfs(int u,int f,int MaxD,int D){
    int ret=0;
    if(D>MaxD)
        ret++;
    for(int i=0;i<int(G[u].size());i++){
        int v=G[u][i];
        if(v!=f)
            ret+=dfs(v,u,MaxD,D+1);
    }
    return ret;
}

int main(){
    scanf("%d%d",&N,&K);
    for(int i=1;i<N;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
        E[i]=(Edge){u,v};
    }
    int Ans=N;
    if(K&1)
        for(int i=1;i<N;i++)
            Ans=min(Ans,dfs(E[i].u,E[i].v,K/2,0)+dfs(E[i].v,E[i].u,K/2,0));
    else
        for(int i=1;i<=N;i++)
            Ans=min(Ans,dfs(i,-1,K/2,0));
    printf("%d",Ans);
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            String[] values = line.split(",");
            double[] xs = new double[4];
            double[] ys = new double[4];
            for (int i = 0; i < 4; i++) {
                xs[i] = Double.parseDouble(values[i * 2]);
                ys[i] = Double.parseDouble(values[i * 2 + 1]);
            }

            double[] dxs = new double[4];
            double[] dys = new double[4];
            for (int i = 0; i < 4; i++) {
                dxs[i] = xs[(i + 1) % 4] - xs[i];
                dys[i] = ys[(i + 1) % 4] - ys[i];
            }

            String result = "YES";
            double signum = calcSignum(dxs[3], dys[3], dxs[0], dys[0]);
            for (int i = 0; i < 3; i++) {
                double s = calcSignum(dxs[i], dys[i], dxs[i + 1], dys[i + 1]);
                if (s != signum) {
                    result = "NO";
                    break;
                }
            }
            out.println(result);
        }
    }

    private static double calcSignum(double x1, double y1, double x2, double y2) {
        return Math.signum(x1 * y2 - x2 * y1);
    }
}

Measured memory_bytes: 9740
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int a[n], b[n];
    int c[m],d[m],arr[m];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    for(int i=0;i<m;i++) cin>>c[i]>>d[i];
    for(int i=0;i<n;i++){ int ans=1e9;
        for(int j=0;j<m;j++){
            //cout<<abs(a[i]-c[j])+ abs(b[i]-d[j])<<endl;
            ans=min(ans , abs(a[i]-c[j])+ abs(b[i]-d[j]) );
            arr[j]= abs(a[i]-c[j])+ abs(b[i]-d[j]) ;
        }
        for(int k=0;k<m;k++){ //cout<<k<<endl;
            if(arr[k]==ans){
                cout<<k+1<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

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...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, P;
	cin >> N >> M >> P;
	while (N != 0) {
		double dP = (double)P;
		double sum = 0;
		double hit = 0;
		REP(i, N) {
			double X;
			cin >> X;
			sum += X;
			if (i + 1 == M)hit = X;
		}
		if (abs(hit) < EPS)cout << 0 << endl;
		else cout << (int)(sum* (100.0 - P) / hit) << endl;
		cin >> N >> M >> P;
	}
	return 0;
}



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

int main() {
  
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B >= C+D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
  
return 0;
}

Measured memory_bytes: 3592
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  solve_his = [];
  for (let i = 0; i < n1; i++)solve_his[i]=[];
  const solve = (i, m) => {
    if (m == 0) return true;
    if (i >= n1) return false;
    let res;
    if (res = solve_his[i][m]) return res;

    res = solve(i + 1, m) || solve(i + 1, m - arr1[i]);
    solve_his[i][m] = res;
    return res;
  };

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();



Measured memory_bytes: 18172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int [] deg = new int[4];
		for (int i = 0; i < 3; ++i) {
			int u = sc.nextInt()-1, v = sc.nextInt()-1;
			deg[u]++;
			deg[v]++;
		}
		int odd = 0;
		for (int i = 0; i < deg.length; ++i) {
			if(deg[i] % 2 != 0)
				odd++;
		}
		out.println(odd == 2?"YES":"NO");
		out.close();
	}
	
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
	}

}


Measured memory_bytes: 22228
#coding: utf-8
k, x = map(int, input().split())

answer = []
for i in (range(x-k+1,x+k)):
    # print(i)
    if x+i >= -10000 and i <= 10000:
        # print(i)
        answer.append(i)

print(" ".join(map(str,answer)))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;


int main() {
  ll x, k, d;
  cin>>x>>k>>d;
  ll x1=abs(x);
  ll a=x1/d;
  ll ans;
  if(a>k)ans=x1-(k*d);
  else{
    ll a1=x1-(a*d);
    ll a2=x1-((a+1)*d);
    if((k-a)%2==0)ans=abs(a1);
    else ans=abs(a2);
  }
cout<<ans;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
struct Node{
    string s;
    int a;
    int index;
    bool operator<(const Node b)const{
        if(s.compare(b.s)==0){
            return a>b.a;
        }
        return s.compare(b.s)<0;
    }
};
Node a[1111];
int main()
{
    int n;
    cin >>n;
    for(int i=0;i<n;i++){
        cin >> a[i].s>> a[i].a;
        a[i].index=i+1;
    }
    sort(a,a+n);
     for(int i=0;i<n;i++){
        cout << a[i].index<<endl;
     }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    int ans = n*n*n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

signed main(){
	IOS;
	string s;
	cin >> s;
	int n = s.size();
	ll ans = 30000;
	for(int i = 0;i <= n - 3;i++){
		ll tmp = abs(stoi(s.substr(i,3)) - 753);
		ans = min(ans,tmp);
	}
	dump(ans);
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	int count[n]={0};
	for(int i=1;i<n;i++){
		cin>>a[i];
		count[a[i]-1]++;
	}
	for(int i=0;i<n;i++){
		cout<<count[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5200
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
ans = 0
if cnt % 2 == 0:
    for i in range(n):
        ans += abs(a[i])
    print(ans)
else:
    tar = abs(a[0])
    for i in range(n):
        ans += abs(a[i])
        if tar > abs(a[i]):
            tar = abs(a[i])
    print(ans-2*tar)


Measured memory_bytes: 14412
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> W(N);
    rep(i, N) cin >> W[i];
    
    set<string> S;
    char old = W[0][W[0].size() - 1];
    S.insert(W[0]);
    string judge = "Yes";
    REP(i, N) {
        if (old != W[i][0]) judge = "No";
        if (S.count(W[i])) judge = "No";
        old = W[i][W[i].size() - 1];
        S.insert(W[i]);
    }
    cout << judge << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {

    int i;
    int h, a, ans;

    scanf("%d%d", &h, &a);
    
    if(h % a == 0) {
        ans = h / a;
    }
    else {
        ans = h / a + 1;
    }

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b;
    cin >> a >> b;

    int mx = b - a;
    int h = mx * (mx-1) / 2;
    cout << h - a << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    H, W, K = map(int, input().split())
    matrix = []
    for _ in range(H):
        c = list(input())
        matrix.append(c)
    ans = 0

    for row in range(2**H):
        for col in range(2**W):
            countK = 0
            for h in range(H):
                for w in range(W):
                    if matrix[h][w] == "#":
                        if (row >> h)&1 and (col >> w)&1:
                            countK += 1
            if countK == K:
                ans += 1
    print(ans)



if __name__ == '__main__':
    solve()

Measured memory_bytes: 73208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
ll mod(ll Q,int W){
  if(Q>0) return Q%W;
  else while(Q<0) Q+=W;
  return Q;
}
int main(){
  ll N,M;
  int L=1000000007;
  cin>>N>>M;
  vector<int> A(N),B(M);
  rep(i,N) cin>>A[i];
  rep(i,M) cin>>B[i];
  ll X[N+1][M+1]={},S[N+1][M+1]={};
  rep(i,N){
    rep(j,M){
      if(A[i]==B[j]) X[i+1][j+1]=(S[i][j]+1)%L;
      S[i+1][j+1]=mod(S[i][j+1]+S[i+1][j]-S[i][j]+X[i+1][j+1],L);
    }
  }
  cout<<(S[N][M]+1)%L<<endl;
}

Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
#define M 1000010
#define MOD 998244353
inline int read() {
	char ch = getchar(); int x = 0, f = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
int a[M], b[M];
int mu[M], pri[M], tot;
bool vis[M];
int f[M];
inline void Add(int &x, int y) {
	if(y < 0) y += MOD;
	x += y;
	if(x >= MOD) x -= MOD;
}
inline int Power(int x, int y) {
	int ret = 1;
	while(y) {
		if(y & 1) ret = 1ll * ret * x % MOD;
		x = 1ll * x * x % MOD; y >>= 1;
	}
	return ret;
}
inline void init(int m) {
	mu[1] = 1;
	for(int i = 2; i <= m; ++ i) {
		if(!vis[i]) {
			pri[++ tot] = i;
			mu[i] = -1;
		}
		for(int j = 1; j <= tot; ++ j) {
			if(i * pri[j] > m) break;
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0) {
				mu[i * pri[j]] = 0;
			}
			else mu[i * pri[j]] = -mu[i];
		}
	}
	for(int i = 1; i <= m; ++ i) {
		int inv = Power(i, MOD - 2);
		for(int j = 1; i * j <= m; ++ j) {
			Add(f[i * j], inv * mu[j]);
		}
	}
}
int main() {
	int n = read(), m = 1000000;
	for(int i = 1; i <= n; ++ i) {
		int x = read();
		Add(b[x], x);
		a[i] = x;
	}
	for(int i = 1; i <= m; ++ i) {
		for(int j = i + i; j <= m; j += i) {
			Add(b[i], b[j]);
		}
	}
	init(m);
	int Ans = 0;
	for(int i = 1; i <= m; ++ i) {
		Add(Ans, 1ll * b[i] * b[i] % MOD * f[i] % MOD);
	}
	for(int i = 1; i <= n; ++ i) {
		Add(Ans, MOD - a[i]);
	}
	Ans = 1ll * Ans * Power(2, MOD - 2) % MOD;
	printf("%d\n", Ans);
}


Measured memory_bytes: 16768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] xs = new int[5];
		
		int checker = 0;
		
		for(int i = 0 ; i < 5 ; i++){
			xs[i] = sc.nextInt();
			if(xs[i] != i+1){
				checker = i+1;
			}
		}
		
		System.out.println(checker);

	}

}

Measured memory_bytes: 27000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string A, B;
    cin >> A >> B;
    int M = sz(A), N = sz(B);
    int dp[M+1][N+1];
    rep(i, M+1) dp[i][0] = i;
    rep(j, N+1) dp[0][j] = j;
    rep(i, M){
        rep(j, N){
            dp[i+1][j+1] = min({dp[i+1][j]+1, dp[i][j+1]+1, dp[i][j]+(A[i] != B[j])});
        }
    }
    cout << dp[M][N] << endl;
}


Measured memory_bytes: 7128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	cout<<(n*(n-1))/2;
	return 0;
}	

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

const int N = (1<<18);

int A[N];
int dp[N];

set<pair<int,int> >ret[N];

void solve() {
    int n;
    scanf("%d",&n);
    int lim = (1<<n);
    for(int i=0;i<lim;++i) {
        scanf("%d",&A[i]);
    }
    ret[0].insert(make_pair(A[0],0));
    int prev = 0;
    set<pair<int,int> >::iterator it;
    for(int bit=1;bit<lim;++bit) {
        for(int i=0;i<n;++i) {
            if(bit&(1<<i)){
                int x = bit^(1<<i);
                for(it  = ret[x].begin();it!= ret[x].end();++it) {
                    ret[bit].insert(*it);
                }
                while(ret[bit].size()>2) {
                    ret[bit].erase(ret[bit].begin());
                }
            }
        }
        ret[bit].insert(make_pair(A[bit],bit));
        if(ret[bit].size()>2) {
            ret[bit].erase(ret[bit].begin());
        }
        
        if(ret[bit].size()==2) {
            int x = 0;
            for(it = ret[bit].begin();it!= ret[bit].end();++it) {
                x += (*it).first;
            }
            prev = max(prev,x);
        }
        printf("%d\n", prev);
    }
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 41984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    double v;
    int i;
    priority_queue<double, vector<double>, greater<double>> pot;
    double ans = 0;

    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> v;

        pot.push(v);
    }

    while (pot.size() != 1)
    {
        double x, y;

        x = pot.top();
        pot.pop();
        y = pot.top();
        pot.pop();

        ans += (x + y) / 2;

        pot.push((x + y) / 2);
    }

    printf("%.6f\n", pot.top());
}

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

int main(){
  int n;	cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  int cp = -1;
  rep(i,n){
    if(cp == a[i]){
      puts("NO");
      return 0;
    }
    cp = a[i];
  }
  puts("YES");
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm> 
#include<string>
using namespace std;
string st;
int a[10];

int main(){
   cin >> st;
   int i=0;
   int p;

   do{
   	   if(st[i+1]>st[i]) {p=st[i]+1;break; }
   	   if(st[i+1]<st[i]) {p=st[i];break;}
       i++;
   }while(1);
   for(int j=0; j<=st.size()-1; j++){
        st[j]=p;
	}
//   }
   cout << st;
   return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	if ('A' <= s[k - 1] && s[k - 1] <= 'Z') {
		s[k - 1] += 'a' - 'A';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll w[100005];
ll s[100005];
ll dp[105][100005];
ll ans = 0;
ll mxw,n;
ll rec(ll index , ll weight)
    {

        if(index>=n)
            {
                return 0 ;
            }
        if(dp[index][weight]!=0)
            return dp[index][weight];
        ll res =0;
        res = max(res,rec(index+1,weight));
        if(weight+w[index]<=mxw)
        res = max(res,rec(index+1,weight+w[index])+s[index]);
        dp[index][weight] = res;

        ans = max(dp[index][weight],ans);
        return res;
    }
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>mxw;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>s[i];
    }
    rec(0,0);
    cout<<ans<<endl;

}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    int M = 0;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        int a; cin >> a;
        while(a != 0 && a % 2 == 0) {
            A[i]++;
            a /= 2;
        }
    }
    sort(A.begin(), A.end());
    cout << A[0] << endl;
    return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

bool ope(int c, string &S, vector<pair<char,char>> &O, int f) {
    for (int i = 0; i < O.size(); i++) {
        if (S[c] == O[i].first) {
            c += (O[i].second == 'L' ? -1 : 1);
        }
        if (f == 0 && c >= (int)S.size()) return true;
        if (f == 1 && c < 0) return true;
        if (f == 0 && c < 0) return false;
        if (f == 1 && c >= (int)S.size()) return false;
    }
    return true;
}

void solve() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<pair<char,char>> O(Q);
    for (int i = 0; i < Q; i++) {
        char c, d;
        cin >> c >> d;
        O[i] = {c, d};
    }

    int l = -1, r = N + 1;
    while(r - l > 1) {
        int c = (r + l) / 2;
        bool ok = ope(c, S, O, 0);

        if (ok) {
            r = c;
        } else {
            l = c;
        }
    }
    int ok_l = r;

    l = -1, r = N + 1;
    while(r - l > 1) {
        int c = (r + l) / 2;
        bool ok = ope(c, S, O, 1);
        if (ok) {
            l = c;
        } else {
            r = c;
        }
    }
    int ok_r = l;

    cout << ok_r - ok_l + 1 << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 976
#include <iostream>

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::cout << n * (n - 1) / 2 + m * (m - 1) / 2 << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		int sum=a+b;
		int digit=1;
		while(sum>=10){
			sum/=10;
			digit++;
		}
		printf("%d\n",digit);
	}
	return 0;
}

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

#define N 200010
#define M 400010

using namespace std;

int ans[N];
int ver[M],nex[M],head[N],nu;
int n,x1,x2;

inline int read(){
	int x=0;char c=getchar();
	for(;c<'0' || c>'9';c=getchar());
	for(;c>='0' && c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-48;
	return x;
}

inline void add(int x,int y){
	ver[++nu]=y;nex[nu]=head[x];head[x]=nu;
}

void dfs(int x,int fa){
	for(int i=head[x];i;i=nex[i]){
		int y=ver[i];
		if(y!=fa)
		{
			dfs(y,x);
			ans[x]^=(ans[y]+1);
		}	
	}
	return;
}

int main(){
	n=read();
	for(int i=1;i<n;i++)
	x1=read(),x2=read(),add(x1,x2),add(x2,x1);
	dfs(1,0);
	if(!ans[1]) printf("Bob\n");
	else printf("Alice\n");
	return 0;
}                                                                                                                                                                                                                     

Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int sum(int *a,int i,int j){
    int sum=0;
    for(int k=i;k<=j;k++){
        sum+=a[k];
    }
    return sum;
}
int slime(int *a,int i,int j,int dp[][401]){
    if(i>=j){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int ans=LONG_LONG_MAX;
    for(int k=i;k<=j-1;k++){
        ans=min(ans,slime(a,i,k,dp)+slime(a,k+1,j,dp));
    }
    return dp[i][j]=sum(a,i,j)+ans;
}
int32_t main(){
    int n;
    cin>>n;
    int a[401];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int dp[401][401];
    memset(dp,-1,sizeof dp);
    cout<<slime(a,1,n,dp)<<endl;
    return 0;
}

Measured memory_bytes: 1536
// In god we trust

#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>


#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000
#define int long long

using namespace std;
using namespace std::chrono;


signed main(){
  string s;
  cin >> s;
  bool a, b;
  a = b = false;
  for (int i = 0; i < 3; i++)
    if (s[i] == 'A')
      a = true;
    else
      b = true;
  if (a && b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const int INF = 1 << 28;

int dp[200010];

int main() {
    string s; cin >> s;
    int n = s.size();
    dp[0] = 0;
    dp[1] = 1;
    dp[2] = (s[0] != s[1] ? 2 : 1);

    for (int i = 3; i <= n ; i++) {
        dp[i] = (s[i - 1] != s[i - 2] ? dp[i - 1] + 1 : dp[i - 3] + 2);
    }

    cout << dp[n] << endl;
}




Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main(){
  ll D, G;
  cin >> D >> G;
  vector<ll> p(D+1), c(D+1);
  for(int i=1; i<=D; i++) cin >> p.at(i) >> c.at(i);

  int ans = 1001001;
  //コンプリートする問題をbit全探索する
  vector<ll> comp_solve(D+1);//これをコメントアウトするとテストケースa04がWAになる??
  //for(int i=1; i<=D; i++) comp_solve[i] = 100*i*p[i] + c[i];
  
  for(int i=0; i<(1<<D);i++){//2^D回(最大1024回)ループ
    vector<bool> is_solve(D+1,false);
    int score = 0;
    int num_solve = 0;
    bool is_ok = false;//目標点を越えたらtrue
    for(int j=1; j<=D ; j++){//j*100点問題を解くか解かないのか?のD回ループ     
      if(i & (1<<(j-1))){//j*100点の問題を解くなら...
        score += 100*j*p[j] + c[j];
        num_solve += p[j];
        is_solve[j] = true;
        //cout << " i: "<<i<<" j: "<<j <<" score: "<<score<<" num_solve: "<<num_solve<< endl;
        if(score >= G){
          is_ok = true;
          ans = min(ans, num_solve);
          //cout << "yah1" <<endl;
          break;//jループを抜ける
        }
      }
    }
    if(is_ok) continue;//iループを次へすすめる
    /*for(int j=D; j>=1; j--){
      cout << "is_solve["<<j<<"]: " << is_solve[j] << " ";
    } cout << endl;*/
    for(int j=D; j>=1; j--){//コンプリートしてない問題で一番得点の高い問題を数問解く(全完しない)
      if(is_solve[j]==true) continue;
      int left_score = G - score;
      int num = ceil( (double)left_score / (100*j));//切り上げ!!int同士の計算だと切り下げになるからdoubleにキャスト
      if(num <= p[j]){
        num_solve += num;
        score += num_solve* 100*j;
      }
      //cout << " left_score: " << left_score<<" num: " <<num<<" num_solve: "<<num_solve<<" p["<<j<<"]: "<<p[j]<<endl;
      if(score >= G) ans = min(ans, num_solve);
      break;//コンプリートしない問題は１種類だけなのでjループを抜ける
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256