akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n), b(n);
	int ans = 0;
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	REP(i, 29) {
		map<int, int> ma, mb;
		int d = (1 << (i + 1));
		REP(i, n)ma[a[i] % d]++;
		REP(i, n)mb[b[i] % d]++;
		vi v, w;
		w.push_back(0);
		for (auto d : mb) {
			v.push_back(d.first);
			w.push_back(d.second);
		}
		REP(i, w.size() - 1)w[i + 1] += w[i];
		int tmp = 0;
		for (auto c : ma) {
			int val = c.first, cnt = c.second;
			if (val&(d >> 1)) {
				int maxv = d + (d >> 1) - val, minv = d - val-1;
				int f = lower_bound(ALL(v), maxv) - v.begin();
				int e = upper_bound(ALL(v), minv) - v.begin();
				tmp += cnt*(w.back() - w[f]);
				tmp += cnt*w[e];
			}
			else {
				int minv = (d >> 1) - val, maxv = d - val - 1;
				int f = upper_bound(ALL(v), maxv) - v.begin(),
					e= lower_bound(ALL(v), minv) - v.begin();
				
				tmp += cnt*(w[f] - w[e]);
			}
		}
		if (tmp % 2)ans |= (d >> 1);

	}
	cout << ans << endl;
}


Measured memory_bytes: 23568
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int N;
    cin>>N;
    vector<int> V(N,0);
    vector<int> C(N,0);
    vector<int> diff(N,0);
    int ans = 0;
    for(int i=0; i<N; i++){
        cin>>V[i];
    }
    for(int i=0; i<N; i++){
        cin>>C[i];
        diff[i] = V[i] - C[i];
    }
    for(int i=0; i<N; i++){
        if(diff[i]>0){
            ans += diff[i];
        }
    }
    cout<<ans<<endl;    
    return 0;
}

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

const int K = (int)(50);

int a, b;
char field[2 * K][2 * K];

void paint(int start_in, int end_out, int threshold, int mod, char mark) {
  int cnt = 1;
  for (int j = 0; j < 2 * K; ++j) for (int i = start_in; i < end_out; ++i){
    if (cnt >= threshold) {
      return;
    }
    if ((j % 2) == 0 && (i % 2) == mod) {
      field[i][j] = mark;
      cnt += 1;
    }

  }
}

int main(void) {
  // Here your code !
	scanf("%d %d", &a, &b);

  for (int i = 0; i < 2 * K; ++i) for (int j = 0; j < 2 * K; ++j) {
    if (i < K) field[i][j] = '.';
    else field[i][j] = '#';
  }

  paint(0, K, b, 0, '#');
  paint(K + 1, 2 * K, a, 1, '.');

  printf("%d %d\n", 2 * K, 2 * K);
  for (int i = 0; i < 2 * K; ++i) {
    for (int j = 0; j < 2 * K; ++j) {
      printf("%c", field[i][j]);
    }
    printf("\n");
  }

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();
        char[] array = s.toCharArray();
        String ans = "No";
        for (int i = 0; i < array.length; i++) {
            if (i % 2 == 0 && (array[i] == 'R' || array[i] == 'U' || array[i] == 'D')) {
                ans = "Yes";
            } else if (i % 2 == 1 && (array[i] == 'L' || array[i] == 'U' || array[i] == 'D')) {
                ans = "Yes";
            } else {
                ans = "No";
                break;
            }

        }
        System.out.println(ans);
    }
}



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const int MAX_A = 420;
const int MAX_B = 420;
const int MAX_N = 41;
int dp[MAX_A][MAX_B][MAX_N];

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

  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;

  const int INF32 = 1 << 30;

  for(int i = 0; i < MAX_A; i++){
    for(int j = 0; j < MAX_B; j++){
      for(int k = 0; k < MAX_N; k++){
        dp[i][j][k] = INF32;
      }
    }
  }
  
  dp[0][0][0] = 0;

  int a, b, c;
  for(int i = 0; i < N; i++){
    cin >> a >> b >> c;
    for(int x = 0; x <= 400; x++){
      for(int y = 0; y <= 400; y++){
        chmin(dp[x][y][i+1], dp[x][y][i]);
        chmin(dp[x+a][y+b][i+1], dp[x][y][i] + c);
      }
    }
  }

  int ans = INF32;
  int mul = 1;
  while(Ma * mul  <= 400 && Mb * mul <= 400){
    for(int i = 0; i <= N; i++){
      chmin(ans, dp[Ma * mul][Mb * mul][i]);
    }
    mul++;
  }

  if(ans == INF32){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 28544
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define pb push_back
using namespace std;
const int N=2e5+5;
vector<int> G[N],a[3];
int ans[N];
void dfs(int u,int f,int d){
    a[d].pb(u);
    rep(i,0,G[u].size()-1){ int v=G[u][i]; if (v!=f) dfs(v,u,d^1); }
}
int main(){
    int n; scanf("%d",&n);
    rep(i,1,n-1){ int u,v; scanf("%d%d",&u,&v); G[u].pb(v),G[v].pb(u); }
    dfs(1,0,1);
    if (a[0].size()>a[1].size()) swap(a[0],a[1]);
    if (a[0].size()<=n/3){
        rep(i,0,a[0].size()-1) ans[a[0][i]]=(i+1)*3;
        int c=0;
        rep(i,1,n){
            if (i%3==0) continue;
            ans[a[1][c++]]=i;
        }
        c=a[0].size();
        rep(i,1,n) if (!ans[i]) ans[i]=(++c)*3;
    }
    else{
        int c=0;
        rep(i,0,a[0].size()-1)
            if (i*3+2<=n) ans[a[0][i]]=i*3+2;
            else ans[a[0][i]]=(++c)*3;
        rep(i,0,a[1].size()-1)
            if (i*3+1<=n) ans[a[1][i]]=i*3+1;
            else ans[a[1][i]]=(++c)*3;
    }
    rep(i,1,n) printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 21620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int A, B;
    cin >> A >> B;
    if(A % 2 == B % 2){
        cout << (A + B) / 2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 100010
#define LL long long
typedef struct
{
    LL x,y;
}Node;
Node e[N*2];
LL s1[N],s2[N];
LL r1[N],r2[N];
int main()
{
    int i,j,k,n;
    LL m,ans,s;
    scanf("%d%lld",&n,&m);
    e[0].x=0;
    e[0].y=0;
    e[n+1].x=m;
    e[n+1].y=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld%lld",&e[i].x,&e[i].y);
        e[i+n+1].x=e[i].x+m;
        e[i+n+1].y=e[i].y;
    }
    ans=0;

    s1[0]=0;
    for(i=1;i<=n;i++)
    {
        s1[i]=s1[i-1]+e[i].y-(e[i].x-e[i-1].x);
        ans=max(ans,s1[i]);
    }
    r1[0]=0;
    for(i=1;i<=n;i++)
        r1[i]=max(r1[i-1],s1[i]);


    s2[n+1]=0;
    for(i=n;i>=1;i--)
    {
        s2[i]=s2[i+1]+e[i].y-(e[i+1].x-e[i].x);
        ans=max(ans,s2[i]);
    }
    r2[n+1]=0;
    for(i=n;i>=1;i--)
        r2[i]=max(r2[i+1],s2[i]);

    for(i=1;i<n;i++)
    {
        s=s1[i]+r2[i+1]-e[i].x;
        ans=max(ans,s);
    }
    for(i=n;i>1;i--)
    {
        s=s2[i]+r1[i-1]-(e[n+1].x-e[i].x);
        ans=max(ans,s);
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  string S;cin>>S;
  int N=siz(S);
  int ans = 0;
  REP(i,N/2) {
    if (S[i]!=S[N-1-i]) ans++;
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int main(){
  string S;
  cin >> S;
  map<char,int> A;
  A['+'] = 0;
  A['-'] = 0;
  for(int i = 0; i < S.size(); i++){
    A[S[i]]++;
  }
  cout << A['+'] - A['-'];
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int t = sc.nextInt();
		for(int i=0;i<t;i++){
			int n = sc.nextInt();
			int k = sc.nextInt();
			int[] a = new int[n];
			for(int j=0;j<n;j++) a[j] = sc.nextInt();
			
			if(n-k<=0){
				System.out.println(0);
			}else{
				int[] b = new int[n-1];
				for(int j=0;j<n-1;j++) b[j] = a[j+1]-a[j];
				Arrays.sort(b);
				int r = a[n-1]-a[0];
				for(int j=1;j<k;j++) r-=b[n-1-j];
				System.out.println(r);
			}
		}
	}	
}

Measured memory_bytes: 113888
#include <bits/stdc++.h>
using namespace std;
 
//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(i,0,n)
//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();}
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------



long long n;
long long num[6];
long long mini = 1e16;
long long plu;

int main(){

    cin >> n;
    REP(i,5){
        cin >> num[i];
        mini = min(num[i], mini);   
        // debug(mini);
    }

    plu = n - mini;
    // debug(plu);
    if(plu > 0){
        if(plu % mini != 0){
            cout << 5 + (plu / mini )+ 1 << endl;
        }else{
            cout << 5 + (plu / mini ) << endl;
        }
    }else{
        cout << "5" << endl;
    }

    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n+10);

  int ac=0,wa=0;
  for (int i = 0; i < m; i++)
  {
    int p;
    string s;
    cin >> p >> s;

    if(s=="WA"){
      if(a[p]==-1){
        continue;
      }
      else{
        a[p]++;
      }
    }
    else{
      if(a[p]==-1){
        continue;
      }
      else{
        wa+=a[p];
        ac++;
        a[p]=-1;
      }
    }
  }
  cout << ac << " " << wa << endl;  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, p;
int a[105];
ll odd = 0, even = 0;
int main()
{
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
            if (!(a[i] & 1)) even++;
            else odd++;
        }
    if (p == 1) {
        if (odd == 0) printf("0\n");
        else printf("%lld\n", (1LL << even) * (1LL << (odd - 1LL)));
    }
    else {
        if (odd == 0) printf("%lld\n", (1LL << even));
        else printf("%lld\n", (1LL << even) * (1LL << (odd - 1LL)));
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i=0; i<m; ++i)
        cin >> b[i];

    int ans = 0;
    for(int i=0; i<n; ++i){
        int sum = c;
        for(int j=0; j<m; ++j){
            int a;
            cin >> a;
            sum += a * b[j];
        }
        if(sum > 0)
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 764
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    string s, t; cin>>s>>t;
    int n = s.size();

    vector<vector<int>> f(26, vector<int>(26, 0));
    for(int i=0; i<n; i++){
        f[s[i] - 'a'][t[i] - 'a'] = 1;
    }

    for(int i=0; i<26; i++){
        int cnt1 = 0, cnt2 = 0;
        for(int j=0; j<26; j++){
            cnt1 += f[i][j];
            cnt2 += f[j][i];
        }

        if(1 < cnt1 || 1 < cnt2){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
int n;
int ans[105];
int cnt;
int main()
{
	scanf("%d",&n);
	if(!n)
	{
		cout<<0<<endl;
		return 0;
	}
	while(n)
	{
		
		++cnt;
		//cout<<n<<endl;
		if(abs(n)%(-2)) 
		{
			ans[cnt]=1;
			n--;
		}
		n/=-2;
        //cout<<ans[cnt]<<endl;
	}
	for(int i=cnt;i>=1;--i)
	   printf("%d",ans[i]);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    } else if (i == N - 1) {
      cout << "Three" << endl;
    }
  }
}


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

namespace AOJ1_10_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] _str = Console.ReadLine().Split(' ');
            double[] _abC = new double[_str.Length];
            string S;
            string L;
            string h;
            for (int i = 0; i < _abC.Length; i++)
            {
                _abC[i] = int.Parse(_str[i]);
            }
            double a = _abC[0];
            double b = _abC[1];
            double sinC = Math.Sin(_abC[2]/180* Math.PI);
            double cosC = Math.Cos(_abC[2]/180*Math.PI);
            S =(a * b * sinC / 2).ToString("F5");//面積
            double c = Math.Sqrt(a * a + b*b - (2 * a * b * cosC));
            L = (a + b + c).ToString("F5");
            h = ((double.Parse(S) / a) * 2).ToString("F5");
            Console.WriteLine(S);
            Console.WriteLine(L);
            Console.WriteLine(h);

        }
    }
}



Measured memory_bytes: 15908
#include "bits/stdc++.h"
using namespace std;

int main() {
stack<int> S1;
stack<pair<int,int> > S2;
char ch;
int sum=0;
for (int i = 0; cin>>ch; ++i) {
	if(ch=='\\')S1.push(i);
	else if (ch=='/'&&S1.size()>0){
		int j=S1.top();S1.pop();
		sum+=i-j;
		int a=i-j;
		while(S2.size()>0&&S2.top().first>j){
			a+=S2.top().second;S2.pop();
		}
		S2.push(make_pair(j,a));
	}
}
vector<int> ans;
int t=0;
while(S2.size()>0){ans.push_back(S2.top().second);S2.pop();}
reverse(ans.begin(),ans.end());
cout<<sum<<endl;
cout<<ans.size();
for (int i = 0; i < ans.size(); ++i) {
	cout<<" ";
	t+=ans[i];
	cout<<ans[i];
}
cout<<endl;
return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<cstring>
#include<vector>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<utility>
#include<climits>
#include<set>
using namespace std;
#define ll long long


int main(){ 
	ios_base::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
	    
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif


	string s;cin>>s;
	if(s[s.length()-1]=='s')
		cout<<s<<"es";
	else
		cout<<s<<'s';
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <cassert>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
int main(){
	int A, P;
	cin >> A >> P;
	int Pa = A * 3;
	cout << (Pa + P) / 2 << endl;
}

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

int N,M,T,P,d,c,x,y;
int A[2][50][50] = {};

int main(){
	while(cin >> N >> M >> T >> P && N>0){
		for(int i=1;i<=N;i++){
			for(int j=1;j<=M;j++){
				A[0][i][j] = 1;
				A[1][i][j] = 0;
			}
		}
		int n = N,m = M;
		for(int t=0;t<T;t++){
			cin >> d >> c;
			if(d==1){
				for(int i=c+1;i<=n;i++){
					for(int j=1;j<=m;j++){
						A[1-t%2][i-c][j] = A[t%2][i][j];
					}
				}
				for(int i=1;i<=c;i++){
					for(int j=1;j<=m;j++){
						A[1-t%2][i][j] += A[t%2][c-i+1][j];
					}
				}
				n = max(n-c,c);
			}else{
				for(int i=1;i<=n;i++){
					for(int j=c+1;j<=m;j++){
						A[1-t%2][i][j-c] = A[t%2][i][j];
					}
				}
				for(int i=1;i<=n;i++){
					for(int j=1;j<=c;j++){
						A[1-t%2][i][j] += A[t%2][i][c-j+1];
					}
				}
				m = max(m-c,c);
			}
			for(int i=1;i<=N;i++){
				for(int j=1;j<=M;j++){
					A[t%2][i][j] = 0;
				}
			}
		}
		for(int i=0;i<P;i++){
			cin >> x >> y;
			cout << A[T%2][x+1][y+1] << endl;
		}
	}
}



Measured memory_bytes: 3112
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;

        for (int i = 0; i<n ; i++){
            double x = sc.nextDouble();
            double y = sc.nextDouble();

            double area = Math.sqrt( (x*x) + (y*y) );
            if (area<=d)
                ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 63924
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
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;
}
using namespace std;
int main(){
   int h,w;
   cin>>h>>w;
   string s;

   rep(i,h){
      cin>>s;
      cout<<s<<endl<<s<<endl;
   }


return 0;
}


Measured memory_bytes: 256
a = input()
n = len(a)

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

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

Measured memory_bytes: 3500
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i = 0; i <= n; i += 4){
        if((n - i) % 7 == 0){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

const int M=1000000007;
int tp,n,m,f1,f2,c1,c2,c;
long long k,ans,a[2][2],b[2][2],d[2][2];
char s[1005][1005];
long long fexp(long long x,long long t){
	if(!t)return 1;
	long long tmp=fexp(x,t>>1);tmp=tmp*tmp%M;
	return (t&1)?tmp*x%M:tmp;
}
void mul(long long x[][2],long long y[][2]){
	memset(d,0,sizeof(d));
	for(int i=0;i<2;i++)for(int k=0;k<2;k++)for(int j=0;j<2;j++)d[i][j]=(d[i][j]+x[i][k]*y[k][j])%M;
	memcpy(b,d,sizeof(d));
}
void fexp(long long t){
	if(!t)return (void)(b[0][0]=b[1][1]=1,b[0][1]=b[1][0]=0);
	fexp(t>>1);
	mul(b,b);
	if(t&1)mul(a,b);
}
int main(){
	tp=1;//scanf("%d",&tp);
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=0;i<n;i++)scanf("%s",s[i]);
	for(int i=0;i<m;i++)if(s[0][i]=='#'&&s[n-1][i]=='#')f2++;
	for(int i=0;i<n;i++)if(s[i][0]=='#'&&s[i][m-1]=='#')f1++;
	for(int i=0;i<n;i++)for(int j=0;j<m-1;j++)if(s[i][j]=='#'&&s[i][j+1]=='#')c1++;
	for(int i=0;i<n-1;i++)for(int j=0;j<m;j++)if(s[i+1][j]=='#'&&s[i][j]=='#')c2++;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(s[i][j]=='#')c++;
	if(k<=1)ans=1;
	else if(f1&&f2)ans=1;
	else if(!f1&&!f2)ans=fexp(c,k-1);
	else{
		a[0][0]=c;
		if(f1)a[1][1]=f1,a[0][1]=M-c1;
		else a[1][1]=f2,a[0][1]=M-c2;
		fexp(k-1);
		ans=(b[0][0]+b[0][1])%M;
	}
	if(!tp)if(ans==1)printf("YES\n");else printf("NO\n");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,t,s=0;
	cin>>a;
	t=a;
	do{
		s=s+t%10;
		t/=10;
	}while(t!=0);
	if(a%s==0)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
/** @Date    : 2017-07-09 20:31:43
  * @FileName: B.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int main()
{
	LL n, a, b, l, r;
	while(~scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &l, &r)){
		int flag = 1;
		LL x, y;
		for(LL i = 0; i <= n - 1; i++)
		{
			x = a + l * i - (n - i - 1) * r;
			y = a + r * i - (n - i - 1) * l;
			if(x <= b && b <= y)
				flag = 0;
		}
		printf("%s\n", flag?"NO":"YES");
	}
    return 0;
}

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

using namespace std;
string s;
long long k;

int main()
{
	cin>>s>>k;
	int n=s.size();
	if(n==1)
	{
		cout<<k/2<<endl;
		return 0;
	}
	if(n==2)
	{
		cout<<(s[0]==s[1])*k<<endl;
		return 0;
	}
	long long a=0,b=0;
	while(s[a]==s[n-1]&&a<n)
		a++;
	while(b<n&&s[0]==s[n-b-1])
		b++;
	long long cnt=0;
	for(int i=0;i<n-1;i++)
	{
		if(s[i]==s[i+1])
		cnt++,i++;
	}
	if(a==n)
	{
		cout<<n*k/2<<endl;
		return 0;
	}
	cout<<cnt*k-((a/2)+(b/2)-((a+b)/2))*(k-1)<<endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w,  y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;
double x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>n>>h>>w;
    y=(n-h);
    z=(n-w);

    ans = (z+1)*(y+1);
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <vector>
#define PB push_back
#define rep(a,b,c) for(int a=b;a<c;a++)
#define Rep(a,b,c) for(int a=b;a<c;a++)
#define rep_(a,b,c) for(c::iterator a=b.begin();a!=b.end();a++)

int l[100005],r[100005],d[100005]={0};
int even[100005]={0};//0 undetermined 1 even 2 odd
vector<int> v[100005];

bool tree1(int t)
{
	rep_(i,v[t],vector<int>)
		if (d[*i]==0)
		{
			d[*i]=d[t]+1;
			if (!tree1(*i)) return false;
			l[t]=max(l[t],l[*i]-1);
			r[t]=min(r[t],r[*i]+1);
			if (even[*i]!=0)
			{
				if (even[*i]==even[t]) return false;
				else even[t]=3-even[*i];
			}
			if (l[t]>r[t]) return false;
		}
	return true;
}

bool tree2(int t)
{
	rep_(i,v[t],vector<int>)
		if (d[*i]==d[t]+1)
			l[*i]=max(l[*i],l[t]-1),tree2(*i);
}

int main()
{
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	int n,k,t1,t2;
	cin >> n;
	rep(i,0,n-1)
	{
		cin >> t1>>t2;
		v[t2].PB(t1);
		v[t1].PB(t2);
	}
	rep(i,1,n+1)
	{
		l[i]=-1000005;
		r[i]=2000005;
	}
	cin >> k;
	rep(i,0,k)
	{
		cin>>t1>>t2;
		l[t1]=r[t1]=t2;
		even[t1]=1+t2%2;
	}
	d[1]=1;
	if (!tree1(1)) cout << "No\n";
	else
	{
		tree2(1);
		cout << "Yes\n";
		rep(i,1,n+1) cout << l[i] << endl;
	}
	//rep(i,1,n+1)
	//	cout << l[i] << ' ' << r[i] << ' '<<even[i] << endl;

}



Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,ans=1;
	string s;
	cin>>a>>b>>s;
	rep(i,a+b+1){
	    if(i==a&&s[i]!='-')ans=0;
	    if(i!=a&&s[i]=='-')ans=0;
	}
	if(ans)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	long[] A;
	long count;
	Map<Long, Set<Integer>> upperMap;
	Map<Long, Set<Integer>> lowerMap;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		tokens = in.readLine().split(" ");
		A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(tokens[i]);
		}
		upperMap = new HashMap<>();
		lowerMap = new HashMap<>();
		for (int i = 0; i < N; ++i) {
			long upper = A[i] + i;
			long lower = i - A[i];
			if (!upperMap.containsKey(upper)) {
				upperMap.put(upper, new HashSet<>());
			}
			upperMap.get(upper).add(i);
			if (!lowerMap.containsKey(lower)) {
				lowerMap.put(lower, new HashSet<>());
			}
			lowerMap.get(lower).add(i);
		}
	}

	void calc() {
		for(Long upper: upperMap.keySet()) {
			if(lowerMap.containsKey(upper)) {
				count += (long)(upperMap.get(upper).size()) * (long)(lowerMap.get(upper).size());
			}
		}
		System.out.println(count);
	}

	void showResult() {
	}
}

Measured memory_bytes: 144652
n, m = map(int, input().split())
list_MAP = [[0]*n for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    list_MAP[a-1][b-1] = 1
    list_MAP[b-1][a-1] = 1

dp = [[0]*n for _ in range(1<<n)]
dp[1][0] = 1
for num in range(1<<n):
    for v in range(n):
        if num & (1<<v) == 0:
            continue
        sub = num ^ (1<<v)

        for u in range(n):
            if sub & (1<<u) and list_MAP[v][u]:
                dp[num][v] += dp[sub][u]
ans = sum(dp[(1 << n) - 1])
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/

const int MAX = 10000000;
/****** define variable start ******/
ll n, r;
/******* define variable end *******/
ll solve(){
    cin >> n >> r;
    if(n < 10){
        cout << r + 100 * (10 -  n) << endl;
    }else{
        cout << r << endl;
    }
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    
    return (int)end_solve;
}


Measured memory_bytes: 764
#include <iostream>

#include <string.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    char s[8];
    cin >> s;
    
    if (strcmp(s, "SUN") == 0) {
        cout << 7 << endl;
    } else if (strcmp(s, "MON") == 0) {
        cout << 6 << endl;
    } else if (strcmp(s, "TUE") == 0) {
        cout << 5 << endl;
    } else if (strcmp(s, "WED") == 0) {
        cout << 4 << endl;
    } else if (strcmp(s, "THU") == 0) {
        cout << 3 << endl;
    } else if (strcmp(s, "FRI") == 0) {
        cout << 2 << endl;
    } else if (strcmp(s, "SAT") == 0) {
        cout << 1 << endl;
    }
    
    return 0;
}


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

int f(int n){
    if(n % 2 == 0){
        return n / 2;
    }else{
        return n * 3 + 1;
    }
}

int findIndex(int value , vector<int> vec){
    vector<int>::iterator iter = std::find( vec.begin(), vec.end(), value);
    int index = std::distance( vec.begin(), iter );
    if(index == vec.size()){
        return -1;
    }
    return index;
}

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

    vector<int> nums(1000000);
    int index = 0;
    int insert = 0;
    nums.at(index) = s;
    bool flag = true;
    while(flag){
        ++index;
        insert = f(nums.at(index - 1));
        if(findIndex(insert, nums) != -1){
            flag = false;
        }else{
            nums.at(index) = insert;
        }
    }
    cout << index + 1 << endl;
}

Measured memory_bytes: 8124
fun main() {
  val N = readInt()
  val A = readInts()
  println(1.0 / A.map { 1.0 / it }.sum())
}

fun gcd(a: Int, b: Int): Int = if (a < b) gcd(b, a) else if (b == 0) a else gcd(b, a % b)
fun gcd(a: Long, b: Long): Long = if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Int, b: Int): Int = (a * b) / gcd(a, b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)

fun readString() = readLine()!!
fun readStrings() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 37864
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

//マクロ定義
#define MAX 10
#define TRUE 1
#define FALSE 0

#define compile 0
/*
デバッグ用
0:実装 1:main関数 2:initialize関数 3:judge関数 4:output関数
*/

//関数のプロトタイプ宣言
void initialize(int array[]); //配列の初期化
int judge(int input[], int cylinderB[], int cylinderC[]);
void output(int flag);

main()
{
	int i = 0, j = 0, n = 0; //i:for文制御変数j:入力制御変数n:ループ上限回数を代入する変数
	int input[MAX], cylinderB[MAX], cylinderC[MAX]; //配列を3つ宣言
	int flag = 0; //結果はフラグで管理
	scanf("%d", &n); //ループ回数を入力
	
	for(i = 0; i < n; i++)
	{
		initialize(input); //配列の初期化
		initialize(cylinderB);
		initialize(cylinderC);
		
		for(j = 0; j < MAX; j++) //入力値の取得
		{
			scanf("%d", &input[j]);
		}
		
		flag = judge(input, cylinderB, cylinderC); //判定を行う
		
#if compile == 1
		printf("flag = %d\n", flag);
#endif
		output(flag);
		flag = 0;
	}
	
	return 0;
}

void initialize(int array[]) //配列の初期化
{
	int i = 0;
	for(i = 0; i < MAX; i++)
	{
		array[i] = 0;
	}
}

int judge(int input[], int cylinderB[], int cylinderC[])
{
	int i = 0, j = -1, k = -1; //i:for文制御変数j:cylinderB[]制御変数k:cylinderC[]制御変数
	cylinderB[++j] = input[i]; //この時点でcylinderB[0]にはinput[0]の値が代入される
	for(i = 1; i < MAX; i++)
	{
		if((input[i] < cylinderB[j]) && (input[i] < cylinderC[k]))
		{
#if compile == 3
			for(i = 0; i < MAX; i++)
			{
				printf("input[%d] = %d cylinderB[%d] = %d cylinderC[%d] = %d\n", i, input[i], i, cylinderB[i], i, cylinderC[i]);
			}
#endif
			return FALSE;
		}
		else if(((input[i] - cylinderB[j]) < 0) && ((input[i] - cylinderC[k]) > 0))
		{
			cylinderC[++k] = input[i];
		}
		else if(((input[i] - cylinderB[j]) > 0) && ((input[i] - cylinderC[k]) > 0))
		{
			cylinderB[++j] = input[i];
		}
		else if((input[i] > cylinderB[j]) && (input[i] > cylinderC[k]))
		{
			if(((input[i] - cylinderB[j]) > (input[i] - cylinderC[k])))
			{
				cylinderC[++k] = input[i];
			}
			else
			{
				cylinderB[++j] = input[i];
			}
		}
	}
#if compile == 3
	for(i = 0; i < MAX; i++)
	{
		printf("input[%d] = %d cylinderB[%d] = %d cylinderC[%d] = %d\n", i, input[i], i, cylinderB[i], i, cylinderC[i]);
	}
#endif
	return TRUE;
}

void output(int flag)
{
	if(flag == FALSE)
	{
		puts("NO");
	}
	else if(flag == TRUE)
	{
		puts("YES");
	}
	return;
}

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

ll power(ll x,ll y,ll p)  
{  
    ll res = 1;     // Initialize result  
    if(y == 0)
        return(1 % p);
    
    x = x % p; // Update x if it is more than or  
                // equal to p 
    if (x == 0)
        return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {   
        // If y is odd, multiply x with result  
        if (y & 1LL)  
            res = (res * x) % p;  
  
        // y must be even now  
        y = y >> 1LL; // y = y/2  
        x = (x * x) % p;  
    }
    
    return res;  
}

ll solve(ll N) //N is of order 1e5
{
    ll c = 1;
    while(N)
    {
        ll set = __builtin_popcount(N);
        N = N % set;
        c++;
    }
    
    return(c);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll T = 1;
    while(T--)
    {
        ll N; cin>>N;
        string s; cin>>s;
        ll count = 0;
        for(ll i=0;i<N;++i)
            count += (s[i] == '1');
       
        //cout<<count<<endl;
        ll pre1[N] = {0};
        ll suff1[N] = {0};
        ll pre2[N] = {0};
        ll suff2[N] = {0};
        
        for(ll i=0;i<N;++i)
        {
            ll bx = (s[i] == '1') ? 1 : 0;
            
            if(count > 1)
                pre1[i] = (((i > 0) ? pre1[i - 1] : 0) + bx * power(2LL,N - i - 1,count - 1)) % (count - 1);
            
            pre2[i] = (((i > 0) ? pre2[i - 1] : 0) + bx * power(2LL,N - i - 1,count + 1)) % (count + 1);
            //cout<<i<<" "<<bx<<" "<<pre2[i]<<endl;
        }
        
        for(ll i=(N - 1);i>=0;--i)
        {
            ll bx = (s[i] == '1') ? 1 : 0;
            if(count > 1)
                suff1[i] = (((i < (N - 1)) ? suff1[i + 1] : 0) + bx * power(2LL,N - i - 1,count - 1)) % (count - 1);
            suff2[i] = (((i < (N - 1)) ? suff2[i + 1] : 0) + bx * power(2LL,N - i - 1,count + 1)) % (count + 1);
        }
        
        for(ll i=0;i<N;++i)
        {
            ll num = 0;
            if(s[i] == '0')
                num = (((i > 0) ? pre2[i - 1] : 0) + ((i < (N - 1)) ? suff2[i + 1] : 0) + power(2LL,N - i - 1,count + 1)) % (count + 1);
            else if(count > 1)
                num = (((i > 0) ? pre1[i - 1] : 0) + ((i < (N - 1)) ? suff1[i + 1] : 0)) % (count - 1);
           
            //cout<<"i: "<<i<<": "<<num<<endl;
            if((count == 1) && (s[i] == '1'))
                cout<<0<<endl;
            else
                cout<<solve(num)<<endl;
        }
    }
}

Measured memory_bytes: 9972
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll csb(ll n){ ll count = 0;while (n){ count += n & 1; n >>= 1; } return count;}


int main()
{

fastIO;
ll test,t,i,j,k,n,m,a,b,x,y,u,temp;
cin>>n;
ll arri[n+5],arrj[n+5],arr[n+5];
ll cnt=0;
map <ll,ll> mp;
rep(i,1,n+1)
{
    cin>>arr[i];
    arri[i]=arr[i]+i;
    arrj[i]=i-arr[i];
    mp[arrj[i]]++;
}
rep(i,1,n+1)
{
    cnt+=mp[arri[i]];
    mp[arrj[i]]--;
}
cout<<cnt;
return 0;
}

Measured memory_bytes: 30996
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort(key=lambda x:-abs(x))
mod=10**9+7

ans=1
if (max(A)<=0 and k%2==1) or n==k:
    for i in range(k):
        ans=ans*A[n-1-i]%mod
else:
    mi=0
    pl=0
    flg=1
    for i in range(k):
        ans=ans*A[i]%mod
        if A[i]>0:
            pl=A[i]
        if A[i]<0:
            mi=A[i]
            flg*=-1
    if ans==0:
        pass
    elif flg==-1:
        mi2=None
        pl2=None
        for i in range(k,n):
            if A[i]>=0:
                pl2=A[i]
                break
        for i in range(k,n):
            if A[i]<=0:
                mi2=A[i]
                break
        can=0
        if mi!=0 and pl2 is not None and pl!=0 and mi2 is not None:
            if pl2*pl > mi2*mi:
                can = pow(mi,-1,mod)*pl2%mod
            else:
                can = pow(pl,-1,mod)*mi2%mod
        elif mi!=0 and pl2 is not None:
            can = pow(mi,-1,mod)*pl2%mod
        elif pl!=0 and mi2 is not None:
            can = pow(pl,-1,mod)*mi2%mod 
        ans=ans*can%mod

print(ans)
               
    


Measured memory_bytes: 31920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;


signed main(){
    IOS();
    string s; cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;


}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        string s;
        cin >> s;
        if (s[2] == s[3] && s[4] == s[5]) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
ap = [e + 1 for e in a]
am = [e - 1 for e in a]

table = [0 for _ in range(10**5 + 2)]
for e in a:
    table[e + 1] += 1
    table[(e+1) + 1] += 1
    table[(e-1) + 1] += 1
print(max(table))



Measured memory_bytes: 16212
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll n, a, b;
  cin>>n>>a>>b;
  ll h[100000];
  for(int i=0; i<n; i++) cin>>h[i];
  ll l=1, r=1e9;
  while(l!=r){
    ll m=(l+r)/2;
    ll c=0;
    for(int i=0; i<n; i++){
      if(h[i]>b*m){
        c+=(h[i]-b*m+a-b-1)/(a-b);
      }
    }
    if(c<=m) r=m;
    else l=m+1;
  }
    cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	int size;
	size = S.size();
	int c;
	c = (size + 1) / 2;
	for (int i = 0; i < c; i++) {
		cout << S[2 * i];
	}

}

Measured memory_bytes: 512
N,Y = list(map(int,input().split()))

ans = '-1 -1 -1'
for x in range(N+1):
    if 10000 * x > Y:
        break
    
    y = (Y//1000-9*x-N)/4
    z = N-x-y
    
    if y.is_integer()==True and z.is_integer():
        if x >=0 and y>=0 and z>=0: 
            ans=' '.join(map(str,[x,int(y),int(z)]))
            break
        
print(ans)

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

const int MAX = 1e5+5;

const int MOD = 1e9 + 7;

ll ara[MAX];
int  n ,d;



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin>>n;
    ll sum = 0;
    for(int i =0 ; i < n ;i++ ) {
        cin>>ara[i];
        sum +=ara[i];
    }
    
    
    ll sum1=  0;
    for(int i =1 ; i < n ; i+=2 ) {
        
         sum1+= ara[i];
    }
    
    sum1*=2;
    
    
    ll first = sum - sum1;
    
    
    vector<ll>ans;
    for(int i =n-1 ; i >=0 ; i-- ) {
        
        ara[i]*=2;
        
        first = ara[i] - first;
        ans.push_back(first);
        
    }
    
    reverse(ans.begin() , ans.end() ) ;
    for(auto x : ans) {
        cout<<x<<" ";
    }
    cout<<endl;
    return 0;
    
}

Measured memory_bytes: 3060
import java.util.Scanner;



public class Main {
	final int N = 12;
	final int[][] ofs = {
			{1, 0}, {0,-1}, {-1, 0}, {0, 1}
	};
	void del(boolean[][] map, int y, int x){
		map[y][x] = false;
		for(int i=0; i<4; ++i){
			int nx = x + ofs[i][0];
			int ny = y + ofs[i][1];
			if(0<=ny && ny<N && 0<=nx && nx<N){
				if(map[ny][nx]){
					del(map, ny, nx);
				}
			}
		}
	}
	
	int solve(boolean map[][]){
		int c = 0;
		
		for(int y=0; y<N; ++y){
			for(int x=0; x<N; ++x){
				if(map[y][x]){
					c++;
					del(map, y, x);
				}
			}
		}
		
		return c;
	}
	
	void io(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char[][] str = new char[N][N];
			for(int i=0; i<N; ++i){
				str[i] = sc.nextLine().toCharArray();
			}
			
			boolean[][] map = new boolean[N][N];
			for(int y=0; y<N; ++y){
				for(int x=0; x<N; ++x){
					map[y][x] = str[y][x]=='1';
				}
			}
			
			System.out.println(solve(map));
			if(sc.hasNext()){ sc.nextLine(); }//から読み
		}
	}
	
	public static void main(String[] args) {
		new Main().io();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
const long long mod = 1000000007LL;

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

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

    long long ans = 0;
    for (int i=0; i<60; ++i) 
    {
        int a0 = 0;
        int a1 = 0;
        for(int j=0; j<N; ++j)
        {
            if (A[j]&(1LL<<i))
                a1++;
            else
                a0++;
        }
        ans = (ans + (1LL<<i) % mod * a1 % mod * a0) % mod;
    }
 
    ans = ans % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
while line = gets.chomp
  break if line == "0 0"
  n,x = line.split(" ").map(&:to_i)
  cnt = 0
  1.upto(n-2) do |a|
    (a+1).upto(n-1) do |b|
      c = x - a - b
      cnt += 1 if (c <= n and c > b)
    end
  end
  puts cnt
end

Measured memory_bytes: 8624
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
    int n, cnt = 0, minj;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) {
        minj = i;
        for (int j = i; j < n; j++){
            if (A[j] < A[minj]) minj = j;
        }
        int a = A[i]; A[i] = A[minj]; A[minj] = a;
        if (i != minj) cnt++;
    }
    for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i == n-1) cout << endl;
        else cout << " ";
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3100