akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String strIn = "";
        int[] array = new int[26];
        int intTemp;
        while(scan.hasNext()){
            strIn += scan.nextLine();
        }
        for(int i = 0; i < strIn.length(); i++){
            intTemp = strIn.charAt(i);
            if('A' <= intTemp && intTemp <= 'Z'){
                array[intTemp - 'A']++;
            }else if('a' <= intTemp && intTemp <= 'z'){
                array[intTemp - 'a']++;
            }
        }
        for(int i = 0; i < array.length; i++){
            System.out.println((char)('a' + i) + " : " + array[i]);
        }
 
        scan.close();
    }
}

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

namespace Atcoder
{
    class _101A
    {
        static void Main(string[] args)
        {
            int[] rawinput = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = rawinput[0]; int b = rawinput[1]; int c = rawinput[2];
            int d = rawinput[3];
            
            if (Math.Abs(a - c) <= d)
            {
                Console.WriteLine("Yes");
                
            }
            else if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	double a,b,c,d;
	cin >> a >> b >> c >> d;
	printf("%.7lf\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
	return 0;
}


Measured memory_bytes: 3296
#include<iostream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<set>

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    vector<pair<long long, int>> C(N);
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        C[i].first = A[i] + B[i];
        C[i].second = i;
    }
    sort(C.rbegin(), C.rend());

    int tak = 0;
    int aok = 1;
    long long ans = 0;
    while(1){
        if(tak >= N) break;
        ans += A[C[tak].second];
        tak += 2;

        if(aok >= N) break;
        ans -= B[C[aok].second];
        aok += 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int bingo[4][4];
	int hantei[4][4];
	rep(i,3){
		rep(j,3){
			hantei[i][j] = 0;
		}
	}
	rep(i,3){
		rep(j,3){
			cin >> bingo[i][j];
		}
	}
	
	int N;
	cin >> N;
	
	rep(i,N){
		int b;
		cin >> b;
		rep(j,3){
			rep(k,3){
				if(bingo[j][k] == b){
					hantei[j][k] = 1;
				}
			}
		}
	}
	
	bool ok = false;
	
	//yoko
	rep(i,3){
		int count = 0;
		rep(j,3){
			if(hantei[i][j] == 1){
				count++;
			}
		}
		if(count == 3) ok = true;
	}
	
	//tate
	rep(j,3){
		int count = 0;
		rep(i,3){
			if(hantei[i][j] == 1){
				count++;
			}
		}
		if(count == 3) ok = true;
	}
	
	//naname
	if(hantei[0][0] == 1 && hantei[1][1] == 1 && hantei[2][2] == 1){
		ok = true;
	}
	
	if(hantei[2][0] == 1 && hantei[1][1] == 1 && hantei[0][2] == 1){
		ok = true;
	}
	
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int n,m;
    cin>>n>>m;
    char a[50][50]={'0'},b[50][50]={'2'};
    rep(i,n){
        rep(j,n) cin>>a[i][j];
    }
    rep(i,m){
        rep(j,m) cin>>b[i][j];
    }
    rep(i,n){
        rep(j,n){
            int x=0;
                rep(k,m){
                    rep(l,m){
                           if(a[i+k][j+l]==b[k][l]){
                               x++;
                               if(x==m*m){
                               cout<<"Yes"<<endl;
                               return 0;
                               }
                           }
                    }
                }
        }
    }
    cout<<"No"<<endl;
    return 0;
}    
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin, x;
    print(x >= 30 ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3636
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

int main(){
  int n,k,q;
  cin >> n >> k >> q;
  map<int, int> participants;

  REP(i, q) {
    int a;
    cin >> a;

    participants[a-1]++;
  }

  REP(i, n) {
    if(k - q + participants[i] >= 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, y;
    cin >> n >> y;
    y /= 1000;

    for (int i = n; i >= 0; i--)
    {
        for (int j = 0; i+j <= n; j++)
        {
            int amari = y-(i*10)-(j*5);
            if (amari == n-i-j){
                cout << i << " " << j << " " << amari << endl;
                return 0;
            }
        }
    }    
    cout << "-1" << " -1" << " -1" <<endl;
}



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

int main()
{
	int n = 0, k = 40;
	long a;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a;
		int j = 0;

		while (a % 2 == 0) {
			a /= 2;
			j++;
		}
		if (j < k)
			k = j;
	}

	cout << k << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)
#define N_MAX 200000

using namespace std;

typedef long long int Int;

Int dp[N_MAX][2]; 

int main(void) {
    string L;
    
    cin>>L;
    int n = L.size();
    dp[0][0] = 1;
    dp[0][1] = 0;
    for(int i = 0;i < n;i++) {
        if(L[i] == '0') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1]*3 % MOD;
        } else {
            dp[i+1][0] = dp[i][0]*2;
            dp[i+1][1] = dp[i][0]+dp[i][1]*3;
        }
        dp[i+1][0] %= MOD;
        dp[i+1][1] %= MOD;
    }

    Int sum = (dp[n][0]+dp[n][1])%MOD;

    cout<<sum<<endl;

    return 0;
}




Measured memory_bytes: 2048
a=int(input())
N=list(map(int,input().split()))
M=list(map(int,input().split()))
#A=list(map(int,input().split()))

count=0
for i in range(a):
    if N[i]>=M[i]:
        count=count+M[i]
    else:
      count=count+N[i]
      if N[i+1]>=M[i]-N[i]:
          count=count+M[i]-N[i]
          N[i+1]=N[i+1]-(M[i]-N[i])
      else:
          count=count+N[i+1]
          N[i+1]=0

print(count)

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

using namespace std;
const int MAXN =1e5+10;

char s[MAXN][20];
long long int march[10];
int main(){
  int N =0;
  scanf("%d",&N);
  long long int ans =0;
  for(int i=0;i<N;i++){
    scanf("%s",&s[i]);
  }
  for(int i=0;i<N;i++){
    if(s[i][0]=='M')    march[0]++;
    if(s[i][0]=='A')    march[1]++;
    if(s[i][0]=='R')    march[2]++;
    if(s[i][0]=='C')    march[3]++;
    if(s[i][0]=='H')    march[4]++;
  }

  ans=march[0]*march[1]*march[2]+march[0]*march[1]*march[3]+march[0]*march[1]*march[4]+march[0]*march[2]*march[3]+march[0]*march[2]*march[4]+march[0]*march[3]*march[4]+march[1]*march[2]*march[3]+march[1]*march[2]*march[4]+march[1]*march[3]*march[4]+march[2]*march[3]*march[4];

  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> 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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int x = 0, ans = 0;
    rep(i,n){
        if(s[i] == 'I') ++x;
        else --x;
        chmax(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
n=gets.to_i
s=gets.chomp

a=0
r=g=b=0
s.chars{|c|
case c
when ?R then r+=1
when ?G then g+=1
when ?B then b+=1
end
}
a+=r*g*b
(1..n).each{|d|
(0...n).each{|i|
break if i+d+d>=n
a-=1 if s[i]!=s[i+d]&&s[i+d]!=s[i+d+d]&&s[i]!=s[i+d+d]
}
}
p a

Measured memory_bytes: 14360
import math  
a,b,x,y=map(int,input().split())  
z1=(y/60-x/12-y/(60*12))*math.pi*2  
z2=(x/12+y/(60*12)-y/60)*math.pi*2  
ka=min(abs(z1),abs(z2))  
ans=a**2+b**2-2*a*b*math.cos(ka)  
print(ans**0.5)

Measured memory_bytes: 9520
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m=MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
void solve(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &it:v)cin>>it;
    sort(all(v));
    int mid=n>>1;
    int ret=v[mid]-v[mid-1];
    cout << ret <<  endl;	
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

total_vote = sum(a)
x = 1 / (4*m)
base = total_vote * x

for i in a[:m]:
    if i < base:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
import random
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.top,   self.bottom = top, bottom
        self.right, self.left   = right, left
        self.front, self.back   = front, back

    def rot(self, d):
        if   d == "N":
            (self.top, self.back, self.bottom, self.front) = (
             self.front, self.top, self.back, self.bottom)
        elif d == "S":
            (self.top, self.back, self.bottom, self.front) = (
             self.back, self.bottom, self.front, self.top)
        elif d == "E":
            (self.top, self.right, self.bottom, self.left) = (
             self.left, self.top, self.right, self.bottom)
        elif d == "W":
            (self.top, self.right, self.bottom, self.left) = (
             self.right, self.bottom, self.left, self.top)

def same(a, b):
    if ((a.top, a.bottom, a.right, a.left, a.front, a.back) ==
        (b.top, b.bottom, b.right, b.left, b.front, b.back)):
        return True
    else:
        return False

ref = {}
ls1 = map(int, raw_input().split())
ls2 = map(int, raw_input().split())
dice1 = Dice(ls1[0], ls1[1], ls1[2], ls1[3], ls1[4], ls1[5])
dice2 = Dice(ls2[0], ls2[1], ls2[2], ls2[3], ls2[4], ls2[5])
for i in xrange(1000):
    d = "NSEW"[random.randint(0,3)]
    dice1.rot(d)
    if same(dice1, dice2):
        print "Yes"
        break
else:
    print "No"

Measured memory_bytes: 5436
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,a,b;
    lli i,j;
    cin>>n>>a>>b;
    if(a/n!=b/n){
        cout<<"OK"<<endl;
    }
    else if(a%n==0||b%n==0){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int d,t,s;
    cin >> d >> t >> s;
    if(s*t>=d) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b,c=MI()
if a==b:
    print(c)
elif b==c:
    print(a)
elif c==a:
    print(b)

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

typedef struct tag{
    int a,b;
}st;

int comp(const void *a,const void *b){
    return ((st*)a)->b - ((st*)b)->b;
}

int main(void){
    int n;
    scanf("%d",&n);
    st ab[n];
    for(int i = 0;i < n;i++){
        scanf("%d %d",&(ab[i].a),&(ab[i].b));
    }
    qsort(ab,n,sizeof(st),comp);
    int time = 0;
    for(int i = 0;i < n;i++){
        time += ab[i].a;
        if(time > ab[i].b){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 3324
import math
if __name__=="__main__":
    # Problem c
    A, B, H, M = map(int, input().split(' '))

    total_min = H*60 + M
    A_rad = 2*math.pi/720 * total_min
    B_rad = 2*math.pi/60 * M
    angle = A_rad-B_rad
    length_pow = A**2 + B**2 - 2*A*B*math.cos(angle)
    print(length_pow**(1/2))

Measured memory_bytes: 9508
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

#import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def fib_memo(n):
    memo = [0] * (n+1)
    memo[0] = 1
    if n < 1:
        return memo
    memo[1] = 1
    for i in range(2, n+1):
        memo[i] = memo[i-1] + memo[i-2]
    return memo

def main_nondp():
    N, M = i2nn()
    A = ii2nn(M)
    MOD = int(1e+9) + 7
    D = [0] * (M+1)
    if M == 0:
        D[0] = N
    else:
        D[0] = A[0] - 1
        for i in range(1, M):
            t = A[i] - A[i-1] - 2
            if t <= -1:
                print(0)
                return
            D[i] = t
        D[M] = N - A[M-1] - 1
    n = 1
    memo = fib_memo(max(D))
    for d in D:
        n = (n * memo[d]) % MOD
    print(n)

def main():
    N, M = i2nn()
    A = ii2nn(M)
    MOD = int(1e+9) + 7
    AS = set(A)
    dp = [0] * (N+9)  # i段目のパターン数
    dp[0] = 1
    for i in range(1, N+1):
        if i in AS:
            dp[i] = 0
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % MOD
    print(dp[N])

main()


Measured memory_bytes: 57820
#include<stdio.h>
#include<string.h>
int main(){
	int a,c;
	scanf("%d%d",&a,&c);
	char q[20],s[20];
	for(int i=0;i<a;i++)q[i]=c;
	for(int i=0;i<c;i++)s[i]=a;
	if(strcmp(q,s)<=0){
		for(int i=0;i<a;i++)
		printf("%d",c);
	}
	else 	for(int i=0;i<c;i++)
		printf("%d",a);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/math/constants/constants.hpp>
using namespace std;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
    template<class R, class P> auto partition_point(const R& r, P p) { return ::std::partition_point(begin(r), end(r), p); }
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

using boost::irange;
using boost::math::double_constants::pi;
using i64 = int64_t;
constexpr char nl = '\n';
auto yesno(bool b) { return b ? "Yes" : "No"; }

template<class T> istream& operator>>(istream& in, vector<T>& vs) { for (T& v :vs) in >> v; return in; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& vs) { for (size_t i = 0; i < vs.size(); ++i) { if(i) { out << ' '; } out << vs[i]; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const T& v) { cout << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cout << nl; for (const auto& v : m) { trace_(v); cout << nl; } }
template<class T> void trace_(const char* s, const T& v) { cout << s << "="; trace_(v); cout << nl; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cout << *s; } cout << "="; trace_(v); cout << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

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

    vector gcds(K+1, vector<int>(K+1));
    for (int a : irange(1, K+1)) {
        for (int b : irange(a, K+1)) {
            int g = gcd(a, b);
            gcds[a][b] = gcds[b][a] = g;
        }
    }

    i64 sum = 0;
    for (int a : irange(1, K+1)) {
        for (int b : irange(1, K+1)) {
            for (int c : irange(1, K+1)) {
                sum += gcds[gcds[a][b]][c];
            }
        }
    }
    cout << sum << nl;
}


Measured memory_bytes: 3748
// AOJ ITP1_11_B Dice II
// 2018.4.29 bal4u
 
#include <stdio.h>
 
int face[7][7][4] = {
{{0},{0},{0},{0},{0},{0},{0}},
{{0},{0},{0,1,2,3},{0,1,3,5},{0,1,4,2},{0,1,5,4},{0}},
{{0},{0,2,1,4},{0},{0,2,3,1},{0,2,4,6},{0},{0,2,6,3}},
{{0},{0,3,1,2},{0,3,2,6},{0},{0},{0,3,5,1},{0,3,6,5}},
{{0},{0,4,1,5},{0,4,2,1},{0},{0},{0,4,5,6},{0,4,6,2}},
{{0},{0,5,1,3},{0},{0,5,3,6},{0,5,4,1},{0},{0,5,6,4}},
{{0},{0},{0,6,2,4},{0,6,3,2},{0,6,4,5},{0,6,5,3},{0}}};
int assign[7];
 
int main()
{
    int q, i, t, f;
 
    for (i = 1; i <= 6; i++) scanf("%d", assign+i);
    scanf("%d", &q);
    while (q--) {
        scanf("%d%d", &t, &f);
        for (i = 1; i <= 6; i++) {
            if (assign[i] == t) t = i;
            if (assign[i] == f) f = i;
        }
        printf("%d\n", assign[face[t][f][3]]);
    }
    return 0;
}


Measured memory_bytes: 2044
N,C=map(int,input().split())
D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x)-1 for x in input().split()] for y in range(N)]

d=[[0 for x in range(C)] for y in range(3)]
for i in range(N):
  for j in range(N):
    d[(i+j)%3][c[i][j]] += 1

a=10**9
for c0 in range(C):
  for c1 in range(c0+1,C):
    for c2 in range(c1+1,C):
      s1,s2,s3,s4,s5,s6=0,0,0,0,0,0
      for c in range(C):
        s1 += d[0][c]*D[c][c0]+d[1][c]*D[c][c1]+d[2][c]*D[c][c2]
        s2 += d[0][c]*D[c][c0]+d[1][c]*D[c][c2]+d[2][c]*D[c][c1]
        s3 += d[0][c]*D[c][c1]+d[1][c]*D[c][c0]+d[2][c]*D[c][c2]
        s4 += d[0][c]*D[c][c1]+d[1][c]*D[c][c2]+d[2][c]*D[c][c0]
        s5 += d[0][c]*D[c][c2]+d[1][c]*D[c][c0]+d[2][c]*D[c][c1]
        s6 += d[0][c]*D[c][c2]+d[1][c]*D[c][c1]+d[2][c]*D[c][c0]
      a=min(a,s1,s2,s3,s4,s5,s6)
print(a)


Measured memory_bytes: 5620
h, w = map(int, input().split())
a = [input() for _ in range(h)]

row = [False]*h
col = [False]*w
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(h):
  if row[i]:
    for j in range(w):
      if col[j]:
        print(a[i][j], end="")
    print()

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


std::vector<bool> d(10,true);

bool chack(int n){
    bool res = true;
    while(n){
        int cur = n % 10;
        if(!d[cur])res = false;
        n /= 10;
    }
    return res;
}

int main()
{
    int n,k;
    std::cin >> n >> k;
    for(int i = 0; i < k; i++){
        int tmp;
        std::cin >> tmp;
        d[tmp] = false;
    }
    while(true){
        if(chack(n)){
            std::cout << n << std::endl;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n;
    cin>>n;
    for(ll i=sqrt(n);i>=1;i--){
        if(n%i==0){
            ll ii=n/i;
            cout<<ii-1+i-1;
            return 0;
        }
    }
	exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 5;
int ans,n,m,dfn[MXN],stk[MXN],top,bel[MXN],scc,inq[MXN],low[MXN],dfs_clock;
vector<int> G[MXN];
inline void tarjan(int x) {
	dfn[x]=low[x]=++dfs_clock; stk[++top]=x; inq[x]=1;
	for(auto w:G[x]) {
		if(!dfn[w]) {
			tarjan(w); low[x]=min(low[x],low[w]);
		} else if(inq[w]) low[x]=min(low[x],dfn[w]);
	}

	if(low[x]==dfn[x]) {
		int v=0;  ++scc;
		do {
			v=stk[top--];
			inq[v]=0;
			bel[v]=scc;
		} while(v!=x);
	}
}
int main() {
#ifdef iloi
	freopen("test.in","r",stdin);
#endif
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1,x;i<=n;++i) cin>>x,G[x+n].push_back(i),G[i].push_back(x+n);
	for(int i=1,x,y;i<=m;++i) cin>>x>>y,G[x].push_back(y),G[y].push_back(x);
	for(int i=1;i<=n*2;++i) 
		if(!dfn[i]) tarjan(i);
	for(int i=1;i<=n;++i) 
		if(bel[i]==bel[i+n]) ++ans;
	cout<<ans<<endl;
}

Measured memory_bytes: 17152
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long
const double pi = 3.141592653589793;

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//階乗
ll fact(ll a) {
	int ans = 1;
	for (int i = 1; i <= a; i++) {
		ans *= i;
	}
	return ans;
}

//コンビネーション
ll combi(ll a, ll b) {
	return fact(a) / (fact(b) * fact(a - b));
}

int main() {
	int x, y;
	cin >> x >> y;
	
	const int tsuru = 2;
	const int kame = 4;
	rep(i, x+1) {
		int leg = i * tsuru + (x - i) * kame;
		if (leg == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3536
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N, W = map(int, input().split())
    dp =[0] *(W+1)
    for i in range(N):
        w,v =map(int,input().split())

        for i in range(W,w-1,-1):
            dp[i] =max(dp[i],dp[i-w]+v)



    print(max(dp))





if __name__ == "__main__":
    main()


Measured memory_bytes: 66500
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30


def hurui(n):
    is_prime = [0] * (10**5)
    for i in range(2, n+1):
        is_prime[i] = 1
    for i in range(2, n+1):
        if is_prime[i] == 1:
            j = i*2
            while j <= n:
                is_prime[j] = 0
                j += i
    return is_prime

def main():
    n = int(input().strip())
    is_prime = hurui(n)
    ans = 1
    for i in range(2, n+1):
        if is_prime[i] == 1:
            c = 0
            for j in range(i, n+1):
                p = j
                while p % i == 0:
                    p //= i
                    c += 1
            ans *= (c+1)
            ans %= (10**9+7)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

itn N, M, A[10101];

int Y[20] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int X[20];
itn dp[10101];

void solve() {
    FOR(M) {
        X[A[i] - 1] = Y[A[i] - 1];
    }
    FOR(m, 9) {
        if (X[m] == 0)
            X[m] = INF;
    }

    FOR(n, 1, N + 1)
    dp[n] = -INF;
    FOR(n, 1, N + 1) {
        for (int m = 8; m >= 0; m--) {
            if (n - X[m] >= 0) {
                chmax(dp[n], dp[n - X[m]] + 1);
            }
        }
    }
    vector<int> ans;
    for (int n = N; n > 0;) {
        for (int m = 8; m >= 0; m--) {
            if (n - X[m] >= 0) {
                if (dp[n] == dp[n - X[m]] + 1) {
                    ans.eb(m + 1);
                    n -= X[m];
                    break;
                }
            }
        }
    }
    sort(all(ans), greater<int>());
    for (auto& x : ans)
        cout << x;
    cout << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    FOR(M)
    cin >> A[i];

    solve();
    return 0;
}


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

int main(void){
  int i, j, n, *a, v;

  scanf("%d",&n);
  a = malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d", &a[i]);

  for(i=0;i<n;i++){
    v = a[i];
    j = i-1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    for(j=0;j<n;j++){
      printf("%d",a[j]);
      if(j==n-1) printf("\n");
      else printf(" ");
    }
  }

  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

    int H, W, D;
    cin >> H >> W >> D;

    vector<pair<int, int>> vec(H*W);
    int tmp;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> tmp;
            tmp--;//0-indexed
            vec[tmp] = make_pair(i, j);
        }
    }

    vector<int> step_sum(H*W);
    for(int i = 0; i < D; i++){
        step_sum[i] = 0;
    }

    for(int i = D; i < H*W; i++){
        step_sum[i] = step_sum[i-D] 
        + abs(vec[i].first - vec[i-D].first) + abs(vec[i].second - vec[i-D].second);
    }


    int Q;
    cin >> Q;
    vector<pair<int, int>> LR(Q);
    int tL, tR;
    for(int i = 0; i < Q; i++){
        cin >> tL >> tR;
        tL--;
        tR--;
        LR[i] = make_pair(tL, tR);
    }

    for(int i = 0; i < Q; i++){
        cout << (step_sum[LR[i].second] - step_sum[LR[i].first]) << endl;
    }


    return 0;
}



Measured memory_bytes: 2944
from collections import deque

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

def calc(seq):
    points = 0
    for a,b,c,d in abcd:
        if seq[b-1]-seq[a-1]==c:
            points += d
    return points

q = deque()
q.append([1])
ans = 0
while q:
    head = q.popleft()
    if len(head)==N:
        pts = calc(head)
        ans = max(ans, pts)
    else:
        for i in range(head[-1], M+1):
            new = head + [i]
            q.append(new)

print(ans)

Measured memory_bytes: 16400
#include <iostream>
using namespace std;
int main(void){
    int N, K;
    int* hi;
    int count = 0;
    
    cin >> N >> K;
    
    hi = new int[N];
    
    for(int i = 0; i < N; i++){
        cin >> hi[i];
        if(hi[i] >= K){
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
    int64_t k;
    cin>>k;
    if(k%2==0 || k%5==0){
        cout<<-1<<endl;
        return 0;
    }
    int64_t ans=0;
    int q=0;
    while(1){
        q = (7+10*q)%k;
        ans ++;
        if(q==0)break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
typedef long long ll;
typedef unsigned long long ull;
/*
id: sadykhzadeh -> @Azer_Sadykhzadeh
Programming Language: (C++)
*/
#define qq2(x,y) cerr << (#x) << " = " << (x) << '\t' << (#y) << " = " << (y) << endl
#define qq(x) cerr << (#x) << " = " << (x) << endl
#define elif else if
#define pb push_back
#define ins insert
#define pow2(x) ((x)*(x))
#define mod(x, m) ((x) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define rus_lang setlocale(LC_ALL , "Russian")
#define F_READ ios_base::sync_with_stdio(false);cin.tie(0)
#define MOD 1000000007
#define line cerr << endl << endl << "========================" << endl
#define COUT(x) return cout << (x) << endl, 0;
#define stop return 0
using namespace std;
#include <bits/stdc++.h>
ll T1 = clock();
void timer(){rus_lang; ll T2(clock());cerr<<"Время: "<<(T2-T1)/1000.<<" секунд."<<endl;
cerr << "Автор: Азер Садыхзаде";}
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

int main(){
    ll a, b;
    cin >> a >> b;
    if(1 <= a && 1 <= b && a <= 9 && b <= 9) cout << a * b << endl;
    else cout << -1 << endl;
}


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

int main(void){
    int x[100] = {1,2,3,5,6,9,10,13,17};
    int a;
    cin >> a;
    for(int i=0;i<9;i++){
        if(a==x[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#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;
using ll = long long;
using p = pair<int, int>;

int f(int a, int b) {
  return max(to_string(a).length(), to_string(b).length());
}

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

  int minv = 1000000000;

  rep2(i, sqrt(n)) {
    if (n % i == 0) minv = min(minv, f(i, n / i));
  }

  cout << minv << endl;

  return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define printpair(v) for(auto val: v){cout<<val.fi<<":"<<val.se<<", ";}cout<<endl;
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
const int mod = 998244353;
#define sz size()
const int inf = 1e18;
int n,w;
int warr[105],varr[105];
int tv;
int dp[105][100005];
int f(int i,int currv){
    if(currv>=tv){
        return 0;
    }
    if(i==n){
        return inf;
    }
    if(dp[i][currv]!=-1){
        return dp[i][currv];
    }
    int lol;
    int ans=inf;
    lol=f(i+1,currv+varr[i]);
    if(lol!=inf){
        ans=min(ans,lol+warr[i]);
    }
    lol=f(i+1,currv);
    if(lol!=inf){
        ans=min(ans,lol);
    }

        dp[i][currv]=ans;

    return ans;

}
void solve() {
    cin>>n>>w;
    int totv=0;
    rep(i,0,n){
        cin>>warr[i]>>varr[i];
        totv+=varr[i];
    }

    int hi,lo,mid;
    hi=totv;
    lo=0;
    while(lo<=hi){
        mid=(hi+lo)/2;
        tv=mid;
        clr(dp,-1);
        if(f(0,0)<=w){
            lo=mid+1;

        }
        else{

            hi=mid-1;
        }
    }
    cout<<lo-1<<endl;



}

int32_t main(){
    fastIO
#ifndef ONLINE_JUDGE
    freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin);
#endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 85692
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
INF=10**9
dp=[[-INF for i in range(N+1)] for j in range(N+1)]
dp[0][0]=0
AI=[]

for i in range(N):
    AI.append([A[i],i+1])
    
AI.sort()
AI.reverse()

for i in range(1,N+1):
    a=AI[i-1][0]
    I=AI[i-1][1]
    for j in range(N+1):
        if j==0:
            dp[i][j]=dp[i-1][j]+abs(I-(N+1-i))*a
        elif j==i:
            dp[i][j]=dp[i-1][j-1]+abs(I-j)*a
        else:
            dp[i][j]=max(dp[i-1][j-1]+abs(I-j)*a,dp[i-1][j]+abs(I-(N+1-(i-j)))*a)
ans=0
for i in range(N+1):
    ans=max(ans,dp[N][i])

print(ans)

Measured memory_bytes: 102224
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static int count;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        List<List<Integer>> g = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            g.add(new ArrayList<>());
        }

        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            g.get(a - 1).add(b - 1);
            g.get(b - 1).add(a - 1);
        }

        dfs(0, new boolean[n], g);

        System.out.println(count);
    }

    private static void dfs(int num, boolean[] visited, List<List<Integer>> graph) {
        visited[num] = true;
        boolean done = true;
        for (int i = 0; i < graph.size(); i++) {
            if (visited[i] == false) {
                done = false;
                break;
            }
        }
        if (done) {
            count++;
            return;
        }

        List<Integer> l = graph.get(num);
        for (Integer i : l) {
            if (visited[i]) {
                continue;
            }
            dfs(i, visited, graph);
            visited[i] = false;
        }
    }
}


Measured memory_bytes: 21844
from math import sqrt, ceil
n = int(input())

ub = int(ceil(sqrt(n)))

factors = []
for i in range(1,ub+1):
        if n % i == 0:
                factors.append(i)
                if n//i != i:
                        factors.append(n//i)
      
ans = 10**18
factors.sort()
for x in factors:
        y = n // x
        ans = min(ans, y-1+x-1)
  


print(ans)


Measured memory_bytes: 3272
#include <iostream>
#include <stack>
#include <algorithm>
#include<string.h>
using namespace std;
typedef pair<int,int>pa;
int ma[42][42];
int main(){
    while(true){
        int a,b,x,y;
        int n;
        cin>>a>>b;
        if(a==0)break;
        cin>>n;
        memset(ma,0,sizeof(ma));
        while(n--){
            cin>>x>>y;x--;
            ma[b-y][x]=-1;
        }
        ma[b-1][0]=1;
        stack<pa>stk;
        stk.push(pa(0, b-1));
        while(stk.size()){
            pa p=stk.top();
            stk.pop();
            x=p.first,y=p.second;
            if(x+1<a&&ma[y][x+1]!=-1){
                ma[y][x+1]+=1;
                stk.push(pa(x+1,y));
            }
            if(y-1>-1&&ma[y-1][x]!=-1){
                ma[y-1][x]+=1;
                stk.push(pa(x,y-1));
            }
            
        }
        
        cout<<ma[0][a-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int main() {
  int N;
  std::vector<int> a[2];

  cin >> N;
  a[0].resize(N);
  a[1].resize(N);
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> a[i][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    int tmp = 0, k = 0;
    for (int j = 0; j < N; ++j) {
      tmp += a[k][j];
      if (i == j) {
        k++;
        tmp += a[k][j];
      }
    }

    ans = std::max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  stack<char> st;
  int ans = 0;
  for(auto v : s){
  	if(st.empty()){
  		st.push(v);
  	}else{
  		if(v == '0' && st.top() == '1'){
  			st.pop();
  			ans += 2;
  		}else if(v == '1' && st.top() == '0'){
  			st.pop();
  			ans += 2;
  		}else{
  			st.push(v);
  		}
  	}
  }
  cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
	int K;
	int A;
	int B;
	cin >> K >> A >> B;
	int flag = 0;
	
	
	for(int i = A;i<=B;i++){
		int j = i;
		if(j%K==0){
			flag++;
		}
		
	}
	
	if(flag>0){
		std::cout << "OK"  <<  std::endl;
	}else{
		std::cout << "NG"  <<  std::endl;
	}
  
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string s = "aiueo";
    char c; cin >> c;

    for(int i=0; i<5; ++i){
        if(c == s[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }

    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=6050;
//↑templete
string S[3]={};
int is_match[3][3][SIZE]={};
bool check(int a, int b, int x, int y){ //aのx+y文字目と、bのy文字目の一致を調べる

    if(S[a].length()<=x+y || S[b].length()<=y)
        return 1;
    if(S[a][x+y]=='?' || S[b][y]=='?')
        return 1;
    if(S[a][x+y]==S[b][y])
        return 1;
    
    return 0;
}
int match(int a, int b, int x){    //aのx文字目以降をbとマッチングさせられるか？

    if(is_match[a][b][x]>=0)
        return is_match[a][b][x];

    for(int i=0;i<S[b].length();i++){
        if(!check(a, b, x, i))
            return is_match[a][b][x]=0;
    }

    return is_match[a][b][x]=1;
}
signed main(){
    
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            for(int k=0;k<SIZE;k++)
                is_match[i][j][k]=-1;

    cin>>S[0]>>S[1]>>S[2];
    vint order={0, 1, 2};
    int ans=INF;
    do{

        int a=order[0], b=order[1], c=order[2];
        string &A=S[a], &B=S[b], &C=S[c];

        for(int x=0;x<=2000;x++){
            for(int y=0;y<=2000;y++){

                if(!match(a, b, x) || !match(b, c, y) || !match(a, c, x+y))
                    continue;
                
                ans=min(ans, int(max({A.length(), x+B.length(), x+y+C.length()})));
            }
        }

    }while(next_permutation(order.begin(), order.end()));

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 512
import heapq
import sys
input = sys.stdin.readline

INF = 10**18

Q = int(input())
count = 0
s = 0

upper = [INF]
lower = [INF]
heapq.heapify(upper)
heapq.heapify(lower)

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0]==1:
        count += 1
        s += q[2]
        a = q[1]
        u = heapq.heappop(upper)
        l = -heapq.heappop(lower)
        if count%2==0:
            if a<l:
                heapq.heappush(lower,-a)
                heapq.heappush(upper,l)
                heapq.heappush(upper,u)
                s += l-a
            else:
                heapq.heappush(lower,-l)
                heapq.heappush(upper,a)
                heapq.heappush(upper,u)
                s += a-l
        else:
            if a<=u:
                heapq.heappush(lower,-l)
                heapq.heappush(lower,-a)
                heapq.heappush(upper,u)
                s += max(0,l-a)
            else:
                heapq.heappush(lower,-l)
                heapq.heappush(lower,-u)
                heapq.heappush(upper,a)
                s += a-u

    else:
        x = -heapq.heappop(lower)
        print(x,s)
        heapq.heappush(lower,-x)

Measured memory_bytes: 96472