akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int p10(int n) {
    int ret = 1;
    for (int i = 0; i < n; i++) {
        ret *= 10;
    }
    return ret;
}

int main(void) {
    int target, num;
    while (cin >> target >> num) {
        if (target == 0 && num == 0) break;
        int keta = 0, tmp = num;
        while (tmp) {
            keta++;
            tmp /= 10;
        }
        int dest = -INF;
        for (int digit = 0; digit < (1<<(keta-1)); digit++) {
//            cout << digit << endl;
            int sum = 0, old = -1;
            for (int i = 0; i < digit; i++) {
                if (((digit >> i) & 1) == 1) {
                    sum += (num % p10(i+1)) / p10(old+1);
                    old = i;
//                    printf("+%d\n", (num % p10(i+1) / p10(old+1)));
                }
            }
            sum += (num % p10(keta)) / p10(old+1);
//            printf("+%d\n", (num % p10(keta) / p10(old+1)));
            if (sum <= target) {
                dest = max(sum, dest);
            }
        }
        if (dest == -INF) cout << "error" << endl;
        
        else {
            int cnt = 0;
            int index = 0;
            bool flag = true;
            for (int digit = 0; digit < (1<<(keta-1)); digit++) {
                int sum = 0, old = -1;
                for (int i = 0; i < keta; i++) {
                    if (((digit >> i) & 1) == 1) {
                        sum += (num % p10(i+1)) / p10(old+1);
                        old = i;
                    }
                }
                sum += (num % p10(keta)) / p10(old+1);
                if (sum == dest) {
                    cnt++;
                    if (cnt > 1) {
                        cout << "rejected" << endl;
                        flag = false;
                        break;
                    }
                    index = digit;
                }
            }
            if (flag) {
                vector<int> ans;
                cout << dest;
                int old = -1;
                for (int i = 0; i < keta; i++) {
                    if (((index >> i) & 1) == 1) {
                        ans.push_back((num % p10(i+1)) / p10(old+1));
                        old = i;
                    }
                }
                ans.push_back((num % p10(keta)) / p10(old+1));
                reverse(ans.begin(), ans.end());
                for (int i = 0; i < ans.size(); i++) {
                    cout << " " << ans[i];
                }
                cout << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1216
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a, p;
signed main() {
	cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int N_MAX = 200;
int combination[N_MAX][N_MAX];
void combination_init() {
    for(int i=0; i<N_MAX; i++) combination[i][0] = 1;
    for(int i=1; i<N_MAX; i++) {
        for(int j=1; j<N_MAX; j++) {
            combination[i][j] = combination[i-1][j] + combination[i-1][j-1];
        }
    }
}

signed main() {
    combination_init();

    int n,p;
    cin>>n>>p;
    vi a(n);
    cin>>a;
    int e=0,o=0;
    REP(i,n) {
        a[i]%=2;
        if(a[i]) o++;
        else e++;
    }
    if(p) {
        int ans=0;
        REPF(i,1,o+1) {
            if(i%2==0) continue;
            REP(j,e+1) {
                ans+=combination[o][i]*combination[e][j];
            }
        }
        cout<<ans<<endl;
    }
    else {
        int ans=0;
        REP(i,o+1) {
            if(i%2==1) continue;
            REP(j,e+1) {
                ans+=combination[o][i]*combination[e][j];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            int N = GetInt();
            var c = GetStr().ToCharArray();

            var max = int.MinValue;
            for(int i = 1; i < N ; i++)
            {
                var X = new char[i];
                Array.Copy(c, 0, X, 0, i);
                X = X.Distinct().ToArray();
                var Y = new char[N - i];
                Array.Copy(c, i, Y, 0, N - i);
                Y = Y.Distinct().ToArray() ;

                Dictionary<char, int> memo = new Dictionary<char, int>();
                for(int j = 0; j < X.Length; j++)
                {
                    memo.Add(X[j], 0);
                }
                for(int j = 0; j < Y.Length; j++)
                {
                    if (memo.ContainsKey(Y[j]))
                    {
                        memo[Y[j]]++;
                    }
                }
                max = Math.Max(max, memo.Values.Count(m => m > 0));
            }

            Console.WriteLine(max);
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13280
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int L = sc.nextInt();
		int max = L + num - 1;
		if(L * max <= 0) {
			System.out.println(num * (L + max) / 2);
		}else {
			System.out.println(num * (L + max) / 2 - (Math.abs(L) <= Math.abs(max) ? L : max));
		}
	}
}

Measured memory_bytes: 22996
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,cou;
    char S[100000];
    scanf("%d",&A);
    if((A>=1)&&(A<=999)){
        printf("ABC");
    }else{
        printf("ABD");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <vector>
#define END 10000
using namespace std;
typedef vector< vector<int> > graph;
int search(graph &gurapu){
  stack<int> st;
  st.push(END);
  st.push(0);
  int i; 
  while( ( i=st.top() ) !=  END ){
    st.pop();

    for(int j=0;j<gurapu.size();j++){
      // cout <<"debug"<<i<<" "<<j<<endl;
      if(i==j) continue;
      if(gurapu[i][j]) 
	if(gurapu[i][j]+gurapu[i][i]>gurapu[j][j]){
	  gurapu[j][j]=gurapu[i][i]+gurapu[i][j];
	  st.push(j);
	}  
   
    }      
  }
        

    return gurapu[gurapu.size()-1][gurapu.size()-1];
}
int main(){
  int n,m,a,b,c,end;
  cin >>n>>m;
  graph gurapu;
  for(int i=0;i<n;i++)
    gurapu.push_back(vector<int>(n,0));
  gurapu[0][0]=0;
  for(int i=0;i<m;i++){
    cin >>a>>b>>c;
    gurapu[a][b]=c;

  }

  cout <<search(gurapu)<<endl;
  
  return 0;
}

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

int main(){
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    long long ans=0;
    if(k<a){
        ans = k;
    }else if(k<=a+b){
        ans = a;
    }else{
        ans= a- (k-a-b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
h,w=map(int,input().split())
m=[[0for _ in range(w+2)]for _ in range(h+2)]
for y in range(h):
  s=input()
  for x in range(w):
    if s[x]=="#":
      for i in [0,1,2]:
        for j in [0,1,2]:
          m[y+j][x+i]+=1
      m[y+1][x+1]=9
for y in range(1,h+1):
  ans=""
  for x in range(1,w+1):
    if m[y][x]>8:
      ans+="#"
    else:
      ans+=str(m[y][x])
  print(ans)

Measured memory_bytes: 3064
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    
    n = I()
    a = [0] + LI()
    ans = [0 for _ in range(n+1)]

    for i in range(n,0,-1):
        cnt = 0
        for j in range(i,n+1,i):
            cnt += ans[j]
        if cnt%2 != a[i]:
            ans[i] = 1
    
    ans_lst = []
    for i in range(1,n+1):
        if ans[i] == 1:
            ans_lst.append(i)

    print(len(ans_lst))
    print(*ans_lst)

    
main()


Measured memory_bytes: 19300
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int a = ri();
	int b = ri();
	int c = ri();
	printf("%s", (c <= a+b) ? "Yes" : "No");
	
	return 0;
}


Measured memory_bytes: 128
n = int(input())
T, X, Y = 0, 0, 0
for i in range(n):
    t, x, y = map(int, input().split())
    dxy = abs(X - x) + abs(Y - y)
    dt = t - T
    if dxy > dt or dxy % 2 != dt % 2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    vector<ll> X(100001, 0);
    for (int i = 0; i < N; ++i) {
        ll tmp;
        cin >> tmp;
        X[tmp]++;
        if(tmp > 0) X[tmp-1]++;
        X[tmp+1]++;
    }
    cout << *max_element(X.begin(), X.end()) << endl;

}

int main(int argc, char *argv[]) {
    string FileName("ABC072"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;i++)
char ca;
const int MOD = 1000000007;
ll  c, d = 0, e,n, i, j, k, h, w,  o, p,ii;
queue<ll> q;
string s;
vector<pair<ll,ll>> m;
vector<ll> v;
const int MAX = 2005;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	cin >> n>>k;
	c = n - k;
	COMinit();
	for (i = 1; i <= k; i++) {
		if (i - 1 > c) {
			cout << 0 << "\n";
			continue;
		}
		o = COM(k - 1, i - 1);
		p = c - i + 1;
		h = COM(p + i, i);
		cout << (o * h) % MOD<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;const ll INF=1LL<<60;
void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
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;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,W; cin>>n>>W;
  vector<ll> w(n),v(n);
  rep(i,n) cin>>w[i]>>v[i];
  auto dp=make_v(n,W+1,(ll)-1);

  function<ll(ll,ll)> solve=[&](ll i,ll x){
    if(x>W) return -INF;
    if(i==n) return (ll)0;
    if(dp[i][x]!=-1) return dp[i][x];
    return dp[i][x]=max(solve(i+1,x),solve(i+1,x+w[i])+v[i]);
  };
  
  cout<<solve(0,0)<<"\n";
}


Measured memory_bytes: 79488
// Problem : D - Dice in Line
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
#define ld long double
void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ld> a(n);
    rep(i,0,n)
    {
    	ll x;
    	cin>>x;
    	ll cnt=x*(x+1)/2;
    	a[i]=cnt*1.0/(x*1.0);
    }
    ld sum=0.0,ans=0.0;
    rep(i,0,k)
    	sum+=a[i];
    ans=sum;
    for(ll i=k;i<n;i++)
    {
    	sum=sum-a[i-k]+a[i];
    	ans=max(ans,sum);
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

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

const int MAX_N=12;
int N, M;
vector<int> g[MAX_N];
ll dp[MAX_N][1<<MAX_N];

void add_edge(int from, int to)
{
	g[from].push_back(to);
	g[to].push_back(from);
}

ll go(int at, int f)
{
	if(f == ((1<<N)-1)) return 1;
	ll& res = dp[at][f];
	if(res != -1) return res;
	res = 0;
	for(int i=0;i<(int)g[at].size();++i){
		int to = g[at][i];
		if(!(f>>to&1)) res+=go(to,f|(1<<to));
	}
	return res;
}

void solve()
{
	memset(dp,-1,sizeof(dp));
	ll res = go(0, 1);
	cout << res << '\n';
}

int main()
{
	cin >> N >> M;
	int a, b;
	for(int i=0;i<M;++i){
		cin >> a >> b;
		add_edge(a-1,b-1);
	}
	solve();
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n,k,a,d=0;
    cin >> n >> k;
    vector<int> v(n, 0);
    rep(n){
        cin >> a;
        a--;
        if(v[a] == 0) d++;
        v[a]++;
    }
    sort(all(v));

    int ans = 0, i = 0;
    while(d > k){
        if(v[i] > 0){
            ans += v[i];
            d--;
        }
        i++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

long long dp[100001][3];

int main()
{
  int n;
  scanf("%d", &n);
  long long h[100000][3];
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld%lld%lld", h[i], h[i] + 1, h[i] + 2);
  }
  dp[1][0] = h[0][0];
  dp[1][1] = h[0][1];
  dp[1][2] = h[0][2];
  for (int i = 1; i < n; ++i)
  {
    dp[i + 1][0] = h[i][0] + std::max(dp[i][1], dp[i][2]);
    dp[i + 1][1] = h[i][1] + std::max(dp[i][2], dp[i][0]);
    dp[i + 1][2] = h[i][2] + std::max(dp[i][0], dp[i][1]);
  }
  printf("%lld\n", std::max(dp[n][0], std::max(dp[n][1], dp[n][2])));
  return 0;
}

Measured memory_bytes: 4864
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

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

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
/*bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second > secondElof.second;
}*/


/*long nCr(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = nCr(n-1,r) + nCr(n-1,r-1);
}*/

int main(){
    int n, m;
    cin >> n >> m;
    LL ans = 0;
    VI a(m);
    REP(i, m){
        cin >> a[i];
        ans+=a[i];
    }
    if(ans>n) cout << -1 << endl;
    else cout << n-ans << endl;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define REP(i, n) for (ll i=0; i<(ll)n; ++i)
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

vll dist(100000);
V<bool> visited(100000, false);
vvll nodes(100000, vll());

void dfs(ll i) {
  for (ll j=0; j<nodes.at(i).size(); j++) {
    if (!visited.at(nodes.at(i).at(j))) {
      visited.at(nodes.at(i).at(j)) = true;
      dfs(nodes.at(i).at(j));
    }
  }
}

int main() {
  ll n, m; cin >> n >> m;
  REP(i, m) {
    ll x, y, z; cin >> x >> y >> z;
    nodes.at(x-1).push_back(y-1);
    nodes.at(y-1).push_back(x-1);
  }
  ll ans = 0;
  REP(i, n) {
    if (!visited.at(i)) {
      visited.at(i) = true;
      dfs(i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int mp[70][70];
int main() {
	int X, Y;
	while (scanf("%d%d", &X, &Y), X) {
		int tx, ty; scanf("%d%d", &tx, &ty); tx--; ty--;
		int kx, ky; scanf("%d%d", &kx, &ky); kx--; ky--;
		rep(i, Y)rep(j, X)scanf("%d", &mp[j][i]);
		map<PP, int>cnt;
		queue<PP>que;
		cnt[{ {tx, ty}, { kx,ky }}] = 1;
		que.push({ {tx,ty},{kx,ky} });
		while (!que.empty()) {
			PP p = que.front(); que.pop();
			if (p.first == p.second) {
				printf("%d\n", cnt[p] - 1);
				goto goal;
			}
			if (cnt[p] >= 100)continue;
			rep(i, 4) {
				int tnx = p.first.first + dx[i];
				int tny = p.first.second + dy[i];
				int knx = p.second.first - dx[i];
				int kny = p.second.second - dy[i];
				if (tnx < 0 || tnx >= X || tny < 0 || tny >= Y || mp[tnx][tny]) {
					tnx = p.first.first;
					tny = p.first.second;
				}
				if (knx < 0 || knx >= X || kny < 0 || kny >= Y || mp[knx][kny]) {
					knx = p.second.first;
					kny = p.second.second;
				}
				if (!cnt[{ {tnx, tny}, { knx,kny }}]) {
					cnt[{ {tnx, tny}, { knx,kny }}] = cnt[p] + 1;
					que.push({ { tnx, tny },{ knx,kny } });
				}
			}
		}
		puts("NA");
	goal:;
	}
}

Measured memory_bytes: 14100
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int num[30];
int main()
{
    char s[103];
    scanf("%s",s);
    int l = strlen(s);
    for(int i=0;i<l;i++)
    {
        num[ s[i]-'a' ]++;
    }
    bool flag = 0;
    for(int i=0;i<26;i++)
        if(num[i]&1)
    {
        flag = 1;
        break;
    }
    if(flag)
        puts("No");
    else puts("Yes");
    return 0;
}


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

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }
    
    vector<int> u(n, 0);
    for (int i = 0; i < n; i++)
        u[uf.find(i)] |= 1;
    
    cout << accumulate(u.begin(), u.end(), 0) << endl;
    
    return 0;
}

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

#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define _t(a) __typeof(a.end())
#define fi first
#define se second
#define gcd __gcd
#define pll pair<ll, ll>

int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++)
        scanf("%lld", &a[i]),
        a[i] += i? a[i -1]: 0;
    ll dp[n +3][n +3];
    for(int i = 0; i < n; i++)
        dp[i][i +1] = 0;
    for(int k = 2; k <= n; k++){
        for(int i = 0; i +k <= n; i++){
            dp[i][i +k] = dp[i][i +1] +dp[i +1][i +k];
            for(int j = i +2; j < i +k; j++)
                dp[i][i +k] = min(dp[i][i +k], dp[i][j] +dp[j][i +k]);
            dp[i][i +k] += a[i +k -1] -(i?a[i -1]:0);
        }
    }
    cout<< dp[0][n] << "\n";
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    string s;
    cin>>s;
    int ans=0;
    for(auto c:s)
    {
        if(c=='+'){
            ans++;
        } else
            ans--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,a10,b5,c,f,n;
    f=0;
    n=9999999;
    cin>>a>>b>>c;
    a10=a/10;
    b5=b/5;
    if(c==500){
        if(a>b){
            f=b;
        }else{
            f=a;
        }
    }else if(a10>b5){
        if(c%500==0){
            f=c/500*b;
        }else{
            f=(c/500+1)*b;
        }
    }else{
        if(c%1000==0){
            f=c/1000*a;
        }else if(c%1000>=501){
            f=(c/1000+1)*a;
            n=c/1000*a+b*2;
        }else{
            f=(c/1000+1)*a;
            n=c/1000*a+b;
        }
        if(f>n){
            swap(f,n);
        }
    }
    cout<<f<<endl;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  int sum=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum=sum+d.at(i)*d.at(j);
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int arr[3001];
int dp[3001][3001];

int f(int s, int e){
    if(s>e) return 0;
    int &ans = dp[s][e];
    if(ans!=-1) return ans;
    
    ans = max(arr[s]+min(f(s+2,e), f(s+1,e-1)),arr[e]+min(f(s,e-2), f(s+1,e-1)));
    return ans;
}

int32_t main(){
    memset(dp,-1,sizeof(dp));
    int n;    
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int temp = f(0,n-1);
    cout<<temp-(sum-temp);
}

Measured memory_bytes: 70784
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;



int main(){
int n; cin>>n;
int x[110000],y[110000],t[110000];
for(int i=0;i<n;i++)
cin>>t[i]>>x[i]>>y[i];

for(int i=0; i<n;i++){
int dist;
if(i==0) {
  dist=abs(x[i])+abs(y[i]);
  if(dist>t[i]) {cout<<"No"<<endl; return 0;}
  else{if((t[i]-dist)%2!=0) {cout<<"No"<<endl; return 0;} }
}
else {
dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);

if(dist > t[i]-t[i-1]) {cout<<"No"<<endl; return 0;}
else{
  if((t[i]-t[i-1]-dist) %2 != 0 ) {cout<<"No"<<endl; return 0;}
}
}
}
cout<<"Yes"<<endl;
}


Measured memory_bytes: 1408
#include <stdio.h>
int main(){

    int a;
    int b;

     scanf("%d",&a);
     scanf("%d",&b);
     
     if(a<b){
		 printf("a < b\n");
     }else if(a>b){
		 printf("a > b\n");
	 }else{
		 printf("a == b\n");
	 }
		 
     return 0;
}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int main(){
    char s[3];
    cin >> s[0] >> s[1] >> s[2];
    int ans = 0;
    for(int i=0;i<3;++i){
        if(s[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n; cin >> n;
    vl a(n), b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ttl1 = accumulate(all(a),0LL);
    ll ttl2 = accumulate(all(b),0LL);
    ll dif = ttl2 - ttl1;
    if(dif < 0){
        out("No");
        return 0;
    }
    ll cnt1 = 0, cnt2 = 0;
    //aに2, bに1
    rep(i,n){
        if(a[i] > b[i])cnt2+= a[i] - b[i]; //bをaに近づける
        else if(b[i] > a[i])cnt1+=(b[i]-a[i])/2; //aをbに近づける
    }
    //dif -= (cnt1 + cnt2);
    cout << (cnt1 >= cnt2?"Yes":"No" ) << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>

using namespace std;

class Dice {
public:
    int num[6];
    
    void Move(const char &dir) {
        int i = num[0];
        switch (dir) {
            case 'N':
                num[0] = num[1];
                num[1] = num[5];
                num[5] = num[4];
                num[4] = i;
                break;
            case 'S':
                num[0] = num[4];
                num[4] = num[5];
                num[5] = num[1];
                num[1] = i;
                break;
            case 'E':
                num[0] = num[3];
                num[3] = num[5];
                num[5] = num[2];
                num[2] = i;
                break;
            case 'W':
                num[0] = num[2];
                num[2] = num[5];
                num[5] = num[3];
                num[3] = i;
                break;
            default:
                break;
            }
    }
};

int main()
{
    Dice dice;
    string dir;
    
    for (int i = 0; i < 6; ++i) {
        cin >> dice.num[i];
    }

    cin >> dir;
    for (unsigned int i = 0; i < dir.length(); i++) {
        dice.Move(dir[i]);
    }
    
    cout << dice.num[0] << endl;
    
    return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vi W(N);
    rep(i, N) {
        cin >> W[i];
    }

    vll Wsum(N + 1);
    rep(i, N) {
        Wsum[i + 1] = Wsum[i] + W[i];
    }
    ll sum = accumulate(all(W), 0LL);

    ll ans = LINF;
    rep(i, 1, N) {
        ans = min(ans, abs(sum - 2 * Wsum[i]));
    }
    write(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <math.h>

using namespace std;
typedef long long int ll;

ll solve(vector<ll>& v)
{
    ll n = v.size();
    vector<vector<ll>> dp(n,vector<ll>(n,0));

    vector<ll> sum(n);

    sum[0] = v[0];
    for (ll i=1;i<n;++i)
    {
        sum[i] = sum[i-1] + v[i];
    }

    //f/or (auto i:sum) cout<<i<<" ";
    //cout<<endl;

    for (ll i=0;i<n-1;++i)
    {
        dp[i][i+1] = v[i] + v[i+1];
    }

    for (ll s=3;s<=n;++s)
    {
        ll lim = n - s;
        for (ll i=0;i<=lim;++i)
        {
            ll k = i + s - 1;

            ll M = INFINITY;
            ll range_sum = sum[k];
            if (i>0) range_sum -= sum[i-1];
            //cout<<i<<" "<<k<<" "<<range_sum<<"####"<<endl;

            for (ll j=i;j<=k-1;++j)
            {
                //cout<<dp[i][j]<<"A"<<j<<" "<<i<<" "<<s<<endl;
                //cout<<dp[j+1][k]<<"B"<<endl;
                ll cand = dp[i][j] + dp[j+1][k] + sum[k];
                if (i>0) cand -= sum[i-1];

                //cout<<cand<<"CAAA"<<endl;

                M = min(M,cand);
            }

            dp[i][k] = M;

        }

    }
    /**
    for (auto v:dp)
    {
        for (auto i:v)
        {
            cout<<i<<" ";
        }
        cout<<endl;
    }
    **/
    return dp[0][n-1];
}

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

    vector<ll> v(N);

    for (ll i=0;i<N;++i)
    {
        cin>>v[i];
    }

    cout<<solve(v)<<endl;

    return 0;
}


Measured memory_bytes: 4536
#include <iostream>
#include <string>

using namespace std;

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

    if (u == s) {
        cout << a - 1 << " " << b << endl;
    } else {
        cout << a << " " << b - 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <ostream>
#include <tuple>
#include <cassert>
#include <vector>
#include <algorithm>

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[";
    bool fst = true;
    for (auto&& v : vs) {
        if (fst) fst = false;
        else os << ",";
        os << v;
    }
    return os << "]";
}

namespace {
    int N, M, T, P;
    vector<int> D, C, X, Y;
    bool input() {
        cin >> N >> M >> T >> P;
        if (N == 0 && M == 0 && T == 0 && P == 0) return false;
        D = vector<int>(T, 0);
        C = vector<int>(T, 0);
        X = vector<int>(P, 0);
        Y = vector<int>(P, 0);
        for (int t = 0; t < T; t++) {
            cin >> D[t] >> C[t];
        }
        for (int p = 0; p < P; p++) {
            cin >> X[p] >> Y[p];
        }
        return true;
    }

    void solve() {
        vector<vector<int>> F(M, vector<int>(N, 1));
        for (int t = 0; t < T; t++) {
            int d = D[t];
            int c = C[t];
            auto trans = [&](int x, int y) {
                if (d == 1) {
                    if (x < c) {
                        return make_tuple(c - x - 1, y);
                    } else {
                        return make_tuple(x - c, y);
                    }
                } else if (d == 2) {
                    if (y < c) {
                        return make_tuple(x, c - y - 1);
                    } else {
                        return make_tuple(x, y - c);
                    }
                } else {
                    assert(false);
                }
            };
            int n = F[0].size();
            int m = F.size();
            vector<vector<int>> nF;
            if (d == 1) {
                nF = vector<vector<int>>(m, vector<int>(max(c, n - c), 0));
            } else if (d == 2) {
                nF = vector<vector<int>>(max(c, m - c), vector<int>(n, 0));
            } else {
                assert(false);
            }
            for (int x = 0; x < n; x++) {
                for (int y = 0; y < m; y++) {
                    int nx, ny;
                    tie(nx, ny) = trans(x, y);
                    nF[ny][nx] += F[y][x];
                }
            }
            //cout << "---nF---" << endl;
            //cout << nF << endl;
            F = nF;
        }
        for (int p = 0; p < P; p++) {
            int x = X[p];
            int y = Y[p];
            cout << F[y][x] << endl;
        }
    }
}

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



Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; ++i) {
    cin >> grid[i];
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if(grid[i][j] == '.') continue;
      vector<string> temp = grid;
      bool flag = false;
      if(i >= 1)
      {
        if(grid[i - 1][j] != '.')
        {
          temp[i - 1][j] = 'b';
          flag = true;
        }
      }
      if(i < h - 1)
      {
        if(grid[i + 1][j] != '.')
        {
          temp[i + 1][j] = 'b';
          flag = true;
        }
      }
      if(j >= 1)
      {
        if(grid[i][j - 1] != '.')
        {
          temp[i][j - 1] = 'b';
          flag = true;
        }
      }
      if(j < w - 1)
      {
        if(grid[i][j + 1] != '.')
        {
          temp[i][j + 1] = 'b';
          flag = true;
        }
      }
      if(flag)
      {
        temp[i][j] = 'b';
        grid = temp;
      }
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if(grid[i][j] == '#')
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)

n = int(input())
s = [list(map(int,input().split())) for i in range(n-1)]
t = defaultdict(list)
for i in range(n-1):
    p = [s[i][1],s[i][2]]
    q = [s[i][0],s[i][2]]
    t[s[i][0]] += [p]
    t[s[i][1]] += [q]

a = [-1]*n
a[0] = 0

def Tree(dic,a,x,lo):
    for i in range(len(dic[x])):
        if a[dic[x][i][0]-1] != -1:
            continue
        else:
            save = lo
            lo += dic[x][i][1]
            a[dic[x][i][0]-1] = lo
            a = Tree(dic,a,dic[x][i][0],lo)
            lo = save
    return a

lis = Tree(t,a,1,0)
for i in range(n):
    if lis[i] % 2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 106984
# coding: utf-8
# Your code here!
import math

HA=input().split()
H=int(HA[0])
N=int(HA[1])

sum=0

T=input().split()

for i in range(N):
    sum=sum+int(T[i])
    


    
if(sum<H):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 10132
N,M=map(int,input().split())
A = list(map(int, input().split()))
select=0
for i in range(len(A)):
    if A[i]>=sum(A)*(1/(4*M)):
        select+=1
    
def ans(M,select):   
    if M<=select:
         return 'Yes'
    
    else:
         return 'No'

print(ans(M,select))

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

int main(){
    ll n;
    cin >> n;
    
    vv f(n, v(10));
    rep(i,n)rep(j,10)cin >> f[i][j];
    
    vv p(n, v(11));
    rep(i,n)rep(j,11)cin >> p[i][j];
    
    
    ll ans = -2002002002LL;
    for(int k=1; k<1<<10; k++){
        ll now = 0;
        rep(i,n){
            int num = 0;
            rep(j,10){
                if((k & 1<<j) && f[i][j])
                    num++;
            }
            now += p[i][num];
        }
        ans = max(now, ans);
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    unordered_map<string,int> mp;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<mp.size()<<endl;
    return 0;
}

Measured memory_bytes: 17616
#include<bits/stdc++.h>
using namespace std;
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
const int N = (int)(1*1e6+10);
typedef long long ss;
int main()
{
   int a[6],i,j;
   for(i=1;i<=5;i++)
   {
       cin>>a[i];
       if(a[i]==0)
        j=i;
   }
   cout<<j<<endl;
   return 0;
}


Measured memory_bytes: 3576
#if 1
#include <bits/stdc++.h>
#else
#include "../../bits/stdc++.h"
#endif

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

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int N, M;
char U[258][12], T[258][12];

void input(){
  cin>>N;
  REP(i, N)cin>>U[i];
  cin>>M;
    REP(i, M)cin>>T[i];
}

void solve(){
  bool d=true;
  REP(i, M) {
    bool c = false;
    REP(j, N) {
      c = [](int x, int y) {
        int k;
        if(U[x][0]!=T[y][0])return false;
        for(k=1;U[x][k-1]!='\0';k++) {
          if(U[x][k]!=T[y][k])return false;
        }
        return true;
      }(j, i);
      if(c) {
        if(d)cout<<"Opened by "<<T[i];
        else cout<<"Closed by "<<T[i];
        d = !d;
        break;
      }
    }
    if(!c)cout<<"Unknown "<<T[i];
    cout<<endl;
  }
}

int main(){
  cin.tie(0);

  input();
  solve();

  return 0;
}

Measured memory_bytes: 3060