akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
 
int x, y;
long long ans;
char data[105][105];
 
int main() {
	cin>> x >> y;
	if(x%3 == 0 || y%3 == 0) {
		cout<< "0" << endl;
		return 0;
	}
	ans = 1e10;
	for(int a = 1; a <  x; a++) {
		long long s_a = 1LL*a*y;
		long long s_b = 1LL*(x - a)/2*y;
		long long s_c = 1LL*(x - a + 1)/2*y;
		long long tmp = max(abs(s_a - s_b), abs(s_a - s_c));
		tmp = max(tmp, abs(s_b - s_c));
		ans = min(ans, tmp);
		s_b = 1LL*y/2*(x - a);
		s_c = 1LL*(y + 1)/2*(x - a);
		tmp = max(abs(s_a - s_b), abs(s_a - s_c));
		tmp = max(tmp, abs(s_b - s_c));
		ans = min(ans, tmp);
	}
	swap(x, y);
	for(int a = 1; a <  x; a++) {
		long long s_a = 1LL*a*y;
		long long s_b = 1LL*(x - a)/2*y;
		long long s_c = 1LL*(x - a + 1)/2*y;
		long long tmp = max(abs(s_a - s_b), abs(s_a - s_c));
		tmp = max(tmp, abs(s_b - s_c));
		ans = min(ans, tmp);
		s_b = 1LL*y/2*(x - a);
		s_c = 1LL*(y + 1)/2*(x - a);
		tmp = max(abs(s_a - s_b), abs(s_a - s_c));
		tmp = max(tmp, abs(s_b - s_c));
		ans = min(ans, tmp);
	}
	cout<< ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
#define is ==
int W,H,N;
const int MAX = 1000;
char f[MAX][MAX];
int d[MAX][MAX];
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
struct P
{
  int x,y;
};
inline bool check(P p){
  return p.x < 0 or p.x >= W or p.y < 0 or p.y >= H;
}
int bfs(P s,int goal){
  if(goal > N+'0')return 0;
  fill(*d,*(d+MAX),-1);
  queue<P> que;
  que.push(s);
  d[s.x][s.y] = 0;
  while(!que.empty()){
    P cur = que.front();que.pop();

    if(f[cur.x][cur.y] is goal)return d[cur.x][cur.y] + bfs(cur,goal+1);

    for (int i = 0; i < 4; ++i){
      P np = {cur.x+dx[i],cur.y+dy[i]};
      if(check(np))continue;
      if(f[np.x][np.y] is 'X')continue;
      if(d[np.x][np.y] > -1)continue;//visited
      d[np.x][np.y] = d[cur.x][cur.y] + 1;
      que.push(np);
    }
  }
  cout << "no goal!" << endl;
  return 0;//error
}

int main(){
  ios::sync_with_stdio(false);
  while(cin >> H >> W >> N){
    P s;
    for (int j = 0; j < H; ++j){
      for (int i = 0; i < W; ++i){
	cin >> f[i][j];
	if(f[i][j] == 'S')s.x = i,s.y = j;
      }
    }
    cout << bfs(s,'1') << endl;
  }
  return 0;
}

Measured memory_bytes: 6108
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	queue<ll> q;
	int k;
	cin >> k;
	for (int i = 1; i < 10; i++) {
		q.push(i);
	}
	set<ll> s;
	while (true) {
		ll c = q.front();
		q.pop();
		ll l = c % 10;
		for (int d = l - 1; d <= l + 1; d++) {
			if (d >= 0 && d <= 9) {
				q.push(c * 10 + d);
			}
		}
		s.insert(-c);
		if (s.size() >= k)break;
	}
	cout << -*(s.begin());
}


Measured memory_bytes: 6528
N,K=map(int,input().split())
H=list(map(int,input().split()))
dp=[[]]*N
dp=[0]*N
for i in range(1,N):
    tmp=[]
    for j in range(min(i,K)):
        tmp.append(dp[i-j-1]+abs(H[i]-H[i-j-1]))
    else:
        dp[i]=min(tmp)
print(dp[N-1])

Measured memory_bytes: 52448
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int N = read();
    vector<int> A(N);
    for (auto& a:A) {
        a = read();
    }
    int tmp = 0;
    for (int i = 0; i<N; i++) {
        tmp += (i%2 == 0) ? A[i] : -A[i];
    }
    printf("%d ", tmp);
    for (int j = 1; j<N-1; j++) {
        tmp = 2 * A[j-1] - tmp;
        printf("%d ", tmp);
    }
    printf("%d\n", 2 * A[N-2] - tmp);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

int main()
{
long long A;
long long B;
long long X;
long long a;
long long b;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;

	X = 0;

	a = A;
	if( a % 2 != 0 )
	{
		X = A;
		a++;
	}

	b = B + 1;
	if( B % 2 == 0 )
	{
		X ^= B;
		b--;
	}

	if( ( ( b - a ) / 2 ) % 2 != 0 ) X ^= 1;

	cout << X << endl;

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))
x = 100000000000000

for i in range(N - K + 1):
    x1 = abs(X[i]) + abs(X[K - 1 + i] - X[i])
    x2 = abs(X[K - 1 + i]) + abs(X[i] - X[K - 1 + i])
    
    x_tmp = min(x1, x2)
    x = min(x, x_tmp)

print(x)

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

int main(){
    int h,m,s,S;
    
    cin >> s;
    
    h = s / 3600;
    m = s % 3600 / 60;
    s = s % 60;
    
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(int(s.find_last_of("F")) > int(s.find_first_of("C")) && int(s.find_first_of("C")) != -1)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  int s = 0, t = 0, sum = 0;
  ll ans = 0;

  while(true){
    while(t < N && (sum ^ A[t]) == (sum + A[t])){
      sum ^= A[t];
      t++;
    }
    if(s == N) break;
    ans += t - s;
    sum ^= A[s++];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n,chk;
map<ll,ll> mp;
bool flag;
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>chk;
        if(++mp[chk]>1)
            {flag=1;break;}
    }
    if(flag)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

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

int main(void){
    int a = 0, b = 0, coin = 0;
    cin >> a >> b;
    for (int i = 0; i < 2;i++){
        if(a>b){
            coin += a;
            a--;
        }else if(b>a){
            coin += b;
            b--;
        }else{
            coin += a;
            a--;
        }
    }
    cout << coin << endl;
}

Measured memory_bytes: 256
N,M,K =map(int, input().split())
mod = 10**9 + 7

# cmbが10**10くらいだけど求められるか？って感じ
# 問題読み違えていた。。。N*M <= 2*10**5だ。。。まあ普通だ。
# もうライブラリ使おう。昔nCrのrが小さい時の工夫とかあったけど今回は大丈夫だ。

# https://ikatakos.com/pot/programming_algorithm/number_theory/mod_combination
import numpy as np
 
def prepare(n, MOD):
    nrt = int(n ** 0.5) + 1
    nsq = nrt * nrt
    facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt)
    facts[0, 0] = 1
    for i in range(1, nrt):
        facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD
    for i in range(1, nrt):
        facts[i] = facts[i] * facts[i - 1, -1] % MOD
    facts = facts.ravel().tolist()
 
    invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt)
    invs[-1, -1] = pow(facts[-1], MOD - 2, MOD)
    for i in range(nrt - 2, -1, -1):
        invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD
    for i in range(nrt - 2, -1, -1):
        invs[i] = invs[i] * invs[i + 1, 0] % MOD
    invs = invs.ravel().tolist()
 
    return facts, invs

facts, invs = prepare(N*M+10,mod)
def cmb(n,r,MOD):
  return (((facts[n] * invs[n-r]) % mod) * invs[r]) % mod

## シグマを分離すること。２点i,jの選び方数、かけることのi,jの距離とする。あとはこれに２点以外の選び方のパターン数をかければ良い
# X,Yを独立して考える
# 例えばXについて考えると、使う列の選び方がN*2, 使う行の選び方はM-dis(1ならM-1だし、M-1離れてるのは１個しか選べない）
# disは距離が答えに寄与するから
# cmb()はその２点以外の選び方の個数の話。
#  もちろん他のi,jについて見たら同じ盤面何度も見てるけど、今のi,jに関する値しか計算してないからOK
ans = 0

for dis in range(M):
  ans += N**2 * (M-dis) * dis * cmb(N*M-2, K-2, mod)
  ans %= mod
for dis in range(N):
  ans += M**2 * (N-dis) * dis * cmb(N*M-2, K-2, mod)
  ans %= mod

print(ans)

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

int main(void)
{
    map<string, int> s;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        if (s.count(tmp) > 0) {
            s[tmp]++;
        }
        else {
            s.insert({tmp, 1});
        }
    }
    int M;
    cin >> M;
    int earn = 0;
    for (int i = 0; i < M; i++) {
        string tmp;
        cin >> tmp;
        if (s.count(tmp) > 0) {
            s[tmp]--;
        }
        else {
            s.insert({tmp, -1});
        }
    }
    for (auto n: s)
        earn = max(earn, n.second);
    cout << earn << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    double mid = *a.rbegin() / 2.0;
    double sa = INF;
    rep(i, n - 1) {
        if (sa > abs(mid - a[i])) {
            sa = abs(mid - a[i]);
            ans = a[i];
        }
    }

    cout << *a.rbegin() << " " << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
 
using namespace std;
 
void calcLucasSequence(vector<long>& lucasSequence, const int numOfTerm);
 
int main() {
    int numOfTerm = 0;
    cin >> numOfTerm;
    
    vector<long> lucasSequence;
    calcLucasSequence(lucasSequence, numOfTerm);
    
    cout << lucasSequence.at(numOfTerm) << endl;  
}
 
void calcLucasSequence(vector<long>& lucasSequence, const int numOfTerm) {
    const long INITIAL_TERM = 2;
    const long SECOND_TERM = 1;
    
    lucasSequence.push_back(INITIAL_TERM);
    lucasSequence.push_back(SECOND_TERM);
    //2がマジックナンバーぽい
    //2の代わりにlucasSequence.size()でできる
    //termIndexにして変数の形式を揃える
    for (int term_i = 2; term_i <= numOfTerm; ++term_i) {
        lucasSequence.push_back(lucasSequence.at(term_i - 1) + lucasSequence.at(term_i - 2));
    }
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  vector<char> a(n), b(n);
  rep(i,n) {
    if (i%2==0) {
      a[i] = '0';
      b[i] = '1';
    }
    else {
      a[i] = '1';
      b[i] = '0';
    }
  }
  
  int x = 0;
  int y = 0;
  rep(i,n) {
    if (s[i] != a[i]) x++;
    if (s[i] != b[i]) y++;
  }
  
  cout << min(x,y) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n;
	cin >> n;
	vector<ll> arr(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	vector<ll> dp(n);
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
	}
	cout << dp[n - 1] << endl;

	return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        const long mod = 1000000007;

        // 入力
        long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];

        long ans = 0;
        long t = 0;
        for (int i = 0; i < a.Length; i++)
        {
            for (int j = i + 1; j < a.Length; j++)
            {
                if (a[i] > a[j]) t++;
            }
        }

        long d = 0;
        for (int i = 0; i < a.Length; i++)
        {
            for (int j = 0; j < a.Length; j++)
            {
                if (a[i] > a[j]) d++;
            }
        }

        ans += t * k % mod;
        ans %= mod;
        ans += (k - 1) * k / 2 % mod * d % mod;
        ans %= mod;

        // 出力
        Console.WriteLine(ans);
    }
}

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

ll n;
int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++)
    {
        if (i % d == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MAXN	200005
#define INF	1e9
#define P	1000000007
int n, X, Y, m, t, f;
int a[MAXN], cnt[MAXN];
int x[MAXN], y[MAXN];
long long fac[MAXN], inv[MAXN];
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
long long power(long long x, long long y) {
	if (y == 0) return 1;
	long long tmp = power(x, y / 2);
	if (y % 2 == 0) return tmp * tmp % P;
	else return tmp * tmp % P * x % P;
}
long long getc(int x, int y) {
	return fac[x] * inv[y] % P * inv[x - y] % P;
}
int main() {
	read(n), read(X), read(Y);
	for (int i = 1; i <= n; i++)
		a[i] = INF;
	for (int i = 1; i <= n; i++) {
		read(x[i]), read(y[i]);
		a[x[i]] = min(a[x[i]], y[i]);
	}
	m = INF; t = INF; f = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] < m) {
			t = m;
			m = a[i];
			f = i;
		} else if (a[i] < t) t = a[i];
	fac[0]  = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % P;
	inv[n] = power(fac[n], P - 2);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1) % P;
	int total = 0;
	for (int i = 1; i <= n; i++)
		if (x[i] != f) {
			if (y[i] + m <= Y || y[i] + a[x[i]] <= X && a[x[i]] + m <= Y) {
				total++;
				cnt[x[i]]++;
			}
		} else if (y[i] + m <= X || y[i] + t <= Y) {
			total++;
			cnt[x[i]]++;
		}
	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		ans = ans * getc(total, cnt[i]) % P;
		total -= cnt[i];
	}
	cout << ans << endl;
	return 0;
}

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

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

//add this function
struct Node *find(struct Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else {
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  struct Node *t;
  int n,i,x;
  char tmp[1000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",tmp);
    if(strcmp(tmp,"find")==0){
      scanf("%d",&x);
      t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(tmp,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(tmp,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 20492
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[100009]={0},b[100009]={0};
int main()
{
    int n,i;
    long long sum=0,s=0,f;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        int n1;
        scanf("%d",&n1);
        a[i]=2*n1;
        s+=n1;
    }
    sum+=a[n];
    for(i=3;i<n;i=i+2){
        sum+=a[i];
    }
    f=s-sum;
    b[1]=a[1]-f;
    for(i=2;i<n;i++)
        b[i]=a[i-1]-b[i-1];
    b[n]=a[n]-b[1];
    for(i=1;i<=n;i++){
        if(i>1)
            printf(" ");
        printf("%d",b[i]);
    }

}


Measured memory_bytes: 4548
#include<iostream>
#include<set>
#include<vector>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;


int main(void)
{
    ll a,b;

    cin >> a >> b;
    if((a*b)%2 == 0) cout << "Even" << '\n';
    else cout << "Odd" << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		string s;
		cin >> s;
		int sz=s.size();
		if(s[0]!='>'||sz<6)
		{
			cout << "NA" << endl;
			continue;
		}
		if(s[1]=='\'')
		{
			int t=sz-3;
			if(t%2==0)
			{
				cout << "NA" << endl;
				continue;
			}
			for(int j=2;j<2+t;j++)
			{
				if(j==2+t/2&&s[j]!='#')
				{
					cout << "NA" << endl;
					goto end;
				}
				else if(j!=2+t/2&&s[j]!='=')
				{
					cout << "NA" << endl;
					goto end;
				}
			}
			if(s[sz-1]!='~')
			{
				cout << "NA" << endl;
				continue;
			}
			cout << "A" << endl;
			end:;
		}
		else if(s[1]=='^')
		{
			int t=sz-4;
			if(t%2==1)
			{
				cout << "NA" << endl;
				continue;
			}
			for(int j=0;j<t;j++)
			{
				if(j%2==0&&s[j+2]!='Q')
				{
					cout << "NA" << endl;
					goto end2;
				}
				else if(j%2==1&&s[j+2]!='=')
				{
					cout << "NA" << endl;
					goto end2;
				}
			}
			if(s[sz-1]!='~'||s[sz-2]!='~')
			{
 
				cout << "NA" << endl;
				continue;
			}
			cout << "B" << endl;
			end2:;
		}
		else
		{
			cout << "NA" << endl;
			continue;
		}
	}
	return 0;
}

Measured memory_bytes: 1208
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = scanner.nextInt();
        }

        int[] minA = new int[n];
        minA[0] = 0;
        for(int i = 1; i < n; i++){
            int min = Integer.MAX_VALUE;
            for(int j = 1; j <= k; j++){
                if(i - j >= 0){
                    min = Math.min(min, Math.abs(arr[i] - arr[i - j]) + minA[i - j]);
                }
            }
            minA[i] = min;
        }

        System.out.println(minA[n - 1]);

    }
}



Measured memory_bytes: 49860
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline
# from collections import defaultdict
# import bisect

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N = int(input())
B = [int(x) for x in input().split()]

A = [1e10] * N

A[0] = B[0]
A[-1] = B[-1]

for i in range(1, N - 1):
    A[i] = min(B[i - 1], B[i])

print(sum(A))


Measured memory_bytes: 3444
#include <iostream>

using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

string ans;
int main()
{

    ll a, b;
    cin >> a;
    cin >> b;

    cout << lcm(a, b);

    return 0;
}

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

bool solve() {
    int N, M, a, b;
    cin >> N >> M;
    vector<int> G(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a]++;
        G[b]++;
    }
    for ( int i = 0; i < N; i++ ) {
        if ( G[i] & 1 ) return false;
    }
    return true;
}

int main() {
    string ans = solve() ? "YES" : "NO";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from operator import itemgetter

def solve():
    cardsNum, turnsNum = tuple(map(int, input().split()))
    cards = sorted([int(x) for x in input().split()])
    turns = sorted([tuple(int(x) for x in input().split()) for _ in range(turnsNum)], key=itemgetter(1), reverse=True)
    
    largeCount = 0
    largeCards = [0,] * cardsNum
    for chances, num in turns:
        for _ in range(chances):
            if (largeCount < cardsNum):
                largeCards[largeCount] = num
                largeCount += 1
            else:
                break
        if (largeCount >= cardsNum):
            break 
    
    for i in range(cardsNum):
        if (largeCards[i] > cards[i]):
            cards[i] = largeCards[i]
        else:
            break
    print(sum(cards))
solve()

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

int main()
{
	int n,i,ten[1001],sum;
	double s,m,l;

	while(1)
	{
		scanf("%d",&n);
		if( n==0 )
			break;
			for(i=0;i<n;i++)
			{
				scanf("%d",&ten[i]);
			}
	sum=0;

	for(i=0;i<n;i++)
	{
		sum+=ten[i];
	}
	m=1.0*sum/n;
	s=0;

	for(i=0;i<n;i++)
	{
		s+=(ten[i]-m)*(ten[i]-m);
	}

	l=sqrt(s/n);

	printf("%.8lf\n",l);
	}
		
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int max(int a,int b,int c){
    int max;
    max=a;
    if(max<b)max=b;
    if(max<c)max=c;
    return max;
}
int min(int a,int b,int c){
    int min;
    min=a;
    if(min>b)min=b;
    if(min>c)min=c;
    return min;
}
int main(void){
    int x,y,z,ax,in,id;
    scanf("%d %d %d",&x,&y,&z);
    ax=max(x,y,z);
    in=min(x,y,z);
    id=x+y+z-ax-in;
    printf("%d %d %d\n",in,id,ax);
    return 0;
}


Measured memory_bytes: 2048
let rec for_fold a b f v = if a > b then v else for_fold (a+1) b f (f v a)

let () =
  Scanf.scanf "%d" @@ fun n ->
  let x = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  for i = 1 to n-1 do x.(i) <- x.(i) + x.(i-1) done;

  let psum l r =
    if l >= r then 0
    else if l = 0 then x.(r-1) else x.(r-1) - x.(l-1)
  in
  let halve a b =
    let rec loop l r =
      if l >= r then r
      else
        let m = (l+r) / 2 in
        if psum a m >= psum m b then loop l m else loop (m+1) r
    in
    let m = loop (a+1) (b-1) in

    if abs (psum a m - psum m b) <= abs (psum a (m-1) - psum (m-1) b) then
      psum a m, psum m b
    else
      psum a (m-1), psum (m-1) b
  in

  for_fold 2 (n-2) (fun v i ->
    let p, q = halve 0 i in
    let r, s = halve i n in
    List.(fold_left max p [p;q;r;s] - fold_left min p [p;q;r;s])
    |> min v
  ) x.(n-1)
  |> Printf.printf "%d\n"


Measured memory_bytes: 6144
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        foreach (var x in ary) {
            if (x % 2 == 0) {
                if (!(x % 3 == 0 || x % 5 == 0)) {
                    return "DENIED";
                }
            }
        }

        return "APPROVED";
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

int beki(int a, int n)
{
    if(n == 0){
        return 1;
    }
    int ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * a;
    }
    return ans;
}

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

    int N; cin >> N;
    vel dp(100005);//dp[i] = x はi円引き出す操作の最小値がx回であること


    dp[0] = 0;
    rep1(i, N+1) {
        dp[i] = dp[i - 1] + 1;//一円が最小の時
        rep1(j,8) {
            if(i - pow(6, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(6,j)] + 1);//6のべき乗円が最小の時
            }
            if(i - pow(9, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(9, j)] + 1);//9のべき乗円が最小の時
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------



int main() {
    CIN(N);
    vector<int> v(N);
    rep(i,N) cin>>v[i];
    bool ok = true;
    rep(i,N){
        if(v[i]%2==0){
            if(v[i]%3==0||v[i]%5==0){
                ok = true;
            }else{
                ok = false;
            }
        }
        if(!ok) break;
    }
    printf(ok?"APPROVED\n":"DENIED\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

#define EPS 1e-7

int main(){
    int N, A, B;
    cin>>N>>A>>B;
    vector<LL> value(N);
    value.resize(N);
    foreach(i, value)cin>>i;
    vector<PLL> dp(N+1, PII(-1, 0));
    dp[0]=PLL(0, 1);
    REP(i, N){
        for(int j=N-1;j>=0;--j){
            if(dp[j].first+value[i]>dp[j+1].first){
                dp[j+1].first=dp[j].first+value[i];
                dp[j+1].second=dp[j].second;
            }else if(dp[j].first+value[i]==dp[j+1].first){
                dp[j+1].second+=dp[j].second;
            }
        }
    }
    long double ans = (long double)dp[A].first/A;
    LL count = dp[A].second;
    for(int i=A+1;i<=B;++i){
        if(abs(ans-(long double)dp[i].first/i)<EPS){
            count+=dp[i].second;
        }else if(ans<(long double)dp[i].first/i){
            ans=(long double)dp[i].first/i;
            count=dp[i].second;
        }
    }
    printf("%.7Lf\n%lld\n", ans, count);
}


Measured memory_bytes: 256
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    sx,sy,tx,ty=map(int,input().split())
    tate=ty-sy
    yoko=tx-sx

    for _ in range(tate):
        print('U',sep='',end='')
    for _ in range(yoko+1):
        print('R',sep='',end='')
    for _ in range(tate+1):
        print('D',sep='',end='')
    for _ in range(yoko+1):
        print('L',sep='',end='')
    for _ in range(1):
        print('U',sep='',end='')
    for _ in range(1):
        print('L',sep='',end='')
    for _ in range(tate+1):
        print('U',sep='',end='')
    for _ in range(yoko+1):
        print('R',sep='',end='')
    for _ in range(tate+1):
        print('D',sep='',end='')
    for _ in range(yoko):
        print('L',sep='',end='')
    print()




resolve()

Measured memory_bytes: 53100
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll x=1,y=1;
    for(int i=0; i<n; i++){
        ll T,A;
        cin>>T>>A;
        ll ma=max((x-1+T)/T,(y-1+A)/A);
        x=ma*T,y=ma*A;
    }
    cout<<x+y<<endl;
}


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

int main() {
	long long n = 0, a = 0, b = 0, c = 0, ans = 0;
	cin >> n >> a >> b;
	ans = n / (a + b) * a;
	c = n % (a + b);
	if (c > a) {
		ans += a;
	}
	else {
		ans += c;
	}
	cout << ans << endl;
}

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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define T ll t; cin>>t; while(t--)

int main(){
  FAST

    ll l;
    cin>>l;
  	double a;
  
  	a=l/3.0;
  	printf("%0.12lf", a*a*a);
  
  return 0;
}








Measured memory_bytes: 256
N=int(input())
A=map(int,input().split())
m=10**9+7
r=1
C=[0,0,0]
for a in A:
    try:
        i=C.index(a)
        r=r*sum([1 if c==a else 0 for c in C])%m
        C[i]+=1
    except:
        print(0)
        exit()
print(r)

Measured memory_bytes: 9944
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int M, N;
    cin >> N >> M;
    if(N<=M) cout << "Yes" <<endl;
    else cout << "No" <<endl; 

    
  	return 0;
}


Measured memory_bytes: 256
local x,y = io.read("*l"):match("(%d+).(%d+)")
local arr = {}
local result = 0
for _ in io.read("*l"):gmatch("%d+") do
  table.insert(arr,tonumber(_))
end
table.sort(arr)
for i = 1,tonumber(x) do
  if arr[i] >= tonumber(y) then
    result = #arr - i + 1
    break
  end
end
print(result)

Measured memory_bytes: 3260
#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 tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 1e5+100;
const int Mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false);

    long long n;
    cin>>n;
    long long inc = 1, Ans = 0;
    while(n){
        n/=2;
        Ans+=inc;
        inc<<=1LL;
    }
    cout<<Ans<<endl;

    return 0;
}


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

const int MAX = 100000;
int n, pa[MAX], ch[MAX], br[MAX];

void solve(){
  for(int i=0;i<n;i++){
    cout << "node " << i << ": parent = " << pa[i] << ", depth = " << flush;

    int cnt = 0;
    for(int j=i; pa[j]!=-1; j=pa[j]) cnt++;
    cout << cnt << ", " << flush;

    if(pa[i] == -1) cout << "root, " << flush;
    else if(ch[i] == -1) cout << "leaf, " << flush;
    else cout << "internal node, " << flush;

    cout << "[";
    for(int j=ch[i]; j!=-1; j=br[j]){
      if(j != ch[i]) cout << ", ";
      cout << j;
    }
    cout << "]" << endl;
  }
}

int main(){
  fill(pa,pa+MAX,-1);
  fill(ch,ch+MAX,-1);
  fill(br,br+MAX,-1);
  cin >> n;
  for(int i=0;i<n;i++){
    int x,prev,y,c;
    cin >> x >> c;
    for(int j=0;j<c;j++){
      cin >> y;
      pa[y] = x;
      if(j == 0) ch[x] = y;
      else br[prev] = y;
      prev = y;
    }
  }
  solve();
}

Measured memory_bytes: 2332
import java.util.Scanner

fun main(args: Array<String>) {
  val scanner = Scanner(System.`in`)
  val A = scanner.nextInt()
  val B = scanner.nextInt()
  var K = scanner.nextInt()
  scanner.close()
  for (i in 100 downTo 1) {
    if (A % i == 0 && B % i == 0) {
      K--
      if (K == 0) {
        print(i)
        return
      }
    }
  }
}

Measured memory_bytes: 31388
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r-1] - T[l-1])

Measured memory_bytes: 6100
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

d = {}

for i in range(N):
    if s[i] in d:
        d[s[i]] += 1
    else:
        d[s[i]] = 1
    
for i in range(M):
    if t[i] in d:
        d[t[i]] -= 1
    else:
        d[t[i]] = -1

v = list(d.values())
v.append(0)
print(max(v))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 1000000007 
#define MAX 1000005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int ll;
using namespace __gnu_pbds;
using namespace std;
//using namespace boost::multiprecision;

#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>

ll fact[MAX],inv_fact[MAX];

ll modular_expo(ll x,ll n)
{
	ll ans = 1;
	while(n)
	{
		if(n&1)
		ans = (ans * x)%MOD;
		x = (x*x)%MOD;
		n = n>>1;
	}
	return ans%MOD;
}

void fun()
{
	fact[0] = 1;
	for(ll i=1;i<MAX;i++)
	fact[i] = (fact[i-1] * i)%MOD;
	inv_fact[MAX-1] = modular_expo(fact[MAX-1],MOD-2);
	for(ll i=MAX-2;i>=0;i--)
	inv_fact[i] = (inv_fact[i+1] * (i+1))%MOD;
}


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

//fun();

ll t=1;
//cin>>t;

while(t--)
{
	ll h1,m1,h2,m2,tm;
	cin>>h1>>m1>>h2>>m2>>tm;
	
	ll hr = tm/60;
	ll min = tm%60;
	
	if(min>m2)
	{
		h2--;
		m2 += 60;
	}
	
	m2 -= min;
	h2 -= hr;
	
	if(m1>m2)
	{
		h2--;
		m2 += 60;
	}
	
	m2 -= m1;
	h2 -= h1;
	
	ll ans = h2*60+m2;
	if(ans<0)
	cout<<"0\n";
	else
	cout<<ans<<"\n";
	
}



return 0;
}

Measured memory_bytes: 3636
a, b, c = [int(x) for x in input().strip().split()]

counter = 0
while True:
	if a% 2 != 0 or b% 2!= 0 or c% 2 != 0:
		print(counter)
		break
	else:
		new_b = a//2 + c//2
		new_c = a//2 + b//2
		a = b//2 + c//2
		b = new_b
		c = new_c
		counter += 1
	if counter >= 100000:
		print('-1')
		break

Measured memory_bytes: 3060
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i,q,r,l;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m>>q;
  std::vector<P> vec;
  rep(i,m){
    cin>>l>>r;
    vec.pb(P(l,r));
  }
  sort(all(vec));
  ll dp[505] = {0};
  ll idx = vec[0].fi;
  ll cnt = 1;
  repl(i,1,m){
    if(vec[i].fi != idx) {
      dp[idx] = cnt;
      cnt = 1;
      idx = vec[i].fi;
    } else {
      cnt++;
    }
  }
  ll dpp[505][505] = {0};
  rep(i,m) dpp[vec[i].fi][vec[i].se] += 1;
  rep(i,n+1) rep(j,n+1) dpp[i][j+1] += dpp[i][j];
  rep(i,q) {
    cin>>l>>r;
    cnt = 0;
    repl(j,l,r+1){
      cnt += dpp[j][r];
    }
    cout<<cnt<<endl;
  }

}

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


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

int main() {
int64_t n,k,a;
  cin>>n>>k;
  a=0;
  for(int64_t i=k;i<=n+1;i++){
  a=a+(n-i+1)*i+1;
    a=a%1000000007;
  }
  cout<<a<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;
const int N=200005;
int n,m,k,s,t,vis[N],h[N];
int pre[N],f[N];
vector<int> e[N];
set<int> a[N];
void dfs(int u){
	for (int &v:e[u])
		if (!h[v]) {
			dfs(v);
			a[u].insert(f[v]);
		}
	for (int i=0;;++i)
		if (!a[u].count(i)) {
			f[u]=i;
			break;
		}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;++i){
		cin>>k;
		pre[i]=k;
		e[k].push_back(i);
	}
	int now=1;
	for (;!vis[now];now=pre[now]) vis[now]=1;
	for (;!h[now];now=pre[now]) h[now]=1;
	int mi=0x3f3f3f3f,mx=0,sum=0;
	for (int i=1;i<=n;++i)
		if (h[i]) {
			dfs(i);
			++sum;
			mi=min(mi,f[i]);
			mx=max(mx,f[i]);
		}
	if (mi==mx && (sum&1)) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
}

Measured memory_bytes: 29056
# -*- coding: utf-8 -*-

N = int(input())
txy = [[0, 0, 0]]
for n in range(N):
    txy.append([int(i) for i in input().split()])

for n in range(N):
    now_time = txy[n][0]
    now_x = txy[n][1]
    now_y = txy[n][2]
    next_time = txy[n+1][0]
    next_x = txy[n+1][1]
    next_y = txy[n+1][2]

    interval = abs(next_time - now_time)

    distance_x = abs(next_x - now_x)
    distance_y = abs(next_y - now_y)
    distance_sum = distance_x + distance_y

    if distance_sum > interval:
        print('No')
        break
    else:
        margin = interval - distance_sum
        if margin % 2 != 0:
            print('No')
            break
else:
    print('Yes')



Measured memory_bytes: 21116
#include <stdio.h>

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





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

int main() {
    int x; cin >> x;
    for (int i = x; i > 0; i--) {
        for (int j = 2; j <= x; j++) {
            int tmp = i;
            int cnt = 0;
            while (tmp%j == 0) {
                //cout << tmp << ": " << i << ": " << j << endl;
                tmp = tmp/j;
                cnt++;
            }
            if (tmp == 1 && cnt > 1) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char s[200005];
int len;
bool f[200005];
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	int ans=0;
	for(int i=1;i<=len;i++)
	{
		if(!f[i-1]&&s[i]==s[i-1])
		{
			f[++i]=1;
			if(i>len)
				ans--;
		}
		ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))

x = n//2
if sum(a)/2 == sum(a[:(n//2)]):
  print(0)
elif sum(a)/2 >= sum(a[:(n//2)]):
  while sum(a)/2 >= sum(a[:x]):
    x += 1  
  print(min(abs(2*sum(a[:x])-sum(a)), abs(2*sum(a[:x-1])-sum(a))))
else:
  while sum(a)/2 <= sum(a[:x]):
    x -= 1
  print(min(abs(2*sum(a[:x])-sum(a)), abs(2*sum(a[:x+1])-sum(a))))


Measured memory_bytes: 31644
#include<cstdio>
#include<complex>
#include<algorithm>
using namespace std;

typedef complex<double> P;

int n;
P p[3000];

int comp(P a,P b){
  if(a.real()<b.real())return -1;
  if(a.real()==b.real()){
    if(a.imag()<b.imag())return -1;
    else if(a.imag()==b.imag())return 0;
  }
  return 1;
}

bool exist(P a){
  int lb = -1,ub = n;
  while(ub-lb>1){
    int mid = (ub+lb)/2;
    if(comp(p[mid],a)==0)return true;
    if(comp(p[mid],a)>0)ub = mid;
    else lb = mid;
  }
  //if(!comp(p[ub],a) || !comp(p[lb],a))return true;
  return false;
}

int main(){
  while(scanf("%d",&n) && n){
    for(int i=0;i<n;i++)scanf("%lf %lf",&p[i].real(),&p[i].imag());

    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	if(comp(p[i],p[j])>0)swap(p[i],p[j]);

    double ans = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j)continue;
	P n = (p[j]-p[i])*P(0,-1);
	if(exist(p[i]+n) && exist(p[j]+n))ans = max(ans,abs(n)*abs(n));
      }
    }
    printf("%d\n",(int)(ans+1e-6));
  }
}

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

namespace _0006
{
    class Program
    {
        static void Main(string[] args)
        {
            // 文字列strを入力し、逆順に出力するプログラム

            char[] str = Console.ReadLine().ToCharArray();

            Array.Reverse(str);

            Console.WriteLine(str);
        }
    }
}



Measured memory_bytes: 15796
#include <iostream>
#include <algorithm>

using namespace std;

static const int MAX = 200000;

int main(void)
{
	int r[MAX], n;

	cin >> n;
	for (int i = 0; i < n; ++i) cin >> r[i];

	int maxv = -2000000000;
	int minv = r[0];
	for (int i = 1; i < n; ++i)
	{
		maxv = max(maxv, r[i] - minv);
		minv = min(minv, r[i]);
	}
	cout << maxv << endl;
}


Measured memory_bytes: 3872
#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <bitset>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

//#define FAST_ALLOCATOR_MEMORY 1e8
#undef LOCAL
//#include "optimization.h"

int main() {
	iostream::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x = 0, y = 0;
	int n;
	cin >> n;
	bool is = 1;
	int now = 0;
	while (n--) {
		int t, tox, toy;
		cin >> t >> tox >> toy;
		int d = t - now;
		if (abs(x - tox) + abs(y - toy) > d)
			is = 0;
		if (((x + y) - (tox + toy) - d) & 1)
			is = 0;

		now = t;
		x = tox, y = toy;
	}
	if (is) {
		cout << "Yes";
	}
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 5;
int n, k, a[N];
bool can[N];
 
inline void readInput() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}
 
inline void solve() {
	sort(a, a + n);
	for (int i = 1; i <= k; i++)
		for (int j = 0; j < n && a[j] <= i; j++)
			can[i] |= !can[i - a[j]];
	cout << (can[k]? "First\n": "Second\n");
}
 
int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	readInput(), solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
    int n = 0;
    std::cin >> n;

    switch (n % 10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        std::cout << "hon";
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        std::cout << "pon";
        break;
    case 3:
        std::cout << "bon";
        break;
    default:
        break;
    } 

}

Measured memory_bytes: 3620
#![allow(non_snake_case)]

use std::io;

fn print_vec(a: &Vec<i32>){
    let s = a.iter().map(|v| v.to_string())
        .collect::<Vec<String>>()
        .join(" ");
    println!("{}", s);
}

fn main() {
    let sin = io::stdin();
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let _n = buf.trim().parse::<u32>().unwrap();

    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let mut a: Vec<i32> = buf.split_whitespace()
        .map(|v| v.parse::<i32>().unwrap())
        .collect();
    a.reverse();
    print_vec(&a);
}



Measured memory_bytes: 5036