akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
    int n,ans=100000;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        ans*=1.05;
        if(ans%1000){
            ans+=1000;
            ans-=ans%1000;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 2756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            c = a + b;
            if (c < a - b)  c = a - b;
            if (c < a * b)  c = a * b;

            Console.WriteLine(c);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
int N, M, A[201010];
int C[201010];
int L[201010], R[201010];
int non[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, N) cin >> A[i];

    int ans = N;
    rep(i, 0, N + 1) non[i] = 1;

    rep(i, 0, N) {
        int a = A[i];
        if (non[a]) {
            L[a] = R[a] = a;
            if (C[a] == 0) ans--;
            C[a]++;
            non[a] = 0;
        } else {
            L[a]--;
            if (0 < L[a]) {
                if (C[L[a]] == 0) ans--;
                C[L[a]]++;
            }
        }
    }

    rep(q, 0, M) {
        int x, y; cin >> x >> y;
        x--;

        int a = A[x];
        if (L[a] == R[a]) {
            if (C[a] == 1) ans++;
            C[a]--;
            non[a] = 1;
        } else {
            if (0 < L[a]) {
                if (C[L[a]] == 1) ans++;
                C[L[a]]--;
            }
            L[a]++;
        }

        A[x] = y;

        a = y;
        if (non[a]) {
            L[a] = R[a] = a;
            if (C[a] == 0) ans--;
            C[a]++;
            non[a] = 0;
        }
        else {
            L[a]--;
            if (0 < L[a]) {
                if (C[L[a]] == 0) ans--;
                C[L[a]]++;
            }
        }

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

Measured memory_bytes: 5376
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

a = I()

print(a + a*a + a*a*a)


Measured memory_bytes: 61684
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int ans=0;
		int j=0;
		while(j<s.size()){
			int cnt=0;
			int t=0;
			while(s[j+t+1]!='0'){
				if(s[j]=='0')break;
				t++;
			}
			if(s[j]=='1'){
				if((t+1)%5==1){
					cout<<".";
				}
				if((t+1)%5==2){
					cout<<",";
				}
				if((t+1)%5==3){
					cout<<"!";
				}
				if((t+1)%5==4){
					cout<<"?";
				}
				if((t+1)%5==0){
					cout<<" ";
				}
			}
			if(s[j]=='2'){
				if((t+1)%3==1){
					cout<<"a";
				}
				if((t+1)%3==2){
					cout<<"b";
				}
				if((t+1)%3==0){
					cout<<"c";
				}
			}
			if(s[j]=='3'){
				if((t+1)%3==1){
					cout<<"d";
				}
				if((t+1)%3==2){
					cout<<"e";
				}
				if((t+1)%3==0){
					cout<<"f";
				}

			}
			if(s[j]=='4'){
				if((t+1)%3==1){
					cout<<"g";
				}
				if((t+1)%3==2){
					cout<<"h";
				}
				if((t+1)%3==0){
					cout<<"i";
				}
			}
			if(s[j]=='5'){
				if((t+1)%3==1){
					cout<<"j";
				}
				if((t+1)%3==2){
					cout<<"k";
				}
				if((t+1)%3==0){
					cout<<"l";
				}
			}
			if(s[j]=='6'){
				if((t+1)%3==1){
					cout<<"m";
				}
				if((t+1)%3==2){
					cout<<"n";
				}
				if((t+1)%3==0){
					cout<<"o";
				}
			}
			if(s[j]=='7'){
				if((t+1)%4==1){
					cout<<"p";
				}
				if((t+1)%4==2){
					cout<<"q";
				}
				if((t+1)%4==3){
					cout<<"r";
				}
				if((t+1)%4==0){
					cout<<"s";
				}
			}
			if(s[j]=='8'){
				if((t+1)%3==1){
					cout<<"t";
				}
				if((t+1)%3==2){
					cout<<"u";
				}
				if((t+1)%3==0){
					cout<<"v";
				}
			}
			if(s[j]=='9'){
				if((t+1)%4==1){
					cout<<"w";
				}
				if((t+1)%4==2){
					cout<<"x";
				}
				if((t+1)%4==3){
					cout<<"y";
				}
				if((t+1)%4==0){
					cout<<"z";
				}
			}
			j+=t+1;
			
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1204
N=int(input())
T,A=map(int,input().split())
H=[i for i in map(int,input().split())]
t1,t2=0,100000
for i in range(N):
	t1=T-H[i]*0.006
	if(abs(A-t1) < abs(A-t2)):
		t3=i+1
		t2=t1
		t1=0
	else:
		t1=0
print(t3)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,maxi=0;
    string s,t;
    scanf("%d",&n);
    map<string,int>ma;
    for(int i=0;i<n;++i){
        cin>>s;
        ++ma[s];
    }
    scanf("%d",&m);
    for(int i=0;i<m;++i){
        cin>>t;
        --ma[t];
    }
    for(auto i:ma)
        if(i.second>maxi)
            maxi=i.second;
    printf("%d",maxi);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i,j;
	int temp1,temp2;
	int x[3] ;

//	for(i=0 ; i<5; i++){
//		x[i] = 0 ;
//	}

//	printf("??´??°????????????????????????????¢??????¨???\n");
	scanf("%d %d %d",&x[0],&x[1],&x[2]);

//	printf("x1=%d x2=%d x3=%d x4=%d x5=%d\n",x[0],x[1],x[2],x[3],x[4]);
//	printf("\n");
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			if(x[i] < x[j]){

				temp1=x[i];
				temp2=x[j];
				x[j]=temp1;
				x[i]=temp2;

//				printf("????????\??????????????????\n");
//				printf("x1=%d x2=%d x3=%d x4=%d x5=%d\n",x[0],x[1],x[2],x[3],x[4]);		
			}
    		else{
//				printf("????????\??????????????????\n");
	//			printf("x1=%d x2=%d x3=%d x4=%d x5=%d\n",x[0],x[1],x[2],x[3],x[4]);
			}
			
		}
//		printf("\n");
	}
//        printf("??????????????????????????????\n");
		printf("%d %d %d\n",x[0],x[1],x[2]);
	return 0;

}

Measured memory_bytes: 596
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        //PrintWriter pw = new PrintWriter("TaskC.out");
        long n = sc.nextLong();
        long min = Long.MAX_VALUE;
        for(int i = 1; i<=Math.sqrt(n); i++){
            if(n%i == 0 && n/i <= n){
                min = Math.min(min, (i-1) + (n/i - 1));
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 1e5 + 10;
VI f[N];
int p[N];

template<class T>
int SZ(T x) { return x.size(); }

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, m; cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    f[x % m].push_back(x);
  }

  for (int x = 0; x < m; x++) {
    sort(f[x].begin(), f[x].end());
    int prv = -1;
    for (int y: f[x]) {
      if (y == prv) {
        p[x]++;
        prv = -1;
      } else {
        prv = y;
      }
    }
  }

  int ans = 0;
  for (int x = 1, y = m - 1; x < y; x++, y--) {
    int cur = min(f[x].size(), f[y].size());
    ans += cur;
    ans += max(0, min(p[x], (SZ(f[x]) - cur) / 2));
    ans += max(0, min(p[y], (SZ(f[y]) - cur) / 2));
  }
  ans += f[0].size() / 2;
  if (m % 2 == 0) ans += f[m / 2].size() / 2;
  cout << ans << endl;

  return 0;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

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


struct UnionFind {
    vector<int> Parent;
    vector<int> Size;

    UnionFind(int N) : Parent(N), Size(N,1){
        for(int i = 0; i < N; i++) Parent[i] = i;
    }

    int root(int A) {
        if (Parent[A] == A) return A;
        return Parent[A] = root(Parent[A]);
    }

    bool merge(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) return false;

        if (Size[A] < Size[B]) swap(A, B);

        Size[A] += Size[B];
        Parent[B] = A;
        return true;
    }

    bool issame(int A, int B) { //
        return root(A) == root(B);
    }

    int findsize(int A) {
        return Size[root(A)];
    }
};

signed main() {
    int n,m,k;
    cin >> n >> m >> k;

    UnionFind F(n);
    map<int,int> mp;

    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--, b--;
        mp[a]++, mp[b]++;
        F.merge(a,b);
    }
    vector<P> block(k);
    for(int i = 0; i < k; i++){
        cin >> block[i].first >> block[i].second;
        block[i].first--, block[i].second--;
    }

    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        ans[i] = F.findsize(i) - 1 - mp[i];
    }

    for(int i = 0; i < k; i++){
        int x = block[i].first, y = block[i].second;
        if(F.issame(x,y)){
            ans[x]--, ans[y]--;
        }
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int a,b;
		cin >> a >> b;
		if(a>b) swap(a,b);
		if(a==1 && b==2) cout<<3;
		if(a==1 && b==3) cout<<2;
		if(a==2 && b==3) cout<<1;
	}   
}     

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(A: int, B: int):
    for C in range(1,4):
        if (A*B*C) % 2 == 1:
            print(YES)
            return
    print(NO)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
using namespace std;
typedef complex<double> P;

double cross(const P& a, const P& b)
{
  return imag(conj(a) * b);
}

double area2(const vector<P>& v)
{
  double a = 0.0;
  const int N = v.size();
  for (int i = 0; i < N; i++) {
    a += cross(v[i], v[(i+1)%N]);
  }
  return abs(a)/2.0;
}

int main()
{
  int N;
  int c = 1;
  while (cin >> N && N != 0) {
    vector<P> polygon(N);
    for (int i = 0; i < N; i++) {
      cin >> polygon[i].real() >> polygon[i].imag();
    }
    printf("%d %.1f\n", c++, area2(polygon));
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  double A, B, H, M; cin >> A >> B >> H >> M;
  const double pi = 3.141592653589793;
  double h = H/12*360 + M/60*30;
  double m = M/60*360;
  double a = abs(h-m) > 180 ? 360-abs(h-m) : abs(h-m);
  if(a == 0){
    cout << fixed << setprecision(12) << abs(A-B) << endl;
  }else if(a == 180){
    cout << fixed << setprecision(12) << A+B << endl;
  }else if(a == 90){
    cout << fixed << setprecision(12) << sqrt(A*A+B*B) << endl;
  }else{
    cout << fixed << setprecision(12) << sqrt(A*A+B*B-2*A*B*cos(pi*a/180)) << endl;
  }
}

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

int main(){
	int inning,score;
	int out,runner;
	string str;
	cin>>inning;
	for(int i=0;i<inning;i++){
		score=runner=out=0;
		while(out<3){
			cin>>str;
			if(str=="OUT")out++;
			if(str=="HIT")runner++;
			if(runner==4){
				score++;
				runner--;
			}
			if(str=="HOMERUN"){
				score=score+runner+1;
				runner=0;
			}
		}
		cout<<score<<endl;
	}
}

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

int main() {
  int a=0,b=0,c=0;
  string s;
  cin>>s;
  rep(i,s.size()) {
    if(s[i]=='a')a++;
    if(s[i]=='b')b++;
    if(s[i]=='c')c++;
  }
  if(max(a,max(b,c))-min(a,min(b,c))<=1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 512
def main():
    n = int(input())
    al = list(map(int, input().split()))
    all_xor = 0
    for a in al:
        all_xor = all_xor ^ a

    ans = []
    for a in al:
        curr_ans = all_xor ^ a
        ans.append(curr_ans)

    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 114968
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int h[100000] = {};
int main() {
	int n, k, min = 1000000000;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	qsort(h, n, sizeof(int), cmpint);
	for (int i = 0; i <= n - k; i++) {
		if (h[i + k - 1] - h[i] < min) {
			min = h[i + k - 1] - h[i];
		}
	}
	printf("%d", min);
	return 0;
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mpr            make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    /*char ch;
    cin>>ch;
    if(ch>='a' && ch<='z')cout<<"a\n";
    if(ch>='A' && ch<='Z')cout<<"A\n";*/
    int n,k;
    cin>>n>>k;
    int p[n+5];
    for(int i=0;i<n;i++)cin>>p[i];
    srt1(p,n);
    ll sum=0;
    for(int i=0;i<k;i++)sum+=p[i];
    cout<<sum<<endl;
}



Measured memory_bytes: 3644
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    int h[30];
    memset(h, 0, sizeof(h));
    string s;
    cin >> s;
    for(auto &x : s){
        h[x - 'a']++;
    }
    for(int i = 1; i < n; i++){
        string s;
        cin >> s;
        vector<int> ch(30, 0);
        for(auto &x : s){
            ch[x - 'a']++;
        }
        for(int i = 0; i < 30; i++){
            h[i] = min(h[i], ch[i]);
        }
    }
    for(char x = 'a'; x <= 'z'; x++){
        while(h[x - 'a'] > 0){
            cout << x;
            h[x - 'a']--;
        }
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n, sum = 0, a = 0, b = 0;
    cin >> n;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    sort(all(v));
    rep(i, n)
    {
        sum += v[i];
        if (i % 2 == 0)
        {
            a += v[i];
        }
    }
    b = sum - a;
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
i = 0
flag = False
while i != (n-1):
    if flag is False:
        if a[i] == a[i+1]:
            first = a[i]
            i += 2
            flag = True
        else:
            i += 1
    else:
        if a[i] == a[i+1]:
            second = a[i]
            print(first*second)
            exit()

        else:
            i += 1

print(0)




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

using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int plus,minus,mul,ans;
    plus = a+b;
    minus = a-b;
    mul = a*b;
    ans = max(max(plus,minus),mul);
    cout << ans << endl;
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int n, k;
    cin >> n >> k;

    int mina = INT_MAX;
    vi a(n);
    rep(i, 0, n) {
        cin >> a[i];
        mina = min(mina, a[i]);
    }

    vi dp(k + 1, 0);
    rep(i, 0, mina) { dp[i] = -1; }

    rep(i, mina, k + 1) {
        rep(j, 0, n) {
            if (i - a[j] >= 0 && dp[i - a[j]] == -1) {
                dp[i] = 1;
                break;
            }
        }
        if (dp[i] == 0) { dp[i] = -1; }
    }

    cout << (dp[k] == 1 ? "First" : "Second") << endl;
    return 0;
}

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

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

    long long A;
    vector<long long> count(1e5 + 5, 0);
    long long ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A;
        count[A]++;
        ans += A;
    }

    size_t Q;
    cin >> Q;
    for (size_t i = 0; i < Q; i++)
    {
        long long B, C;
        cin >> B >> C;
        ans += C * count[B];
        ans -= B * count[B];
        count[C] += count[B];
        count[B] = 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 4044
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	string N;
	cin >> N;
	char prop_c[N.length()+1];
	for(int i=0;i<N.length();i++){
		prop_c[i]='9';
	}
	prop_c[N.length()]=0;
	string prop(prop_c);


	prop[0]=N[0];
	if(N==prop){
		cout << ( (N.length()-1)*9+((N[0]-'0')) ) << endl;
	}else{
		cout << ( (N.length()-1)*9+((N[0]-'0')-1) ) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<50;

int main(int argc, char **argv)
{
	ll H, W; cin >> H >> W;
	vector<vector<char>> vec(H+2, vector<char>(W+2));
	for (ll i = 1; i <= H; ++i)
		for (ll j = 1; j <= W; ++j)
			cin >> vec[i][j];

	for (ll i = 0; i < W+2; ++i)
		vec[0][i] = vec[H+1][i] = '#';
	for (ll i = 0; i < H+2; ++i)
		vec[i][0] = vec[i][W+1] = '#';

	for (ll i = 0; i < H+2; ++i)
	{
		for (ll j = 0; j < W+2; ++j)
			std::cout << vec[i][j];
		std::cout << std::endl;
	}
}


Measured memory_bytes: 256
// Longest Common Subsequence (LCS) Problem
#include <bits/stdc++.h>
#define ll long long
using namespace std;

// dp[i][j] = length of the LCS of strings s[0....i-1] and t[0....j-1]
int dp[3001][3001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s, t, ans = "";
	cin >> s >> t;
	int n = s.length(), m = t.length();

	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= m; j++) {
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else if (s[i-1] == t[j-1])
				dp[i][j] = 1 + dp[i-1][j-1];
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}

	int i = n, j = m;
	while(i > 0 && j > 0) {
		if (s[i-1] == t[j-1]){
			ans = s[i-1] + ans;
			i--;
			j--;
		}
		else if (dp[i-1][j] > dp[i][j-1])
			i--;
		else
			j--;
	}

	cout << ans << endl;

}

Measured memory_bytes: 35456
MOD = 1000000007


n = input()
s = raw_input()

dp = [[0] * n for _ in range(n)]
dp[0][0] = 1
for i in range(1, n):
    if s[i - 1] == '<':
        for j in range(1, i + 1):
            dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) %  MOD
    else:
        for j in range(i - 1, -1, -1):
            dp[i][j] = (dp[i - 1][j] + dp[i][j + 1]) %  MOD
print(sum(dp[n - 1]) % MOD)


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

int32_t main()
{
    uint64_t a, b, x;
    cin >> a >> b >> x;
    
    if (a == 0) {
        cout << b / x + 1 << endl;
    } else {
        cout << b / x - (a - 1) / x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> X[i];
  sort(X.begin(), X.end());
  vector<int> sub(M);
  for (int i = 1; i < M; i++)
  {
    sub[i] = X[i] - X[i - 1];
  }
  sort(sub.begin(), sub.end());
  long ans = 0;
  for (int i = 0; i < M - N + 1; i++)
    ans += sub[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    ll a,b,c,k; 
    cin >> a >> b >> c >> k;
    ll zero = 0L;
    cout << min(a, k) - max(min(k-a-b, c),zero) << endl;
    return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int r;
	cin >> r;
	if (r < 1200)
		puts("ABC");
	else if (r < 2800)
		puts("ARC");
	else
		puts("AGC");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	private static final void solve() {
		try (Scanner cin = new Scanner(System.in)) {
			int suna = cin.nextInt();
			int t = cin.nextInt();

			if (suna >= t) {
				System.out.println(suna - t);
			} else {
				System.out.println(0);
			}
		} finally {
		}
	}

}


Measured memory_bytes: 21844
N = int(input())
x = [list(map(int, input().split())) for i in range(N)]

counter = 0
max = 0
for i in range(N):
  if x[i][0] == x[i][1]:
    counter = counter + 1
  else:
    if max < counter:
      max = counter
    counter = 0

if max >=3 or counter >= 3:
  a = 'Yes'
else:
  a = 'No'
    
print(a)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int32_t A, B, C, K, ans=0;
    cin >> A >> B >> C >> K;
    for (int32_t i = 0; i < K; i++) {
        if (A > 0) {
            A--;
            ans++;
        } else if (B > 0) {
            B--;
        } else if (C > 0) {
            C--;
            ans--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
from math import floor, sqrt

# xが素数かどうか判定する
def isPrime(x):
    for d in range(2, floor(sqrt(x)) + 1):
        if x % d == 0:
            return False
    return x != 1

N = int(input())

# (5*i+1)の形で表せる素数のみを採用する
anss = []
for i in range(11111):
    x = 5 * i + 1
    if isPrime(x):
        anss.append(x)
        if len(anss) == N: break

print(' '.join(map(str, anss)))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    string s;
    cin >> n;
    int b_a = 0, sofa = 0, bed = 0;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        int l = s.size();
        int j = 0;
        while (j < l - 1) {
            if (s[j] == 'A' && s[j + 1] == 'B') {
                ++ans;
                ++j;
            }
            ++j;
        }
        if (s[0] == 'B' && s[l - 1] == 'A') ++b_a;
        else if (s[0] == 'B') ++bed;
        else if (s[l - 1] == 'A') ++sofa;
    }
    if (sofa >= 1 && bed >= 1) {
        ans += b_a + 1 + min(sofa - 1, bed - 1);
    } else if (sofa >= 1 || bed >= 1) {
        ans += b_a;
    } else {
        ans += max(b_a - 1, 0);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,n,c[502],f[502],b;
    long long s[502],ans;
	scanf("%d",&n);
	for(i=1;i<n;i++)
    {
        scanf("%d %lld %d",&c[i],&s[i],&f[i]);
	}
	for(i=1;i<=n;i++)
	{
		ans=0;
		for(j=i;j<n;j++)
		{
			if(ans<=s[j])
			{
				ans=s[j];
				ans+=c[j];
			}
			else{
				if(ans%f[j]==0)
				{
					ans+=c[j];
				}
				else
				{
					//ans += (ans % f[j]);
					ans=ans+f[j]-(ans%f[j]);
					ans+=c[j];
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    // Your code here!
    int n,m;cin>>n>>m;
    vector<ll> x(m);
    rep(i,m) cin>>x[i];
    sort(x.begin(),x.end());
    ll sum=x[m-1]-x[0];
    //cout<<sum<<endl;
    priority_queue<ll> que;
    if(n>=m||m==1){
        cout<<0<<endl;
        return 0;
    }
    rep(i,m-1)que.push(x[i+1]-x[i]);
    rep(i,n-1){
        ll buf=que.top();que.pop();
        sum-=buf;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 2168
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		new AOJ1138();
	}
	
	class AOJ1138{
		int n,m,p,a,b;
		final int INF=Integer.MAX_VALUE/4;
		AOJ1138(){
			while(true){
				n=sc.nextInt();
				m=sc.nextInt();
				p=sc.nextInt();
				a=sc.nextInt();
				b=sc.nextInt();
				if(n==0)	break;
				solve();
			}
		}
		void solve(){
			int[] tickets=new int[n];
			for(int i=0; i<n; ++i)	tickets[i]=sc.nextInt();
			int[][] path=new int[m][m];
			for(int i=0; i<m; ++i)for(int j=0; j<m; ++j)path[i][j]=INF;
			for(int i=0; i<p; ++i){
				int x=sc.nextInt(),y=sc.nextInt(),z=sc.nextInt();
				--x;
				--y;
				path[x][y]=z;
				path[y][x]=z;
			}
			
			--a;
			--b;
			
			int bit=(1<<n)-1;
//			System.out.println(Integer.bitCount(bit));
			double[][] closed=new double[m][bit+1];
			for(int i=0; i<m; ++i)for(int j=0; j<=bit; ++j)closed[i][j]=(i==a? 0 : INF);
			
			PriorityQueue<state> open = new PriorityQueue<state>();
			open.add(new state(a,bit,0));
			
			double ans=INF;
			
			while(!open.isEmpty()){
				state now = open.poll();
//				System.out.println(now);
				if(now.p==b){
					ans=min(ans,now.z);
					continue;
				}
				for(int to=0; to<m; to++){
					if(path[now.p][to]>=INF)	continue;
					if(now.p==to)	continue;
					for(int i=0; i<n; ++i){
						if( (now.t & (1<<i) ) == 0 )	continue;
						double a = (double)path[now.p][to]/(double)tickets[i];
						int b = now.t^(1<<i);
						if(closed[to][b] <= now.z+a)	continue;
						closed[to][b] = now.z+a;
						open.add(new state(to,b,now.z+a));
					}
				}
			}
			
			System.out.println(ans>=INF ? "Impossible" : ans);
		}
		class state implements Comparable<state>{
			int p,t;
			double z;
			state(int p,int t,double z){
				this.p=p;
				this.t=t;
				this.z=z;
			}
			@Override public int compareTo(state o){
				return (int)(this.z-o.z);
			}
			@Override public String toString(){
				return "p:"+p+" t:"+Integer.toBinaryString(t)+" z:"+z;
			}
		}
	}
	
	class AOJ1135{
		AOJ1135(){
			int n=sc.nextInt();
			while(--n>=0)	solve();
		}
		void solve(){
			int m=sc.nextInt(),y=sc.nextInt(),n=sc.nextInt(),ans=0;
			while(--n>=0){
				int a=sc.nextInt();
				double rate = sc.nextDouble();
				int b=sc.nextInt();
				if(a==0){
					int mm=m,c=0;
					for(int i=0; i<y; ++i){
						c += (double)mm*rate;
						mm-=b;
					}
					ans=max(ans, mm+c);
				}else{
					int mm=m;
					for(int i=0; i<y; ++i){
						mm+=(double)mm*rate;
						mm-=b;
					}
					ans=max(ans, mm);
				}
			}
			System.out.println(ans);
		}
	}
	
	

}

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

int b;

int calc(int n){
    int p = b / n - (n - 1) / 2;
    int tmp = (2 * p + n - 1) * n;
    if(n * (n - 1) / 2 > b) return -2;
    if(tmp != 2 * b || p <= 0) return -1;
    return p;
}

signed main(){
    while(cin >> b, b){
        P ans = {0, 0};
        for(int i = 1; i <= b; i++){
            int tmp = calc(i);
            if(tmp == -2) break;
            if(tmp != -1){
                ans = {tmp, i};
            }
        }
        cout << ans.first << ' ' << ans.second << endl;
    }
}


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

class Node {
public:
  int pre;
  int now;
  int vel;
  double time;

  Node(int p, int n, int v, double t) {
    pre = p;
    now = n;
    vel = v;
    time = t;
  }

  bool operator<(const Node &n) const {
    return time > n.time;
  }
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;

    if (n == 0) {
      break;
    }

    int s, g;
    cin >> s >> g;

    vector<vector<int> > d(n + 1), c(n + 1);
    for (int i = 0; i <= n; i++) {
      d[i].resize(n + 1);
      c[i].resize(n + 1);
      fill(d[i].begin(), d[i].end(), -1);
      fill(c[i].begin(), c[i].end(), 0);
    }

    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      cin >> d[x][y] >> c[x][y];
      d[y][x] = d[x][y];
      c[y][x] = c[x][y];
    }

    bool f[31][31][31];
    for (int i = 0; i < 31; i++) {
      for (int j = 0; j < 31; j++) {
	for (int k = 0; k < 31; k++) {
	  f[i][j][k] = false;
	}
      }
    }
  
    bool goal = false;
    Node snd(0, s, 0, 0.0);
    priority_queue<Node> q;
    q.push(snd);
    while (!q.empty()) {
      Node nd = q.top();
      q.pop();
      if (nd.now == g && nd.vel == 1) {
	goal = true;
	cout << nd.time << endl;
	break;
      }
      if (f[nd.pre][nd.now][nd.vel]) {
	continue;
      }
      f[nd.pre][nd.now][nd.vel] = true;
      for (int i = 1; i <= n; i++) {
	if (i != nd.pre && d[nd.now][i] != -1) {
	  for (int j = -1; j <= 1; j++) {
	    int vel = nd.vel + j;
	    if (vel > 0 && vel <= c[nd.now][i]) {
	      Node next(nd.now, i, vel, nd.time + (double)d[nd.now][i] / vel);
	      q.push(next);
	    }
	  }
	}
      }
    }

    if (!goal) {
      cout << "unreachable" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 21688
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    int N, M;
    bool flag = false;
    set<int> s;
    set<int> g;
    cin >> N >> M;
    vector<int>a(M), b(M);
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        if(a[i] == 1){
            s.insert(b[i]);
        }
        if(b[i] == N){
            g.insert(a[i]);
        }
    }
    for(auto k : s){
        if(g.count(k) > 0)flag = true;
    }

    if(flag){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 11136
s = input()

if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    print(3)
elif (s[0] == 'R' and s[1] == 'R') or (s[1] == 'R' and s[2] == 'R'):
    print(2)
elif 'R' in s:
    print(1)
else:
    print(0)


Measured memory_bytes: 9096
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  vector<ll> ans(n);
  ans[0] = sum;
  rep(i,n/2) ans[0]-=2*a[i*2+1];
  cout << ans[0] << " ";
  rep(i,n-1){
    ans[i+1] = (a[i] - ans[i]/2)*2;
    cout << ans[i+1] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[10004];

int main()
{
	ll t;
	cin >> n >> m >> t;
	fill(v, v + 10004, 0);
	REP(i, n)
	{
		ll a, b, c;
		cin >> a;
		a - m > 0 ? b = a - m : b = 0;
		m + a > t ? c = t : c = m + a;
		FOR(i, b, c) v[i] = 1;
	}
	REP(i, t) ans += v[i];
	cout << t - ans << endl;
}

Measured memory_bytes: 3232
N = int(input())
A = list(map(int, input().split()))
A = [i + 1 for i in A]

bucket = [0] * (10 ** 5 + 10)

for a in A:
    bucket[a - 1] += 1
    bucket[a] += 1
    bucket[a+1] += 1

print(max(bucket))

Measured memory_bytes: 20808
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            n -= in.nextInt();
        }
        if (n < 0) {
            out.println(-1);
        } else {
            out.println(n);
        }
        out.close();
    }
}


Measured memory_bytes: 39704
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
string s;
int main(){
	cin>>n>>s;
	int pre = 0;
	ll ans = 1;
	rep(i,2*n){
		if(s[i] == 'B'){
			if(pre%2 == 0) pre++;
			else {ans*=pre;ans%=mod;pre--;}
		}
		else{
			if(pre%2 == 1) pre++;
			else {ans*=pre;ans%=mod;pre--;}
		}
	}
	if(pre != 0) ans = 0;
	ll x = (ans%mod+mod)%mod;
	for(int i=1;i<=n;i++) x = x*1LL*i%mod;
	cout<<x<<endl;
}


Measured memory_bytes: 640
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

s = S()
k = I()
ans = 1
for i in range(k):
    if i < len(s) and s[i] != '1':
        ans = s[i]
        break
print(ans)


Measured memory_bytes: 63852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  sort(p.begin(), p.end());

  // int min = 9999999;
  int num = x;
  int ans;
  while (1) {
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (num == p[i]) {
        flag = false;
      }
    }
    if (flag == true) {
      ans = num;
      break;
    }
    num--;
  }

  int num2 = x;

  while (1) {
    bool flag = true;
    for (int i = 0; i < n; i++) {
      if (num2 == p[i]) {
        // cout << " bb" << endl;
        flag = false;
      }
    }
    if (flag == true) {
      if (abs(ans - x) > abs(num2 - x)) {
        // cout << "aa " << endl;
        ans = num2;
        break;
      }
      break;
    }
    num2++;
  }

  cout << ans << endl;
}

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

using namespace std;

using ll=long long int;

template<typename T>
constexpr T modpow(T a,T n,T mod){
    T ret=1;
    while(n>0){
        if((n&1)!=0){
            ret=ret*a%mod;
        }
        a=a*a%mod;
        n=n/2;
    }
    return ret;
}

template <typename T>
struct LazySegmeTree{
private:
    int n;
    T init;
    vector<T> node;
    vector<T> lazy;
    void update(int k){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            if(k<n-1){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
            lazy[k]=0;
        }
    }
public:
    explicit LazySegmeTree(int sz,T initv=0){
        n=1;
        init=initv;
        while(n<sz)n=n*2;
        node.resize(static_cast<unsigned int>(2*n-1),init);
        for (int i = 0; i < sz; ++i) {
            node[i+n-1]=init;
        }
        for (int i = n-2; i >= 0; --i) {
            node[i]=node[2*i+1]+node[2*i+2];
        }
        lazy.resize(static_cast<unsigned int>(2*n-1),init);
        for (int i = 0; i < sz; ++i) {
            lazy[i+n-1]=init;
        }
        for (int i = n-2; i >= 0; --i) {
            lazy[i]=lazy[2*i+1]+lazy[2*i+2];
        }
    }

    void add(int p,int q,T val,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        update(k);
        if(r<=p||l>=q)return;
        if(p<=l&&r<=q){
            lazy[k]+=val*(r-l);
            update(k);
        }
        else{
            add(p,q,val,2*k+1,l,(l+r)/2);
            add(p,q,val,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    T getsum(int p,int q,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=p||l>=q)return 0;

        update(k);
        if(p<=l&&r<=q)node[k];
        T vl=getsum(p,q,2*k+1,l,(l+r)/2);
        T vr=getsum(p,q,2*k+2,(l+r)/2,r);
        return vl+vr;
    }


};

bool solve(){
    ll n,d,x;
    ll mod=1000000007;
    cin>>n>>d>>x;
    if(n==0)return false;

    //vector<LazySegmeTree<ll>> dp(n+1,LazySegmeTree<ll>(n+1,0ll));
    vector<vector<ll> > dp(n+1,vector<ll>(n+1,0ll) );
    dp[0][n] = 1;

    for (int i = 1; i < n+1; ++i) {
        for (int j = 1; j < n+1; ++j) {
            int l=max(0ll,j-x+1);
            //dp[i].add(l,j,dp[i-1].getsum(j,j+1));
	    dp[i][l] += dp[i-1][j];
	    dp[i][l] %= mod;
	    dp[i][j] -= dp[i-1][j];
	    dp[i][j] += mod;
	    dp[i][j] %= mod;
        }

	for(int j=0;j<n;j++){
	    dp[i][j+1]+=dp[i][j];
	    dp[i][j+1]%=mod;
	}

    }

    ll sum=0;

    for (ll i = 0; i <n+1; ++i) {
        ll dck=1;
        for (ll j = 0; j < i ; ++j) {
            dck*=(d-j)%mod;
            dck%=mod;
            dck*=modpow(j+1,mod-2,mod);
	    //cout<<"mo"<<modpow(j+1,mod-2,mod)<<endl;
            dck%=mod;
        }
	//cout<<' '<<dck<<endl;
	//dck += mod;
	//dck %= mod;
	//cout<<"days"<<i<<' '<<dck<<' '<<dp[i][0]<<' '<<(dp[i][0]*dck)%mod<<endl;
        sum+= (dp[i][0]*dck)%mod;
        sum%=mod;
    }
    cout<<sum<<endl;
   // cout<<"mod#"<< (3*modpow(3ll,mod-2,mod) )%mod<<endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}


Measured memory_bytes: 34284
while True:
    try:
        L1=map(int,raw_input().split())
        L2=map(int,raw_input().split())
        hit,blow=0,0
        for i in range(4):
            blow+=L1.count(L2[i])
            if L1[i]==L2[i]:
                blow-=1
                hit+=1
        print hit,blow

    except:
        break

Measured memory_bytes: 4204
# vim: fileencoding=utf-8


def main():
    w, h, n = map(int, input().split())
    r = [[0] * h for i in range(w)]
    for i in range(n):
        x, y, a = map(int, input().split())
        if a == 1:
            for j in range(x):
                for k in range(h):
                    r[j][k] = 1
        elif a == 2:
            for j in range(x, w):
                for k in range(h):
                    r[j][k] = 1
        elif a == 3:
            for j in range(w):
                for k in range(y):
                    r[j][k] = 1
        elif a == 4:
            for j in range(w):
                for k in range(y, h):
                    r[j][k] = 1
    ans = 0
    for i in range(w):
        for j in range(h):
            if r[i][j] == 0:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73744