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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,T,res,m;

	int maxi=-mx,mini=mx,count=0,mm=-mx,nn=mx;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	double x,y;

    cin>>s;

    int len = strlen(s);

    mem(arr);

    f(i,0,len-1)
    {
        arr[s[i]]++;
    }


    rf(i,len-1,0){
        flag=true;

        arr[s[i]]--;

        f(j,'a','z'){
            if(arr[j]){
                if(arr[j] & 1){
                    flag=false;
                    break;
                }
            }
        }
        if(flag==true){

            m=i/2;

            f(i,0,m-1){
                if(s[i]!=s[i+m]){
                    flag=false;
                    break;
                }
            }


            if(flag==true)cout<<i<<endl,exit(0);
        }

    }



}


Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,s1;
    cin>>s>>s1;
    int c=0;
    if(s[0]==s1[0])
    {
        c++;
    }
    if(s[1]==s1[1])
    {
        c++;
    }
    if(s[2]==s1[2])
    {
        c++;
    }
    cout<<c;
}


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

int main()
{
    string s;
    cin>>s;
    int* count = new int[26]();
    for(int i=0;i<s.length();i++)
    {
        count[ s[i] -'a' ]++;
    }
    for(int i=0;i<26;i++)
    {
        if( count[i]%2)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

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

int main(){

 string a,b,c;
 cin >> a >> b >> c;

 a = toupper(a.at(0));
 b = toupper(b.at(0));
 c = toupper(c.at(0));
 cout <<a <<b<<c  << endl;
}

Measured memory_bytes: 3544
import java.util.*;
import java.lang.Math;
class Main{
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int a;
		int b;
		int c;
		int K;
		int m;
                int n;
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		K = sc.nextInt();
		m=Math.max(a,b);
                n=Math.max(m,c);
		for(int i=0;i<K;i++) {
			n*=2;
		}
		System.out.println(a+b+c-Math.max(m,c)+n);
	}

}


Measured memory_bytes: 21844
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 L, R, d;
  std::cin >> L >> R >> d;
  std::cout << R / d - (L - 1) / d << std::endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll t, n, x;
    scl(n);
    for (int i = 0; i < n; i++)
    {
        scl(x);
        mp[x] += 1;
    }
    ll cnt = 0;
    for (auto k : mp)
    {
        if (k.first != k.second)
        {
            if (k.first > k.second)
            {
                cnt += k.second;
            }
            else
            {
                cnt += (k.second - k.first);
            }
        }
    }
    pcl(cnt);
    return 0;
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x;
int main()
{
    cin >> x;
    for(ll i = -400; i <= 400; i++){
        for(ll j = -400; j <= 400; j++){
            if(i*i*i*i*i-j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3620
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

n,a,b = readInts()
x = math.floor(n/(a+b))
y = n-(a+b)*x
ans=a*x+min(y,a)
print(ans)

Measured memory_bytes: 3932
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;


int main() {

	string S, T;

	cin >> S >> T;

	int a, b;

	cin >> a >> b;

	string U;

	cin >> U;

	if (U == S) {
		a--;
	}
	else {
		b--;
	}

	cout << a<<' '<<b << endl;

	return 0;
}

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

int n, m, a, b, f = 0, s = 0;
int fst[200000];
int scd[200000];

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        if(a == 1){
            fst[f] = b;
            f++;
        }else if(b == n){
            scd[a] = 1;
        }
    }
    for(int j = 0; j <= f; j++){
        if(scd[fst[j]] == 1){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1408
//
//  main.cpp
//  dictionary
//
//  Created by ???????????? on 2017/10/06.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <cstring>
#include <stdio.h>


#define NIL (0)

using namespace std;

int m = 1046527;

int char_to_int(char str){
    if(str == 'A'){
        return 1;
    }
    else if(str == 'C'){
        return 2;
    }
    else if(str == 'G'){
        return 3;
    }
    else if(str == 'T'){
        return 4;
    }
    cout << "Unexpected input given" << endl;
    return 0;
}

long long get_key(char string[]){
    long long key_str = 0, p = 1;
    size_t n = strlen(string);
    for (int i = 0; i < n; i++){
        key_str += p*char_to_int(string[i]);
        p *= 5;
    }
    return key_str;
}

int h1(int key){
    return key % m;
}

int h2(int key){
    return 1+(key % (m-1));
}

int h(int key, int i){
    return (h1(key) + i*h2(key)) % m;
}

void insert(int T[], int key){
    int i = 0;
    while(true){
        int j = h(key, i);
        if (T[j] == NIL){
            T[j] = key;
            break;
        }
        else{
            i++;
        }
    }
}

bool search(int T[], int key){
    int i = 0;
    while(true){
        int j = h(key, i);
        if(T[j] == key){
            return true;
        }
        else if(T[j] == NIL || i > m){
            return false;
        }
        else{
            i++;
        }
    }
}

int main(int argc, const char * argv[]) {
    int n, i;
    long long key;
    char com[10], string[10];
    int T[m];
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s %s", com, string);
        key = get_key(string);
        if(com[0] == 'i'){
            insert(T, key);
        }
        else if(com[0] == 'f'){
            if(search(T, key)){
                cout<<"yes"<<endl;
            }
            else{
                cout<<"no"<<endl;
            }
        }
        else{
            cout << "Got unexpected command" << endl;
        }
    }
    
    
    
    return 0;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,k,i,j,x;
    cin>>n>>k;
    long long int A[n],result[n]={0};
    for(i=0;i<n;i++){
        cin>>A[i];
    }
    result[0]=0;
    for(i=1;i<n;i++){
        x=INT_MAX;
        for(j=1;j<=k;j++){
            if(i-j<0)
            break;
            x=min(x,result[i-j]+abs(A[i]-A[i-j]));
        }
        result[i]=x;
    }
    cout<<result[n-1];
    return 0;
}


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

int main(){
	int N, K;
	cin >> N >> K;
	int R, S, P;
	cin >> R >> S >> P;
	string T;
	cin >> T;
	
	map<char, int> mp;
	mp['r'] = P;
	mp['s'] = R;
	mp['p'] = S;
	
	int64_t point = 0;
	for(int i = 0; i < N; ++i){
		if(i < K){
			point += mp[T[i]];
		}
		else{
			if(T[i-K] == T[i]){
				T[i] = 'a';
			}
			else{
				point += mp[T[i]];
			}
		}
	}
	cout << point << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

vector<string> rez = {"First", "Second"};
int inv = 0;

void ok() {
    cout << rez[inv] << '\n';
    exit(0);
}

void fail() {
    inv = 1 - inv;
    ok();
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    forn(i, 0, n) cin >> a[i];
    if (n == 1) {
        assert(a[0] == 1);
        cout << rez[1] << '\n';
        return 0;
    }
    if (n == 2) {
        cout << rez[1 - (a[0] + a[1]) % 2] << '\n';
        return 0;
    }

    while (1) {
        ll sum = 0;
        forn(i, 0, n) sum += a[i];
        if (sum % 2 != n % 2) ok(); 
        int cnt = 0;
        forn(i, 0, n) cnt += a[i] % 2;
        if (cnt >= 2) fail();
        int pos = -1;
        forn(i, 0, n) if (a[i] % 2) pos = i;
        if (a[pos] == 1) fail();
        --a[pos];
        int g = a[0];
        forn(i, 0, n) g = __gcd(g, a[i]);
        forn(i, 0, n) a[i] /= g;
        inv = 1 - inv;
    }
}


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

const ll MX = 1000000005;

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

  vector<bool> exist(MX,false);
  int ans = 0;
  rep(i,n){
    int a;
    cin >> a;
    exist[a] = !(exist[a]);
    if(exist[a]==true) ans++;
    else ans--;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 125200
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC152D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[,] dd = new int[11, 11];
            for (int i = 1; i <= N; i++)
            {
                int top = int.Parse(i.ToString()[0].ToString());
                int last = i % 10;

                dd[top, last]++;
            }

            long ans = 0;
            for (int i = 1; i <= 10; i++)
            {
                for (int j = 1; j <= 10; j++)
                {
                    ans += dd[i, j] * dd[j, i];
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 15308
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

int main() {
    int t1, t2; cin >> t1 >> t2;
    ll a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2;
    if (a1 > b1 && a2 < b2) {
        if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) < 0) {
            cout << 0 << endl;
            return 0;
        }
        else if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) == 0) {
            cout << "infinity" << endl;
            return 0;
        }
        double k = 1.0*(a1 - b1)*t1 / ((b2 - a2)*t2 + (b1 - a1)*t1);
        if ((a1 - b1)*t1 % ((b2 - a2)*t2 + (b1 - a1)*t1) != 0) {
            cout << ll(2LL * ll(k)) + 1 << endl;
        }
        else {
            cout << ll(2LL * ll(k)) << endl;
        }
    }
    else if (a1 < b1 && a2 > b2) {
        swap(a1, b1);
        swap(a2, b2);
        if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) < 0) {
            cout << 0 << endl;
            return 0;
        }
        else if (b1 * t1 + b2 * t2 - (a1 * t1 + a2 * t2) == 0) {
            cout << "infinity" << endl;
            return 0;
        }
        double k = 1.0*(a1 - b1)*t1 / ((b2 - a2)*t2 + (b1 - a1)*t1);
        if ((a1 - b1)*t1 % ((b2 - a2)*t2 + (b1 - a1)*t1) != 0) {
            cout << ll(2LL * ll(k)) + 1 << endl;
        }
        else {
            cout << ll(2LL * ll(k)) << endl;
        }
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

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

const int N = 1e5 + 5;
int n, h[N], dp[N];
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    dp[n - 1] = 0;
    dp[n - 2] = abs(h[n - 2] - h[n - 1]);
    for(int i = n - 3; i > -1; i--) dp[i] = min(abs(h[i] - h[i + 1]) + dp[i + 1], abs(h[i] - h[i + 2]) + dp[i + 2]);
    cout << dp[0];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
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; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N,L;

int main(){
    cin >> N >> L;
    vector<string> s(N);
    rep(i,N) cin >> s[i];
    sort(all(s));

    rep(i,N) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++)
    {
        for(int j = 1; j < 10; j++)
        {
            if(i * j == n)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 3616
void main(){
	long x, a, b;
	scanf("%ld %ld %ld", &x, &a, &b);
	if(abs(x-a)>abs(x-b))writeln("B");
	else writeln("A");
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2552
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(abs(a-b)%2==1){
        cout << "IMPOSSIBLE\n";
    }else{
        cout << (a+b)/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# AGC038A - 01 Matrix
def main():
    H, W, A, B = tuple(map(int, input().split()))
    for i in range(H):
        if i < B:
            x = "0" * A + "1" * (W - A)
        else:
            x = "1" * A + "0" * (W - A)
        print(x)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#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;

constexpr int mod = 1000000007;
vector<int> fact;
int ModPow(int x, int y) {
    if (y == 0) return 1;
    long long a = ModPow(x, y / 2);
    if (y & 1) return a * a % mod * x % mod;
    else return a * a % mod;
}
int ModCom(int x, int y) {
    if (x < y) return 0;
    int res = fact[x];
    res = (long long)ModPow(fact[y], mod - 2) * res % mod;
    res = (long long)ModPow(fact[x - y], mod - 2) * res % mod;
    return res;
}

int main() {
    fact = vector<int>(100010, 1);
    REP(i, 100010) fact[i] = (long long)fact[i - 1] * i % mod;
    
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    rep(i, n + 1) --a[i];
    
    vector<int> cnt(n, 0);
    int x = -1;
    rep(i, n + 1) {
        if (cnt[a[i]]) x = a[i];
        else cnt[a[i]] = 1;
    }
    int l0 = -1, l1 = -1;
    rep(i, n + 1) {
        if (a[i] == x) {
            if (l0 == -1) l0 = i;
            else l1 = n - i;
        }
    }
    
    rep(i, n + 1) {
        int ans = ModCom(n + 1, i + 1);
        ans -= ModCom(l0 + l1, i);
        if (ans < 0) ans += mod;
        cout << ans << "\n";
    }
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A;
	for (int i = 0; i < N; i++) {
		int x; cin >> x;
		A.push_back(x);
	}
	sort(A.begin(), A.end());
	if (N == 1) {
		cout << 0 << endl;
		return 0;
	}

	int maxcand = A[N - 1] + A[N - 2];
	int maxt = log2(maxcand);

	map<int, int> m;

	for (int i = 0; i < N; i++) {
		if (m.count(A[i]) > 0) {
			m[A[i]]++;
		}
		else {
			m[A[i]] = 1;
		}
	}

	int counterPair = 0;
	while (m.size() > 0) {
		auto p = m.end(); p--;
		pair<int,int> pr = *p;
		int x = pr.first;

		bool found = false;
		for (int i = 0; i < maxt; i++) {
			int z = pow(2, maxt - i);
			int y = z - x;
			if (y <= 0) continue;
			auto q = m.find(y);
			if (q != m.end()) {
				if (y == x && m[y] == 1) continue;
				m[x]--; if (m[x] <= 0) m.erase(x);
				m[y]--; if (m[y] <= 0) m.erase(y);
				found = true;
				counterPair++;
				break;
			}
		}
		if (!found) {
			m[x]--; if (m[x] <= 0) m.erase(x);
		}


	}


	//while (s.size()>0) {
	//	auto p = s.end(); p--;
	//	int x = *p;

	//	bool found = false;		
	//	for (int i = 0; i < maxt; i++) {
	//		int z = pow(2, maxt - i);
	//		int y = z - x;
	//		if (y <= 0) continue;			
	//		auto q = s.find(y);
	//		if (q != s.end()) {
	//			if (y == x && s.count(y) == 1) continue;
	//			s.erase(p); s.erase(q);
	//			found = true;
	//			counterPair++;
	//			break;
	//		}
	//	}
	//	if (!found) {
	//		s.erase(x);			
	//	}
	//}
	cout << counterPair << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    rep(i, 0, n) {
        cin >> w[i];
        sum += w[i];
    }

    vector<int> s(n + 1, 0);
    rep(i, 0, n) {
        s[i + 1] = s[i] + w[i];
    }
    int ans = sum;
    rep(i, 0, n) {
        ans = min(ans, abs(s[i] - (sum - s[i])));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a,b,c;

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

  cout<< min(b/a, c) <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int l=0,r=n-1;
    int ans=0;
    while(l<r){
        if(s[l]=='W' && s[r]=='R'){
            ans++;
            l++,r--;
        } 
        else if(s[l]=='W' && s[r]=='W') r--;
        else if(s[l]=='R' && s[r]=='W') r--,l++;
        else if(s[l]=='R' && s[r]=='R') l++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3696
#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 rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  map<string, int> mp;
  rep(i, n) ++mp[s[i]];

  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll n,pl=0,mi=0,ans=0; cin>>n;
  vector<ll>v(n);
  rep(i,n) cin>>v[i];
  rep(i,n){
  ll t; cin>>t;
    v[i]-=t;
  if(v[i]>=0)pl+=v[i];
    else {
      mi-=v[i]; ans++;
    }
    }
  if(mi>pl){
  cout<<-1<<endl; return 0;
  }
 sort(all(v));
 reverse(all(v));
  rep(i,n){
   if(mi<=0) break;
   if(v[i]<=0)break;
   mi-=v[i]; ans++;
  }
  cout<<ans<<endl;
}

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

int main(){
	long long A,B,i;
	long long result=0;
	string S,S1;
	cin>>A>>B;
	
	for(i=A;i<=B;i++){
		S=to_string(i);
		S1=S;
		reverse(S1.begin(),S1.end());
		if(S==S1)result++;
	}
	cout<<result<<endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int x,n; cin>>x>>n;
	vector<bool>v(102,false);
	for(int i=0;i<n;++i){
		int p; cin>>p;
		v.at(p)=true;
	}
	int ans=600;
	for(int i=0,tmp=600;i<v.size();++i){
		if(!v.at(i)&&abs(i-x)<tmp){
			tmp=abs(i-x);
			ans=i;
		}
	}
	cout<<ans<<"\n"s;
}

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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

ll p = -1 ;

int main(){

    int n ;
    string s ;
    cin >> n >> s ;
    for(int i = 0 ; i < s.size() ; i ++ ){
        if(s[i]+n>=91){
            s[i]-=26;
        }
            cout<<char(s[i]+n);
    }

}


Measured memory_bytes: 256
<?php

# 試行回数　番号
fscanf(STDIN, "%d %d", $op_times, $number);

# 配列にキーの値がいくつあるか記録する
while($input = fscanf(STDIN, "%d %d", $a, $b)) {
    $tmp[$a] = isset($tmp[$a]) ? $tmp[$a] + $b: $b;
}

# キーで配列昇順
ksort($tmp);

# 配列に値を埋める
foreach ($tmp as $index => $item) {
    if ($number <= $item) {
        $target = $index;
        break;
    } else{
        $number = $number - $item;
    }
}

# 出力
echo $target;


Measured memory_bytes: 13044
n, p = map(int, input().split())
s = list(map(int, list(input())))

ans = 0

if p == 2:
    for i in range(n):
        if s[i] % 2 == 0:
            ans += i + 1
    print(ans)
    exit()

if p == 5:
    for i in range(n):
        if s[i] == 0 or s[i] == 5:
            ans += i + 1
    print(ans)
    exit()

num = 1
l = [0]
for i in range(n-1, -1, -1):
    l.append((num * s[i] + l[-1]) % p)
    num *= 10
    num %= p

from collections import Counter

dic = Counter(l)
for i in dic.values():
    ans += i * (i - 1) // 2

print(ans)

Measured memory_bytes: 13572
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int lake=scan.nextInt();
    int home=scan.nextInt();
    int leng[]=new int[home];
    for(int a=0; a<home; a++){
      leng[a]=scan.nextInt();
    }
    int max=0, plus=0, hint=0;
    for(int a=0; a<home-1; a++){
      hint=leng[a+1]-leng[a];
      if(max<hint){
        max=hint;
      }
      plus+=hint;
    }
    hint=lake-leng[home-1]+leng[0];
    if(max<hint){
      max=hint;
    }
    plus+=hint;
    System.out.println(plus-max);
  }
}

Measured memory_bytes: 85924
x,k,d=[int(x) for x in input().split()]
if k<(abs(x)/d):
  print(abs(abs(x)-d*k))
else:
  if x%d==0:
    if (k-(abs(x)/d))%2==0:
      print(0)
    elif (k-(abs(x)/d))%2==1:
      print(d)
  else:
    n=int(abs(x)/d)+1
    if (k-n)%2==0:
      print(abs(abs(x)-d*n))
    elif (k-n)%2==1:
      print(abs(abs(x)-d*(n-1)))

Measured memory_bytes: 9220
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, Q = map(int, readline().split())

N0 = 2**(N-1).bit_length()
data = [None]*(2*N0)
INF = (-1, 2**31-1)
def update(l, r, v):
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            data[R-1] = v

        if L & 1:
            data[L-1] = v
            L += 1
        L >>= 1; R >>= 1
def _query(k):
    k += N0-1
    s = INF
    while k >= 0:
        if data[k]:
            s = max(s, data[k])
        k = (k - 1) // 2
    return s
def query(k):
    return _query(k)[1]


ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        ans.append(str(query(cmd[0])))
    else:
        s, t, x = cmd
        update(s, t+1, (q, x))
write("\n".join(ans))
write("\n")



Measured memory_bytes: 15604
object Main extends App {
  @scala.annotation.tailrec
  def loop(nums: Seq[Int], count: Int): Int = {
    val next = nums.combinations(2).map(_.sum / 2).toSeq.sorted
    if (nums == next) -1 else if (nums.exists(_ % 2 == 1)) count else loop(next, count + 1)
  }
  val sc = new java.util.Scanner(System.in)
  println(loop(Seq.fill(3)(sc.nextInt()).sorted, 0))
}


Measured memory_bytes: 25504
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

int MAXS = 2600;

struct edge
{
  ll to;
  ll money;
  ll time;

  edge(ll t, ll c, ll ti): to(t), money(c), time(ti){}
};

void dijk(const vector<vector<edge>> &G, int s, vector<vector<ll>> &dp, vector<int> C, vector<int> D)
{
  chmin(s, MAXS);
  auto f = [](edge a, edge b){
    return a.time > b.time;};
  dp[0][s] = 0;
  priority_queue<edge, vector<edge>, decltype(f)> pq(f);
  pq.emplace(edge(0, s, 0));
  while(!pq.empty()){
    edge p = pq.top();
    pq.pop();
    ll v = p.to;
    ll money = p.money;
    ll time = p.time;

    if(money + C[v] <= MAXS){
      ll admoney = money + C[v];
      ll adtime = time + D[v];
      if(chmin(dp[v][admoney], adtime)) pq.emplace(edge(v, admoney, adtime));
    }

    for(auto e: G[v]){
      if(money < e.money) continue;
      ll nxt = e.to;
      ll decmoney = money - e.money;
      ll adtime = time + e.time;
      if(chmin(dp[nxt][decmoney], adtime)) pq.emplace(edge(nxt, decmoney, adtime));
    }
  }
}


int main()
{
  int N, M, S; cin  >> N >> M >> S;
  vector<vector<edge>> G(N);
  rep(i, 0, M){
    int u, v, a, b; cin >> u >> v >> a >> b;
    --u, --v;
    G[u].push_back(edge(v, a, b));
    G[v].push_back(edge(u, a, b));
  }
  vector<int> C(N);
  vector<int> D(N);
  rep(i, 0, N) cin >> C[i] >> D[i];
  vector<vector<ll>> dp(N, vector<ll>(MAXS + 1, INF));

  dijk(G, S, dp, C, D);

  rep(i, 1, N){
    ll ans = INF;
    rep(k, 0, MAXS) chmin(ans, dp[i][k]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 7452
import os, sys, re, math

A,B,C,D = [int(s) for s in input().split(' ')]

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

lcm = C * D // gcd(C, D)

ret = B // C - (A-1) // C
ret += B // D - (A-1) // D
ret -= B // lcm - (A-1) // lcm
print(B-A+1-ret)


Measured memory_bytes: 3188
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
    var c = parseInt(input[2], 10);
    var d = parseInt(input[3], 10);
    var e = parseInt(input[4], 10);
    var k = parseInt(input[5], 10);
  var message = "Yay!";
    for(var i=0; i < 4; i++){
      for(var j=i+1; j<5;j++){
          if(Math.abs(input[i]-input[j])>k
)message=":("
          }
          }
  
  console.log(message);
      
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/*
    Author:DurJoy
*/
#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int tot = 1;
    bool ok = false;
    for(int i = 1; i < 10; i++){
        if(((n % i) == 0) && ((n / i) < 10)){
            ok = true;
        }
    }
    if(ok){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
K = 4000
A = input()
B = input()
C = input()
la, lb, lc = len(A), len(B), len(C)

def check(S, T):
    R = [1] * (K * 2 + 1)
    for i in range(-len(T), len(S)):
        for j in range(max(i, 0), min(len(S), len(T)+i)):
            if S[j] != T[j-i] and S[j] != "?" and T[j-i] != "?":
                R[i] = 0
                break
    return R

AB = check(A, B)
AC = check(A, C)
BC = check(B, C)

mi = K * 3
for ib in range(-K, K + 1):
    if AB[ib] == 0: continue
    for ic in range(-K, K + 1):
        if AC[ic] == 0 or BC[ic - ib] == 0: continue
        mi = min(mi, max(ib + lb, ic + lc, la) - min(ib, ic, 0))

print(mi)

Measured memory_bytes: 55388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,flag=1;
    map<string,int> mp;
    cin >> n;
    string s;
    char last;
    rep(i,n){
        cin >> s;
        if(!i){
            mp[s]=0;
            last=s[s.length()-1];
        }
        else if(!mp.count(s)){
            if(s[0]==last){
              last=s[s.length()-1];
              mp[s]=1;
            }
            else{
                flag=0;
                break;
            }
        }
        else{
            flag=0;
            break;
        }
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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,a;
    cin >> n;
    if(n<10) a=n;
    else a=n%10;

    if(a==2||a==4||a==5||a==7||a==9){
        cout << "hon" << endl;
    }else if(a==3){
        cout << "bon" << endl;
    }else cout << "pon" << endl;

    return 0;
}

Measured memory_bytes: 3596
main :: IO ()
main = do
  input <- getLine
  putStrLn $ solve (reverse input) []

solve :: String -> String -> String
solve [] res = res
solve str@(s:ss) res
  | s == 'B' = solve (delete str) res
  | otherwise = solve ss $s:res

delete :: String -> String
delete str = drop n str
  where
    n = 2 * (length . takeWhile (== 'B')) str


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

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

long long MOD = 10000000000 + 7;

ll f(ll X){
  if(X<0){
    return 0;
  }

  ll ret = 0;
  ll Y = X / 4;
  Y *= 4;
  for(ll i = Y; i <= X; i++){
    ret ^= i;
  }

  return ret;
}

int main(){
  cout << setprecision(10);
  ll A,B; cin >> A >> B;
  cout << ( f(B) ^ f(A-1)) << endl;
}


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

int main() {
    long long h;
    cin >> h;

    if (h == 1) {
        cout << 1 << endl;
        return 0;
    }
    long long index = 1;
    long long cnt = 1;
    while (1) {
        if (cnt >= h) break;
        index *= 2;
        cnt += index;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
string bpqd = "bpqd";
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string ans = "Yes";
  for(int i = 0; i < S.size(); i++) {
    for(int j = 0; j < 4; j++) {
      if(S[i] == bpqd[j]) {
        if(S[S.size() - 1 - i] != bpqd[3-j]) ans = "No";
      }
    }
  }
  cout << ans;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
cnt = 0

for i in range(2**N):
  flg = True
  for j in range(len(L)):
    #jの情報は、(hito=x, singi = y=1,0)
    #iの情報は、(singi = (1/0,...,1/0))
    for x,y in L[j]:
      #jさんの情報      
      #i[j] :sinngi　正解
      #y:sinngi　を変換
      if (i >> j) & 1 == 1:
        if i>>(x-1) & 1 !=y:
          flg = False
          break
  if flg:
    cnt = max(cnt,bin(i).count('1'))
print(cnt)

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

const ll MOD=1e9+7;
int main(){
    ll n; cin>>n;
    vector<ll> box(1010,0);
    
    for(int i=2; i<=n; i++){
        ll now=i;
        ll j=2;
        while(now!=1){
            if(now%j==0){
                now/=j;
                box[j]++;
            }else{
                j++;
            }
        }
    }
    ll ans=1;
    for(int i=0; i<box.size(); i++){
        if(box[i]!=0) ans = (ans*(box[i]+1))%MOD;
    }
    cout<<ans%MOD<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main() {
  int n, a[20], b[20], c[20], ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; i++) {
    ans += b[a[i]];
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &c[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i] + 1 == a[i + 1]) {
      ans += c[a[i]];
    }
  }
  printf("%d\n", ans);
}

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int n;
  string s;
  cin >> n >> s;
  int r[10000], g[10000], b[10000];
  int r_sum = s[n - 1] == 'R', g_sum = s[n - 1] == 'G', b_sum = s[n - 1] == 'B';
  r[n - 1] = r_sum;
  g[n - 1] = g_sum;
  b[n - 1] = b_sum;
  for (int i = n - 2; i >= 0; i--)
  {
    r[i] = r[i + 1] + (s[i] == 'R');
    g[i] = g[i + 1] + (s[i] == 'G');
    b[i] = b[i + 1] + (s[i] == 'B');
  }

  int ret = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      bool nr = (s[i] == 'G' && s[j] == 'B') || (s[j] == 'G' && s[i] == 'B');
      bool ng = (s[i] == 'R' && s[j] == 'B') || (s[j] == 'R' && s[i] == 'B');
      bool nb = (s[i] == 'R' && s[j] == 'G') || (s[j] == 'R' && s[i] == 'G');
      if (nr)
        ret += max(0LL, r[j + 1] - (2 * j - i < n && s[j + (j - i)] == 'R'));
      if (ng)
        ret += max(0LL, g[j + 1] - (2 * j - i < n && s[j + (j - i)] == 'G'));
      if (nb)
        ret += max(0LL, b[j + 1] - (2 * j - i < n && s[j + (j - i)] == 'B'));

      // cout << nr << ng << nb << endl;
    }
  }
  cout << ret << endl;
}

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


int main(int argc, const char * argv[]) {
    int a,b,s;
    cin >>a>>b>>s;
    if (a==b) {
        cout<<s<<endl;
    }if (a==s) {
        cout<<b<<endl;
    }if (s==b) {
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  cout << 3*N*N << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n;cin >> n;vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();

		int max = a;
		int min = a;

		if(max < b)
		{
			max = b;
		}
		if(min > b)
		{
			min = b;
		}
		if(max < c)
		{
			max = c;
		}
		if(min > c)
		{
			min = c;
		}

		System.out.println(max - min);

	}

}


Measured memory_bytes: 35612
#67 組み合わせの数

while True:
    n, x = map(int, input().split())
    
    if n == x == 0:
        break
    
    ans = 0
    for i in range(1, n+1):
        for j in range(1, i):
            for k in range(1, j):
                if i + j + k == x:
                    ans += 1
    
    print(ans)
        


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
    fastio;
    int n,m;
    cin >> n >> m;
    int arr[n];
    int sum = 0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    sort(arr,arr+n);
    vector<pii> query(m);
    for(int i=0;i<m;i++){
        cin >> query[i].ss >> query[i].ff;
    }
    sort(td(query),greater<pii>());
    int hs = 0;
    //cout << endl;
    for(int i=0;i<m;i++){
        //cout << query[i].ff << " " << query[i].ss << endl;
        int pos = upper_bound(arr+hs,arr+n,query[i].ff) - arr;
        sum += query[i].ff * min(query[i].ss,(pos - hs));
        //cout << pos << " " << sum <<  endl;
        hs = min(query[i].ss + hs,pos);

    }
    for(int i=hs;i<n;i++){
        sum+=arr[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int koike = 0;
    for(int i = 0; i < 3; i++){
      if(a.charAt(i) == b.charAt(i)){
        koike++;
      }
    }
    System.out.println(koike);
  }
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);

  cout << abs(A[N-1] - A[0]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct RollingHash{
  typedef unsigned long long ull;
  string S;
  ull B;
  int len;
  vector<ull> hash,p;
  RollingHash(){}
  RollingHash(string S_,ull B_=1000000007LL):
    S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
    hash[0]=0;p[0]=1;
    for(int i=0;i<len;i++){
      hash[i+1]=hash[i]*B+S[i];
      p[i+1]=p[i]*B;
    }
  }
  //S[l,r)
  ull find(int l,int r){
    return hash[r]-hash[l]*p[r-l];
  }
};
//END CUT HERE

signed main(){
  string t,p;
  cin>>t>>p;
  RollingHash rt(t),rp(p);
  for(int i=0;i<(int)(t.size()-p.size())+1;i++){
    if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<endl;
  }
  return 0;
}
/*
verified on 2017/10/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B&lang=jp
*/

Measured memory_bytes: 20508