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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

// ------------------------------------------------------------------------------------------

const int MOD = 1e9 + 7;
string K;
int D;

int dp[10010][2][110] = {0};

signed main() {
  cin >> K >> D;
  int n = K.size();

  dp[0][0][0] = 1;
  for (int digit = 0; digit < n; digit++) {
    for (int smaller : {0, 1}) {
      int lim = smaller == 1 ? 9 : K[digit] - '0';
      for (int num = 0; num <= lim; num++) {
        for (int modD = 0; modD < D; modD++) {
          dp[digit+1][smaller || num < lim][(modD + num) % D] += dp[digit][smaller][modD] % MOD;
        }
      }
    }
  }

  int ans = 0;
  for (int smaller : {0, 1}) {
    ans += dp[n][smaller][0] % MOD;
  }
  // cout << (ans-1) % MOD << endl;

  cout << (dp[n][0][0] + dp[n][1][0] - 1 + MOD) % MOD << endl;

  return 0;
}

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

#define int long long
#define w cout
#define e '\n'
#define sz(x) (int)x.size()
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.first >> p.second; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 + 10 , mod = 998244353;


signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n , m ;cin >> n >> m;
	if(n ==m ) cout << "Yes";
	else w << "No";
}



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

struct p{
    double x,y;
    double sqdist(p b){
        return (x-b.x)*(x-b.x) + (y-b.y)*(y-b.y);
    }
    void read(){
        cin >> x >> y;
    }
    p operator -(p b){
        return {x - b.x , y - b.y};
    }
    double operator *(p b){
        return x*b.y - y*b.x;
    }
};
vector<p> v(51);
int n;

double findCircle(double x1, double y1, double x2, double y2, double x3, double y3){ 
    double x12 = x1 - x2;
    double x13 = x1 - x3;
    double y12 = y1 - y2;
    double y13 = y1 - y3;
    double y31 = y3 - y1;
    double y21 = y2 - y1;
    double x31 = x3 - x1;
    double x21 = x2 - x1;
    double sx13 = pow(x1, 2) - pow(x3, 2);
    double sy13 = pow(y1, 2) - pow(y3, 2);
    double sx21 = pow(x2, 2) - pow(x1, 2);
    double sy21 = pow(y2, 2) - pow(y1, 2);
    double f = ((sx13) * (x12)
             + (sy13) * (x12)
             + (sx21) * (x13)
             + (sy21) * (x13))
            / (2 * ((y31) * (x12) - (y21) * (x13)));
    double g = ((sx13) * (y12)
             + (sy13) * (y12)
             + (sx21) * (y13)
             + (sy21) * (y13))
            / (2 * ((x31) * (y12) - (x21) * (y13)));
    double c = -pow(x1, 2) - pow(y1, 2) - 2 * g * x1 - 2 * f * y1;
    double h = -g;
    double k = -f;
    double sqr_of_r = h * h + k * k - c;
    double r = sqrt(sqr_of_r);
    for(int i = 0 ; i < n ; i += 1){
        if(r - sqrt((h - v[i].x)*(h-v[i].x) + (k-v[i].y)*(k-v[i].y)) >= -0.0000000000001){
            continue;
        }
        return 1000000000.0;
    }
    return r;
}

double check(double x1 , double y1 , double x2 , double y2){
    double h,k,r;
    r = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))/2;
    h = x1 + (x2-x1)/2;
    k = y1 + (y2-y1)/2;
    for(int i = 0 ; i < n ; i += 1){
        if(r - sqrt((h - v[i].x)*(h-v[i].x) + (k-v[i].y)*(k-v[i].y)) >= -0.0000000000001){
            continue;
        }
        return 1000000000.0;
    }
    return r;
}

int main(){
    cin >> n;
    for(int i = 0 ; i < n ; i += 1){
        v[i].read();
    }
    double mini = 1000000.0;
    for(int i = 0 ; i < n-2 ; i += 1){
        for(int j = i+1 ; j < n-1 ; j += 1){
            for(int k = j+1 ; k < n ; k += 1){
                mini = min(mini,findCircle(v[i].x,v[i].y,v[j].x,v[j].y,v[k].x,v[k].y));
            }
        }
    }
    for(int i = 0 ; i < n-1 ; i += 1){
        for(int j = i+1 ; j < n ; j += 1){
            mini = min(mini , check(v[i].x,v[i].y,v[j].x,v[j].y));
        }
    }
    cout << setprecision(6) << fixed;
    cout << mini << endl;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> xx,yy;
    vector<bool> b;
    map<int,set<int>> ms0,ms1,ms2,ms3,u1,v1,u2,v2;
    for (int i = 0;i < n;++i) {
        int x,y;char c;
        cin >> x >> y >> c;
        if (c == 'U') {
            ms0[x].insert(y);
            xx.push_back(x);
            yy.push_back(y);
            b.push_back(true);
        } else if (c == 'D') {
            ms1[x].insert(y);
            xx.push_back(x);
            yy.push_back(y);
            b.push_back(false);
        }
        else if (c == 'R') {
            ms2[y].insert(x);
            u1[x+y].insert(x);
            v1[x-y].insert(x);
        } else {
            ms3[y].insert(x);
            u2[x+y].insert(x);
            v2[x-y].insert(x);
        }
    }
    bool ok = true;
    int ans = 1e9;
    for (auto& it : ms0) {
        auto& st0 = it.second;
        auto& st1 = ms1[it.first];
        auto itr = st0.begin();
        while (st1.lower_bound(*itr) != st1.end()) {
            ans = min(ans,(*st1.lower_bound(*itr)-*itr)*5);
            itr++;
            if (itr == st0.end()) break;
        }
    }
    for (auto& it : ms2) {
        auto& st0 = it.second;
        auto& st1 = ms3[it.first];
        auto itr = st0.begin();
        while (st1.lower_bound(*itr) != st1.end()) {
            ans = min(ans,(*st1.lower_bound(*itr)-*itr)*5);
            itr++;
            if (itr == st0.end()) break;
        }
    }
    int m = xx.size();
    for (int i = 0;i < m;++i) {
        if (b[i]) {
            auto& st1 = u1[xx[i]+yy[i]];
            if (st1.size() > 0 && st1.lower_bound(xx[i]) != st1.begin()) ans = min(ans,(xx[i]-*prev(st1.lower_bound(xx[i])))*10);
            auto& st2 = v2[xx[i]-yy[i]];
            if (st2.size() > 0 && st2.lower_bound(xx[i]) != st2.end()) ans = min(ans,(*st2.lower_bound(xx[i])-xx[i])*10);
        } else {
            auto& st1 = v1[xx[i]-yy[i]];
            if (st1.size() > 0 && st1.lower_bound(xx[i]) != st1.begin()) ans = min(ans,(xx[i]-*prev(st1.lower_bound(xx[i])))*10);
            auto& st2 = u2[xx[i]+yy[i]];
            if (st2.size() > 0 && st2.lower_bound(xx[i]) != st2.end()) ans = min(ans,(*st2.lower_bound(xx[i])-xx[i])*10);
        }
    }
    if (ans < 1e9) cout << ans << endl;
    else cout << "SAFE" << endl;
}

Measured memory_bytes: 77496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a<b)
        swap(a,b);
    if(a<c)
        swap(a,c);
    printf("%d\n",a*10+b+c);
    return 0;
}


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

using namespace std;

int par[100005];

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

int ffind(int x) {
  return par[x] = (par[x] == x ? x : ffind(par[x]));
}

bool same(int a, int b) {
  if (ffind(a) == ffind(b)) return true;
  return false;
}

void unite(int x, int y) {
  if (same(x, y)) return ;
  int xx = ffind(x), yy = ffind(y);
  par[xx] = yy;
  return ;
}

int main() {
  int n, m;
  cin >> n >> m;
  init(n);
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    unite(a, b);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (par[i] == i) ans++;
  }
  cout << ans - 1 << endl;
  return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
namespace ztd{
    using namespace std;
    #define reg register
    #define ms(a) memset(a,0,sizeof(a))
    #define count(x) __builtin_popcountll(x)
    #define smallest_one(x) __builtin_ffsll(x)
    typedef long long ll;
    typedef unsigned long long ull;
    typedef unsigned int uint;
    typedef double db;
    //basic I/O
    template<typename T> inline T read(T& t) {//fast read
        t=0;short f=1;char ch=getchar();double d = 0.1;
        while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
        while (ch>='0'&&ch<='9') t=t*10+ch-'0',ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t*=f;
        return t;
    }
    bool is_prime(ll x){
        for(ll i = 2; i*i <= x; ++i) if(!(x%i)) return 0;
        return x >= 2;
    }
    ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

    void exgcd(int a, int b, int &x, int &y){
        if(!b) {x = 1, y = 0; return;}
        exgcd(b,a%b,x,y);
        int p = x; x = y; y = p-a/b*y;
     }
    inline ll ksm(ll x, ll y, ll mod){
        ll ret = 1;
        while(y){if(y & 1) ret = ret * x % mod; y >>= 1; x = x*x%mod;}
        return ret;
    }
    inline ll inv(ll x, ll mod){return ksm(x,mod-2,mod);}
}
using namespace ztd;
const int maxn = 2e5+7;
ll n, d, a, b, ans;
signed main(){
    read(n); read(d);
    for(int i = 1; i <= n; ++i){
        read(a); read(b);
        if(d*d >= a*a+b*b){
        	++ans;
//        	cout << i << endl;
        } 
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main(){
    int m,f,r;
while(true){
    cin>>m>>f>>r;
    if(m==f && f==r && r==-1){
        break;
    }
    if(m==-1 || f==-1){
        cout<<"F"<<endl;
    }
    else if(m+f>=80){
        cout<<"A"<<endl;
    }
    else if(m+f>=65){
        cout<<"B"<<endl;
    }
    else if(m+f>=50){
        cout<<"C"<<endl;
    }
    else if(m+f>=30){
        if(r>=50){
            cout<<"C"<<endl;
        }
        else {
            cout<<"D"<<endl;
        }
    }
    else {
        cout<<"F"<<endl;
    }
}
}


Measured memory_bytes: 3084
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    if(Math.abs(n - m) > 1){
      System.out.println(0);
    }else if(n == m){
      long tmp1 = 1, tmp2 = 1;
      for(int i = 2; i <= n; i++){
        tmp1 = (i * tmp1) % 1000000007;
      }
      for(int i = 2; i <= m; i++){
        tmp2 = (i * tmp2) % 1000000007;
      }
      long ans = (tmp1 * tmp2 * 2) % 1000000007;
      System.out.println(ans);
    }else{
      long tmp1 = 1, tmp2 = 1;
      for(int i = 2; i <= n; i++){
        tmp1 = (i * tmp1) % 1000000007;
      }
      for(int i = 2; i <= m; i++){
        tmp2 = (i * tmp2) % 1000000007;
      }
      long ans = (tmp1 * tmp2) % 1000000007;
      System.out.println(ans);
    }
    
  }
}


Measured memory_bytes: 24916
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int a,b,c,cnt=0; cin>>a>>b>>c;
    if(a==b) cnt++;
    if(a==c) cnt++;
    if(c==b) cnt++;
    cout<<(cnt==1 ? "Yes" : "No");
}

Measured memory_bytes: 256
S = input()
N = len(S)

def is_palindrome(s):
    n = len(s)
    i, j = 0, n-1
    while i < j:
        if s[i] != s[j]:
            return False
        else:
            i += 1
            j -= 1
    return True

if is_palindrome(S) and is_palindrome(S[:(N-1)//2]) and is_palindrome(S[(N+1)//2:]):
    print('Yes')
else:
    print('No')

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


int main() {

    int a, b, c;
    cin >> a >> b >> c;
    cout << min({a+b, b+c, c+a}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <complex>
#include <math.h>
#include <cstdio>
#include <iomanip>

using namespace std;

int main(void)
{
	double a, b, H, M, G, J,V, hen, sum;
	double si, co;
	double pi = 3.14159265358979, ka=360;
	string K;
	cin >> a >> b >> H >> M;
	vector<int> vec;

	G = (ka / (12 * 60) )* ((H * 60) + M);
	//cout << G << endl;
	J = ka / 60 * M;
	V = abs(G - J);

	

	hen = pi / 180;
	//cout << V << endl;
	V = hen * V;

	//cout << V << endl;

	si = a * sin(V);
	co = b - a * cos(V);

	sum = sqrt(si * si + co * co);

	cout << fixed << setprecision(20) <<sum << endl;

}

Measured memory_bytes: 4100
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String ans = "NG";
    for(int i = a; i <= b; i++) {
      if((i % k) == 0) {
        ans = "OK";
        break;
      }
    }
    System.out.println(ans);
  }
}

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

int main() {
    int A, B, K;

    cin >> A >> B >> K;

    vector<int> vec;
    for (int i = 1; i <= 100; i++) {
        if (A%i == 0 && B%i == 0) {
            vec.push_back(i);
        }
    }
    sort(vec.begin(), vec.end(), greater<int>());

    cout << vec[K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
 
#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007
 
TLong getSum(TLong n,TLong i,TLong sum)
{
	if(n / i == 0)	return (n + sum);
	return getSum(n / i, 10, sum + n % i) + getSum(n, i * 10, sum);
}
 
int main(int argc, char const *argv[])
{
	TLong n;
	scanf("%lld",&n);
	printf("%lld", getSum(n, 10, 0));
	return 0;
 }

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


int main(){
  int n,m;
  cin >> n >> m;
  int sum = 0;
  for(int i = 0;i < m;i ++){
    int x;
    cin >> x;
    sum += x;
  }
  if(sum > n){
    cout << -1 << endl;
  }
  else{
    cout << n - sum << endl;
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    ll N,kill;
    cin >> N;
    for(ll i = sqrt(N);i>0;i--){
        if(N%i==0){
            kill = i;
            break;
        }
    }
    cout <<kill + (N/kill) - 2<< "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    ans=1
    for x in a:
        if ans *x >10**18:
            print(-1)
            exit(0)
        ans*=x
    print(ans)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

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

int main() {
  int N;cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  
  rep(i,N){
    cin >> A[i];
  }
  
  rep(j,N){
    B[A[j]-1] = j+1;
  }
  
  rep(k,N){
    
    if(k == N-1){
      cout << B[k] << endl;
    }
    
    else {
    cout << B[k] << " ";
  }
  } 
}

Measured memory_bytes: 1536
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (map.get(a) == null) {
				map.put(a, 1);
			} else {
				map.put(a, map.get(a) + 1);
			}
		}
		
		int sum = 0;
		for (int key : map.keySet()) {
			int v = map.get(key);
			sum += v >= key ? v - key : v;
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 61988
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

// 全パターンのvectorを返す
vector<vector<int>> get_all_combinations(int n){
    vector<vector<int>> ret;
    for(int bit = 0; bit < (1 << n); ++bit){
        vector<int> S;
        for(int i = 0; i < n; ++i){
            if(bit & (1 << i)) {
                S.push_back(i + 1);
            }
        }
        ret.push_back(S);
    }
    return ret;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> grid(M);
    rep(i, M){
        int k;
        cin >> k;
        rep(j, k){
            int ipt;
            cin >> ipt;
            grid[i].push_back(ipt);
        }
    }
    vector<int> p(M);
    rep(i, M) cin >> p[i];
    vector<vector<int>> bit_all = get_all_combinations(N);

    int ans = 0;
    for(int i = 0; i < bit_all.size(); i++){
        bool flag = true;
        for(int j = 0; j < M; j++){
            int cnt = 0;
            for(int k = 0; k < grid[j].size(); k++){
                for(int m = 0; m < bit_all[i].size(); m++){
                    if(grid[j][k] == bit_all[i][m]){
                        cnt++;
                    }
                }
            }
            if(cnt % 2 != p[j]){
                flag = false;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Node{
	Integer data;
	Node left;
	Node right;
	Node(Integer data){
		left = null;
		right = null;
		this.data = data;
	}
}
public class Main{
	Scanner sc = new Scanner(System.in);
	StringBuilder output = new StringBuilder();
	private static Node root;
	int m;
	String order;
	int[] T;
	int number;
	public Main() {
		root = null;
	}
	public Node insert(Integer key) {
		Node p = root;
		Node parent = null;
		boolean isLeftChild = false;
		while(p != null) {
			int result = key.compareTo(p.data);
			if(result == 0) {
				return null;
			}else if(result < 0) {
				parent = p;
				isLeftChild = true;
				p = p.left;
			}else {
				parent = p;
				isLeftChild = false;
				p = p.right;
			}
		}
		Node newNode = new Node(key);
		if(parent == null) {
			root = newNode;
		}else if(isLeftChild) {
			parent.left = newNode;
		}else {
			parent.right = newNode;
		}
		return newNode;
	}
	
	//二分探索木からkeyをもつ節を探索するメソッド
	//Javaプログラマのためのアルゴリズムとデータ構造 p.224参照
	public Node search(Integer key) {
		//まず根に注目する
		Node p = root;
		
		//注目している節がある限り繰り返し処理を行う
		while(p != null) {
			
			//注目している節とkeyを比較する
			int result = key.compareTo(p.data);
			
			//節とkeyが等しい
			if(result == 0) {
				return p;
				
			//keyの方が小さいときは左分木に進む
			}else if(result < 0) {
				p = p.left;
				
			//keyの方が大きいときは右分木に進む
			}else {
				p = p.right;
			}
		}
		//探索に失敗したらnullを返す
		return null;
	}
	public void input() {
		m = sc.nextInt();
		T = new int[m];
		for(int i=0; i<m; i++) {
			order = sc.next();
			if(order.equals("print")) {
				inorder(root);
				output.append("\n");
				preorder(root);
				output.append("\n");
			}else if(order.equals("find")) {
				number = sc.nextInt();
				if(search(number) == null) { output.append("no\n"); }
				else { output.append("yes\n"); }
			}else {
				T[i] = sc.nextInt();
				insert(T[i]);
			}
		}
		System.out.print( output.toString() );
	}
	public void inorder(Node p) {
		if(p == null) {
			return;
		}else {
			inorder(p.left);
			output.append(" "+p.data);
			inorder(p.right);
		}
	}
	public void preorder(Node p) {
		if(p == null) {
			return;
		}else {
			output.append(" "+p.data);
			preorder(p.left);
			preorder(p.right);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
	}
}


Measured memory_bytes: 335912
from bisect import bisect_left
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N == 2:
    print(A[1], A[0])
    exit()
a = A[-1]
k = bisect_left(A, a/2)
x = a/2-A[k-1]
y = A[k]-a/2
if x <= y:
    b = A[k-1]
else:
    b = A[k]
print(a, b)


Measured memory_bytes: 84428
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
l = 3010
def main():
    s = input().strip()
    t = input().strip()
    dp = [[0] * l for i in range(l)]
    rdp = [[0] * l for i in range(l)]
    for i in range(len(s)):
        for j in range(len(t)):
            if s[i] == t[j]:
                if i == 0 or j == 0:
                    dp[i][j] = 1
                else:
                    dp[i][j] = dp[i-1][j-1] + 1
                rdp[i][j] = (i-1, j-1)
            else:
                if dp[i-1][j] < dp[i][j-1]:
                    dp[i][j] = dp[i][j-1]
                    rdp[i][j] = (i, j-1)
                else:
                    dp[i][j] = dp[i-1][j]
                    rdp[i][j] = (i-1, j)

    # print(dp[len(s)-1][len(t)-1])
    ans = ''
    p, q = len(s)-1, len(t)-1
    while True:
        if p == -1 or q == -1:
            break
        nextp, nextq = rdp[p][q]
        if nextp != p and nextq != q:
            ans += s[p]
        p = nextp
        q = nextq

    print(''.join(reversed(ans)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 457776
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<ll,int>
#define vi vector<ll>
#define vvi vector<vector<double>>
#define vpii vector<pii>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
 
    int t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int x;
        vi a;
        Fr(i,0,n-1){
            cin>>x;
            a.pb(x);
        }
        vi b(n,0);
        Fr(i,1,n-1){
            if(i==1){
                b[i]=abs(a[i]-a[i-1]);
            }
            else{
                b[i]=min(abs(a[i]-a[i-2])+b[i-2],abs(a[i]-a[i-1])+b[i-1]);
            }
        }
        cout<<b[n-1]<<endl;
    }
    return 0;
} 

Measured memory_bytes: 1908
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a1 = sc.nextInt();
    int a2 = sc.nextInt();
    if ((a1>9)||(a2>9)){
      System.out.println(-1);
    }else{
    System.out.println(a1*a2);
    }
  }    
}

Measured memory_bytes: 23380
ans = []
while True:
  l = input().split()
  a, op, b = int(l[0]), str(l[1]), int(l[2])
  if op == '+':
    ans.append(a + b)
  elif op == '-':
    ans.append(a - b)
  elif op == '*':
    ans.append(a * b)
  elif op == '/':
    ans.append(int(a / b))
  elif op == '?':
    break
for i in range(0, len(ans)):
  print(ans[i])


Measured memory_bytes: 5592
#include<stdio.h>

int merge(int a[],int temp[],int left,int middle,int right){
    int count = 0;
    int i = left, j = middle ; 
    for(int k = left; k <=right; k++){
        count++;
       //left exists and (right null or <)
       if(i<middle&&(j>right||a[i]<a[j])){
            temp[k] = a[i++];
       }else {
             temp[k]= a[j++];
        }
    }
    //copy back
    for(int k = left; k<=right; k++){
        a[k] = temp[k];
    }
    return count;
 
}
//divide until 1 and then merge
//return count
int divide(int a[],int temp[], int left, int right) {
int count = 0;
     //case
    if(left>=right) return count;//can not be the same
    
    int middle = (left+right)/2;
    //divide
    count = divide(a, temp, left, middle);//left count
    count += divide(a, temp, middle+1, right);//left count

    count = count + merge(a, temp, left, middle+1, right);
     return count;
}

//merge sort
int main(){
   int n = 0;
   scanf("%d", &n);
   int a[n+1];
   int count = 0;
   int temp[n+1];
   for(int i = 0; i<n; i++){
      scanf("%d",&a[i]);
   }
   count = divide(a, temp, 0, n-1);
int i = 0;
   for(i = 0; i<n-1; i++){
      printf("%d ",a[i]);
   }
   printf("%d\n",a[i]);
   printf("%d\n",count);
   
   return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    string s;
    stringstream ss;

    cin >> s ;

    ss << s[0]; 
    ss << s.size()-2;
    ss << s[s.size()-1];

    string ans = ss.str();

    cout << ans << endl;


}

    


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

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

int main(){
  long h,w,n;
  cin >> h >> w >> n;
  set<pll> black;
  set<pll> searched;
  queue<pll> que;
  rep(i,n){
    long a,b;
    cin >> a >> b;
    black.insert(pll(a,b));
    rep(i,9){
      long na = a + dx[i];
      long nb = b + dy[i];
      if(na <= 1 || nb <= 1 || na >= h || nb >= w) continue;
      que.push(pll(na,nb));
    }
  }
  vector<long> ans(10,0);
  ans.at(0) = (h-2)*(w-2);
  while(que.size()){
    pll P = que.front();
    que.pop();
    if(searched.count(P)) continue;
    searched.insert(P);
    int cnt = 0;
    rep(i,9){
      long x = P.first + dx[i];
      long y = P.second + dy[i];
      if(black.count(pll(x,y))) cnt++;
    }
    ans.at(0)--;
    ans.at(cnt)++;
  }
  rep(i,10) cout << ans.at(i) << endl;
}


Measured memory_bytes: 63412
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define N 102
char board[N][N];
int hang[N],lie[N];
int h,w;
/*
void cut(){
	int i,j,cnt;
	for( i=0;i<h;i++ )
	{
		cnt=0;
		for( j=0;j<w;j++ ){  //一行都是点 
			if( board[i][j]=='.' )
				cnt++;
			else
				break;
		}
		if( cnt==w )  //一行都是点就删除 
		{
			for( j=0;j<w;j++ )
				vis[i][j]=0;
		}
	}
	for( i=0;i<w;i++ ){
		cnt=0;
		for( j=0;j<h;j++ ){
			if( board[j][i]=='.' )
				cnt++;
			else
				break;
		}
		if( cnt==h )  //一列都是点
		{
			for( j=0;j<h;j++ )
				vis[j][i]=0;
		} 
	}
} */
int main() {
	int i,j;
	cin>>h>>w;
		int flag1;
		for( i=0;i<w;i++ )
			lie[i]=0;
		for( i=0;i<h;i++ ){
			flag1=0;
			for( j=0;j<w;j++ ){
				cin>>board[i][j];
				if( board[i][j]=='#' )  //这行这列有#,不要删除 
				{
					hang[i]=1;
					lie[j]=1;
					flag1=1;
				}
			}
			if( !flag1 )
				hang[i]=0;
		}
		int flag;
		for( i=0;i<h;i++ )
		{
			flag=0;
			for( j=0;j<w;j++ )
			{
				if( hang[i] && lie[j] )
				{
					cout<<board[i][j];
					flag=1;
				}
			}
			if( flag )
				cout<<endl;
		}
	return 0;
	}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;


int main()
{
  int x, k;
  scanf("%d %d", &x, &k);
  
  if (x * 500 >= k)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
map<int,int> M;
char s[N];
int main(){
	scanf("%s",s+1);
	int n = strlen(s+1);
	int tmp = 0;
	for(int i =1;i<=n;i++){
		tmp^=1<<(s[i]-'a');
	}
	//cout<<tmp<<endl;
	if(tmp==0){
		puts("1");
		return 0;
	}
	tmp = 0;
	M[0] = 0;
	int tmp2,cnt;
	for(int i =1;i<=n;i++){
		tmp^=1<<(s[i]-'a');
		tmp2 = 1e9;
		cnt = 0;
		for(int j = 0;j<26;j++) {
		
			if(M.count(tmp^(1<<j)))
				tmp2 = min(tmp2,M[tmp^(1<<j)]+1);
			if(tmp>>j&1) cnt++;
		}
		if(cnt==1) tmp2 = 1;
		if(M.count(tmp)) M[tmp] = min(M[tmp],tmp2);
		else M[tmp] = tmp2;
	}
	printf("%d\n",M[tmp]);
	return 0;
} 

Measured memory_bytes: 9856
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;





int main()
{
	int a, b,c;
	while (cin >> a) {
		cin >> b;
		c = log10(a + b)+1;
		cout << c << endl;
	}

		





}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
using Int = long long;


template<typename T> 
struct BIT{
  Int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(Int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(Int i){
    T s=0;
    for(Int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(Int i,T a){
    if(i==0) return;
    for(Int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  Int lower_bound(Int w){
    if(w<=0) return 0;
    Int x=0,r=1;
    while(r<n) r<<=1;
    for(Int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
	w-=bit[x+k];
	x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(Int i){
    return sum(i+1);
  }
  void add0(Int i,T a){
    add(i+1,a);
  }
};

signed main(){
  string s;
  cin>>s;
  Int n=s.size();
  {
    vector<Int> c(26,0);
    for(Int i=0;i<n;i++) c[s[i]-'a']++;
    Int x=0;
    for(Int i=0;i<26;i++) if(c[i]&1) x++;
    if(x>1){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<deque<Int> > x(26);
  for(Int i=0;i<n;i++) x[s[i]-'a'].push_back(i);


  BIT<Int> bit(n+1000,0);
  
  Int ans=0;
  Int cnt=0,pos=-1;
  vector<Int> used(n,0);
  for(Int i=0;i<n;i++){
    if(used[i]) continue;
    Int c=s[i]-'a';
    if(x[c].size()==1u){
      pos=cnt++;
      bit.add0(i,1);
      continue;
    }
    Int a=x[c].front(),b=x[c].back();
    assert(a==i);
    x[c].pop_front();x[c].pop_back();
    used[b]=1;
    //cout<<n-(cnt+1)<<" "<<(b-bit.sum0(b))<<endl;
    ans+=(n-(cnt+1))-(b-bit.sum0(b));
    bit.add0(b,1);
    cnt++;
  }
  //cout<<pos<<endl;
  if(~pos) ans+=(n/2-pos);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

template<int MOD>
struct Modular {
  int value;
  Modular(const Modular& k) : value(k.value) {}
 
  template<typename V>
  Modular(const V& v) : value(v % MOD) {
    if (value < 0) {
      value += MOD;
    }
  }
  
  Modular() : Modular(0) {}
 
  Modular& operator+=(Modular const& b) { value += b.value; if (value >= MOD) value -= MOD; return *this; } 
  Modular& operator-=(Modular const& b) { value -= b.value; if (value < 0) value += MOD; return *this; }
  Modular& operator*=(Modular const& b) { value = (long long)value * b.value % MOD; return *this; }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { return *this += 1; }
  Modular operator--(int) { return *this -= 1; }

  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) { return os << a.value; }
  friend bool operator==(Modular const& a, Modular const& b) { return a.value == b.value; }
  friend bool operator!=(Modular const& a, Modular const& b) { return a.value != b.value; }
};
 
template <int T, typename V>
Modular<T> mexp(Modular<T> a, V e) {
  if (a == 0) return e == 0 ? 1 : 0; 
  Modular<T> res = 1; 
  while (e) { 
    if (e & 1) 
      res *= a; 
    a *= a; 
    e >>= 1; 
  }
  return res;
}

const int N = 3010;

using Mint = Modular<998244353>;

Mint dp[N][N][2];

void Run() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b][0] = 1;
  for (int i = a; i <= c; ++i) {
    for (int j = b; j <= d; ++j) {
      dp[i][j][1] += i * dp[i][j - 1][1];
      dp[i][j][1] += dp[i][j - 1][0];
      if (i > a) {
        dp[i][j][0] += j * dp[i - 1][j][1];
        dp[i][j][0] += j * dp[i - 1][j][0]; 
      } else {
        dp[i][j][0] += (a - 1) * dp[i][j - 1][0];
        if (j == b - 1) ++dp[i][j][0];
      }
    }
  }
  cout << dp[c][d][0] + dp[c][d][1] << '\n';
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}

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

using namespace std;

#define mod 1000000007
#define int int64_t
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"

const int maxn=2e5+5;
int ar[maxn];

void solve()
{
    int n;
    cin>>n;
    int sum=0,ans=0;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    for(int i=0;i<n;i++)
        sum=(sum+ar[i])%mod;
    for(int i=0;i<n-1;i++)
    {
        sum=(sum-ar[i]+mod)%mod;
        ans=(ans+(ar[i]%mod*sum))%mod;
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 5180
import math
N = int(input())
List = list(map(int,input().split()))
L=[0]*N
R=[0]*N
for i in range(1,N):
  L[i] = math.gcd(L[i-1],List[i-1])
  R[-i-1] = math.gcd(R[-i],List[-i])
ans = 0
for i in range(N):
  ans = max(ans,math.gcd(L[i],R[i]))
print(ans)

Measured memory_bytes: 20732
# include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string S;
	char b;
	int len = 0;
	int maxlen = 0;
	cin >> S;

	for (int i = 0; i < S.size(); ++i)
	{
		b = S.at(i);
		if (b == 'A' || b == 'T' || b == 'C' || b == 'G')
		{
			++len;
		}
		else
		{
			if (len > maxlen)
			{
				maxlen = len;
			}
			len = 0;
		}
	}
	if (len > maxlen)
	{
		maxlen = len;
	}
	cout << maxlen << endl;
}


Measured memory_bytes: 256
s = input()
t = input()

ans = 10004
cnt = 0
for i in range(len(s) - len(t) + 1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 9108
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	final int MAX = 10000000;

	boolean[] prime = new boolean[MAX + 10];

	void run() {
		Scanner sc = new Scanner(System.in);

		Arrays.fill(prime, true);

		//エラトステネスの篩
		prime[0] = prime[1] = false;
		for (int i = 2; i * i < MAX + 10; i++) {
			if (prime[i]) {
				for (int j = i + i; j < MAX + 10; j += i) {
					prime[j] = false;
				}
			}
		}

		while (true) {
			int n = sc.nextInt();
			int max = 0;

			if (n == 0) {
				break;
			}

			for (int i = n; i >= 8; i--) {
				if (prime[i] && prime[i - 2] && prime[i - 6] && prime[i - 8]) {
					max = i;
					break;
				}
			}
			System.out.println(max);

		}

	}

	public static void main(String[] args) {
		new Main().run();
	}

}

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

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

using namespace std;

int main(){
	int h,w; cin>>h>>w;
	string B[100];
	rep(i,h) cin>>B[i];

	bool fr[100]={},fc[100]={};
	rep(i,h){
		fr[i]=true;
		rep(j,w) if(B[i][j]=='#') fr[i]=false;
	}
	rep(j,w){
		fc[j]=true;
		rep(i,h) if(B[i][j]=='#') fc[j]=false;
	}

	rep(i,h) if(!fr[i]) {
		rep(j,w) if(!fc[j]) cout<<B[i][j];
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,k;
vector<int> G[100010];

int dfs(int d,int v,int par){
	int ret = 1,tmp = k - 1 - !!d;
	for(int to : G[v]){
		if(to == par) continue;
		ret = ret * tmp % MOD * dfs(d + 1,to,v) % MOD;
		tmp--;
	}
	return ret;
}

signed main(){
	cin >> n >> k;
	for(int i = 0;i < n - 1;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cout << dfs(0,0,0) * k % MOD << endl;
}

Measured memory_bytes: 11520
#include <stdio.h>

int main(void) {
	int a, b, c, cnt;
	
	scanf("%d%d%d", &a, &b, &c);
	
	if(a <= b){
	    cnt = 0;
	    //aからbまでの間にcの約数がいくつあるかを数える
	    for(; a <= b; a++) {
	        //aがcの約数だったらカウントする
	        if(c % a == 0) {
	             cnt++;
	        }
	    }
	    
	    printf("%d\n", cnt);
	}
	return 0;
}


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

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

  while( (n!=0)||(x!=0) ){
  int count = 0;  
  for(int i = 1; i<=n-2;i++ ){
      for(int j= i+1;j<=n-1;j++){
        for(int k= j+1;k<=n;k++){
          if(i+j+k == x) count++;
        }
      }
    }
    cout << count << endl;
    cin >> n >> x;
  }




}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1e9+7

vll prime_factrize(ll n){
    vll prime_factrize_ret;
    ll temp=n;
    for(ll i=2;i*i<=n;i++){
        while(temp%i==0){
            prime_factrize_ret.push_back(i);
            temp/=i;
        }
    }
    if(temp!=1) prime_factrize_ret.push_back(temp);
    return prime_factrize_ret;
}

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

ll mod_inv(ll n, ll mod){
    return fast_pow(n,mod-2,mod);
}

ll comb(ll n, ll r, ll mod){
    ll temp=1;
    for(int i=r+1;i<=n;i++){
        temp=(temp*i)%mod;
    }
    ll temp2=1;
    for(int i=2;i<=n-r;i++){
        temp2=(temp2*i)%mod;
    }
    return temp*mod_inv(temp2,mod)%mod;
}

int main(){
    int x,y;
    cin >> x >> y;
    int n,m;
    n=(2*x-y)/3;
    m=(2*y-x)/3;
    if(n<0||m<0||(x+y)%3!=0){
        cout << "0" << endl;
        return 0;
    }    
    cout << comb(n+m,n,MOD) << endl;    
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    int a,b,ans;
    cin>>a>>b;
    bool flag = false;
    rep(i,10000){
        if(int(i * 0.08) == a && int(i * 0.1) == b){
            flag = true;
            ans = i;
            break;
        }
    }
    if(flag)cout<<ans<<endl;
    else cout<<-1<<endl;
}

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

int main(){
  int n, m;
  int64_t count = 0;
  cin >> n >> m;
  std::vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < m; i++) {
    count += a.at(i);
  }
  if(count <= n){
    cout << n - count << endl;
  }
  else{
    std::cout << "-1" << '\n';
  }
  return 0;
}




Measured memory_bytes: 3672
/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

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

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 200004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);


using namespace std;

vector<int> graph[maxn];
int ans[maxn],vis[maxn]={0};
    
void dfs(int node,int parent,int depth){
    vis[node]=1;
    for(auto x: graph[node]){
        if(!vis[x]) dfs(x,node,depth+1);
        ans[node]=max(ans[node],1+ans[x]);
    }
    
    // cout<<node<<" "<<depth<<endl;
}

void solution(){

    // This is the main code
    int n,m,u,v;
    cin>>n>>m;
    forn(i,0,m){
        cin>>u>>v;
        graph[u].pb(v);
    }
    forn(i,1,n+1){
        if(vis[i]==0) dfs(i,0,0);
    }
    int a=0;
    forn(i,1,n+1) a=max(a,ans[i]);
    std:: cout<<a; 
}


int main(){
    
    #ifndef ONLINE_JUDGE
    freopen("E:/CP/input.txt","r",stdin);
    freopen("E:/CP/output.txt","w",stdout);
    #endif  
    
    FIO()   
    
    ll t=1;
    //cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}

Measured memory_bytes: 15572
#include <stdio.h>
int main(void)
{
    int n, number;
    char mark;
    scanf("%d", &n);
    int a[4][13] = {0}; //持ってるカードを記入するための表を用意する//表をきれいにする（すべてのセルに0を記入）
    for (int k = 0; k < n; k++)
    {
        scanf(" %c %d", &mark, &number);
        if (mark == 'S')
        {
            a[0][number - 1] = 1; //number-1列目に「1」
        }
        else if (mark == 'H')
        {
            a[1][number - 1] = 1;
        }
        else if (mark == 'C')
        {
            a[2][number - 1] = 1;
        }
        else
        {
            a[3][number - 1] = 1;
        }
    } //持っているカードに対応するセルにチェック（1を記入）
    for (int k = 0; k < 13; k++)
    {
        if (a[0][k] == 0)
            printf("S %d\n", k + 1);
    }
    for (int k = 0; k < 13; k++)
    {
        if (a[1][k] == 0)
            printf("H %d\n", k + 1);
    }
    for (int k = 0; k < 13; k++)
    {
        if (a[2][k] == 0)
            printf("C %d\n", k + 1);
    }
    for (int k = 0; k < 13; k++)
    {
        if (a[3][k] == 0)
            printf("D %d\n", k + 1);
    }
    //表のセルを順番に確認し、0が記入されている場合（a[i][j]=0）そのセルに対応するカードの番号を出力
    return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

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()
{
    ll n;
    cin >> n;
    vector <ll> a(n), b(n), c(n), d(n), e(n+1, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];

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

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        auto Iterc = lower_bound(c.begin(), c.end(), b[i]+1);
        d[i] = int(c.end() - Iterc);
    }
    for (int i = 0; i < n; i++) {
        e[i+1] = e[i] + d[i];
    }
    //reverse(e.begin(), e.end());
    //cout <<  "----" << endl;
    for (int i = 0; i < n; i++) {
        auto Iterb = lower_bound(b.begin(), b.end(), a[i]+1);
        //cout << e[n] - e[n - int(b.end() - Iterb)]  << endl;
        ans += e[n] - e[n - ll(b.end() - Iterb)];
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
def main():
    H, W, D = map(int, input().split())
    A = [
        list(map(int, input().split())) for _ in range(H)
    ]
    Q = int(input())
    ST = [
        list(map(int, input().split())) for _ in range(Q)
    ]

    pos = [0] * (H * W + 1)
    for i, row in enumerate(A):
        for j, value in enumerate(row):
            pos[value] = (i, j)

    d = [0] * (H * W + 1)
    for x in range(D + 1, H * W + 1):
        y = x - D
        p1, p2 = pos[x], pos[y]
        d[x] = d[y] + abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

    for l, r in ST:
        print(d[r] - d[l])


if __name__ == '__main__':
    main()


Measured memory_bytes: 42248