akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int x;cin>>x;
    cout<<1-x<<endl;
    return 0;
}

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

int main(){
    int X,Y,A,B,C; cin >> X >> Y >> A >> B >> C;
    vector <int> Z(X+Y);
    
    vector <int> P(A);
    rep(i,A) cin >> P[i];
    sort(P.begin(),P.end(),greater<int>());
    
    vector <int> Q(B);
    rep(i,B) cin >> Q[i];
    sort(Q.begin(),Q.end(),greater<int>());
    
    vector <int> R(C);
    rep(i,C) cin >> R[i];
    sort(R.begin(),R.end(),greater<int>());
    
    
    ll ans=0;
    rep(i,X){
        ans+=P[i];
        Z[i]=P[i];
    }
    rep(i,Y){
        ans+=Q[i];
        Z[i+X]=Q[i];
    }
    sort(Z.begin(),Z.end(),greater<int>());
    
    //rep(i,X+Y) cout << Z[i] << " " ;
    //cout << endl;
    
    //rep(i,C) cout << Z[(X+Y-1)-i] << " ";
    //cout << endl;
    
    rep(i,min(X+Y,C)){
        if (R[i]>Z[(X+Y-1)-i]){
            ans-=Z[(X+Y-1)-i];
            ans+=R[i];
        }else{
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
whs = []

while True:
    hw = list(map(int, input().split()))
    if hw[0] == 0 and hw[1] ==0:
        break
    whs.append(hw)

for i in range(len(whs)):
    h = whs[i][0]
    sqs = "#" * whs[i][1]
    for j in range(h + 1):
        if j == h:
            print("")
        else:
            print(sqs)


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

int main(){
  int L, R, d;
  cin >> L >> R >> d;

  int r = 0;
  for (int n = L; n <= R; n++){
    if (n % d == 0){
      r++;
    }
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 3564
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
#define mod 998244353
#define inf 1e9
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, ll, hash<ll> > ht;

// find_by_order()  // order_of_key
typedef tree<
    int,
    null_type,
    less<long long int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c=c%mod;if(b%2==1) c*=a;c=c%mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



  int main()
{    fast;
    ll n,m,k;cin>>n>>m>>k;
    if(m==1)
    {
        if(k==n-1)cout<<1<<endl;
        else cout<<0<<endl;return 0;
    }
     ll ans=m*power1(m-1,n-1),a=1,b=power1(m-1,n-1);
    // cout<<ans<<endl;
     for(ll i=1;i<=k;i++)
     {
         a=((a*(n-i))%mod)*mi(i,mod);a%=mod;//cout<<a<<endl;
         b=b*mi(m-1,mod);b%=mod;//b=1;
         ans+=(((a*m)%mod)*b)%mod;ans%=mod;
     }
     ans%=mod;
     cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
//batyanotame,nishuume

int main() {
    vector<vector<int> > A(3,vector<int>(3,0));
    vector<vector<bool> > Abool(3,vector<bool>(3,0));
    int ans = 0;
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }
    int N = 0;
    cin >> N;
    vector<int> B(N,0);
    for(int i = 0; i < N; i++) {
        cin >> B.at(i);
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(A.at(j).at(k) == B.at(i)) {
                    Abool.at(j).at(k) = 1;
                    //cout << i << ' ' << j << ' ' << k << endl;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++) {
        //cout << ans << endl;
        if(Abool.at(i).at(0) && Abool.at(i).at(1) && Abool.at(i).at(2)) {
            ans++;
        }
        if(Abool.at(0).at(i) && Abool.at(1).at(i) && Abool.at(2).at(i)) {
            ans++;
        }
        if(Abool.at(0).at(0) && Abool.at(1).at(1) && Abool.at(2).at(2)) {
            ans++;
        }
        if(Abool.at(2).at(0) && Abool.at(1).at(1) && Abool.at(0).at(2)) {
            ans++;
        }
    }
    if(ans) {
    cout << "Yes" << endl;
    } else {
    cout << "No" << endl;
    }
    





    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    ll Q;
    cin >> Q;
    vector<ll> B(Q), C(Q);
    rep(i, Q) cin >> B.at(i) >> C.at(i);
    map<ll, ll> V;
    ll S = 0;
    rep(i, N){
        V[A.at(i)]++;
        S += A.at(i);
    }
    rep(i, Q){
        if(V.count(B.at(i))){
            S += (C.at(i) - B.at(i)) * V[B.at(i)];
            if(B.at(i) != C.at(i)){
                V[C.at(i)] += V[B.at(i)];
                V.erase(B.at(i));
            }
        }
        cout << S << endl;
    }
}

Measured memory_bytes: 9544
#include<iostream>
using namespace std;
 
bool f(int x){
    int keta = 0;
    while (x){
        keta++;
        x /= 10;
    }
    return keta %2 == 1;
}

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


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

int main()
{
    int n, k[1000], p[1000];

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> k[i] >> p[i];
        if( k[i] % p[i] == 0 )
            cout << p[i] << endl;
        else
            cout << k[i] % p[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
int main(){
  int  m,f,r,sum=0;
  while(1){
  scanf("%d%d%d",&m,&f,&r);
  sum=m+f;
  if(m==-1 && f==-1 && r==-1)break;
  if(m==-1 || f==-1)printf("F\n");
  else if(sum>=80)printf("A\n");
  else if(sum>=65)printf("B\n");
  else if(sum>=50)printf("C\n");
  else if(sum>=30)
    {
      if(r>=50)printf("C\n");
      else printf("D\n");
    }
  else printf("F\n");
  

  
}


  return 0;
}
    

Measured memory_bytes: 584
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X, A, B;
cin >> X >> A >> B;
cout << (X - A) % B;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int K,A,B,i,C,d=0;

    scanf("%d%d%d",&K,&A,&B);
    for(i=1; i<=B; i++)
    {
        C=K*i;
        if(A<=C && C<=B)
        {
            printf("OK");
            d++;
            break;
        }

    }
   if(d==0)
        printf("NG");

    return 0;
}

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

int main(){
    long long n, sum = 0, i;
    cin>>n;

    for(i = 1; i<=n; i++){
        if(i%3 == 0 || i%5 == 0)
        continue;
        sum+=i;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3620
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int k;
	cin >> k;

	rep(i, k) cout << "ACL";


	Would you please return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    map<int,int> m;
    cin >> n;
    rep(i,n){
        int x;
        cin >> x;
        m[x]++;
    }
    int cnt = 0;
    for(auto i:m){
        if(i.second%2){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;

struct node {
    std::vector<int> nextnode;
};

void seeker(std::vector<node>& tree, int now, std::vector<int>& val, std::vector<int>& c, int& nowc)
{
    for (int i = 0; i < tree[now].nextnode.size(); i++) {
        int next = tree[now].nextnode[i];
        if (val[next] != -1) {
            continue;
        }
        nowc++;
        val[next] = c[nowc];
        seeker(tree, next, val, c, nowc);
    }
}

signed main()
{
    int n;
    cin >> n;
    std::vector<int> val(n, -1);
    int out = 0;
    std::vector<node> tree(n);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].nextnode.pb(b);
        tree[b].nextnode.pb(a);
    }
    std::vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    std::sort(all(c), std::greater<int>());
    val[0] = c[0];
    int nowc = 0;

    seeker(tree, 0, val, c, nowc);
    for (int i = 1; i < n; i++) {
        out += c[i];
    }
    cout << out << endl;

    for (int i = 0; i < n; i++) {
        cout << val[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
// B - Unplanned Queries

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int cnt[100000];

int main() {
	int N, M;
	cin >> N >> M;

	for (int i=0; i<M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		cnt[a]++;
		cnt[b]++;
	}

	bool valid = true;
	for (int i=0; i<N; i++) {
		if (cnt[i] % 2 == 1) valid = false;
	}

	string ans;
	if (valid) ans = "YES";
	else ans = "NO";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;


ll f(ll x){
    if(x==1)return 1;
    return (x*f(x-1))%MOD;
}


int main(){
    ll n,m; cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }else if(n==m){
        cout<<(f(n)*f(m)*2)%MOD<<endl;
    }else{
        cout<<(f(n)*f(m))%MOD<<endl;       
    }
}

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

namespace AOJ1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i > 0; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int H = int.Parse(str[0]);
                int W = int.Parse(str[1]);
                if (H == 0 && W == 0)
                {
                    break;
                }
                else
                {
                    for (int j = 0; j < W; j++)//上辺かく
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");//改行
                    for (int h = 0; h < H - 2; h++)//Hの数ー２（上辺と底辺の数）だけ#...#をかく
                    {
                        Console.Write("#");//左の辺
                        for (int k = 0; k < W - 2; k++)//中身
                        {
                            Console.Write(".");
                        }
                        Console.Write("#");//右の辺
                        Console.Write("\n");//改行
                    }
                    for (int l = 0; l < W; l++)//底辺かく
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                    Console.Write("\n");
                }
            }
        }
    }
}



Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
 
LL a[N];
LL before[N],last[N];
int main() {
    int n;
    scanf("%d",&n);
 
    LL maxSum=0,minSum=0;
    priority_queue<LL> minSumQ;
    priority_queue<LL, vector<LL>, greater<LL> > maxSumQ;
    for(int i=1;i<=3*n;i++){
        scanf("%d",&a[i]);
        if(i<=n){
            maxSum+=a[i];
            maxSumQ.push(a[i]);
        }
        else if(i>2*n){
            minSum+=a[i];
            minSumQ.push(a[i]);
        }
    }
 
    before[n]=maxSum;
    for(int i=n+1;i<=2*n;i++) {
        LL temp=maxSumQ.top();
        if(temp<a[i]){
            maxSum+=a[i]-temp;
            maxSumQ.pop();
            maxSumQ.push(a[i]);
        }
        before[i]=maxSum;
    }
 
    last[2*n]=minSum;
    for(int i=2*n-1;i>=n;i--){
        LL temp=minSumQ.top();
        if(temp>a[i+1]){
            minSum+=a[i+1]-temp;
            minSumQ.pop();
            minSumQ.push(a[i+1]);
        }
        last[i]=minSum;
    }
 
    LL res=before[n]-last[n];
    for(int i=n+1;i<=2*n;i++)
        res=max(res,before[i]-last[i]);
    printf("%lld\n",res);
 
    return 0;
}

Measured memory_bytes: 8820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int a, b;
  cin >> a >> b;
  int s;
  s = a + b;

  if (((a % 3) == 0) || ((b % 3) == 0) || ((s % 3) == 0)){
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl; 
  }

  return 0;
}


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

long gcd(long a, long b){
  long t;
  if(a>b){t=a; a=b; b=t;}
  t=b%a;
  while(t!=0){
    b=a;
    a=t;
    t=b%a;
  }
  return a;
}

int main(void){
  long a, b;
  int c, d;
  scanf("%ld%ld%d%d", &a, &b, &c, &d);
  long l = ((long)c)*d/gcd(c, d);
  long x = b - b/c - b/d + b/l;
  a--; long y = a - a/c - a/d + a/l;
  printf("%ld\n", x-y);
}


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

int main() {
  int64_t h,w;
  cin >> h >> w;
  int64_t case1 = 0;
  int64_t case2 = 0;
  int64_t answer = 0;
  if(h == 1 || w == 1)
    answer = 1;
  else if(w % 2 == 0 && h % 2 == 0){
    case1 = w / 2;
    case2 = case1;
    for(int i=0;i<h/2;i++){
      answer += case1 +case2;
    }
  }
  else if(w % 2 == 0 && h % 2 == 1){
    case1 = w / 2;
    case2 = case1;
    for(int i=0;i<(h-1)/2;i++){
      answer += case1 + case2;
    }
    answer += case1;
  }
  else if(w % 2 == 1 && h % 2 == 0){
    case1 = (w+1)/2;
    case2 = case1 - 1;
    for(int i=0;i<h/2;i++){
      answer += case1 +case2;
    }
  }
  else if(w % 2 == 1 && h % 2 == 1){
    case1 = (w+1)/2;
    case2 = case1 - 1;
    for(int i=0;i<(h-1)/2;i++){
      answer += case1 + case2;
    }
    answer += case1;
  }
  
  
  
  
  cout << answer << endl;
    
}


Measured memory_bytes: 3616
# coding: utf-8
import math
 
a, b = map(int, raw_input().split())
 
xa = int(math.ceil(a / 0.08))
xb = int(math.ceil(b / 0.10))

z = 1e10
if int(xa * 0.10) == b and xa < z:
    z = xa
    #print 'xa',xa
if int(xb * 0.08) == a and xb < z:
    z = xb
    #print 'xb',xb

print [z, -1][z == 1e10]
 

Measured memory_bytes: 2568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		long a = scan.nextLong(), b = scan.nextLong();
		boolean check = false;
		if(a == 0) {
			a++;
			check = true;
		}
		long ans = f(b)^f(a-1);
		if(check) ans ^= 0;
		System.out.println(ans);
	}
	
	public static long f(long a) {
		long[] res = {a,1,a+1,0};
		return res[(int) (a%4L)];
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }

}


Measured memory_bytes: 23252
N, M = map(int, input().split())

m = 1000000007

if abs(N - M) > 1:
    print(0)
    exit()

k = min(N, M)
t = 1
for i in range(2, k + 1):
    t = t * i % m
t = t * t % m

if N == M:
    print(2 * t % m)
else:
    print(t * (k + 1) % m)


Measured memory_bytes: 9068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

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

    vector<int> A, B;
    int x;
    rep(i, n)
    {
        cin >> x;
        if (i % 2 == 0) A.push_back(x);
        else B.push_back(x);
    }

    map<int, int> a, b;
    
    rep(i, n/2)
    {
        a[A[i]]++;
        b[B[i]]++;
    }

    priority_queue<pair<int, int>> p, q;
    for (auto& c : a) p.push(make_pair(c.second, c.first));
    for (auto& c : b) q.push(make_pair(c.second, c.first));

    int a_1, a_2, b_1, b_2;
    a_1 = p.top().first;
    b_1 = q.top().first;

    if (a_1 + b_1 == n && p.top() == q.top())
    {
        cout << n / 2 << endl;
        return 0;
    }

    if (!(p.top().second == q.top().second)) cout << n - a_1 - b_1 << endl;
    else
    {
        p.pop();
        q.pop();
        a_2 = p.top().first;
        b_2 = q.top().first;
        cout << n - max(a_1 + b_2, a_2 + b_1) << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl

vector<ll> friends[200010];
bool vis[200010];
ll dfs(ll st)
{
	vis[st] = 1;
	ll num=0;
	num++;
	FOR(i,0,friends[st].size())
	{
		if(!vis[friends[st][i]])
		{
			num+=dfs(friends[st][i]);
		}
	}
	return num;
} 
int main()
{
	ll n,q;
	cin>>n>>q;
	FOR(i,0,q)
	{
		ll a,b;
		cin>>a>>b;
		friends[a].pb(b);
		friends[b].pb(a);
	}
	ll ma = -1;
	FORE(i,1,n)
	{
//		memset(vis,0,sizeof(vis));
		ma = max(ma,dfs(i));
	}
	cout<<ma<<Endl;
	return 0;
}

Measured memory_bytes: 24020
#include<stdio.h>
int main()
{
	int i,n,m,a,b,c;
	char f[7];
	for(i=0;i<7;i++){
		scanf("%c",&f[i]);
	}
	if(f[0]==f[6]&&f[1]==f[5]&&f[2]==f[4])printf("YES\n");
	else printf("NO\n");
	return 0;
} 

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

int main() {
    int n;
    int dx[] = {0, 1, 0, -1};
    int dy[] = {-1, 0, 1, 0};
    while (cin >> n, n) {
        vector<int> x(n), y(n);

        for (int i = 1; i < n; i++) {
            int m, d;
            cin >> m >> d;
            x[i] = x[m] + dx[d];
            y[i] = y[m] + dy[d];
        }

        int max_x = 0, min_x = n + 1;
        for (auto i : x) max_x = max(max_x, i + 1);
        for (auto i : x) min_x = min(min_x, i);

        int max_y = 0, min_y = n + 1;
        for (auto i : y) max_y = max(max_y, i + 1);
        for (auto i : y) min_y = min(min_y, i);

        cout << (max_y - min_y) << " " << (max_x - min_x) << endl;
    }

    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, m, a[N];
ll ans, dp[N], f[N];
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	dp[0] = 1;
	int q = 1;
	for (int i = 1; i <= n; ++i) {
		if (a[i] == a[i - 1]) {
			dp[i] = dp[i - 1];
			continue;
		}
		dp[i] = dp[i - 1] + f[a[i]];
		dp[i] %= mod;
		if (a[q] != a[i]) {
			(f[a[q]] += dp[q - 1]) %= mod;
			q = i;
		}
		//cout << dp[i] << "/";
	}
	//while (a[n] == a[n - 1]) --n;
	cout << dp[n];
}

Measured memory_bytes: 4096
import sys
import heapq


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N):
        A[i] *= -1
    heapq.heapify(A)

    for i in range(M):
        maxa = -1 * heapq.heappop(A)
        if maxa == 0:
            print("0")
            exit()
        heapq.heappush(A,  maxa // 2 * (-1))
    print(sum(A) * (-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 68392
# solution

import io
import sys
import math
from itertools import accumulate as acc
import numpy as np
from collections import Counter

data = int(input())
array = list(map(int, input().split(" ")))

MIN = min(array)
MAX = max(array)

print(2 * data - 1)

if abs(MAX) > abs(MIN):
    index = np.argsort(array)[-1] + 1
    for i in range(1, data + 1):
        if i != index:
            print(index, i)
    print(index, index)
    for i in range(1, data):
        print(i, i + 1)
else:
    index = np.argsort(array)[0] + 1
    for i in range(1, data + 1):
        if i != index:
            print(index, i)
    print(index, index)
    for i in range(1, data)[::-1]:
        print(i + 1, i)

Measured memory_bytes: 12428
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000000
#define VMAX 10000

int main(){
  int i,n,*a,*b,c[VMAX],sai=0;
  scanf("%d",&n);
  a=malloc(sizeof(int)*n);
  b=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]>sai){
      sai=a[i];
    }
  }

  //countingsort
  for(i=0;i<=sai;i++){
    c[i]=0;
  }
  for(i=0;i<n;i++){
    c[a[i]]++;
  }
  for(i=1;i<=sai;i++){
    c[i]+=c[i-1];
  }
  for(i=n-1;i>=0;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }
  for(i=1;i<=n;i++){
    printf("%d",b[i]);
    if(i==n){
      printf("\n");
    }else{
      printf(" ");
    }
  }
}
  
  



Measured memory_bytes: 17452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int a, b, ans;

void solve(){
    if(a>b) {
        ans += a;
        a--;
    }
    else {
        ans += b;
        b--;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>a >>b;
    ans =0;
    solve();
    solve();
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

s = input()
t = input()
n = len(s)

ms = defaultdict(str)
mt = defaultdict(str)
for i in range(n):
    if ms[s[i]] == '':
        ms[s[i]] = t[i]
    if mt[t[i]] == '':
        mt[t[i]] = s[i]
    if ms[s[i]] != t[i] or mt[t[i]] != s[i]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 4016
fn main() {
    let s = read::<String>();
    let v: Vec<char> = s.chars().into_iter().collect();

    let mut ret = 0;
    let mut cnt = 0;
    for c in v.iter() {
        match *c {
            'A' | 'C' | 'G' | 'T' => {
                cnt += 1;
                if ret < cnt { ret = cnt; }
            },
            _ => cnt = 0,
        }
    }
    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll h,w;
    cin>>h>>w;
    if(h==1 || w==1){
        cout<<1<<endl;
        return 0;
    }
    if(w%2==0){
        cout<<(w/2)*h<<endl;
    }else if(w%2!=0){
        if(h%2==0) cout<<w * (h/2)<<endl;
        else if(h%2!=0) cout<<w *((h-1)/2) + w/2 +1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
static const int MAX_N = 100000;
static const int inf  = 1ll<<60;
static const int MAX_SEG=1<<17;
typedef pair<int,int> pii;

int N;
int a[300];
int ans;

signed main(){
    cin>>N;
    for(int i=0;i<2*N;++i){
        cin>>a[i];
    }
    sort(a,a+2*N);
    for(int i=0;i<2*N+50;i+=2){
        int x=min(a[i],a[i+1]);
        ans+=x;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define pii pair<int,int>
#define fs first
#define sc second
using namespace std;
int n,lk[210];
bool vis[210];
pii a[110],b[110];

int read()
{
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
struct edge
{
	int t;
	edge *next;
}*con[220];
void ins(int x,int y)
{
	//cout<<"ins:"<<x<<' '<<y<<endl;
	edge *p=new edge;
	p->t=y;
	p->next=con[x];
	con[x]=p;
}
bool match(int x)
{
	vis[x]=1;
	for(edge *p=con[x];p;p=p->next)
		if(lk[p->t]==-1||(!vis[lk[p->t]]&&match(lk[p->t]))) {lk[p->t]=x;return 1;}
	return 0;	
		
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i].fs=read(),a[i].sc=read();
	for(int i=1;i<=n;i++)
		b[i].fs=read(),b[i].sc=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i].fs<b[j].fs&&a[i].sc<b[j].sc) ins(i,j+n);
	int ans=0;
	memset(lk,-1,sizeof(lk));
	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		ans+=match(i);			
	}
	printf("%d",ans);
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	ll n, x, t;
	cin >> n >> x >> t;

	cout << ( ( n + ( x - 1 ) ) / x ) * t << endl;

	return ( 0 );
}


Measured memory_bytes: 3228
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
P = 0
for _ in range(Q):
    q = list(input().split())
    if q[0]=="1":
        P += 1
        P = P%2
    else:
        c = q[2]
        if q[1]=="1":
            if P==0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if P==0:
                S.append(c)
            else:
                S.appendleft(c)
if P==1:
    S = list(S)
    S = S[::-1]
print("".join(S))

Measured memory_bytes: 103828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	bool found=false;
	rep(i,b){
		if(a*i%b==c){
			found=true;
		}
	}
	if(found){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
/* 2017-12-30-18.01.58 */

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

int main()
{
    int i,j,cnt[N];
    bool marked[N],isprime[N];
    isprime[0]=false,isprime[1]=false;
    for(i=2;i<=N;i++) marked[i]=false,isprime[i]=false;
    for(i=0;i<=N;i++) cnt[i]=0;
    for(i=2;i<=N;i++)
    {
        if(!marked[i])
        {
            isprime[i]=true;
            for(j=i;j<=N;j+=i) marked[j]=true;
        }
    }
    for(i=1;i<=N;i+=2)
    {
        if(isprime[i]&&isprime[(i+1)/2])
            cnt[i]=1;
    }
    for(i=1;i<=N;i++) cnt[i]+=cnt[i-1];
    int q;
    cin >> q;
    while(q--)
    {
        int l,r;
        cin >> l >> r;
        printf("%d\n",cnt[r]-cnt[l-1]);
    }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=5e3+10;
const int M=220;
ll a[N],b[N][M],cnt[N][N];
int n,m,S[N],top,L[N][M],R[N][M];
inline int rd(){
	int x=0;int f=1;char s=getchar();
	while(!isdigit(s)){if(s=='-')f=-1;s=getchar();}
	while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return x*f;
}

int main(){
//	freopen("a.in","r",stdin);
	n=rd();m=rd();a[0]=a[1]=0;
	for(int i=2;i<=n;i++) a[i]=a[i-1]+1ll*rd();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) b[i][j]=1ll*rd();
	for(int j=1;j<=m;j++){
		top=0;
		for(int i=1;i<=n;i++){
			while(top && b[S[top]][j] <b[i][j] ) top--;
			L[i][j]=top?S[top]+1:1;
			S[++top]=i;
		}
		top=0;
		for(int i=n;i>=1;i--){
			while(top && b[S[top]][j]<b[i][j] ) top--;
			R[i][j]=top?S[top]-1:n;
			S[++top]=i;
		}
		for(int i=1;i<=n;i++){
			cnt[L[i][j]][i]+=b[i][j];
			cnt[L[i][j]][R[i][j]+1]-=b[i][j];
			cnt[i+1][i]-=b[i][j];
			cnt[i+1][R[i][j]+1]+=b[i][j];
		}
	}	
	ll ans=0;
	for(int i=1;i<=n;i++){
		
		for(int j=1;j<=n;j++) cnt[i][j]+=cnt[i][j-1];
		for(int j=1;j<=n;j++) cnt[i][j]+=cnt[i-1][j];
		for(int j=i;j<=n;j++) ans=max(ans,cnt[i][j]-a[j]+a[i]); 
	} 
	printf("%lld\n",ans); 
	return 0;
}

Measured memory_bytes: 213632
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long int
bool cmp (pair <ll, ll> a, pair <ll, ll> b){
    return a.fi>b.fi;
}
int main(){
    ll a, b;
    cin>>a>>b;
    ll arr[a+2];
    for (ll i=1; i<=a; i++) cin>>arr[i];
    pair <ll, ll> aa[b+2];
    for (ll i=1; i<=b; i++) cin>>aa[i].se>>aa[i].fi;
    sort (aa+1, aa+b+1, cmp);
    sort (arr+1, arr+a+1);
    ll tar=0;
    cout<<endl;
    for (ll i=1; i<=b; i++){
        for (ll j=tar; j<=min(a, tar+aa[i].se); j++){
            arr[j]=max(arr[j], aa[i].fi);
        }
        tar=tar+aa[i].se;
        if (tar>a) break;
    }
    ll ans=0;
    for (ll i=1; i<=a; i++) ans+=arr[i];
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<bool> snack(N, false);
    for (ll i = 0; i < K; ++i) {
        ll d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            ll a;
            cin >> a;
            --a;
            snack[a] = true;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < N; ++i) {
        if (!snack[i]) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


void f(int n,int m,int t,int p){
  int a[1000][1000]={};
  rep(i,m){
    rep(j,n){
      a[i][j]=1;
    }
  }
  int sx=0,sy=0;
  /*
  rep(i,20){
    rep(j,20){
      cout<<a[i][j]<<' ';
    }
    cout<<endl;
  }
  cout<<endl;
   */

  while(t--){
    int d,c;
    cin>>d>>c;
    if(d==1){
      rep(i,m){
        rep(j,c){
          a[sy+i][sx+2*c-j-1]+=a[sy+i][sx+j];
        }
      }
      sx+=c;
    }
    if(d==2){
      rep(j,n){
        rep(i,c){
        
          a[sy+2*c-i-1][sx+j]+=a[sy+i][sx+j];
        }
      }
      sy+=c;
    }


/*  rep(i,20){
    rep(j,20){
      cout<<a[i][j]<<' ';
    }
    cout<<endl;
  }
  cout<<endl;
 */  
  }

/*  rep(i,20){
    rep(j,20){
      cout<<a[i][j]<<' ';
    }
    cout<<endl;
  }
  */
  
  while(p--){
    int x,y;
    cin>>x>>y;
    cout<<a[sy+y][sx+x]<<endl;
  }
}



int main(){
  int n,m,t,p;
  while(true){
    cin>>n>>m>>t>>p;
    if(!n) break;
    f(n,m,t,p);
  }

}



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


typedef long long ll;
int main() {
  int n, x, y; cin >> n >> x >> y;
  --x; --y;
  vector<int> dist(n);
  for (int i = 0; i < n; ++i) { 
    for (int j = i+1; j < n; ++j) { 
      if (i < x && j > y) { 
        int d = (x-i)+(j-y)+1;
        // cerr << i << " " << j << " " << d << endl;
        ++dist[d];
        continue;
      }
      if (i < x) {
        int d = (x-i);
        d += min(j-x, 1+y-j);
        ++dist[d];
        continue;
      }
      if (j > y) {
        int d = (j-y);
        d += min(y-i, 1+i-x);
        ++dist[d];
        continue;
      }
      int d = min(j-i,i-x+y-j+1);
      ++dist[d];
    }
  }
  for (int k = 1; k < n; ++k) {
    cout << dist[k] << endl;
  }
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;
const int MAXM = 110;

struct tnode
{
    int s, t, c;
}a[MAXN];

int now[MAXM], use[MAXM], reuse[MAXN];

bool cmp (tnode a, tnode b)
{
    if (a.s == b.s)
    {
        return a.t < b.t;
    }
    return a.s < b.s;
}

int main ()
{
    int n, m;
    scanf ("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d%d%d", &a[i].s, &a[i].t, &a[i].c);
    }
    sort (a + 1, a + n + 1, cmp);
    int ans = 1;
    memset (use, 0, sizeof (use));
    memset (reuse, 0, sizeof (reuse));
    memset (now, 0, sizeof (now));
    for (int i = 1; i <= n; i ++)
    {
        if (use[a[i].c])
        {
            now[use[a[i].c]] = a[i].t;
        }
        else
        {
            int tmp = 0;
            for (int j = 1; j <= ans; j ++)
            {
                if (now[j] < a[i].s)
                {
                    tmp = j;
                    break;
                }
            }
            if (!tmp)
            {
                ans ++;
                now[ans] = a[i].t;
                use[a[i].c] = ans;
                reuse[ans] = a[i].c;
            }
            else
            {
                use[reuse[tmp]] = 0;
                now[tmp] = a[i].t;
                use[a[i].c] = tmp;
                reuse[tmp] = a[i].c;
            }
        }
    }
    printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1792
from itertools import product

k = int(input())
ls = []

ls = [i for i in range(1, 10)]
digit = 1

while len(ls) < k:
    for i in range(1, 10):
        for j in product([-1, 0, 1], repeat=digit):
            num = str(i)
            skip = 0
            for y in j:
                x = int(num[-1])+y
                if x < 0 or 9 < x:
                    skip = 1
                    break
                num += str(x)
            if skip:
                continue
            ls.append(int(num))
    digit += 1
print(ls[k-1])

Measured memory_bytes: 10968
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
import collections
D=collections.defaultdict(int)
ans=0
for i in range(n):
  ans+=D[i-A[i]]
  D[A[i]+i]+=1
print(ans)

Measured memory_bytes: 61412
import sys

#+++++
		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	k=[abs(x) for x in al]
	bb=min(k)
	ss=sum(k)
	cc=len([x for x in al if x < 0])%2
	ans = ss - bb * cc*2
	#print(ss,bb,cc)
	
	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 14412
from collections import deque 
from collections import defaultdict
n, x, y = map(int, input().split())
graph = [[] for _ in range(n)]     
for i in range(n-1):
  graph[i] += [i+1]
  graph[i+1] += [i]
graph[x-1] += [y-1]
graph[y-1] += [x-1]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0)) 

def bfs(s):
  dist = [float('inf')]*n
  dist[s] = 0
  q = deque([s])

  while q:
    u = q.popleft() 
    for v in graph[u]:
      if dist[v] == float('inf'):
        q += [v]
        dist[v] = dist[u] + 1

  return dist

ans = defaultdict(int)
for i in range(n):
  d = bfs(i)
  for j in range(i+1, n):
    ans[d[j]] += 1 

for i in range(1, n):
  if i in ans.keys():
    print(ans[i])
  else:
    print(0)


Measured memory_bytes: 76764
# AtCoder
S = input()

if not S[0] == 'A':
    print('WA')
    exit()

if not S.count('C', 2, -1) == 1:
    print('WA')
    exit()

for i in S:
    if i == 'A' or i == 'C':
        pass
    else:
        if not i.islower():
            print('WA')
            exit()


print('AC')


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



int main(){
    int N,M,result=0;
    cin>>N>>M;
    vector<pair<int,int> > R(M);
    for(int i=0;i<M;i++){
        cin>>R.at(i).first>>R.at(i).second;
    }
    vector<int> n(N-1);
    for(int i=0;i<N-1;i++){
        n.at(i)=i+2;
    }
    do{
        bool y=false;
        for(int i=0;i<M;i++){
            if(R.at(i).first==1&&n.at(0)==R.at(i).second){
                y=true;
            }
        }
        if(y){
            bool x=true;
            for(int i=0;i<N-2;i++){
                for(int j=0;j<M;j++){
                    if((R.at(j).first==n.at(i)&&R.at(j).second==n.at(i+1))||(R.at(j).second==n.at(i)&&R.at(j).first==n.at(i+1))){
                        break;
                    }
                    if(j==M-1){
                        x=false;
                    }
                }
            }
            if(x){
                result++;
            }
        }
    }
    while(next_permutation(n.begin(),n.end()));
    cout<<result<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int cnt[100007];
signed main(){
	int n;
	cin >> n;
	int a[n];
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
		cnt[a[i]]++;
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int x, y;
		cin >> x >> y;
		sum += (y - x) * cnt[x];
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 5140
#include <iostream>

using namespace std;

int main() {
    int N[3];
    int max_val = 0;
    for (int i = 0; i < 3; ++i) {
        cin >> N[i];
        max_val = max(max_val, N[i]);
    }

    int even = -1, odd = 0;
    for (int i = 0; i < 3; ++i) {
        if ((max_val - N[i]) & 1) {
            odd++;
        } else {
            even++;
        }
    }

    int ans = 0;
    for (int i = 0; i < 3; ++i) {
        ans += (max_val - N[i]) / 2;
    }

    if (odd == 2) {
        ans++;
    } else if (even == 2) {
        ans += 0;
    } else {
        ans += 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# author:  Taichicchi
# created: 14.09.2020 22:23:14

import sys
from itertools import combinations

N, M, X = map(int, input().split())

C = []
A = []

for i in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
comb = [0, 1, 2]

save = []

for choice in range(1, N + 1):
    for comb in combinations(list(range(N)), choice):
        ls = [0 for _ in range(M)]
        for i in comb:
            for m in range(M):
                ls[m] += A[i][m]
            if all(list(map(lambda x: x >= X, ls))):
                save.append(sum([C[_] for _ in comb]))
if save:
    print(min(save))
else:
    print(-1)


Measured memory_bytes: 9472
/*
[jsc2019-qual] B - Kleene Inversion
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 2000;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
};

int N;
ll K;
int A[MAX_N];

ll solve() {
    gf inv2 = 5e8 + 4;

    ll cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (A[i] < A[j]) {
                cnt0++;
            } else if (A[i] > A[j]) {
                cnt1++;
            }
        }
    }

    gf ans = inv2 * cnt0 * K * (K - 1) + inv2 * cnt1 * K * (K + 1);

    return ans.n;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256