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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007
void init();
void solve();

signed main()
{
	init();
	solve();
}

struct BIT {
	vector<vector<int>> node;
	int n;
	BIT(int n_) : node(n_+1, vector<int>(n_+1, 0)), n(n_) {}
	void add(int r, int c, int v) {
		for (int i = r+1; i <= n; i += i & -i) {
			for (int j = c+1; j <= n; j += j & -j) {
				node[i][j] += v;
			}
		}
	}
	int get(int r, int c) {
		int res = 0;
		for (int i = r+1; i; i -= i & -i) {
			for (int j = c+1; j; j -= j & -j) {
				res += node[i][j];
			}
		}
		return res;
	}
	int get_sum(int r1, int c1, int r2, int c2) {
		r1--;
		c1--;
		r2--;
		c2--;
		return get(r2, c2) - get(r1, c2) - get(r2, c1) + get(r1, c1);
	}
};

void init()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	BIT bit(N);
	rep(i, M) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		bit.add(l, r, 1);
	}
	rep(i, Q) {
		int l, r;
		cin >> l >> r;
		l--;
		cout << bit.get_sum(l, l, r, r) << endl;
	}
}

void solve()
{
}

Measured memory_bytes: 1920
#include <stdio.h>

#define MAX 100002
#define inf 2000000000

struct card {
	char suit;
	int value;
};


struct card L[MAX/2 + 2], R[MAX/2 + 2];

void merge(struct card A[], int n, int left, int mid, int right) {
	 int n1 = mid - left;
	 int n2 = right - mid;
	 for (int i = 0; i < n1; i++) L[i] = A[left + i];
	 for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	 L[n1].value = inf;
	 R[n2].value = inf;
	 int i1 = 0, i2 = 0;
	 for (int j = left; j < right; j++) {
	 	if (L[i1].value <= R[i2].value) {
	 		A[j] = L[i1];
	 		i1 += 1;
	 	} else {
	 		A[j] = R[i2];
	 		i2 += 1;
	 	}
	 }
}


void mergesort(struct card A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergesort(A, n, left, mid);
		mergesort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}


int partion(struct card A[], int p, int r) {
	int x = A[r].value;
	int i = p - 1;
	struct card t;
	for (int j = p; j < r; j++) {
		if (A[j].value <= x) {
			i += 1;
			t = A[j];
			A[j] = A[i];
			A[i] = t;
		}
	}
	t = A[r];
	A[r] = A[i+1];
	A[i+1] = t;
	return i + 1;
}

void quicksort(struct card A[], int p, int r) {
	if (p < r) {
		int q = partion(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q+1, r);
	}
}

int main() {
	struct card A[MAX], B[MAX];
	int n;
	char s[6];
	scanf("%d", &n);
	int value;
	bool stable = true;
	for (int i = 0; i < n; i++) {
		scanf("%s %d", s, &value);
		A[i].suit = B[i].suit = s[0];
		A[i].value = B[i].value = value;
	}

	mergesort(B, n, 0, n);
	quicksort(A, 0, n-1);

	for (int i = 0; i < n; i++) {
		if (A[i].suit != B[i].suit) {
			stable = false;
			break;
		} 
	}

	if (stable) printf("Stable\n");
	else printf("Not stable\n");
	for (int i = 0; i < n; i++) {
		printf("%c %d\n", A[i].suit, A[i].value);
	}

	return 0;
}



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

class Main {
    void solve() {
	Scanner sc = new Scanner( System.in );
	int l = sc.nextInt();
	int n = sc.nextInt();
	String s = sc.next();

	long oocnt = 0;
	for ( int i=0; i<s.length()-1; ++i ) {
	    if ( s.charAt(i) == 'o' && s.charAt(i+1) == 'o' ) ++oocnt;
	}
	long total_oocnt = 0;
	for ( int i=0; i<n; ++i ) {
	    total_oocnt += oocnt;
	    oocnt *= 2;
	}

	System.out.println( 3*total_oocnt + s.length() );	    
    }
    public static void main( String[] a ) { new Main().solve(); }    
}



Measured memory_bytes: 26284
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(c-a)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(b-a)<=d && abs(c-b)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, a = gets.chomp.split(" ").map(&:to_i)

x = gets.chomp.split(" ").map(&:to_i)
ki = (x.pop - a).abs
ans  = 0
if x != []
x.each do |i|
    i = (i - a).abs 
    #p i
    ans = ki.gcd(i)
    ki = ans
end
puts ans
elsif x == []
    puts ki
end



Measured memory_bytes: 21604
#include <iostream>
#include <cmath>

using namespace std;

int main(){

  int x,a,b;

  while(cin >> x >> a >> b){

    int dist_a = abs(x-a), dist_b = abs(x-b);

    if(dist_a < dist_b) cout << "A" << endl;

    else cout << "B" << endl;

  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=2e6+10;
ll ans[maxn];
int main()
{
   int n,x,y;
   cin>>n>>x>>y;
   for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
    {
        int t1=j-i;
        int t2=1+abs(y-j)+abs(x-i);
        int t3=1+abs(x-j)+abs(y-i);
        int t=min(t1,min(t2,t3));
        ans[t]++;
        //if(t==2) debug(i),debug(j);
    }
    for(int i=1;i<n;i++)
    cout<<ans[i]<<endl;
   //system("pause");
   return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

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

  int sn = 0;
  rep(i, n.size()){
    sn+=(int)(n.at(i)-'0');
  }

  if(stoi(n)%sn==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}

Measured memory_bytes: 256
abcde = [int(input()) for _ in range(5)]
k = int(input())
ans = 0
for i in range(4):
    for j in range(i+1,5):
        if abcde[j] - abcde[i] > k:
            ans += 1
if ans == 0:
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 2940
import java.util.*;
class Main{
   static Integer[]cache;
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int []x=new int[n];
    cache=new Integer[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
    }
    System.out.println(ans1(x,0,k));
  }
 
    public static int ans1(int []h,int index,int k){
        if(index==h.length-1) return 0;
        if(cache[index]!=null) return cache[index];
        int current=Integer.MAX_VALUE;
        for(int i=1;i<=k;i++){
            if(index+i<h.length) {
                current = Math.min(current, Math.abs(h[index] - h[index + i]) + ans1(h, index + i, k));
            }
        }
 
        return cache[index]=current;
    }
 
}

Measured memory_bytes: 79132
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N;cin >> N;
rep(i, 0, 1000){

if(i*1000 >= N){cout << i*1000 - N;exit(0);}

}

}

Measured memory_bytes: 3580
n=int(input())

candidates={}
for i in range(n):
    candidate=input()
    if candidate in candidates:
        candidates[candidate]+=1
    else:
        candidates[candidate]=1

max_k_list = []
maxvalue=max(candidates.values())
for candidate in candidates:
    if candidates[candidate]==maxvalue:
        max_k_list.append(candidate)


max_k_list.sort()
for i in max_k_list:
    print(i)


Measured memory_bytes: 32216
#include<bits/stdc++.h>
using namespace std;
int neao(int x, int y){
  if(fabs(x)>=fabs(y))return y;
  else return x;
}
int main(){
  int N, L;
  cin>>N>>L;
  int allapp=N*L+N*(N-1)/2;
  vector<int> tas(N);
  for(int i=0;i<N;i++){
    tas.at(i)=L+i;
  }
  int k=neao(tas.at(0),tas.at(1));
  for(int j=2;j<N;j++){
    k=neao(k,tas.at(j));
  }
  cout<<allapp-k;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    rep(i,n/2){
        if(s[i]!=s[n-1-i]) ans++; 
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int a,b,k;
  cin>>a>>b>>k;
  int min;
  if(a>b)min=b;
  else min=a;
  int c(0);
  for(int i(min);i>=1;i--){
    if(a%i==0 && b%i==0)c++;
    if(c==k){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int px[90001];
int py[90001];
int ret[90001];
int mp( int a, int b ){ return abs( px[a] - px[b] ) + abs( py[a] - py[b] ); }
int main( void )
{
  ios::sync_with_stdio(false);
  int H, W, D, Q, a, l, r;
  cin >> H >> W >> D;
  for( int y=0; y<H; y++ ){
    for( int x=0; x<W; x++ ){
      cin >> a;
      px[a] = x;
      py[a] = y;
    }
  }
  for( int i=1; i<=H*W; i++ ){
    if( i - D > 0 ){
      ret[i] = ret[i-D] + mp( i, i-D );
    }
  }
  cin >> Q;
  for( int i=0; i<Q; i++ ){
    cin >> l >> r;
    cout << ret[r] - ret[l] << endl;
  }
}

Measured memory_bytes: 2176
import java.util.*;
import java.lang.*;

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

        Scanner s = new Scanner(System.in);

        int n =s.nextInt();

        int x=0;

        while(n>0){

            int digit = n%10;
            n=n/10;

            if(digit==7){
                x++;
                break;
            }
        }

        if (x>0){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}






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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    ll N;
    cin >> N;
    vector<ll> A;
    REP(i,0,N){
        ll n;
        cin >> n;
        A.push_back(n);
    }
    ll cur = 0;
    for(ll a : A){
        if(a == cur+1){
            cur++;
        }
    }
    if(cur == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << N - cur << endl;
    
    return 0;
}


Measured memory_bytes: 2420
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

A = collections.deque()
n = int(input())
for _ in range(n):
    b = input()
    if b[0] == 'i':
        A.appendleft(b[7:])
    elif b[6] == ' ':
        try:A.remove(b[7:])
        except:pass
    elif len(b)>10:
        A.popleft()
    elif len(b)>6:
        A.pop()
print(*A)


Measured memory_bytes: 70756
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ctn =0
for aa in range(a+1):
    for bb in range(b+1):
        for cc in range(c+1):
            if x == aa*500+bb*100+cc*50:
                ctn += 1
print(ctn)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
X = int(input())
ans = 0
pn = [2]
flag = 0
for i in range(3,100005):
  for k in pn:
    if i%k == 0:
      flag = 0
      break
    else:
      flag = 1
  if flag == 1:
    pn.append(i)
for i in range(len(pn)-1):
  if pn[i] == X:
    ans = pn[i]
  elif pn[i] < X < pn[i+1]:
    ans = pn[i+1]
print(ans)

Measured memory_bytes: 41180
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


void minimization()
{
  int n, k;
  cin >> n >> k;

  cout << ceil((float)(n - 1) / (float)(k - 1)) << "\n";
}


void linear_approximation()
{
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    b[i] = a - (i + 1);
  }

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

  int mid = b[n / 2];
  long long int ans = 0;
  for (int i = 0; i < n; ++i) ans += abs(mid - b[i]);
  cout << ans << "\n";

}


void modulo_summation()
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ans += a - 1;
  }

  cout << ans << "\n";
}


//skip
void all_green()
{
  int d, g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  for (int i = 0; i < d; ++i) cin >> p[i] >> c[i];


}


void base_2_number()
{
  int n;
  cin >> n;

  string s = "";
  if (n == 0) s = '0' + s;
  while (n != 0)
  {
    if (n % 2 != 0)
    {
      --n; //-２進数の整合性
      s = '1' + s;
    }
    else
    {
      s = '0' + s;
    }
    n /= -2;
  }

  cout << s << "\n";
}


void to_infinity()
{
  string s;
  long long int k;
  cin >> s >> k;

  char digit = '1';
  for (int i = 0; i < k; ++i)
  {
    if (s[i] != '1')
    {
      digit = s[i];
      break;
    }
  }
  cout << digit << "\n";
}


int main()
{
  //minimization();
  //linear_approximation();
  //modulo_summation();
  //all_green();
  //base_2_number();
  to_infinity();
}


Measured memory_bytes: 256
#include<cstdio>
#define SQ(x) ((x)*(x))
int x1, y1, x2, y2;
void solve(int x, int y){
	const int x2m1 = x2 - x1;
	const int y2m1 = y2 - y1;
	int xm1 = x-x1;
	int ym1 = y-y1;
	int x2m = x2-x;
	int y2m = y2-y;
	double temp1 = SQ(xm1)+SQ(ym1)+SQ(x2m1)+SQ(y2m1)-SQ(x2m)-SQ(y2m);
	double temp2 = SQ(x2m1)*2+SQ(y2m1)*2;
	double res = temp1/temp2;
	printf("%.10f %.10f\n", (x2m1*res+x1), (y2m1*res+y1));
}
int main(){
	int x, y, q;
	scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &q);
	while(q--){
		scanf("%d%d", &x,&y);
		solve(x, y);
	}
}


Measured memory_bytes: 2720
N = int(input())
S = input()
ans = 0
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if (S[i] == S[j]):
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0
ans = 0
for i in range(N):
    for j in range(N):
        now = min(dp[i][j], abs(i-j))
        ans = max(ans, now)
print(ans)


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

#define int long long

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

signed main() {
    int a[5] = {};
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') {
            a[0]++;
        } else if (s[0] == 'A') {
            a[1]++;
        } else if (s[0] == 'R') {
            a[2]++;
        } else if (s[0] == 'C') {
            a[3]++;
        } else if (s[0] == 'H') {
            a[4]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += a[i] * a[j] * a[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != "0 0") {
                int[] count = input.Split().Select(p => int.Parse(p)).ToArray();
                var player = new Queue<int>(Enumerable.Range(1, count[0]));
                while(player.Count != 1) {
                    for(int i=0; i < count[1] - 1; ++i) {
                        player.Enqueue(player.Dequeue());
                    }
                    player.Dequeue();
                }
                Console.WriteLine(player.Dequeue());
            }
        }
    }
}

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

using namespace std;

int a[100010];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    --a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[a[i]] == i) {
      ++ans;
    }
  }
  printf("%d\n", ans / 2);
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    LL m;
    LL k;
    cin >> n >> m >> k;
    vector<LL> a(n);
    vector<LL> b(m);
    LL sum=0;
    LL ans=0;
    LL max_ans;

    for(LL i=0; i<n; i++){
        cin >> a[i];
    }

    for(LL i=0; i<m; i++){
        cin >> b[i];
    }

    LL i=0;
    while(true){
        if(sum+a[i]>k){
            break;
        }
        sum+=a[i];
        i++;
        ans++;
        if(i>=n){
            break;
        }
    }
    max_ans=ans;
    //cout << ans << " " << sum << endl;
    LL idx=ans-1;
    for(LL i=0; i<m; i++){
        while(sum+b[i]>k && idx>=0){
            sum-=a[idx];
            ans--;
            idx--;
            //cout << idx << " " << sum << endl;
        }
        if(sum+b[i]<=k){
            ans++;
            sum+=b[i];
        }else{
            break;
        }
        if(ans>max_ans){
            max_ans=ans;
        }
        //cout << ans << " " << sum << " " << idx << endl;
    }

    cout << max_ans << endl;

    return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
string S;
cin >> S;
bool A = false, B = false, C = false;

REP(i, 3){
    if(S[i] == 'a') A = true;
    if(S[i] == 'b') B = true;
    if(S[i] == 'c') C = true;
}

if(A && B && C) yes;
else no;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    while (true) {
        val input = readLine()!!.split(" ")

        val a = input[0].toInt()
        val op = input[1]
        val b = input[2].toInt()

        when(op) {
            "+" -> println(a + b)
            "-" -> println(a - b)
            "*" -> println(a * b)
            "/" -> println(a / b)
            "?" -> return
        }
    }
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  vector<int> sum(n);
  for (int i = 0; i < k; i++) {
    sum[0] += p[i];
  }
  int smax = sum[0];
  for (int i = 0; i < n - k; i++) {
    sum[i + 1] = sum[i] - p[i] + p[i + k];
    smax = max(smax, sum[i + 1]);
  }
  cout << fixed << setprecision(15);
  cout << (double)(smax + k) / 2. << '\n';
  return 0;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h> 
using namespace std; 
#define ll int long long
ll com(ll n)
{
   ll temp;
   if(n>=2)
   temp= n*(n-1)/2;
   else
   temp=0;
   
   return temp;
}
int main()
{
   ll k;cin>>k;
   ll arr[k+1];
   ll freq[k+1]={0};
   for(int i=1;i<=k;i++)
   {
       cin>>arr[i];
       freq[arr[i]]++;
   }
   ll sum=0;
   for(int i=1;i<=k;i++)
   sum+= com(freq[i]);
   
   for(int i=1;i<=k;i++)
   {
       ll t= sum+com(freq[arr[i]]-1)-com(freq[arr[i]]);
       cout<<t<<endl;
   }
   
   
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int A, B;

int main()
{
	in >> A >> B;
	out << A * B - (A + B) + 1 << std::endl;
	return 0;
}


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

int main(){
    int a,b;
    
    while(1){
        cin >> a >>b;
        
        if (a ==0 && b ==0){
            break;
        }
        
        for (int i = 0 ; i < b; i++){
            cout << "#";
        }
        cout << endl;
        for (int j = 0 ; j < a-2; j++){
            cout << "#";
            for(int i = 0; i < b-2; i++){
                cout << ".";
            }
            cout << "#";
            cout << endl;
        }
        for (int i = 0 ; i < b; i++){
            cout << "#";
        }
        cout<<endl;
        cout <<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3044
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;

const int maxn = 505;

char s[maxn][maxn];
char a[maxn][maxn];
char b[maxn][maxn];
int H,W;
int main()
{
	#ifdef Amberframe
		freopen("agc004c.in","r",stdin);
		freopen("agc004c.out","w",stdout);
	#endif
	scanf("%d %d",&H,&W);
	for (int i=1;i<=H;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=H;i++)
	for (int j=1;j<=W;j++) a[i][j]=b[i][j]='.';
	for (int j=1;j<=W;j++) a[1][j]='#';
	for (int j=1;j<=W;j++) b[H][j]='#';
	for (int j=1;j<=W;j++)
	{
		if (j&1) for (int i=2;i<H;i++) a[i][j]='#';
		else for (int i=2;i<H;i++) b[i][j]='#';
	}
	for (int i=1;i<=H;i++)
	for (int j=1;j<=W;j++)
		if (s[i][j]=='#') a[i][j]=b[i][j]='#';
	for (int i=1;i<=H;i++) printf("%s\n",a[i]+1);puts("");
	for (int i=1;i<=H;i++) printf("%s\n",b[i]+1);
	return 0;
}

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

using namespace std;

int N, A, B ,C;
vector<int> bamboo;

int dfs(int depth, int a, int b, int c){
    if(depth == N){
        if(a==0 || b==0 || c==0) return 1000000000;
        return abs(A-a) + abs(B-b) + abs(C-c);
    }

    int ans = dfs(depth+1, a, b, c);

    if(a>=1){
        ans = (min)({ans, dfs(depth+1, a+bamboo[depth], b, c) + 10});
    }else ans = (min)({ans, dfs(depth+1, a+bamboo[depth], b, c)}); 

    if(b>=1){
        ans = (min)({ans, dfs(depth+1, a, b+bamboo[depth], c) + 10});
    }else ans = (min)({ans, dfs(depth+1, a, b+bamboo[depth], c)}); 

    if(c>=1){
        ans = (min)({ans, dfs(depth+1, a, b, c+bamboo[depth]) + 10});
    }else ans = (min)({ans, dfs(depth+1, a, b, c+bamboo[depth])}); 

    return ans;
}

int main(void){
    cin>>N>>A>>B>>C;
    bamboo.resize(N+1);
    for(int i=0; i<N; i++){
        cin>>bamboo[i];
    }

    cout<<dfs(0, 0, 0, 0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    char a;
    cin>>a;
    if(a>=97) cout<<"a";
    else      cout<<"A";
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n, h, w;
  cin >> n >> h >> w;
  int ret = 0;
  while(n--) {
    int a, b;
    cin >> a >> b;
    ret += h<=a && w<=b;
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005],ans[100005],sum;
struct node2
{
	int head;
	int tail;
}road[300005];
int cmp(node2 xx,node2 yy)
{
   if(xx.head<yy.head)return 1;
   return 0;	
}
int main()
{
	int n,k,i,j;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=k;i++)
	{
		cin>>road[i].head>>road[i].tail;
		road[i+k].head=road[i].tail;
		road[i+k].tail=road[i].head;
	}
	k*=2;
	sort(road+1,road+1+k,cmp);
	i=1;
	while(i<=k)
	{   
	    j=road[i].head;
		if(a[j]>a[road[i].tail])
		{   
			while(road[i].head==j)
			{
				if(a[j]<=a[road[i].tail])
				{
					ans[j]=1;
				}
				i++;
			}
		}
		else
		{
			ans[j]=1;
			while(road[i].head==j)i++;
		}
		
	}
	for(i=1;i<=n;i++)
	if(ans[i]==0)
	{
		sum++;
	}
	cout<<sum;	
} 

Measured memory_bytes: 5984
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
int main() {
	int S, W;
	cin >> S >> W;
	if (W >= S) {
		cout << "unsafe";
	}
	else {
		cout << "safe";
	}
	return 0;
}

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

int main()
{
  char c;
  int a = 0;
  rep(i, 3){
    cin >> c;
    if(c == '1') a++;
  }
  cout << a << endl;
  
  return 0;
}

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

int main()
{
	int N;
	cin >> N;
	
	unordered_map<string, int> hashmap;
	string s;
	for (int i = 0; i < N; i++) {
		cin >> s;
		hashmap[s]++;
	}

	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> s;
		hashmap[s]--;
	}

	int ans = 0;
	for (pair<string, int> p : hashmap) {
		ans = max(ans, p.second);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << abs(a[0] - a[1]) + abs(a[1] - a[2]) << endl;
}

Measured memory_bytes: 888
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    if (N <= 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<vector<int>> A(22, vector<int>(7));

    rep(i,22) rep(j,7) A[i][j] = 7*i+j+1;
    vector<ll> data(12);
    rep(i,11) {
        int cnt = 0;
        rep(j,5) {
            int val = A[i][j] + A[i][j+1] + A[i][j+2] + A[i+1][j] + A[i+1][j+1] + A[i+1][j+2] + A[i+2][j] + A[i+2][j+1] + A[i+2][j+2];
            if (val%11==K) cnt++;
        }
        data[(i+2)%11+1] = cnt;
    }

    rep(i,11) data[i+1] += data[i];
    ll p = N/11;
    ll q = N%11;
    if (p==0) cout << data[q] - data[2] << endl;
    else cout << p*data[11] + data[q] - data[2] << endl;
}

Measured memory_bytes: 256
// After contest. 
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

struct edge
{
	int u, v, y;
};
vector<edge> edges;

long long sum[maxn];

int n, m, ans, fa[maxn], cnt[maxn];

bool mycmp(edge &a, edge &b) {
	return a.y < b.y;
}

vector<vector<int> > g;

int getfa(int u) {
	if (fa[u] != u)
		fa[u] = getfa(fa[u]);

	return fa[u];
}

// void unify(int a, int b) {
// 	sum[b] += sum[a];
// 	sum[a] = 0;

// 	fa[a] = b;
// }

// void keepEdges(int u, int lim) {
// 	if (vis[u])
// 		return;

// 	vis[u] = true;
// 	for (int i = 0; i < g[u].size(); ++i) {
// 		int idx = g[u][i];
// 		if (edges[idx].y <= lim) {
// 			ok[idx] = true;
// 			keepEdges(edges[idx].v, lim);
// 		}
// 	}
// }

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> sum[i];
		fa[i] = i;
	}

	edges = vector<edge>(m);
	for (int i = 0; i < m; ++i)
		cin >> edges[i].u >> edges[i].v >> edges[i].y;

	sort(edges.begin(), edges.end(), mycmp);

	g = vector<vector<int> >(n+1);

	for (int i = 0; i < m; ++i) {
		int u = edges[i].u, v = edges[i].v;
		g[u].push_back(i);
		g[v].push_back(i);

		int f1 = getfa(u);
		int f2 = getfa(v);

		++cnt[f1];
		if (f1 != f2) {
			cnt[f1] += cnt[f2];
			cnt[f2] = 0;

			sum[f1] += sum[f2];
			sum[f2] = 0;

			fa[f2] = f1;
		}
		
		if (sum[f1] >= edges[i].y) {
			ans += cnt[f1];
			cnt[f1] = 0;
		}
	}

	ans = m - ans;
	cout << ans << endl;

	return 0;
}

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

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> p(n);
  for (auto &i : p) {
    std::cin >> i;
  }

  int64_t count = 0;
  for (int64_t i = 0; i < n; i++) {
    if (p[i] == i + 1) {
      count++;
      i++;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int x, ans = 1;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> x;
    erep(i, 2, 1000) {
        int p = 2;
        while ((int)pow(i, p) <= x) {
            ans = max(ans, (int)pow(i, p));
            p++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
fun max(a: Int, b: Int) = if (a > b) a else b

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    var mx = 1
    var mn = n
    repeat(m) {
        val (l, r) = readLine()!!.split(' ').map(String::toInt)
        if (mx < l) {
            mx = l
        }
        if (mn > r) {
            mn = r
        }
    }
    println(max(mn - mx + 1, 0))
}

Measured memory_bytes: 56664
#include<bits/stdc++.h>
using namespace std;
long long m=998244353;

long long power(long long x,long long y)
{
    long long res = 1; x=x%m;
    while (y > 0)
    {
        if (y & 1) res = (res*x)%m;
        y = y>>1;
        x = (x*x)%m;
    }
    return res%m;
}


int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range;

void main(){
    auto hwd=readln.split.map!(to!int).array;
    auto H=hwd[0],W=hwd[1],d=hwd[2];

    foreach(w;0..H){
        foreach(h;0..W){
            auto k=w+h;
            auto j=w-h;
            auto x=k.div(d);
            auto y=j.div(d);
            draw(x.mod(2)+2*y.mod(2));
        }
        writeln();
    }
}

int mod(int a,int d){
    if(a>=0)return a%d;
    return (a%d+d)%d;
}

int div(int a,int d){
    return (a-a.mod(d))/d;
}

void draw(int i){
    "RYGB"[i].write;
}


Measured memory_bytes: 508
#include <vector>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0;i < n;i++){
        cin >> vec.at(i);
    }
    bool H = 1;
    for(int i = 0;i < n;i++){
        if(vec.at(i)%2 == 0){
            if(vec.at(i)%3  == 0|| vec.at(i)%5 == 0){
                H = 1;
            }
            else{
                H = 0;
                break;
            }
        }
    }
    if(H){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }
    
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    bool answer = false;
    if(N % 2 == 1) {
        answer = false;
    }
    else {
        int H = N/2;
        for(int i = 0; i < H; i++) {
          if(S.at(i) == S.at(i+H)) {
            answer = true;
          }
          if(S.at(i) != S.at(i+H)) {
            answer = false;
            break;
          }
        }
    }
    if(answer == true) {
        cout << "Yes" << endl;
    }
    else if(answer == false) {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define N 100000

int p[N + 1];

int main(){
	int ans, n, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		scanf("%d", p + i);
	}

	ans = 0;

	for (i = 2; i <= n; i++){
		if (p[i] == i and p[i - 1] == i - 1){
			swap(p[i], p[i - 1]);
			ans++;
		}
	}

	for (i = 1; i <= n; i++){
		if (p[i] == i){
			ans++;
		}
	}

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

	return 0;
}

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

int main()
{
    string S;
    cin >> S;
    vector<int> a(26);

    for (int i = 0; i < S.length(); i++)
    {
        a.at(S.at(i) - 'a')++;
    }
    string min = "";
    for (int i = 0; i < 26; i++)
    {
        if (!a.at(i))
        {
            min = 'a' + i;
            break;
        }
    }
    if (min == "") cout << "None" << endl;
    else cout << min << endl;
    
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    SaikyouA2019 solver = new SaikyouA2019();
    solver.solve(1, in, out);
    out.close();
  }

  static class SaikyouA2019 {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int m = in.nextInt();
      int d = in.nextInt();
      int cnt = 0;
      for (int i = 1; i <= d; i++) {
        int ju = i / 10;
        int ichi = i % 10;
        if (ju >= 2 && ichi >= 2 && ju * ichi <= m) {
          cnt++;
        }
      }
      out.println(cnt);
    }

  }
}



Measured memory_bytes: 21716
#include<stdio.h>

#define MAX 100000

int partition(int,int);
 
int arr[MAX],n;

int main(){

  int i,x;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  
  x = partition(0,n-1);
  
  for(i=0;i<x;i++){
    printf("%d ",arr[i]);
  }

  printf("[%d] ",arr[x]);
  
  
  for(i=x+1;i<n-1;i++){
    printf("%d ",arr[i]);
  }
  printf("%d\n",arr[n-1]);

  return 0;
}


int partition(int a,int b){

  int x,i,j,tmp;

  x = arr[b];
  i = a - 1;

  for(j=a;j<b;j++){
    if(arr[j]<=x){
      i++;
      tmp=arr[i];
      arr[i]=arr[j];
      arr[j]=tmp;
    }
  } 
  tmp=arr[i+1];
  arr[i+1]=arr[b];
  arr[b]=tmp; 
  return i+1;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int Q;
    cin >> Q;

    for (int q = 0; q < Q; q++) {
        int k;
        cin >> k;

        long long cnt_D = 0, cnt_M = 0, cnt_DM = 0, cnt_DMC = 0;
        for (int i = 0; i < n; i++) {
            if (s.at(i) == 'D') cnt_D++;
            else if (s.at(i) == 'M') {
                cnt_M++;
                cnt_DM += cnt_D;
            }
            else if (s.at(i) == 'C') cnt_DMC += cnt_DM;

            if (k - 1 <= i) {
                if (s.at(i - k + 1) == 'D') {
                    cnt_D--;
                    cnt_DM -= cnt_M;
                }
                else if (s.at(i - k + 1) == 'M') cnt_M--;
            }
        }

        cout << cnt_DMC << endl;
    }
}

Measured memory_bytes: 1540
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h;
    cin >> h;
    ll cnt=0;
    ll curr=1;
    while(h!=0)
    {
        h/=2;
        cnt+=curr;
        curr*=2;
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int int_cmp(const int *a, const int *b){
  if (*a < *b)
    return (-1);
  else if (*a > *b)
    return (1);
  return (0);} 
int main () {
int f[1001];
int F[1001];
int N,i,V,d,count;
N=1001;
f[0]=2;
f[1]=3;
for(i=2;i<1001;i++){f[i]=f[i-1]+f[i-2];f[i]=f[i]%N;}
for(;~scanf("%d%d",&V,&d);){
  count = 1;
  for(i=0;i<V;i++)F[i]=f[i];
  qsort(F,V,sizeof(int),(int(*)(const void*, const void*))int_cmp);
  for(i=1;i<V;i++)
    if( F[ i] - F[ i - 1] > d - 1)
      count++;
  printf( "%d\n" , count);
 }
 return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, a, b;
int main(void) {
    while(~scanf("%d", &n)) {
        int aa = 0, bb;
        for(int i = 0; i < n; ++i) {
            scanf("%d%d", &a, &b);
            if(a > aa) aa = a, bb = b;
        }
        printf("%d\n", aa + bb);
    }
}

Measured memory_bytes: 256
while n = STDIN.gets.to_i
	
	break if n == 0
	
	m = STDIN.gets.to_i
	line = STDIN.gets
	
	cnt = 0
	idx = 0
	ptn = "I"
	
	for i in 1..n do
		ptn += "OI"
	end
	
	while idx = line.index(ptn, idx)
		if(idx.nil?)
			break
		else
			cnt += 1
			idx += 1
		end
	end
		
	puts cnt
end

Measured memory_bytes: 9424
package main

import (
	"fmt"
)

func main() {
	var K, X int
	fmt.Scan(&K)
	fmt.Scan(&X)

	begin := true
	for i := X - K + 1; i <= X + K - 1; i++ {
		if !begin {
			fmt.Print(" ")
		}
		fmt.Print(i)
		begin = false
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
constexpr int MOD = 1000000007;
ll sum(ll a,ll b)
{
	return ((a+b)*(b-a+1))/2;
}
int main(){
	int n,k;
	cin>>n>>k;
	ll su=0;
	for(int i=k;i<=n+1;i++)
	{		
		su+=sum(n-i+1,n)-sum(0,i-1)+1;
		su%=MOD;
	}
	cout << su;
	return 0;
}
#if 0
1.選択数が同じループならば10^100の係数は必ず同じ値になるため、
無視して端数部分の和だけ考える
2.そのループで登場する和は
端数の最大値から最小値までの範囲で1刻みで現れる
->最大値-最小値+1で和の個数を求められる
3.注意、この問題はその和になるための組み合わせ個数ではなく、和の個数を求める問題である
#endif


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  vector<vector<ii>> a(n);
  for (auto &i : a) {
    int k; cin >> k;
    i.resize(k);
    for (auto &j : i) {
      cin >> j.fi >> j.sc;
      j.fi--;
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    vector<int> b(n);
    for (int j = 0; j < n; j++) {
      if (get_bit(i, j)) b[j] = 1;
      else b[j] = 0;
    }
    int f = 0;
    for (int j = 0; j < n; j++) {
      if (get_bit(i, j)) {
        for (auto &k : a[j]) {
          if (b[k.fi] != k.sc) {
            f = 1;
            break;
          }
        }
        if (f) break;
      }
    }
    if (!f) ans = max(ans, (int)__builtin_popcount(i));
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3628
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VAL_CNT		3										// 値の数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// ソート関数 - int昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// 昇順
	if (*lipVal1 >  *lipVal2) {
		return(1);
	}
	else if (*lipVal1 < *lipVal2) {
		return(-1);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 整数取得
	int li1Val[D_VAL_CNT];
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d%d", &li1Val[0], &li1Val[1], &li1Val[2]);

	// ソート
	qsort(li1Val, D_VAL_CNT, sizeof(int), fSortFnc);

	// １・２番目の値に加算
	int liCnt = li1Val[2] - li1Val[1];
	li1Val[0] += liCnt;
	li1Val[1] += liCnt;

	// １・３番目の値の差を比較
	int liDF = li1Val[2] - li1Val[0];
	if (liDF % 2 == 0) {				// 割り切れる
		liCnt += liDF / 2;
	}
	else {								// 割り切れない
		liCnt += liDF / 2 + 2;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}




int main(){

  ll X;
  cin >> X;
  FOR(i,1,1000000){
    X -= i;
    if(X<=0){
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define PI 3.141592

struct xy{
  double x;
  double y;
};

double cos(double x);


int kock(int,struct xy,struct xy);

int main(){
  int n;
  struct xy p1={0.0,0.0},p2={100.0,0.0};

  scanf("%d",&n);
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  return 0;
}

int kock(int n,struct xy p1,struct xy p2){
  struct xy s,t,u;
  
  if(n==0) return 0;
  
  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  kock(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);

  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;

  u.x=(t.x-s.x)*cos(PI/3)-(t.y-s.y)*sin(PI/3)+s.x;
  u.y=(t.x-s.x)*sin(PI/3)+(t.y-s.y)*cos(PI/3)+s.y; 

  kock(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  
  
  kock(n-1,u,t);
  printf("%f %f\n",t.x,t.y);

  kock(n-1,t,p2);

}

Measured memory_bytes: 636
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'



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

	set<int> st;
	rep(i, 0, 3)
	{
		int x;
		cin >> x;
		st.insert(x);
	}

	if (sz(st) == 2)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

struct Node{
	Node * Lson;
	Node * Rson;
	Node * parent;
	int key;
}; 

void print();
void insert(int k);
void In(Node * p);
void Pro(Node * p);
int find(int k);
void Delete(int k);
Node * getDelete(Node * p);

Node * root;

int main(void)
{
	int m;
	
	cin>>m;
	while(m--)
	{
		char order[10];
		
		cin>>order;
		if(order[0]=='i')
		{
			int k;
			
			cin>>k;
			insert(k);
		}
		else if(order[0]=='p') 
		{
			print();
		}
		else if(order[0]=='f')
		{
			int k;
			
			cin>>k;
			if(find(k))
			{
				cout<<"yes"<<endl;
			}
			else
			{
				cout<<"no"<<endl;
			}
		}
		else
		{
			int k;
			
			cin>>k;
			Delete(k);
		}
	}
	
	return 0;
}

int find(int k)
{
	Node * temp=root;
	
	while(temp!=NULL&&temp->key!=k)
	{
		if(k<temp->key)
		{
			temp=temp->Lson; 
		}
		else temp=temp->Rson;
	}
	if(temp==NULL)
		return 0;
	else return 1;
}

void insert(int k)
{
	Node *father,*temp;
	
	father=NULL;
	temp=root;
	
	Node *New=new Node;
	New->key=k;
	New->parent=NULL;
	New->Lson=NULL;
	New->Rson=NULL;
	
	while(temp!=NULL)
	{
		father=temp;
		if(k<temp->key)
			temp=temp->Lson;
		else temp=temp->Rson;
	}
	
	New->parent=father;
	if(father==NULL)
		root=New;
	else if(k<father->key)
		father->Lson=New;
	else father->Rson=New;
}

void print()
{
	In(root);
	cout<<endl;
	Pro(root);
	cout<<endl;
}

void In(Node * p)
{
	if(p==NULL)
		return;
	In(p->Lson);
	cout<<" "<<p->key;
	In(p->Rson);
}

void Pro(Node * p)
{
	if(p==NULL)
		return ;
	cout<<" "<<p->key;
	Pro(p->Lson);
	Pro(p->Rson);
}

void Delete(int k)
{
	Node * temp=root,*wait_delete,*wait_temp;//temp k??????  wait_delete´????????? wait_temp ´????????????£??×?????  
	if(find(k))
	{
		while(temp!=NULL&&temp->key!=k)
		{
			if(k<temp->key)
			{
				temp=temp->Lson; 
			}
			else temp=temp->Rson;
		}
		if(temp->Lson==NULL||temp->Rson==NULL)
		{
			wait_delete=temp;
		} 
		else wait_delete=getDelete(temp);
		if(wait_delete->Lson!=NULL)
			wait_temp=wait_delete->Lson;
		else wait_temp=wait_delete->Rson;
		
		if(wait_temp!=NULL)
			wait_temp->parent=wait_delete->parent;
		
		if(wait_delete->parent==NULL)	
			root=wait_temp;
		else if(wait_delete==wait_delete->parent->Lson)
			wait_delete->parent->Lson=wait_temp;
		else wait_delete->parent->Rson=wait_temp;
		
		if(wait_delete!=temp)
			temp->key=wait_delete->key;
	}
	delete wait_delete;
} 

Node * getDelete(Node * p)
{
	if(p->Rson!=NULL)
	{
		p=p->Rson; 
		while(p->Lson!=NULL)
			p=p->Lson;
		return p;
	}
	Node * father=p->parent;
	while(father!=NULL&&p==father->Rson)
	{
		p=father;
		father=father->parent;
	}
	return father;
}

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

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

    long long count = 100;
    int i = 0;
    while(true){
        i++;
        count += count * 0.01;
        if(count >= X)
            break;
    }

    cout << i << endl;
}

Measured memory_bytes: 3636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・そもそもとして、ゲームが長引くことはありえない
"""

N,Z,W,*A = map(int,read().split())

A = A[::-1]

if N == 1:
    answer = abs(A[0] - W)
    print(answer)
    exit()

x = abs(A[0] - W)
y = abs(A[1] - A[0])
answer = max(x,y)
print(answer)

Measured memory_bytes: 3188