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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;


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

    if(k > (n-1) * (n-2) / 2) {
        cout << "-1" << endl;
        return 0;
    }

    int muda = (n-1) * (n-2) / 2 - k;
    cout <<  n-1 + muda << endl;

    REPN(i, 1, n) {
        cout << 1 << " " << i+1 << endl;
    }

    if(muda == 0) return 0;
    int idx = 0;
    REPN(i, 1, n) REPN(j, i+1, n) {
        cout << i+1 << " " << j+1 << endl;
        
        idx++;
        if(idx == muda) return 0;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 5e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
int c[N] ;
int ft[N] ;
int ans[N] ;
vector<array<int,2>> v[N] ;
int n , q ;

void upd(int i,int x){
	for(++i;i<=n;i+=i&-i)
		ft[i]+=x ;
}
int get(int i){
	// answer of [0,i)
	int sm = 0 ;
	for(; i; i-=i&-i)
		sm += ft[i] ;
	return sm ;
}
void solve(){
	cin >> n >> q ;
	for(int i = 0 ; i < n ; i++){
		cin >> c[i] ;
	}
	for(int i = 0 ; i < q ; i++){
		int l,r ;
		cin >> l >> r ;
		--l ; --r ;
		v[r].pb({l,i}) ;
	}
	map<int,int> mp ;
	for(int i = 0 ; i < n ; i++){
		if(mp.find(c[i])!=mp.end())
			upd(mp[c[i]],-1) ;
		upd(i,1) ;
		for(auto x : v[i]){
			ans[x[1]]=get(n)-get(x[0]) ;
		}
		mp[c[i]] = i ;
	}
	for(int i = 0 ; i < q ; i++){
		cout << ans[i] << endl ;
	}

}

int32_t main(){
    FAST_IO ;
    int t = 1 ;
//    cin >> t ;
    while(t--){
        solve() ;
    }
}


Measured memory_bytes: 71596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	run()
}

func run() {
	setSpace()
	x, a := readN(), readN()

	if x >= a {
		fmt.Println(10)
		return
	}
	fmt.Println(0)
}

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll k, a, b;
    cin >> k >> a >> b;

    exrep(i, a, b) {
        if(i%k == 0) {
            out("OK");
            re0;
        }
    }
    
    out("NG");
    re0;
}

Measured memory_bytes: 3624
using System;

namespace abc072_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            for (int i = 0; i < s.Length; i += 2)
            {
                Console.Write(s[i]);
            }
            Console.WriteLine();
        }
    }
}

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

int main(){
    int n; ll W;
    cin >> n >> W;
    ll w[n], v[n];
    rep(i,n) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(n+1,vector<ll>(VMAX,INF));
    dp[0][0] = 0;
    rep(i,n){
        rep(j,VMAX){
            if(j < v[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
        }
    }
    for(int i = VMAX-1; i >= 0; i--){
        if(dp[n][i] <= W){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 80256
import numpy

k, n = map(int,input().split())
a = list(map(int,input().split()))

distance = numpy.empty(n,dtype=numpy.int)
distance[0] = a[0]

for i in range(1,n):
    distance[i] =  a[i] - a[i-1]

distance[0] = k - a[n-1] + a[0]

print(k - max(distance))


Measured memory_bytes: 34164
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

#define AMAX 10010
#define INF 1001001001

int d[AMAX],color[AMAX];
vector<pair<int,int>> M[AMAX];
int n;

void dijk(int s){
  
  rep(i,n){
    d[i]=INF;
    color[i]=0;
  }
  d[s]=0;
  
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> p;
  p.push({0,s});
  
  pair<int,int> u;
  while(!p.empty()){
    u=p.top(); p.pop();
    color[u.second]=2;
    
    for(auto v:M[u.second]){
      if(color[v.first]!=2){
        if(d[u.second]+v.second<d[v.first]){
          d[v.first]=d[u.second]+v.second;
          color[v.first]=1;
          p.push({d[v.first],v.first});
        }
      }
    }
  }

}

int main(){
  cin>>n;
  
  int u,k,v,c;
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      cin>>v>>c;
      M[u].push_back({v,c});
    }
  }
  
  dijk(0);
  
  rep(i,n) cout<<i<<" "<<d[i]<<endl;
      
  return 0;
}


Measured memory_bytes: 8408
#include <bits/stdc++.h>
#define MAX 234
using namespace std;

int N;
char str[MAX];
int color[MAX];
int graph[MAX][MAX];
int depth[MAX];

int bfs(int cur)
{
	queue<int> q;
	q.push(cur);
	color[cur] = 0;
	depth[cur] = 0;
	int ret = 0;
	while (!q.empty())
	{
		cur = q.front();
		q.pop();
		for (int i = 0; i < N; i++)
		{
			if (graph[cur][i])
			{
				if (color[i] == color[cur])
				{
					cout << -1 << endl;
					exit(0);
				}
				if (color[i] < 0)
				{
					q.push(i);
					color[i] = !color[cur];
					depth[i] = depth[cur] + 1;
					ret = depth[i];
				}
			}
		}
	}
	return ret;
}

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> str;
		for (int j = 0; j < N; j++) graph[i][j] = str[j] - '0';
	}
	int mmax = -1;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			depth[j] = -1;
			color[j] = -1;
		}
		mmax = max(mmax, bfs(i));
	}
	cout << mmax + 1 << endl;
	return 0;
}


Measured memory_bytes: 384
import bisect
import math

n = int(input())
a = list(map(int,input().split()))

a.sort()

n1 = math.ceil(math.log(1000000000,2))+1

s = [0 for _ in range(n)]
s[0] = a[0]
for i in range(1,n) :
  s[i] = s[i-1]+a[i]

ans = 0
for i in range(n) :
  h = 0
  m = a[i]*2
  for j in range(n1) :
    mg = bisect.bisect_left(a,m)
    if mg <= n-1 and m == a[mg] :
      mg += 1
    m = s[mg-1]*2
    if m >= a[n-1] :
      ans += 1
      break
  
print(ans)

Measured memory_bytes: 64232
import sys
import os


N = int(input())
dices = []
for i in range(N):
    dice = list(map(int, input().split()))
    dices.append(dice)

def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    # Y???????????¢
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice


def check(dice0_input, dice1_input):
    # ??????????????¶?????????????????????????????????copy?????±???
    dice0 = dice0_input[:]
    dice1 = dice1_input[:]

    # up???????????????
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False

    # front???????????????
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False

    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False


def check2(dice0, dice1):
    # ?????¨????????¢???????????????6????????§????????????
    for i in range(6):
        result = check(dice0, dice1)
        if result:
            return True
        else:
            if i % 2 == 0:
                dice0 = dice_roll(dice0, 'N')
            else:
                dice0 = dice_roll(dice0, 'E')
    return False

for i in range(N):
    for j in range(i+1, N):
        is_same = check2(dices[i], dices[j])
        if is_same:
            print('No')
            quit()
print('Yes')


Measured memory_bytes: 5624
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

static const int INFTY = 100000008;

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

struct edge { int from, to, cost; };

int dist[102][102];

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

	edge g[1003];

	REP(i, M) {
		cin >> g[i].from >> g[i].to >> g[i].cost;
		g[i].from--;
		g[i].to--;//0-indexed
	}

	REP(i, N) {
		REP(j, N) dist[i][j] = INFTY;
	}
	REP(i, M) {
		dist[g[i].from][g[i].to] = g[i].cost;
		dist[g[i].to][g[i].from] = g[i].cost;
	}
	REP(i, N) dist[i][i] = 0;

	REP(k, N) {
		REP(i, N) {
			REP(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	}

	int ans = 0;
	REP(i, M) {
		if (g[i].cost > dist[g[i].from][g[i].to]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    int N;
    int num[4] = {};
    char str[10];
    
    scanf("%d",&N);
    
    for(int i = 0; i < N; i++){
        scanf("%9s",str);
        if(strcmp(str,"AC") == 0){
            num[0]++;
        }
        else if(strcmp(str,"WA") == 0){
            num[1]++;
        }
        else if(strcmp(str,"TLE") == 0){
            num[2]++;
        }
        else if(strcmp(str,"RE") == 0){
            num[3]++;
        }
    }
    
    printf("AC x %d\n",num[0]);
    printf("WA x %d\n",num[1]);
    printf("TLE x %d\n",num[2]);
    printf("RE x %d\n",num[3]);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> m >> n;
    vi v(n);
    REP(i,n) {
        cin >> v[i];
    }
    vi vv;
    REP(i,n){
        ll a = 2 * v[i] - 1 - m;
        vv.push_back(a);
    }
    vv.push_back(sum);
    sort(ALL(vv));
    cout << vv.back() << endl;
}

Measured memory_bytes: 256
console.log((args=>{
  const [[n],a] = args.trim().split`\n`.map(r=>r.split` `.map(v=>v|0));
  a.sort((a,b)=>b-a);
  const max = a[0];
  let med = 1e9;
  for ( let i = 1; i < n; i++ ) {
    if ( Math.abs(max/2 - med) > Math.abs(max/2-a[i]) ) med = a[i];
  }
  return `${max} ${med}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 42200
import java.util.Scanner;

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

        for(int i=1;i<=10;i++){
            x=r*x-d;
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for(i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for(i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
};

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  vl c(26, 0), o(26, 0);
  rep(i, n) c[s[i] - 'a']++;
  ll odd = 0;
  rep(i, 26) {
    odd += c[i] % 2;
    o[i] = c[i] % 2;
  }
  if((n % 2 && odd != 1) || (n % 2 == 0 && odd > 0)) {
    cout << -1 << endl;
    return 0;
  }
  vl v(n), j(26, 0);
  vector<vl> k(26);
  ll r = 0;
  rep(i, n) {
    ll a = s[i] - 'a';
    if(o[a] == 1) {
      if(j[a] == (c[a] - 1) / 2) {
        v[i] = n / 2;
        j[a]++;
        r++;
        continue;
      }
    }
    if(j[a] < c[a] / 2) {
      v[i] = i - r;
      k[a].push_back(v[i]);
    } else {
      ll nj = c[a] - 1 - j[a];
      v[i] = n - k[a][nj] - 1;
      r++;
    }
    j[a]++;
  }
  vl sv = v;
  sort(all(sv));
  BIT<ll> b(n + 100);
  ll ans = 0;
  rep(i, n) {
    ll in = lower_bound(all(sv), v[i]) - sv.begin();
    ans += b.sum(n - 1 - in);
    b.add(n - 1 - in);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9200
import java.util.*;

public class Main {
    public static void main(String[] arg) {
        Scanner scan = new Scanner(System.in);
        int h = Integer.parseInt(scan.next());
        int a = Integer.parseInt(scan.next());

        int count = 0;
        while(h > 0) {
            h = h-a;
            count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
from operator import itemgetter
n=int(input())
A=[tuple(map(int,input().split())) for i in range(n)]
B=[tuple(map(int,input().split())) for j in range(n)]
A.sort()
B.sort()
count=0
for i in range(n):
    box=[A[j] for j in range(len(A)) if (A[j][0]<B[i][0]) and (A[j][1]<B[i][1])]
    #条件を満たす一番大きいものから消していく
    if any(box):
        box=sorted(box, key=itemgetter(1))
        A.remove(box[-1])
        count +=1
print(count)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  int max_num = max(A, max(B, C));
  int empty_area = (3 * max_num) - (A + B + C);

  if (empty_area % 2 == 0) {
    cout << (empty_area / 2) << endl;
  } else {
    cout << ((empty_area + 3) / 2) << endl;
  }
}


Measured memory_bytes: 3620
import bisect
N=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
    aa=bisect.bisect_left(a,i)
    cc=N-bisect.bisect_right(c,i)
    ans+=aa*cc
print(ans)

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


int main() {
    ll N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if (N <= K) cout << N * X << endl;
    else cout << K * X + (N - K) * Y << endl;
}



Measured memory_bytes: 3616
s=str(input())
t=str(input())
num=len(s)
p=0
if s==t:
    print('Yes')
else:
    for i in range(1,num,1):
        a=s[-i:]
        b=s[:num-i]
        c=a+b
        if c==t:
            print('Yes')
            break
        else:
            p+=1
if p==num-1:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S; cin >> S;
  int ssize = (int)S.size();
  int gtime = 0;
  int ptime = 0;
  int win = 0;
  int lose = 0;
  rep(i,ssize){
    char tophand = S[i];
    if(tophand == 'g'){
      if(ptime < gtime){
        ptime++;
        win++;
      }
      else{
        gtime++;
      }
    }
    else{ // 'p'
      if(ptime < gtime){
        ptime++;
      }
      else{
        gtime++;
        lose++;
      }
    }
  }
  cout << win - lose << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N;
vector<ll> A, B;


int main() {
    string S, T;
    cin >> S >> T;
    A.resize(S.size()+1, 0);
    B.resize(T.size()+1, 0);
    REP(i, S.size()) {
        A[i+1] = A[i];
        if(S[i]=='A') A[i+1]++;
    }
    REP(i, T.size()) {
        B[i+1] = B[i];
        if(T[i]=='A') B[i+1]++;
    }

    ll q;
    cin >> q;
    ll a, b, c, d;
    ll l, r;
    REP(i, q) {
        cin >> a >> b >> c >> d;
        l = A[b] - A[a-1] + b - a + 1;
        r = B[d] - B[c-1] + d - c + 1;
        cout << (l%3==r%3?"YES":"NO") << endl;
    }
	return 0;
}

Measured memory_bytes: 2560
// D - Redistribution
#include <bits/stdc++.h>
using namespace std;
int64_t C[2000];

int main(){
	int S; cin>>S;
	C[0] = 1;
	for(int n=3; n<=S; ++n) C[n] = (C[n-1] + C[n-3]) % 1'000'000'007;
	cout<< C[S] <<'\n';
}


Measured memory_bytes: 3512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

void solve(int N, int K, vector<pair<int, long long>> A) {
  long long ans = 0;
  map<int, vector<long long>> m;
  for (auto a : A) {
    m[a.first].emplace_back(a.second);
  }

  vector<long long> y0, y1;

  for (auto x : m) {
    vector<long long> v = x.second;
    sort(v.begin(), v.end());
    y1.push_back(v.back());
    v.pop_back();
    y0.insert(y0.end(), v.begin(), v.end());
  }
  sort(y0.rbegin(), y0.rend());
  sort(y1.rbegin(), y1.rend());
  int Y = max(0, K - (int)y0.size());
  long long X = 0;
  for (int i = 0; i < Y; i++) {
    X += y1[i];
  }
  for (int i = 0; i < K - Y; i++) {
    X += y0[i];
  }
  for (;;) {
    ans = max(ans, X + (long long)Y * Y);
    if (Y >= K || Y >= y1.size()) {
      break;
    }
    X += y1[Y];
    X -= y0[K - Y - 1];
    Y++;
  }
  printf("%lld\n", ans);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, long long>> A(N);
  for (int i = 0; i < N; i++) {
    int t;
    long long d;
    cin >> t >> d;
    A[i] = make_pair(t, d);
  }
  solve(N, K, A);
  return 0;
}

Measured memory_bytes: 15480
#include <stdio.h>

int main(){
	int card[10],c1,c2,c3,i,y;
	while(scanf("%d %d %d",&c1,&c2,&c3) != EOF){
		y = 0;
		for(i = 0;i < 10;i++) card[i] = 0;
		card[c1] = 1;
		card[c2] = 1;
		card[c3] = 1;
		for(i = 0;i < 10;i++){
			if(!card[i]){
				if(c1 + c2 + i <= 20) y++;
			}
		}
		if(y > 4) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  map<string, int> cnt;
  rep(i, n) cnt[s[i]]++;
  printf("AC x %d \n", cnt["AC"]);
  printf("WA x %d \n", cnt["WA"]);
  printf("TLE x %d \n", cnt["TLE"]);
  printf("RE x %d \n", cnt["RE"]);
  return 0;
}

Measured memory_bytes: 6432
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

	int n;
	int d;
	int md;
	int inum;
	int sum;
	int cha;
	string s;
	string snum;
	vector<int> hyo[1000];

	cin>>n;

	for(int i=0;i<n;i++){
		cin>>s;
		d=0;
		md=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='[') d++,md=d;
			else if(s[i]==']') d--;
			else{
				snum=("");
				while(1){
					if(s[i]=='['||s[i]==']') break;
					snum+=s[i];
					i++;
				}
				i--;
				inum=0;
				for(int j=0;j<snum.size();j++) inum+=(snum[j]-'0')*pow(10.0,(double)snum.size()-1-j);
				hyo[d].push_back(inum);
			}
			if(d<=md-2){
				if(d==md-2) cha=2;
				else cha=1;
				sort(hyo[d+2].begin(),hyo[d+2].end());
				sum=0;
				for(int j=0;j<hyo[d+2].size()/2+1;j++){
					sum+=hyo[d+2][j]/cha;
					if(cha==2) sum++;
				}
				hyo[d+2].clear();
				hyo[d+1].push_back(sum);
			}
		}
		sum=0;
		for(int j=0;j<hyo[1].size()/2+1;j++){
			sum+=hyo[1][j];
		}
		cout<<sum<<endl;
		for(int j=0;j<1000;j++){
			if(!hyo[j].empty()) hyo[j].clear();
		}
	}
}

Measured memory_bytes: 1340
A,B,C,D = map(int,input().split(" "))
list = [0] * 101
for j in range(A,B):
    list[j] += 1
for j in range(C,D):
    list[j] += 1
#print(list)
count = 0
for i in range(101):
    if list[i] == 2:
        count += 1
print(count)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Integer> d = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            d.add(Integer.parseInt(sc.next()));
        }
        int answer = 0;
        for (int i = 0; i < (n - 1); i++) {
            for (int j = 1 + i; j < n; j++) {
                answer += d.get(i) * d.get(j);
            }
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 35752
n = int(input())
[t,a] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
ls = []
for i in range(len(h)):
  ls.append(abs(t - h[i]*0.006 - a))
ans = -1
cri = 10000000000
for i in range(len(ls)):
  if ls[i] < cri:
    ans = i+1
    cri = ls[i]
print(ans)

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

string S,T;
int main()
{
   	cin >> S;
   	cin >> T;
   	int total = 0;

  	for(int i=0;i<S.length();i++){
        if(S[i]!=T[i])
            total += 1;
  	}
  	cout << total <<endl;
}


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

int main()
{
	string S;
	int w;
	cin >> S >> w;

	string ans;
	for( int i = 0; i < S.size(); i++ ) {
		if( i % w == 0 ) {
			ans += S[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int cmp(const void *a,const void *b)
{
    return *(int *)b - *(int *)a;
}

int main()
{
    int num[100000]={};
    int i;
    long long max1,max2;
    int n;
    while (cin>>n)
    {
        memset(num,0,sizeof (num));
        max1=max2=0;
        for (i=0;i<n;i++)
        {
            cin>>num[i];
        }
        qsort(num,n,sizeof (num[0]),cmp);
        for (i=0;i<n-1;i++)
        {
            if (num[i]==num[i+1])
            {
                max1=num[i];
                i+=2;
                break;
            }
        }
        for (;i<n-1;i++)
        {
            if (num[i]==num[i+1])
            {
                max2=num[i];
                break;
            }
        }
        cout<<max1*max2<<endl;
    }
    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<stack>

using namespace std;



int main(){
	stack<int> s;
	int n;
	
	
	while(cin>>n){
		if(n==0){
			cout<<s.top()<<endl;
			s.pop();
		}else{
			s.push(n);
		}
	}
	
	return 0;
}

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

using LL = long long int;
LL MOD = 1e9 + 7;

class Solution {
    LL fact(LL N) {
        LL r = 1;
        for(LL i = 2; i <= N; ++ i) {
            r *= i;
            r %= MOD;
        }
        return r;
    }
public:
    int solve(int N, int M) {
        switch(abs(N - M)) {
            case 0:
                return fact(N) * fact(M) % MOD * 2 % MOD;
            case 1:
                return fact(N) * fact(M) % MOD;
            default:
                return 0;
        }
    }
};

int main() {
    Solution s;
    int N, M;

    while(cin >> N >> M) {
        cout << s.solve(N, M) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
    vs args(argv, argv+argc);
    string sample = make_sample(args, "sample-4");
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int N,H; cin>>N>>H;
    vi A(N),B(N); REP(i,N) cin>>A[i]>>B[i];

    sort(B.rbegin(), B.rend());
    sort(A.rbegin(), A.rend());
    int Amax = A[0];

    int cnt = 0;
    int hp = H;
    REP(i,N) {
        if (B[i] <= Amax) break;
        hp -= B[i];
        cnt += 1;
        if (hp <= 0) {
            cout << cnt << endl;
            return 0;
        }
    }

    cnt += (hp + Amax-1)/Amax;

    int ans = cnt;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, i = 1;
		n = sc.nextInt();
		
		for(i = 1; i <= n / i; ++i) {
			
		}
			
			System.out.println((i - 1) * (i - 1));
		
		sc.close();
	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+50,mod=1e9+7;
int n,m,a[N],f[N],s1[N],s2[N],J[N],ans,cnt,dat,sum;bool flag[N];
void add(int x){for(;x<=n;x+=x&-x)f[x]++;}
int ask(int x){int y=0;for(;x;x-=x&-x)y+=f[x];return y;}
int main(){
    scanf("%d",&n);J[0]=1;
    for(int i=1;i<=n;i++)J[i]=1ll*J[i-1]*i%mod;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),flag[a[i]]=1;
    for(int i=1;i<=n;i++)if(!flag[i])(sum+=i-1)%=mod;
    for(int i=1;i<=n;i++)s1[i]=s1[i-1]+!flag[i];
    for(int i=n;i;i--)s2[i]=s2[i+1]+!flag[i];m=s1[n];
    for(int i=1;i<=n;i++){
        int anss=0;
        if(a[i]){
            add(a[i]);
            anss=(anss+1ll*(a[i]-ask(a[i]))*J[m])%mod;
            if(m)anss=(anss-1ll*s1[a[i]]*cnt%mod*J[m-1])%mod;
            (dat+=s2[a[i]])%=mod;
        }
        else{
            anss=(anss+1ll*(sum-dat)*J[m-1])%mod;
            if(m>1)anss=(anss-1ll*m*(m-1)/2%mod*cnt%mod*J[m-2])%mod;
            cnt++;
        }
        ans=(ans+1ll*anss*J[n-i])%mod;
    }
    printf("%d\n",((ans+J[m])%mod+mod)%mod);
    return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N; cin >> N;
    int ct = 0;
    int four_ct = N/4;
    REP(i, four_ct+1) {
        if ( (N-i*4) %7 == 0) {
            print("Yes");
            return 0;
        }
    }
    print("No");


    
    return 0;
}

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

using namespace std;

int main(){
    int64_t n, k;
    cin >> n >> k;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());

    auto B = A;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end(), greater<int64_t>());

    vector<int64_t> N, P;
    for (const auto &a: A)
        (a >= 0 ? P : N).push_back(a);
    vector<int64_t> NR(N.size()), PR(P.size());
    copy(P.rbegin(), P.rend(), PR.begin());
    copy(N.rbegin(), N.rend(), NR.begin());

    auto count = [&](auto &A, auto &B, auto m, auto cmp){
        int64_t cnt = 0;  // mより小さい数が何個か
        int i = B.size() - 1;
        for (const auto &a : A){
            while (i >= 0 and m < B[i] * a){
                i--;
            }
            cnt += i + 1;
            if (i >= 0 and cmp(a, B[i]))
                cnt--;
        }
        return cnt;
    };

    auto check = [&](auto m){
        int64_t cnt = 0;  // mより小さい数が何個か
        cnt += count(P, P, m, [](auto &a, auto &b){return a <= b;});
        cnt += count(PR, N, m, [](auto &l, auto &r){return false;});
        cnt += count(PR, N, m, [](auto &l, auto &r){return false;});
        cnt += count(NR, NR, m, [](auto &a, auto &b){return a >= b;});

        return k <= cnt / 2;
    };

    const int64_t INF = 1e18 + 1;
    int64_t l = -INF, r = INF;

    while (r - l > 1){
        auto mid = (l + r) / 2;
        (check(mid) ? r : l) = mid;
    }

    cout << r << endl;
}

Measured memory_bytes: 6644
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll sosuu[107];
map<ll,ll> M;
ll c74,c2,c24,c4,c14;

int main() {
  ll N,C=0;
  cin >> N;
  Rep(i,1,N+1){
    ll M=i;
    Rep(j,2,sqrt(N)+1){
      while(M%j==0){
        sosuu[j]++;
        M/=j;
      }
    }
    if(M>1){
      sosuu[M]++;
    }
  }
  Rep(i,2,N+1){
    if(sosuu[i]>=74){
      c74++;
    }
    if(sosuu[i]>=2){
      c2++;
    }
    if(sosuu[i]>=24){
      c24++;
    }
    if(sosuu[i]>=4){
      c4++;
    }
    if(sosuu[i]>=14){
      c14++;
    }
  }
  C+=c74;
  C+=c24*(c2-1);
  C+=c14*(c4-1);
  C+=((c4*(c4-1))/2)*(c2-2);
  cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007
#define MOD2 998244353

using namespace std;
typedef long long int ll;

int main(void)
{
	fast;
	#ifndef ONLINE_JUDGE
	// freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
	#endif

	ll a, b, c; cin >> a >> b >> c;
	ll have = min(a, c);
	c -= have;
	a -= have;
	if (c)
	{
		ll x = min(c, b);
		have += 2*x;
		c -= x;
		b -= x;
	}

	if (b) have += b;
	if (c) ++have;

	cout << have;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    ll cnt[100] = {};
    cnt[0] = 2;
    cnt[1] = 1;
    int N;
    cin >> N;

    for (int i = 2; i <= N; ++i) {
        cnt[i] = cnt[i-1] + cnt[i-2];
    }

    cout << cnt[N] << endl;


    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<stack>
#include<sstream>
#include<complex>

#define pb push_back
#define clr clear()
#define sz size()
#define fs first
#define sc second

#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)−1;i>=0;i−−)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)−(b)) < EPS)
#define INIT(a) memset(a,0,sizeof(a))

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const D EPS = 1e-8;
const int INF = 1e8;
const D PI = acos(-1);

int par[10000]; //親ノート&#12441;
int r[10000]; //木の高さ

void init(int n){
  for(int i=0;i<n;i++){par[i] = i;r[i] = 0;}
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x==y)return;
  if(r[x] < r[y])par[x] = y;
  else par[y] = x;
  if(r[x] == r[y])r[x]++;
}

bool same(int x,int y){return find(x)==find(y);}

int v; //頂点数
int m;
int a,b,c;
//辺の定義。必要に応し&#12441;て削る
struct edge{
  int from,to,cost;
  bool operator<(const edge x)const{return cost>x.cost;}
};

vector<edge> G[10000];
void AddEdge(int s,int g,int p){
  G[s].pb((edge){s,g,p});
}

int Kruskal(){
  init(v);
  priority_queue<edge> q;
  rep(i,v)rep(j,G[i].sz)q.push(G[i][j]);

  int res = 0;
  while(q.size()){
    edge e = q.top(); q.pop();
    if(!same(e.from,e.to)){
      res += e.cost;
      unite(e.from,e.to);
    }
  }
  return res;
}

int main(){
  while(cin >> v,v){
    cin >> m;
    rep(i,v)G[i].clr;
    rep(i,m){
      scanf("%d,%d,%d",&a,&b,&c);
      AddEdge(a,b,c/100-1);
    }

    cout << Kruskal() <<  endl;
  }
    
}

Measured memory_bytes: 1716
#include<iostream>

using namespace std;
const long long int MOD=1e9+7;

int main(){
    long long int n, m, cntn=1, cntm=1;
    cin >> n >> m;
    for(int i=1;i<=n;i++)cntn =(cntn*i)%MOD;
    for(int i=1;i<=m;i++)cntm =(cntm*i)%MOD;

    if(n==m){
        cout << 2*cntn*cntm %MOD << endl;
    }
    else if(n-1==m || n+1==m){
        cout << cntn*cntm %MOD << endl;
    }
    else{
        cout << 0 << endl;
    }
}

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

typedef unsigned long long ull;

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();
    int k = len;
    char last = s[0];
    for(int i = 1; i < len; ++i) {
        if(s[i] != last) {
            k = min(k, max(i, len-i));
last = s[i];
        }
    }
    cout << k;
}


Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>

#define INF 1050000000
#define MOD 1000000007
#define LONGINF 1005000000000000000
using namespace std;

int main() {

	int n; cin >> n;
	int l, r;

	int ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> l >> r;
		ans += (r - l) + 1;
	}

	cout << ans << endl;




}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  if(a=="A"){
    cout << "T" << endl;
  }
  else if(a=="T"){
    cout << "A" << endl;
  }
  else if(a=="C"){
    cout << "G" << endl;
  }
  else{
    cout << "C" << endl;
  }
}

Measured memory_bytes: 256
//atcoder怎么看不了数据。。。测试一发标程
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=105;

int n,t[N];

int main()
{
    scanf("%d",&n);int mx=0;
    for (int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        t[x]++;mx=max(mx,x);
    }
    if (!(mx&1)&&t[mx/2]!=1||(mx&1)&&t[(mx+1)/2]>2) {puts("Impossible");return 0;}
    for (int i=(mx+1)/2+1;i<=mx;i++) if (t[i]<2) {puts("Impossible");return 0;}
    for (int i=1;i<(mx+1)/2;i++) if (t[i]) {puts("Impossible");return 0;}
    puts("Possible");
    return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int q = 1;
  int s = A;
  if(B > 1){
  for(int i = 0; i < 100; i++) {
    if(s < B) {
      s = s + (A - 1);
      q++;
    }
    else {
      break;
    }
  }
  cout << q << endl;
  }
  else{
    cout << "0" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;

int main()
{
    int N;  cin >> N;
    if(N == 1)  cout << "Hello World" << endl;
    if(N == 2){
        int A, B;   cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdlib>

using namespace std;

int main() {
	int a[5];
	int i,k,time,count;

	time = 0;
	count = 0;

	for (i = 0; i < 5; i++)
		a[i] = 0;

	cin >> a[0] >> a[1] >> a[2]>> a[3] >> a[4];

	for (i = 0; i < 5; i++){
		if (a[i] % 10 == 0 ) {
			time += a[i];
			a[i] = 0;
			count++;
		}
	}

	for (k = 9; 0 < k;k--) {
		for (i = 0; i < 5; i++) {
			if (a[i] % 10 == k) {
				count++;
				if (count < 5) {
					time = time + a[i] + (10 - k);
					a[i] = 0;
				}
				else
					time = time + a[i];
			}
		}
	}
	cout << time;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,i;
	int a[1000];
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	for(i = n-1;i >= 0;i--){
		if(i){
			printf("%d ",a[i]);
		}else{
			printf("%d",a[i]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans;
int main(){
    scanf(" %lld %lld",&n,&m);
    if(n==1 && m==1){
        ans=1;
    }
    else if((n==1 && m!=1) || (n!=1 && m==1)){
        ans=n*m-2;
    }
    else{
        n-=2;
        m-=2;
        ans=n*m;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 256
//一番近い素数までの合計距離

import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	boolean[] PrimeN = new boolean[1299710];//問題中の最大素数まで
	putN(PrimeN);

	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		solve(n, PrimeN);
	    }
	}
    }

    static void solve(int n, boolean[] PrimeN){
	if(PrimeN[n]) System.out.println("0");
	else{
	    int fn = n+1;
	    int bn = n-1;
	    while(!PrimeN[fn]) fn++;
	    while(!PrimeN[bn]) bn--;
	    System.out.println(fn-bn);
	}
    }

    static void putN(boolean[] p){
	Arrays.fill(p, true);
	p[0] = false;
	p[1] = false;
	for(int i=2; i<p.length; i++){
	    if(p[i]){
		for(int j=i+i; j<p.length; j+=i){
		    p[j] = false;
		}
	    }
	    //System.out.println(i+" "+p[i]);
	}
    }
}

Measured memory_bytes: 24328
#include <stdio.h>

#define N 100000

int partition(int *,int,int);
int h;
int main()
{
  int n,i,j,p,r,A[N],k;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);
  p = 0;
  r = n-1;

  k = partition(A,p,r);

  for(i=0;i<k;i++) printf("%d ",A[i]);
  printf("[%d] ",A[k]);
  for(j=k+1;j<n-1;j++) printf("%d ",A[j]);
  printf("%d\n",A[n-1]);

  return 0;
}

int partition(int *A,int p,int r)
{
  int j,x=A[r],i=p-1,k;

  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      k = A[j];
      A[j] = A[i];
      A[i] = k;
    }
  }
  k = A[i+1];
  A[i+1] = A[r];
  A[r] = k;
  return i + 1;
}
      
  

  



Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,b,c,d; cin>>a>>b>>c>>d;

    if((a+b) > (c+d)) {
        cout << "Left" << endl;
    }
    else if (a+b == c+d) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);
//桁数に注意 long long　にする

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int taka = 0;
  
  vector<int> p(n);
  
  rep(i,n) {
  cin >> p[i];
   if(taka<=p[i])ans++;
  taka = max(taka, p[i]);
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
/*AtCoder Beginner Contest 074 A-Bichrome Cells課題2_3 kento_titech*/
#include <stdio.h>
 
int main(void){
  int N,A;
  
  scanf("%d\n",&N);//N入力
  scanf("%d",&A);//A入力
  if((1<=N<=100)&&(0<=A<=(N*N))){ 
    printf("%d\n",N*N-A);//N*N-A出力
  }
  return 0;
 
}


Measured memory_bytes: 128
N,M=map(int,input().split())
AB=[]
for i in range(N):
  a,b=map(int,input().split())
  AB.append([a,b])
AB.sort()
ans=0
count=0
while(count<N):
  if AB[count][1]<=M:
    ans+=AB[count][0]*AB[count][1]
    M-=AB[count][1]
    count+=1
  else:
    ans+=AB[count][0]*M
    break
print(ans)

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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> A(n + 1);
  A.at(0) = 0;
  for (int i = 0; i < n ; i++){
    int x;
    cin >> x;
    A.at(i + 1) = A.at(i) + x;
  }
  
  int cnt = 0;
  
  for ( int i = 0; i < n + 1; i++){
    if( x >= A.at(i)){
      cnt++;
    }
  }
  
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;


int main()
{
    int d,g, p[11], c[11];
    cin >> d >> g;
    for(int i = 0; i < d; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int bit = 0; bit < (1<<d); bit++){
        int sum = 0,num = 0;
        for(int i = 0; i < d; i++){
            if(bit >> i & 1){
                sum += c[i] + p[i] * 100 * (i+1);
                num += p[i];
            }
        }
        if(sum >= g){
            ans = min(ans,num);
        }else{
            for(int i = d-1; i >= 0; --i){
                if(bit & (1<<i)){
                    continue;
                }
                for(int j = 0; j < p[i]; ++j){
                    if(sum >= g) break;
                    sum += 100 * (i+1);
                    num++;
                }
            }
        }
        ans = min(num,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256