akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

#define MAX_H 20
#define MAX_W 20
#define MAX_G 10

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

struct S {
    int y, x, t;
    S(int y, int x, int t) : y(y), x(x), t(t) {}
};

#define INF (1<<28)

string field[MAX_H];
int number[MAX_H][MAX_W];
int graph[MAX_G][MAX_G];
int dp[MAX_G][1<<MAX_G]; 
int h, w;
int garbage_count;

int solve(int v, int s) {
    if (dp[v][s] != INF) return dp[v][s];
    if (s == ((1<<garbage_count)-1)) return 0;
    int min_cost = INF;
    for (int i = 0; i < garbage_count; i++) {
        if (s & (1<<i)) continue;
        min_cost = min(min_cost, solve(i, (s + (1<<i))) + graph[v][i]);
    }
    return dp[v][s] = min_cost;
}

int main() {
    while (cin >> w >> h) {
        if (w == 0 && h == 0) break;
        memset(graph, -1, sizeof(graph));
        memset(number, -1, sizeof(number));
        for (int i = 0; i < MAX_G; i++) for (int j = 0; j < (1<<MAX_G); j++) dp[i][j] = INF;
        for (int i = 0; i < h; i++) 
            cin >> field[i];
        
        int cur = 1;
        for (int i = 0; i < h; i++) 
            for (int j = 0; j < w; j++) {
                if (field[i][j] == 'o') number[i][j] = 0;
                if (field[i][j] == '*') number[i][j] = cur++;
            }
        garbage_count = cur;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (field[i][j] == 'o' || field[i][j] == '*') {
                    bool visited[h][w]; memset(visited, 0, sizeof(visited));
                    queue<S> q;
                    q.push(S(i, j, 0)); visited[i][j] = true;
                    while (!q.empty()) {
                        S s = q.front(); q.pop();
                        if (field[s.y][s.x] == 'o' || field[s.y][s.x] == '*') {
                            graph[number[i][j]][number[s.y][s.x]] = s.t;
                        }
                        for (int k = 0; k < 4; k++) {
                            int ny = s.y + dy[k];
                            int nx = s.x + dx[k];
                            if (0 <= ny && ny < h && 0 <= nx && nx < w && !visited[ny][nx] && field[ny][nx] != 'x') {
                                visited[ny][nx] = true;
                                q.push(S(ny, nx, s.t+1));
                            }
                        }
                    }
                }
            }
        }

        bool possible = true;
        for (int i = 0; i < garbage_count; i++) 
            for (int j = 0; j < garbage_count; j++) 
                if (graph[i][j] == -1) {
                    possible = false;
                    break;
                }

        if (!possible) cout << -1 << endl;
        else cout << solve(0, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







long long floor_sum(long long n, long long m, long long a, long long b) {
    long long ans(0);
    if(a >= m){
        ans += (n - 1) * n / 2 * (a / m);
        a %= m;
    }
    if(b >= m){
        ans += n * (b / m);
        b %= m;
    }

    long long y_max((a * n + b) / m), x_max((y_max * m - b));
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}

int main(){
    int T; std::cin >> T;
    {
        int N, M, A, B;
        for(int i(0); i < T; ++i){
            std::cin >> N >> M >> A >> B;
            std::cout << floor_sum(N, M, A, B) << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<ll> x(N);
    for(int i=0;i<N;i++){
        cin >> x[i];
    }

    ll ans = 1LL << 61;
    for(int i=0;i + K - 1<N;i++){
        ans = min(ans, abs(x[i]) + abs(x[i] - x[i + K - 1]));
        ans = min(ans, abs(x[i + K - 1]) + abs(x[i] - x[i + K - 1]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

Ans = "War"
maxX = max(x)
minY = min(y)
for i in range(maxX+1,minY+1):
    if X < i <= Y:
        Ans = "No War"

print(Ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

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


Measured memory_bytes: 256
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();

        boolean canDivide = false;

        for (int i = 1; i < 10; i++) {
            if (N % i == 0 && N / i < 10) {
                canDivide = true;
                break;
            }
        }

        System.out.println(canDivide ? "Yes" : "No");
    }
}

Measured memory_bytes: 23764
def resolve():
    '''
    code here
    '''
    N, M = [int(item) for item in input().split()]
    PY = [[int(item) for item in input().split()] for _ in range(M)]

    memo = [[] for _ in range(N+1)]

    for p, y in PY:
        memo[p] += [y]

    res_list = []
    for lst in memo:
        lst.sort()
        temp_dic = dict(zip(lst, range(1,len(lst)+1)))
        res_list.append(temp_dic)

    for p, y in PY:
        pi = str(p).zfill(6)
        x = str(res_list[p][y]).zfill(6)
        print(pi+x)


if __name__ == "__main__":
    resolve()


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

#define max 100000

//qsort(d, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}

int main()
{
    int n, m, nans, mans, ans;
     
    scanf("%d %d", &n, &m);
    if (m>=2)
        mans=m*(m-1)/2;
    else
        mans=0;
    if(n>=2)
        nans=n*(n-1)/2;
    else
        nans=0;
    
    printf("%d", mans+nans);
    
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int w = tx - sx, h = ty - sy;
    string res = "";

    rep(x, w){
        res += 'R';
    }
    rep(y, h){
        res += 'U';
    }
    rep(x, w){
        res += 'L';
    }
    rep(y, h){
        res += 'D';
    }
    res += 'L';
    rep(y, h + 1){
        res += 'U';
    }
    rep(x, w + 1){
        res += 'R';
    }
    res += 'D';
    res += 'R';
    rep(y, h + 1){
        res += 'D';
    }
    rep(x, w + 1){
        res += 'L';
    }
    res += 'U';

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <map>
#include <set>

using namespace std;


int S,N,T;
string wkd,timea;
int P,M;
map<string,int> m;
int wkdNum;
int timeInfo;

const double EPS=1e-8;
bool EQ(double a,double b){
  return abs(a-b)<EPS;
}

double simu2(int sweek,int stime){
  double res=0;
  int nowTime=stime;
  int nowWeek=sweek;
  int cnt=0;
  // M stage実験する
  for(int i=0;i<M;i++){
    if(!(wkdNum==7||nowWeek==wkdNum)){}
    // どちらもallなら無条件でOK
    else if(wkdNum==7&&timeInfo==0)cnt++;
    else{
      bool ok=false;
      const int from=nowTime;
      const int to=nowTime+S;
      // s秒後、次の曜日になる場合
      if(to>=24*60){
        if(from<18*60){}
        // weekはallでないとx
        else if(wkdNum!=7){}
        else{
          if(timeInfo==1){}
          else{
            if(to-24*60<6*60)ok=true;
            else{}
          }
        }
      }
      // そうでない場合
      else{
        if(timeInfo==0)ok=true;
        else if(from>=0&&to<6*60&&timeInfo==2)ok=true;
        else if(from>=6*60&&to<18*60&&timeInfo==1)ok=true;
        else if(from>=18*60&&to<24*60&&timeInfo==2)ok=true;
      }
      if(ok)cnt++;
    }
    if(nowTime+T>=24*60)nowWeek=(nowWeek+1)%7;
    nowTime=(nowTime+T)%(24*60);
  }
  const double a=1.0/P;
  const double b=(1-pow((1-a),N));
  res=(1-pow((1-b),cnt));
  return res;
}

int main(){
  m["Sun"]=0;
  m["Mon"]=1;
  m["Tue"]=2;
  m["Wed"]=3;
  m["Thu"]=4;
  m["Fri"]=5;
  m["Sat"]=6;
  while(cin>>S>>N>>T>>wkd>>timea>>P>>M&&N){
    if(wkd=="All")wkdNum=7;
    else wkdNum=m[wkd];
    if(timea=="All")timeInfo=0;
    else if(timea=="Day")timeInfo=1;
    else timeInfo=2;
    double res=0;
    // 開始設定
    for(int i=0;i<7;i++)
      for(int j=0;j<24*60;j++)
        res=max(res,simu2(i,j));// この設定でsimulate
    printf("%.10f\n",res);
  }
  
  return 0;
}

Measured memory_bytes: 1332
import math

def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    # nの平方根まで計算する
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True

X = int(input())

while not isPrime(X):
    X += 1
print(X)

Measured memory_bytes: 38588
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=3005;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
inline int Fp(int x,int k,int Mod){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
int n,Mod,C[MAXN][MAXN],S[MAXN][MAXN],Ans;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),Mod=read();
	S[0][0]=C[0][0]=1;
	Rep(i,1,n+1){C[i][0]=1;Rep(j,1,i)S[i][j]=(S[i-1][j-1]+1ll*j*S[i-1][j])%Mod,C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;}
	Rep(i,0,n){
		int tmp=1,o=Fp(2,n-i,Mod),Sum=0;
		Rep(j,0,i)Sum=(Sum+1ll*S[i+1][j+1]*tmp)%Mod,tmp=1ll*tmp*o%Mod;
		if(i&1)Ans=(Ans-1ll*Sum*Fp(2,Fp(2,n-i,Mod-1),Mod)%Mod*C[n][i])%Mod;else Ans=(Ans+1ll*Sum*Fp(2,Fp(2,n-i,Mod-1),Mod)%Mod*C[n][i])%Mod;
	}cout<<(Ans+Mod)%Mod<<"\n";
	return 0;
}




Measured memory_bytes: 58704
from math import sqrt

def main():
    X = int(input())

    a = int(sqrt(2 * X))

    for i in range(0, 5):
        b = a + i
        if b * (1 + b) / 2 >= X:
            ans = b
            break

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && b>=1 && a<=10000 && b<=10000)
    {
      a=a*b;
      if(a%2==0)
      {
        System.out.println("Even");
      }else
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 21844
//https://atcoder.jp/contests/abc174/tasks/abc174_c

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

int main() {
	int ans=1;

	int k;
	cin >> k;

	int num=7;


	while(ans<=pow(10,6)){
		if(num%k==0) break;

		//事後条件
		num= (num%k)*10+7;
		ans++;
	}

	if(ans <=1000000) cout << ans << endl;
	else cout << "-1" << endl;

}

Measured memory_bytes: 3616
#include <cstdio>
#include <cmath>
using namespace std;
long long n;
long long ans;
int main()
{
	scanf("%lld",&n);
	ans=n;
	for (long long i=1;i*i<=n;i++)
		if (n%i==0)
			if (i+n/i-2<ans)
				ans=i+n/i-2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+10;
int h,w,a,b,fl=0;
int lie[maxn],hang[maxn];
int g[maxn][maxn];
void init(){
	scanf("%d%d%d%d",&h,&w,&a,&b);
}
void work(){
	for(int i=1;i<=b;++i)
		for(int j=1;j<=a;++j)
			g[i][j]=1;
	for(int i=b+1;i<=h;++i)
		for(int j=a+1;j<=w;++j)
			g[i][j]=1;
}
void prin(){
	for(int i=1;i<=h;++i){
			for(int j=1;j<=w;++j)
				printf("%d",g[i][j]);
			printf("\n");
		}
}
int main(){
	init();
	work();
	prin();
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    sort(all(a));
    vi div(1000030,0);
    rp(i,n-1){
        if(a[i]==a[i+1]){
            if(div[a[i]]==0){
                div[a[i]]=1;
                for(ll j=a[i]; j<=1000002; j+=a[i]){
                    div[j]=1;
                }
            }
        }
    }
    int ctr=0;
    rp(i,n){
        if(div[a[i]]==0) {
            ctr++;
            for(ll j=a[i]; j<=1000002; j+=a[i]){
                div[j]=1;
            }
        }
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

using ll = long long;

const int MAXN = 310;
int N;
int A[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			int d = A[i][j]+1;
			for (int k = 0; k < N; k++) {
				if (i != k && j != k) {
					d = min(d, A[i][k] + A[k][j]);
				}
			}
			if (d < A[i][j]) {
				cout << -1 << '\n';
				exit(0);
			}
			if (d > A[i][j]) {
				ans += d-1;
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	
    	if( A == B && B == C ) {
    		System.out.println("Yes");
    	}
    	else {
    		System.out.println("No");
    	}
    	
    	sc.close();
    }
}

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

int main(){
  long n, ans=0;
  cin >> n;
  if(n%2 == 1){
    cout << 0 << endl;
  }else{
    n /= 2;
    while(n){
      ans += n/5;
      n = n/5;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int[] x = new int[n], y = new int[n];
			IntStream.range(0, n).forEach(i -> {
				x[i] = scanner.nextInt();
				y[i] = scanner.nextInt();
			});
			long answer = Long.MAX_VALUE;
			int[] sortedX = x.clone();
			int[] sortedY = y.clone();
			Arrays.sort(sortedX);
			Arrays.sort(sortedY);
			for (int xi = 0; xi < n; xi++) {
				for (int xj = xi + 1; xj < n; xj++) {
					for (int yi = 0; yi < n; yi++) {
						for (int yj = yi + 1; yj < n; yj++) {
							int count = 0;
							for (int i = 0; i < n; i++) {
								if ((sortedX[xi] <= x[i]) && (x[i] <= sortedX[xj]) && (sortedY[yi] <= y[i])
										&& (y[i] <= sortedY[yj])) {
									count++;
								}
							}
							if (count >= k) {
								answer = Math.min(answer,
										1L * (sortedX[xj] - sortedX[xi]) * (sortedY[yj] - sortedY[yi]));
							}
						}
					}
				}
			}
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 27604
a, b, q = map(int, input().split())
S = [int(input()) for _ in range(a)]
T = [int(input()) for _ in range(b)]
S.sort()
T.sort()
INF = 10**18
S = [-INF] + S + [INF]
T = [-INF] + T + [INF]

import bisect
for _ in range(q):
    x = int(input())
    i = bisect.bisect_right(S, x)
    j = bisect.bisect_right(T, x)
    ans = INF
    for s in [S[i-1], S[i]]:
        for t in [T[j-1], T[j]]:
            d1 = abs(s-x) + abs(t-s)
            d2 = abs(t-x) + abs(s-t)
            ans = min([ans, d1, d2])
    print(ans)

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 100005;
const LL MOD = 1e9 + 7;

LL bigmod(LL b,LL p,LL m)
{
    LL ret = 1;
    while(p > 0){
        if(p % 2 == 1)ret = (ret * b) % m;
        p = p >> 1;
        b = (b * b) % m;
    }
    return ret;
}
int n , m;
int main()
{
    cin >> n >> m;

    int sq = sqrt(m);
    vector<pii>fac;
    for(int i = 2;i <= sq;i++){
        int cnt = 0;
        while(m % i == 0){
            cnt++;
            m/=i;
        }
        if(cnt > 0)fac.push_back(mk(i,cnt));
    }
    if(m > 1){
        fac.push_back(mk(m,1));
    }
    LL ret = 1;
    for(int i = 0;i < fac.size();i++){
        int up = n + fac[i].second - 1;
        int d1 = n - 1;
        int d2 = fac[i].second;
        LL ans = 1;
        for(int j = d1 + 1;j <= up;j++)ans = (ans * j) % MOD;
        for(int j = 1;j <= d2;j++)ans = (ans * bigmod(j,MOD-2,MOD)) % MOD;
        ret = (ret * ans) % MOD;
    }
    cout << ret << "\n";


}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(),
        b = sc.nextInt(),
        c = sc.nextInt(),
        d = sc.nextInt(),
        e = sc.nextInt(),
        k = sc.nextInt();
    String res = "Yay!";    
    if (e - a > k){
        res = ":(";
    }
    System.out.println(res);

  }
}


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

int main(){
    for(int i=0;i<500000;i++){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0) break;
        else{
            for(int i=0;i<h;i++){
                for(int k=0;k<w;k++){
                    if(i==0||i==h-1){
                        cout<<'#';
                    }
                    else{
                        if(k==0||k==w-1) cout<<'#';
                        else cout<<'.';
                    }
                }
                cout<<endl;
            }
        cout<<endl;
        }
    }
}


Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  ll N = S.size();
  ll ans = 0;
  REP(i, N / 2) {
    if (S[i] != S[N - 1 - i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using LL = long long;

LL sum(auto& a, auto l, auto r) {
  LL s=0;
  for(auto i=l; i<=r;++i) s+= a[i];
  return s;
}

int main() {
  int N;
  cin >> N;
  vector<LL> A(3*N);
  for(auto& i: A) cin >> i;

  priority_queue<LL, vector<LL>, greater<LL>> l;
  vector<LL> L(3*N), R(3*N);
  L[N-1] = sum(A, 0, N-1);
  for(auto i=0; i<N; ++i) l.emplace(A[i]);
  for(auto i=N; i<2*N; ++i) {
    l.emplace(A[i]);
    L[i] = L[i-1] + A[i] - l.top();
    l.pop();
  }

  priority_queue<LL> r;
  R[2*N] = sum(A, 2*N, 3*N-1);
  for(auto i=2*N; i<3*N; ++i) r.emplace(A[i]);
  for(auto i=2*N-1; N<=i; --i) {
    r.emplace(A[i]);
    R[i] = R[i+1] + A[i] - r.top();
    r.pop();
  }

  LL s=-1e18;
  for(auto i=N-1; i<2*N; ++i) s=max(s, L[i]-R[i+1]);
  cout<<s<<endl;
}


Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
string str;
map<char,long long>ma;
long long ans;
int main(){
    cin>>str;
    for(register long long i=0;i<str.length();++i){
        ma[str[i]]++;
    }
    for(register int i=0;i<25;++i){
        for(register int j=i+1;j<26;++j){
            ans+=ma[i+'a']*ma[j+'a'];
        }
    }
    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

max_z = 0
for i in range(2**n):
  #print("i:",i)
  x = 0
  y = 0
  for j in range(n):
    if i&(1<<j)!=0:
      #print('j:',j)
      x+=v[j]
      y+=c[j]
  z=x-y
  #print(z)
  max_z = max(max_z,z)
print(max_z)
  


Measured memory_bytes: 41196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		int A,B,C;
		A = input.nextInt();
		B = input.nextInt();
		C = input.nextInt();
		if ((A==5&&B==5&& C== 7)|| (A==5&&B==7&& C== 5) || (A==7&&B==5&& C== 5) ) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	  
	}

}


Measured memory_bytes: 26924
import sys

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

idx_of_result = 0
min_diff = sys.maxsize
for i, h_i in enumerate(h):
    temprature = t - h_i * 0.006
    diff = abs(temprature - a)
    if diff < min_diff:
        min_diff = diff
        idx_of_result = i

print(idx_of_result + 1)


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

int main(){
    int N,M;
    cin>>N>>M;
    int L=1,R=N;
    for(int i=0;i<M;i++){
        int l,r;
        cin>>l>>r;
        if(l>L) L=l;
        if(r<R) R=r;
    }
    if(R<L) cout<<0<<endl;
    else cout<<R-L+1<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static char[] Ops;
    static int[] L;

    static void dfs(int i, int sum, char[] ops)
    {
        if (i == 3 && sum == 7)
        {
            Ops = ops;
            return;
        }
        if (i == 3)
        {
            //Console.WriteLine(sum);
            return;
        }
        ops[i] = '+';
        dfs(i + 1, sum + L[i + 1], ops);
        if (Ops != null) return;
        ops[i] = '-';
        dfs(i + 1, sum - L[i + 1], ops);
        return;
    }

    static void Main(string[] args)
    {
        L = Console.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();
        var ops = new char[3];
        dfs(0, L[0], ops);
        /*if (Ops == null)
        {
            Console.WriteLine("Null");
            return;
        }*/
        var res = $"{L[0]}{Ops[0]}{L[1]}{Ops[1]}{L[2]}{Ops[2]}{L[3]}=7";
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next().replaceAll("\\?", ".");
		String t = sc.next();
		int ns = s.length();
		int nt = t.length();
		for(int i = 0 ; i + nt <= ns ; i++) {
			String regex = s.substring(ns - nt - i, ns - nt - i + nt);
			if(t.matches(regex)) {
				String ans = s.replaceFirst(s.substring(0, ns - nt - i) + regex, s.substring(0, ns - nt - i) + t).replaceAll("\\.", "a");
				System.out.println(ans);
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
}

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

int n,k;
int w[100001];

bool check(int p) {
  ll sum=0;
  int idx=0;
  rep(i, k) {
    sum=0;
    while (w[idx]+sum<=p) {
      sum+=w[idx];
      idx++;
      if (idx==n) return true;
    }
  }
  return false;
}

int main() {
  cin>>n>>k;
  rep(i, n) cin>>w[i];

  ll l=0;
  ll r=100000*10000;
  while (r-l>1) {
    ll mid=(r+l)/2;
    if (check(mid)) r=mid;
    else l=mid;
  }
  cout<<r<<endl;
}


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

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

  int n, m;
  cin >> n >> m;
  vector<string> canvas(n);
  for (int i = 0; i < n; i++) cin >> canvas[i];
  vector<string> target(m);
  for (int i = 0; i < m; i++) cin >> target[i];

  bool flag = false;
  for (int i = 0; i < n - m + 1; i++) {
    for (int j = 0; j < n - m + 1; j++) {
      flag = false;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if (canvas[i+y][j+x] == target[y][x]) continue;
          flag = true;
          break;
        }
        if (flag) break;
      }
      if (flag) continue;
      cout << "Yes" << '\n';
      return 0;
    }
  }
  cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        "\n"
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;


int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
ll n;
cin>>n;
unordered_map<int,int> map;
int arr[2*100000];
rep(i,1,n)
{
cin>>arr[i];
map[arr[i]]++;
}
rep(i,1,n+1)
cout<<map[i]<<endl;
return 0;
}

Measured memory_bytes: 12252
x,y = map(int, input().strip().split(' '))
def group(n):
  if n in {1,3,5,7,8,10,12}:
    return 0
  elif n in {4,6,9,11}:
    return 1
  elif n in {2}:
    return 2
print('Yes' if group(x) == group(y) else 'No')

Measured memory_bytes: 3060
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int main(){
    char s[100];
    char s2[200];
    char p[100];
    scanf("%s %s", s, p); 
    strcpy(s2,s);
    strcat(s2,s) ;
    if ( strstr(s2,p) == NULL ) printf("No\n");
    else printf("Yes\n");
    return 0;
    
}


Measured memory_bytes: 3152
def gcd(a, b)
  a, b = b, a if a < b
  r = a % b
  r == 0 ? b : gcd(b, r)
end
a, b, k = gets.chomp.split(' ').map(&:to_i)
ab = gcd(a, b)

counter = 0
100.downto(1) do |i|
  counter += 1 if ab % i == 0
  if counter == k
    puts i
    break
  end
end

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
long long MOD=mod;
#define SIZE 2000005
long long fac[SIZE],finv[SIZE],inv[SIZE];

void make() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long C(long long  n, long long  k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    long long k;
    cin>>k;
    string s;
    cin>>s;
    
    make();

    //long long now=C(k+s.size(),s.size());
    
    /*
        文字列sの最後の文字Snの位置を固定して
        Sn以降は26文字のどれでも使っていよい、
    */
    long long ans=0;
    long long L=s.size()+k;
    long long l=s.size();
    for(long long i=s.size();i<=L;i++){
        long long total=modpow(26,L-i);
        total*=C(i-1,s.size()-1);
        total%=mod;

        total*=modpow(25,i-l);
        total%=mod;

        //total*=modpow(26,L-i);
        //total%=mod;

        ans+=total;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 51152
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            sample[] PS = new sample[N];
            for (int i = 0; i < N; i++)
            {
                string[] tmp = Console.ReadLine().Split(' ').ToArray();
                PS[i] = new sample{Index = i + 1,  city = tmp[0], num = int.Parse(tmp[1]) };
            }
            foreach (var a in PS.OrderBy(t => t.city).ThenByDescending(t => t.num))
            {
                Console.WriteLine(a.Index);
            }
        }
    }
    class sample
    {
       public string city { get; set; }
       public int num { get; set; }
       public int Index { get; internal set; }
    }
}

Measured memory_bytes: 11612
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
N = int(input())

for i in range(10000):
    if i * (i + 1) / 2 == N:
        for i in range(1, i + 1):
            print(i)
        break
    elif i * (i + 1) / 2 > N:
        remove = i * (i + 1) / 2 - N
        for i in range(1, i + 1):
            if i != remove:
                print(i)
        break

Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
int F[105][10];
ll P[105][11];

int main() {
  ll N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<ll> cnt(N, 0);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
        if (bit & (1 << j)) {
          if (F[i][j] == 1) cnt[i]++;
        }
      }
    }
    ll cost = 0;
    for (int i = 0; i < N; i++) {
      cost += P[i][cnt[i]];
    }
    ans = max(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {

	 public static void main(String[] args)throws Exception{

	 Scanner sc = new Scanner(System.in);


		 int n = sc.nextInt();

		 for(int i=0;i<n;i++)
		 {
			 String a = sc.next();
			 String b = sc.next();

			 a = a.trim();
			 b = b.trim();

			 int x = calcSum(a);
			 int y = calcSum(b)  ;

			 String result = tranceResult(x + y);
			 System.out.println(result);

		 }

	 }

	 public static String tranceResult(int num)
	 {

		 
		 String result ="";
		 
		 int tmp;
		 
		 tmp = num/1000;
		 if(tmp > 0){
			 if(tmp ==1)
				 result = result + "m";
			 else
				 result = result + tmp +"m";
		 }
		 
		 tmp = num % 1000 / 100;
		 if(tmp > 0){
			 if(tmp ==1)
				 result = result + "c";
			 else
				 result = result + tmp +"c";
		 }
		 
		 tmp = num % 100 / 10;
		 if(tmp > 0){
			 if(tmp ==1)
				 result = result + "x";
			 else
				 result = result + tmp +"x";
		 }
		 
		 tmp = num % 10;
		 if(tmp > 0){
			 if(tmp ==1)
				 result = result + "i";
			 else
				 result = result + tmp +"i";
		 }
		 
		 return result;
	 }
	 
	 public static  boolean isNumber(String num) {
		    String regex = "^[0-9]*$";
		    Pattern p = Pattern.compile(regex);
		    Matcher m = p.matcher(num);
		    return m.find();
		}

	 public static int calcSum(String str){

		 String[] A = str.split("");
		 int count = 0;

		 for(int i=0;i<A.length;i++)
		 {
			 if(A[i].equals("m"))
			 {
				 
				 if(i >0 &&isNumber(A[i-1]))
					 count += 1000 * Integer.parseInt(A[i-1]);
				 else
					 count += 1000;
			 }

			 if(A[i].equals("c"))
			 {
				 if(i >0 && isNumber(A[i-1]))
					 count += 100 * Integer.parseInt(A[i-1]);
				 else
					 count += 100;
			 }
			 if(A[i].equals("x"))
			 {
				 if(i >0 && isNumber(A[i-1]))
					 count += 10 * Integer.parseInt(A[i-1]);
				 else
					 count += 10;
			 }
			 if(A[i].equals("i"))
			 {
				 if(i >0 && isNumber(A[i-1]))
					 count += Integer.parseInt(A[i-1]);
				 else
					 count += 1;
			 }

		 }

		 return count;

	 }



}

Measured memory_bytes: 56176
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1011];
int main()
{
	int n,i,sum=0,pl,mn=10000000;
	double p;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]),sum+=a[i];
//	p=sum;
	for(i=1;i<=n;i++)
	{
		if(abs(a[i]*n-sum)<mn)
			mn=abs(a[i]*n-sum),pl=i-1;
	}
	printf("%d\n",pl);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int __int128
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


#define D  18
#define A first
#define B second

signed main(){
	cout<<fixed<<setprecision(10);
	
	long long N;
	long long table[40][40] = {};
	long long count = 0;
	
	cin>>N;
	
	
	
	for(int i = 0; i < N; i++){
		bool flag = false, flag2 = false;
		int a = 0, GCD, con = 0;
		int maximum = 0;
		string num;
		
		cin>>num;

		if(std::count(num.begin(), num.end(), '.') == 0) num += ".000000000000000000000";
		else num += "0000000000000000000000";
		
		// cout<<"num = "<<num<<endl;
		
		for(int i = 0; i < num.size(); i++) {
			if(num[i] == '.') {
				flag = true;
				
				
					// cout<<"i = "<<i<<" num[i] "<<num[i]<<" con = "<<con<<endl;
			} else {
				if(flag) {
					con++;
				}
				
				if(con > 9 && num[i] != '0') flag2 = true;
				
				if(con <= 9) {
					a = a * 10 + num[i] - '0';
					// cout<<"i = "<<i<<" num[i] "<<num[i]<<" con = "<<con<<endl;
				}
			}
		}
		
		// cout<<"i = "<<i<<" a = "<<a<<endl;
		
		if(flag2 == false) {
			
			int two = 0, five = 0;
			
			// cout<<"A = "<<(long long)a<<endl;
			
			for(; a%5 == 0 && a != 0;){
				five++;
				a /= 5;
			}
			
			
			for(; a%2 == 0 && a != 0;){
				two++;
				a /= 2;
			}
			
			
			// cout<<"five = "<<(long long)five<<" two = "<<(long long)two<<endl;
			for(int k = 0; k < 40; k++){
				for(int j = 0; j < 40; j++){
					if(k + two >= D && j + five >= D) {
						count += table[k][j];
						// if(table[k][j])cout<<k<<" "<<j<<endl;
					}
				}
			}
			// cout<<" count = "<<count<<endl;
			
			// cout<<endl<<endl;
			table[min(two, (int)D+1ll)][min(five,(int)D+1ll)]++;
			// table[two][five]++;
		}
	}
	
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

int lsone(int n)
{
	return (n&-n);
}

ll pow1(ll a, ll b)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2);
		x *= x;
		x %= mod;
		if (b%2)
		{
			x *= a;
			x %= mod;
		}
		return x;
	}
}

int h, w, k, num[310], ans[310][310];
char grid[310][310];

int main()
{
	fastio;		
	cin>>h>>w>>k;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin>>grid[i][j];
			if (grid[i][j] == '#') {
				num[i]++;
			}
		}
	}

	int index = 1;
	for (int i = 1; i <= h; i++) {
		if (num[i] == 0)
			continue;
		int lef = num[i];
		for (int j = 1; j <= w; j++) {
			ans[i][j] = index;
			if (grid[i][j] == '#' and lef > 1) {
				lef--;
				index++; 
			}
		}
		index++;
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (ans[i][j] == 0) {
				if (i == 1) {
					for (int k = 2; k <= h; k++) {
						if (ans[k][j] != 0) {
							ans[i][j] = ans[k][j];
							break;
						}
					}
				}
				else
					ans[i][j] = ans[i-1][j];
			}
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}

	return 0;
}


Measured memory_bytes: 1280
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    s = input()
    t = ""
    i = 0
    while i < len(s):
        if s[i] == "A":
            t += "A"
            i += 1
        elif s[i] == "B":
            if i < len(s) - 1:
                if s[i+1] == "C":
                    t += "D"
                    i += 2
                else:
                    t += "X"
                    i += 1
            else:
                t += "X"
                i += 1
        else:
            t += "X"
            i += 1
    
    total = 0
    numA = 0
    for i in range(len(t)):
        if t[i] == "X":
            numA =  0
        else:
            if t[i] == "A": numA += 1
            else: total += numA

    print(total)
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3884
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int A, B, C, X;
    if (scanf("%d%d%d%d", &A, &B, &C, &X) < 4) return 0;

    int cnt = 0;
    for (int i = 0; i < A + 1; i++)
    {
        for (int j = 0; j < B + 1; j++)
        {
            for (int k = 0; k < C + 1; k++)
            {
                if (500 * i + 100 * j + 50 * k == X) cnt++;
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
function Main(input) {
    input = input.split(" ");
    var a = parseInt(input[0]);
    var b = parseInt(input[1]); 
    if (a<b) {
        console.log("a < b");
    }else if (a>b) {
        console.log("a > b");
    }else if (a==b) {
        console.log("a == b")
    }
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug() {
    var input = document.getElementById("input").value;
    Main(input);
}

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15096
bingo = []
for _ in range(3):
    bingo.append(list(map(int, input().split())))
n = int(input())

for i in range(n):
    num = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == num:
                bingo[j][k] = None


flag = False
for row in range(3):
    for col in range(3):
        if bingo[row][col] is None:
            continue
        else:
            break
    else:
        flag = True

for row in range(3):
    for col in range(3):
        if bingo[col][row] is None:
            continue
        else:
            break
    else:
        flag = True

if bingo[0][0] is None and bingo[1][1] is None and bingo[2][2] is None:
    flag = True
if bingo[0][2] is None and bingo[1][1] is None and bingo[2][0] is None:
    flag = True

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38536
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int idx;
	vi sum(n);

	//R
	idx = 0;

	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'R' && idx < 0) idx = i;
		if (s[i] == 'R' && s[i + 1] == 'L') {
			int t = i - idx + 1;

			sum[i] += t / 2;
			sum[i + 1] += t / 2;
			if (t % 2 == 1) {
				sum[i]++;
			}
			idx = -1;
		}
	}

	/*rep(i, n) cout << sum[i] << " ";
	cout << endl;*/

	//L
	idx = n - 1;

	for (int i = n - 1; i > 0; i--) {
		if (s[i] == 'L' && idx < 0) idx = i;
		if (s[i - 1] == 'R' && s[i] == 'L') {
			int t = idx - i + 1;
			sum[i] += t / 2;
			sum[i - 1] += t / 2;
			if (t % 2 == 1) sum[i]++;
			idx = -1;
		}
	}

	rep(i, n) {
		if (i == n - 1) cout << sum[i] << endl;
		else cout << sum[i] << " ";
	}
}

Measured memory_bytes: 1024