akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int d[100][100];
//main
signed main(){
  int N,D;cin>>N>>D;
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>d[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int res=0;
      for(int k=0;k<D;k++)res+=abs(d[i][k]-d[j][k])*abs(d[i][k]-d[j][k]);
      for(int a=0;a<=res;a++)if(a*a==res)ans++;
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int a[101], n;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	REP(i, 0, n) cin >> a[i];

	sort(a, a + n);
	cout << a[n - 1] - a[0] << endl;

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a = [0]*n
seen = [0]*n
flg = 0
ans = 0
for i in range(m):
  tmp = list(map(int,input().split()))
  if seen[tmp[0]-1] == 0:
    a[tmp[0]-1] = tmp[1]
    seen[tmp[0]-1] = 1
  else:
    if a[tmp[0]-1] == tmp[1]:
      pass
    else:
      flg = 1
if n != 1 and a[0] == 0 and seen[0] == 1:
  flg = 1
if flg == 1:
  print(-1)
else:
  if a[0] == 0 and n != 1:
    a[0] = 1
  print(''.join(map(str, a)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
//const long long INF = 10000000000;
int N,M,L;
int A[45000],B[45000],C[45000];
long long road[301][301];//最短距離を入れる ない場合は-1
int less_than_L[301][301];

void warshall_floyd(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(road[i][k]>0&&road[k][j]>0){
                    if(road[i][j]<0)road[i][j] = road[i][k] + road[k][j];
                    else road[i][j] = min(road[i][j], road[i][k]+road[k][j]);
                }
            }
        }
    }
    return;
}

void solve(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(less_than_L[i][k]>0&&less_than_L[k][j]>0){
                    if(less_than_L[i][j]==0)less_than_L[i][j] = less_than_L[i][k] + less_than_L[k][j];
                    else less_than_L[i][j] = min(less_than_L[i][j], less_than_L[i][k]+less_than_L[k][j]);
                }
            }
        }
    }
    return;
}

int main(void){
    cin>>N>>M>>L;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            road[i][j] = -1;
            if(i==j)road[i][j] = 0;
        }
    }
    rep(i,M){
        int A,B,C;cin>>A>>B>>C;
        A--;B--;
        road[A][B] = C;
        road[B][A] = C;
    }
    warshall_floyd();
    rep(i,N){
        rep(j,N){
            less_than_L[i][j] = 0;
            if(road[i][j]<=L&&road[i][j]>0)less_than_L[i][j]=1;
        }
    }
    int Q;
    cin>>Q;
    solve();
    rep(i,Q){
        int s,t;cin>>s>>t;
        s--;t--;
        cout<<less_than_L[s][t]-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import bisect

n = int(input())
as_ = list(map(int, input().split()))
bs_ = list(map(int, input().split()))
cs_ = list(map(int, input().split()))

as_.sort()
bs_.sort()
cs_.sort()

ans = 0
for b in bs_:
  ans += bisect.bisect_left(as_, b) * (n-bisect.bisect_right(cs_, b))
print(ans)

Measured memory_bytes: 23360
n = input()
s = [raw_input().strip() for _ in xrange(n)]
dic = {'M':0,'A':0,'R':0,'C':0,'H':0}
for i in s:
	if i[0] in "MARCH":
		dic[i[0]] += 1
key = "MARCH"
ans = 0
for i in range(5):
	for j in range(i+1,5):
		for k in range(j+1,5):
			ans += (dic[key[i]]*dic[key[j]]*dic[key[k]])
print ans


Measured memory_bytes: 8180
import io.StdIn.readLine


object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine().toInt

    var t, a = BigDecimal(1.0)

    for (i <- 1 to n) {
      val Array(ti, ai) = readLine().split(' ').map(BigDecimal(_))
      val x = (t / ti).setScale(0, BigDecimal.RoundingMode.CEILING)
      val y = (a / ai).setScale(0, BigDecimal.RoundingMode.CEILING)
      val times = if (x < y) y else x
      t = ti * times
      a = ai * times
    }

    println((t + a).toBigInt)
  }
}


Measured memory_bytes: 33268
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
    char a;
    cin>>a;
    switch(a){
        case 'A':
            cout<<'T'<<endl;
            break;
        case 'C':
            cout<<'G'<<endl;
            break;
        case 'G':
            cout<<'C'<<endl;
            break;
        case 'T':
            cout<<'A'<<endl;
            break;
    }
    return 0;
}



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

int main()
{
    int n,k,ans=0;
    cin>>n>>k;
    string s[n];
    for(int i=0;i<n;i++)
        cin>>s[i];
    sort(s,s+n);
    for(int i=0;i<n;i++)
        cout<<s[i];

    return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi a(n);
    rep(i, n) cin >> a[i];
    priority_queue<int> q;
    rep(i, n) q.push(a[i]);
    rep(i, m) {
        int p = q.top(); q.pop();
        q.push(p/2);
    }
    ll sum = 0;
    while (!q.empty()) {
        int p = q.top(); q.pop();
        sum += p;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;

    int h=0, m=n;

    while(n>0){
        h+=n%10;
        n/=10;
    }

    if(m%h==0){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))
    
    max_num = max(num, avg, max(data))
    dp = [[[0 for i in range(max_num ** 2 + 1)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(max_num ** 2 + 1):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 95324
L, R = map(int, input().split())

mod = 2019
res = 2019

if R - L < 2019:
    for i in range(L % mod, L % mod + (R - L) + 1):
        for j in range(L % mod, L % mod + (R - L) + 1):
            if i == j:
                continue
            res = min(res, ((i % mod) * (j % mod)) % mod)
else:
    res = 0

print(res)

Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int ave = (a + b) / 2;
		if((a + b) % 2 != 0) {
			ave++;
		}
		System.out.println(ave);
	}
}

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

int main()
{
int i;
int a;
int b;

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

	cin >> a;
	cin >> b;

	if( b >= 100 )
		a = a * 1000 + b;
	else if( b >= 10 )
		a = a * 100 + b;
	else
		a = a * 10 + b;
	
	i = (int) sqrt( (double) a );

	if( i * i == a )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}






Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int r, c;
    long long x[101][101];
    cin >> r >> c;
    for (int yoko = 0; yoko < r; yoko++) {
        x[yoko][c] = 0;
        for (int tate = 0; tate < c; tate++) {
            cin >> x[yoko][tate];
            x[yoko][c] += x[yoko][tate];
        }
    }
    for (int tate = 0; tate <= c; tate++) {
        x[r][tate] = 0;
        for (int yoko = 0; yoko < r; yoko++) {
            x[r][tate] += x[yoko][tate];
        }
    }
    for (int yoko = 0; yoko <= r; yoko++) {
        for (int tate = 0; tate <= c; tate++) {
            if (tate<c) {
                cout << x[yoko][tate] << " ";
            }
            else {
                cout << x[yoko][tate];
            }
        }
        cout << endl;
    }
    return 0;
}

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

vector<ll> a, b;

ll ceil(ll n, ll m) {
    return n % m == 0 ? n / m : n / m + 1;
}

vector<vector<ll>> dp;

ll solve(ll h, ll i, ll n) {
    if (h <= 0) return 0;
    if (i == n - 1) return ceil(h, a[i]) * b[i];
    if (dp[i][h] != -1) {
        return dp[i][h];
    }
    dp[i][h] = min(solve(h - a[i], i, n) + b[i], solve(h, i + 1, n));
    return dp[i][h];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h, n;
    cin >> h >> n;
    dp = vector<vector<ll>>(n, vector<ll>(h + 1, -1));
    a = vector<ll>(n);
    b = vector<ll>(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    cout << solve(h, 0, n);
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 110

int n, x;
int a[MAX];

bool cal(int m) {
	int cnt = x;
	for (int i = 0; i < m; i++) {
		cnt -= a[i];
	}
	if (m == n) return cnt == 0;
	return cnt >= 0;
} 

int32_t main() {
	cin >> n >> x;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);

	int x = 0, y = n + 1, ans;
	while (x < y) {
 		int m = x + (y - x) / 2;
 		if (cal(m)) {
 			ans = m;
 			x = m + 1;
 		} else {
 			y = m;
 		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

bool valid(int i1, int j1, int i2, int j2) {
    return (i2 <= i1 && j2 <= j1) || (i1 <= i2 && j1 <= j2);
}

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

    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    rep(i1, n) {
        rep(j1, m) {
            rep(i2, n) {
                rep(j2, m) {
                    if (s[i1][j1] == '#' && s[i2][j2] == '#' && !valid(i1, j1, i2, j2)) {
                        cout << "Impossible" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << "Possible" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer n = sc.nextInt();
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer total = 0;
		
		for(int i = 1; i <= n; i++) {
			int sum = sumOfDigits(i);
			if(sum >= a && sum <= b) {
				total += i;
			}
		}
		System.out.println(total);
	}
	
	//各桁の和を計算するメソッド
	public static Integer sumOfDigits(Integer n) {
		Integer sum = 0;
		while(n > 0) {
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[110][100010];
vector <pair<int, int>> wv;

signed main()
{
	int n, w;
	cin >> n >> w;
	//int k=0; // 最大value總和 
	for (int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		wv.emplace_back(a, b); //wv
		//k+=b;
	}
	int MAX = w+100;
	for (int i = 0; i < 100010; i++){
		dp[0][i] = MAX;
	}
	for (int i = 0; i < 110; i++){
		dp[i][0] = MAX;
	}
	int cnt1 = 0, cnt2=0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= 100010; j++){ 
			if (wv[i-1].second >= j){
				dp[i][j] = min(dp[i-1][j], wv[i-1].first);
			}else{
				dp[i][j] = min(dp[i-1][j-wv[i-1].second]+wv[i-1].first, dp[i-1][j]);
			}
		}
	}
	/*
	for (int i = 1; i <= 110; i++)
		cout << setw(4) << i << " ";
	cout << "\n";
	for (int i = 1; i <=n; i++){
		for (int j = 1; j <= 110; j++){
			cout << setw(4)<<dp[i][j] <<" "; 
		}
		cout << "\n";
	}
	*/
	for (int i = 1; i < 100010; i++){
		if (dp[n][i+1]>w){
			cout << i << "\n";
			break;
		}
	}
} 

Measured memory_bytes: 84224
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N; cin >> N; string S[N];
  rep(i, N){
    cin >> S[i];
  }
  int ans[26];
  rep(i, 26){
    ans[i] = inf;
  }
  rep(i, N){
    int cnt[26] = {0};
    rep(j, S[i].size()){
      cnt[S[i][j] - 'a']++;
    }
    rep(j, 26){
      ans[j] = min(cnt[j], ans[j]);
    }
  }
  rep(i, 26){
    rep(j, ans[i]){
      cout << (char) (i + 'a');
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)

def dfs(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= a[N-1] + 1:
    return dfs(N-1, X-1)
  else:
    return p[N-1] + 1 + dfs(N-1, X-a[N-1]-2)
  
print(dfs(N, X))


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

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

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

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

signed main(){
	int l,n,x[400010],ma = 0;
	cin >> l >> n;
	for(int i = 0;i < n;i++) cin >> x[i];
	for(int t = 0;t < 2;t++){
		x[n] = l;
		for(int i = n + 1;i <= n * 2;i++) x[i] = x[i - n - 1] + l;
		//for(int i = 0;i <= 2 * n;i++) cout << x[i] << " ";
		//cout << endl;
		int sum = x[n] - x[0];
		for(int i = 0;i < n;i++){
			//cout << sum << endl;
			chmax(ma,sum);
			if(i != n - 1){
				sum -= x[i + 1] - x[i];
				sum -= 2 * (x[i * 2 + 1] - x[i + 1]);
				sum += 2 * (x[n + i + 1] - x[i * 2 + 2]);
			}
		}
		for(int i = 0;i < n;i++) x[i] = l - x[i];
		//cout << ma << endl;
		sort(x,x + n);
	}
	cout << ma << endl;
}

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

int main() {
  
  string N;
  cin>>N;
  
  if(N=="110"||N=="101"||N=="011"){
    cout<<2<<endl;
  }
  
  if(N=="000"){
    cout<<0<<endl;
  }
  
   if(N=="111"){
    cout<<3<<endl;
  }
  
   if(N=="100"||N=="010"||N=="001"){
    cout<<1<<endl;
  }
 
}
  


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n, m;
int par[100001], ran[100001];
int p[100001];

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

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(ran[x] < ran[y]) {
    par[x] = y;
  }else {
    par[y] = x;
    if(ran[x] == ran[y]) ran[x]++;
  }
}

signed main() {
  cin >> n >> m;
  rep(i, 0, n) cin >> p[i], par[i] = i;
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    unite(x, y);
  }
  int ans = 0;
  rep(i, 0, n) {
    if(find(p[i]) == find(i + 1)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
S = input()

YYMM = []
MMYY = []

for y in range(100):
    for m in range(1,13):
        YYMM.append("%02d%02d"%(y, m))

for m in range(1, 13):
    for y in range(100):
        MMYY.append("%02d%02d"%(m, y))

if S in YYMM and S in MMYY:
    print('AMBIGUOUS')
elif S in YYMM:
    print('YYMM')
elif S in MMYY:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int ret = 0;
    for(int i=0; i<10; ++i){
        int s;
        cin >> s;
        ret += s;
    }
    cout << ret << endl;

    return 0;
}

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




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		long n = sc.nextLong();

		long ans = n;
		for(long i = 1; i*i <= n;i++){
			if(n % i == 0){
				long mm = Math.max(i, n/i);
				long keta = String.valueOf(mm).length();
				ans = Math.min(ans, keta);
			}
		}
		System.out.println(ans);



	}
}

class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  sort(ALL(p));

  int x1 = distance(p.begin(), upper_bound(ALL(p), a));
  int x2 = distance(upper_bound(ALL(p), a), upper_bound(ALL(p), b));
  int x3 = distance(upper_bound(ALL(p), b), p.end());

  cout << min(x1, min(x2, x3)) << endl;
}

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

int main()
{
    int x;
string S;
cin>>x;
cin>>S;
for(int i=0;i<S.size();i++)
{

if(S[i]+x>'Z'){
    int y='Z'-S[i];
    int r=x-y;
  S[i]=static_cast<char>('A'+r-1);}
else
S[i]=static_cast<char>(S[i]+x);


}
cout<<S;
    return 0;

}


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


using namespace std;

int h, w, i, j, dp[20004][20004], N=1e9+7;
string s[20005];
int main()
{
    cin>>h>>w;
    for(i=0;i<h;i++)
        cin>>s[i];
        dp[0][0]=1;
     for(i=0;i<h;i++)
        {for(j=0;j<w;j++)
            {if(i>0  && s[i-1][j]=='.')
            dp[i][j]+=dp[i-1][j]; dp[i][j]=dp[i][j]%N;

        if(j>0 && s[i][j-1]=='.')
            dp[i][j]+=dp[i][j-1]; dp[i][j]=dp[i][j]%N;}}

        cout<<dp[h-1][w-1];

    return 0;
}


Measured memory_bytes: 79488
#include <stdio.h>

int main(void)
{
	char a[4];
	scanf("%s",&a);
	if(a[0]!=a[1]&&a[1]!=a[2]&&a[2]!=a[0]){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll H,W,K;
string s[500];
ll m[500][500];

int main(){
    cin >> H >> W >> K;
    for(int i=0;i<H;i++) cin >> s[i];
    ll p = 0;
    for(int i=0;i<H;i++){
        bool f = false;
        for(int j=0;j<W;j++){
            if(s[i][j] == '#'){
                f = true;
                p++;
            }
            if(!f) continue;
            m[i][j] = p;
        }
    }
    for(int i=0;i<H;i++){
        for(int j=W-2;j>=0;j--){
            if(m[i][j]==0) m[i][j] = m[i][j+1];
        }
    }
    for(int i=1;i<H;i++){
        for(int j=0;j<W;j++){
            if(m[i][j] == 0) m[i][j] = m[i-1][j];
        }
    }
    for(int i=H-2;i>=0;i--){
        for(int j=0;j<W;j++){
            if(m[i][j] == 0) m[i][j] = m[i+1][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout << m[i][j];
            if(j != W-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
  long long n,ni=0,yon=0,ichi=0,a;
  std::cin >> n;
  rep(i,n){
    std::cin >> a;
    if(a%4==0) yon++;
    if(a%2==0) ni++;
    else ichi++;
  }
  if(ni==n) std::cout << "Yes" << std::endl;
  else if(n<=3&&yon>0) std::cout << "Yes" << std::endl;
  else if(ichi<=yon) std::cout << "Yes" << std::endl;
  else if(ichi+yon==n&&ichi==yon+1) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long n = scan.nextLong();
		long k = scan.nextLong();
		long min = n%k;
		long a = k-min;

		if(min > a) {
			min =a;
		}

		System.out.println(min);
		scan.close();
	}

}


Measured memory_bytes: 26988
n = gets.chop
s = gets.split(" ").map(&:to_i)

ssort = s.sort

count = 0
if ssort == s
  puts "YES"
else
  ssort.each_with_index do |i,index|
    if i != s[index]
      count += 1
    end
  end

  if count != 2
    puts "NO"
  else
    puts "YES"
  end
end



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

using namespace std;

#define ll long long

int main() {
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
    int red,green,blue,k;
    bool flag=0;
    cin>>red>>green>>blue;
    cin>>k;
    while(green<=red&&k>0){
    	green*=2;
    	k--;
	}
	while(blue<=green&&k>0){
		blue*=2;
		k--;
	}
	if(blue>green&&green>red)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

//blue card>green card>red card


Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K,Q;
  cin >> N >> K >> Q;
  vector<ll> A(N);
  REP(i,Q){
      ll ai;
      cin >> ai;
      A[ai-1]++;
  }
  
  REP(i,N){
    cout << ((A[i]+K-Q > 0) ? "Yes" : "No") << "\n";
  }
  return 0;
}


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

int N,M,i,cnt;

int main(void){
  cin >> N >> M;
  int a[M];
  for(i=0;i<M;i++){
    cin >> a[i];
  }
  int b[N+1];
  for(i=0;i<=N;i++){
    b[i]=1;
  }
  for(i=0;i<M;i++){
    b[a[i]]=0;
  }
  int dp[N+1];
  for(i=0;i<=N;i++){
    dp[i]=0;
  }
  dp[0]=1;
  if(b[0]==1){
    dp[1]=1;
  }

  for(i=2;i<=N;i++){
    if(b[i-1]==1){
      dp[i] = dp[i] + dp[i-1];
    }
    if(b[i-2]==1){
      dp[i] = dp[i] + dp[i-2];
    }
    dp[i] = dp[i]%1000000007;
  }
  cnt = dp[N]; 
  
  
  printf("%d\n",cnt);
  return 0;
}


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

ll a, b, x, ans;

int main(){
    cin >> a >> b >> x;
    ans = b/x - a/x;
    if(a%x == 0)    ++ans;
    cout <<  ans << endl;
}

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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  
  if (n >= m) {
    cout << '0' << endl;
    return 0;
  }
  
  int x[100005];
  for (int i = 0; i < m; i++)
    cin >> x[i];
  
  sort(x, x+m);
  
  int dif[100005];
  for (int i = 0; i < m-1; i++)
    dif[i] = x[i+1]-x[i];
  
  sort(dif, dif+m-1);
  
  int sum = 0;
  for (int i = 0; i < m-n; i++)
    sum += dif[i];
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1024
a, b = map(int, input().split())
count = 0
for x in range(1,10) :
    for y in range(0,10) :
        for z in range(0, 10) :
            if (a <= (10001 * x + 1010 * y + 100 * z)) and ((10001 * x + 1010 * y + 100 * z) <= b) :
                count += 1
print(count)

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main()
{
  int m, f, r;

  cin >> m >> f >> r;
  
  while ( m != -1 || f != -1 || r != -1 )
    {
      if ( m == -1 || f == -1 )
        {
          cout << "F" << endl;
        }
      else if ( m + f >= 80 )
        {
          cout << "A" << endl;
        }
      else if ( m + f >= 65 )
        {
          cout << "B" << endl;
        }
      else if ( m + f >= 50 )
        {
          cout << "C" << endl;
        }
      else if ( m + f >= 30 )
        {
          if ( r >= 50 )
            cout << "C" << endl;
          else
            cout << "D" << endl;
        }
      else
        cout << "F" << endl;
      
      cin >> m >> f >> r;
    }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=100+5;

int main(){
    GO();
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0){
        if(k%2==0){
            cout<<x<<"\n";
        }
        else{
            cout<<d<<"\n";
        }
        return 0;
    }
    ll mi;
    if(x>0){
      if(k%2==0)
      mi=x;
      else
        mi=min(llabs(x+d),llabs(x-d));
      ll F= x/d;
      if(k>F){
        k-=F;
        x= x%d;
        if(k%2==0){
        mi=min(mi,x);
        x-=d;
        x-=d;
        mi=min(mi,llabs(x));
        }
        else{
        x-=d;
        mi=min(mi,llabs(x));
        }
      }
      else if(k==F){
        k-=F;
        x%=d;
        mi=min(mi,x);
      }
      else{
        x= x- k*d;
        mi=min(mi,x);
      }
    }
    else{
        if(k%2==0)
        mi=llabs(x);
        else
        mi=min(llabs(x+d),llabs(x-d));

        ll F= llabs(x/d);
        if(k>F){
            x%=d;
            k-=F;
            if(k%2==0){
                mi=min(mi,llabs(x));
                x+=d;
                x+=d;
                mi=min(mi,llabs(x));
            }
            else{
                x+=d;
                mi=min(mi,llabs(x));
            }

        }
        else if(k==F){
            x%=d;
            mi=min(mi,llabs(x));
        }
        else{
            x= x+k*d;
            mi=min(mi,llabs(x));
        }

    }
    cout<<mi<<"\n";

}





































































































































































































Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef long long int ll;
const ll MOD=1000000007;

ll n,k;
ll dp[1001][1001]={};

int main(){
	scanf("%lld %lld",&n,&k);
	if(n>k) printf("0\n");
	else
	printf("1\n");
}


Measured memory_bytes: 3172
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_set>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	int N, H, W;
	cin >> N >> H >> W;
	print((N-W+1)*(N-H+1));
}

Measured memory_bytes: 3592
import kotlin.comparisons.*

data class Point(val x: Int, val y: Int)

fun readPoint(): Point {
    val (x, y) = readLine()!!.split(' ').map(String::toInt)
    return Point(x, y)
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val red = Array(n) { readPoint() }
        .sortedWith(compareByDescending(Point::y).thenBy(Point::x))
        .toMutableList()
    val pairs = Array(n) { readPoint() }
        .sortedWith(compareBy(Point::x).thenByDescending(Point::y))
        .count { b ->
            val i = red.indexOfFirst { it.x < b.x && it.y < b.y }
            if (i != -1) {
                red.removeAt(i)
                true
            } else {
                false
            }
        }
    println(pairs)
}


Measured memory_bytes: 38176
import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]
C = [w for w, y in enumerate(Y) if y == maxY]

ans = maxX + maxY
if len(R) * len(C) <= M:
    blank = set((r, c) for r in R for c in C)
    blank -= set(bomb)
    if len(blank) == 0:
        ans -= 1
print(ans)


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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        double[] v = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
        Array.Sort(v);
        double ans = v[0];
        for (int i = 1; i < n; i++)
        {
            ans = (ans + v[i]) / 2;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		unsigned temp;
		cin >> temp;
		for (int b = 0; b < 32; b++) {
			if (temp & 0x01)
				break;
			temp = temp >> 1;
			sum += 1;
		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
K, N = (int(x) for x in input().split())
A = list(map(int, input().split()))

A.sort()
D = []
D.append(K - max(A) + min(A))

for i in range(0, N-1):
    D.append(A[i+1] - A[i])

print(K - max(D))

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

#define for_(i,a,b) for(int i=a;i<b;++i)

int N, W, H;

int main() {
	cin >> N >> W >> H;
	vector< pair< int, int > > xp, yp;
	
	for_(i,0,N) {
		int x, y, w; cin >> x >> y >> w;
		xp.push_back(make_pair(x-w, x+w));
		yp.push_back(make_pair(y-w, y+w));
	}
	
	sort(xp.begin(), xp.end());
	sort(yp.begin(), yp.end());
	
	int xe = 0, ye = 0;
	for_(i,0,N) {
		if (xe >= xp[i].first) xe = max(xe, xp[i].second);
		if (ye >= yp[i].first) ye = max(ye, yp[i].second);
	}
	
	bool fx = (xe >= W), fy = (ye >= H);
	cout << (fx || fy ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2908
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[][] ab=new int[n][2];
		int time=0;
		ArrayList<Integer> c=new ArrayList<Integer>();
		for(int i=0;i<n;i++){
			ab[i][0]=sc.nextInt();
			ab[i][1]=sc.nextInt();
		}
		Arrays.sort(ab,(a,b)->Integer.compare(a[1],b[1]));

		for(int i=0;i<n;i++){
				time+=ab[i][0];
				if(time>ab[i][1]){
					System.out.println("No");
					return;
				}
		}
		System.out.println("Yes");
	}
		
}

Measured memory_bytes: 109204
#include <bits/stdc++.h>
using namespace std;
long long hhhh(vector<long long> a,vector<long long> b,long long c){
  int y = a.size();
  long long d = 0;
  for(int i = 0;i < y;i++){
    long long s = b.at(i);
    long long j = c / a.at(i);
    long long zeroa = 0;
    d += max(s-j,zeroa);
  }
  return d;}

int main() {
  long long n,k;
  cin >> n >> k;
  vector<long long> h(n);
  for(int i = 0;i < n;i++){
    cin >> h.at(i);}
  vector<long long> t(n);
  for(int i = 0;i < n;i++){
    cin >> t.at(i);}
  sort(h.begin(),h.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  long long ng = -1;
    long long ok = 1000000000000;
  while(abs(ng-ok) > 1){
    long long mid = (ng+ok)/2;
    if(hhhh(t,h,mid)<=k)ok = mid;
    else{ng = mid;}
  }
  cout << ok << endl; 
}

Measured memory_bytes: 6552
#include <iostream>

using namespace std;

int euclidean_gcd(int a, int b) {
  if(a < b) return euclidean_gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int k;
  int sum = 0;
  cin >> k;
  
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        sum += euclidean_gcd(euclidean_gcd(a, b), c);
      }
    }
  }
  
  cout << sum;
  
  return 0;
}


Measured memory_bytes: 3164
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int r=gi();

	   
	    System.out.print(3*r*r);

//        if ((x.charAt(0)==x.charAt(1) && x.charAt(2)==x.charAt(3) && x.charAt(0)!=x.charAt(2))
//        || (x.charAt(0)==x.charAt(2) && x.charAt(1)==x.charAt(3) && x.charAt(0)!=x.charAt(1))
//        || (x.charAt(0)==x.charAt(3) && x.charAt(2)==x.charAt(1) && x.charAt(0)!=x.charAt(2))) {
//        	System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n),ans;
    for(int i = 0;i < n;i ++){
        cin >> b[i];
    }  
    while(b.size()){
        bool delP = false;
        for (int i = b.size()-1;i >= 0;i --){
            if(b[i]==i+1) {
                delP=true;
                ans.push_back(b[i]);
                b.erase(b.begin()+i);
                break;
            }
        }
        if(!delP) {cout << -1 << endl;return 0;}
    }
    for (int i = n-1;i >= 0;i --){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
    int year, month, day;
    char c1, c2;
    cin >> year >> c1 >> month >> c2 >> day;

    if (year >= 2019 && month >= 5) {
        cout << "TBD";
    } else {
        cout << "Heisei";
    }
}

Measured memory_bytes: 256
from itertools import tee
N = int(input())
w0, w1 = tee((input() for _ in range(N)), 2)

words = {next(w1)}
flag = 'Yes'
for a,b in zip(w0,w1):
  if a[-1] != b[0] or b in words:
    flag = 'No'
  words.add(b)

print(flag)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define F(i, n) for (i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b, k, i;
  bool flag = false;
  cin >> k;
  cin >> a >> b;
  for (i = a; i <= b; i++)
  {
    if (i % k == 0)
    {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3628
from collections import deque


def nearlist(N):  # 隣接リスト
    NEAR = [set() for _ in range(3 * N)]
    for a, b in uv:
        a, b = 3 * (a - 1), 3 * (b - 1)
        NEAR[a].add(b + 1)
        NEAR[a + 1].add(b + 2)
        NEAR[a + 2].add(b)
    return NEAR


def bfs(S, T, N):  # 幅優先探索  # キュー
    S, T = 3 * (S - 1), 3 * (T - 1)
    dist, flag = [-3] * (3 * N), [0] * (3 * N)  # 前処理
    dist[S], flag[S] = 0, 1
    que = deque([S])

    while que:
        q = que.popleft()
        for i in near[q]:  # 移動先の候補
            if flag[i]:  # 処理済みか否か
                continue
            dist[i], flag[i] = dist[q] + 1, 1
            que.append(i)
    return dist[T] // 3


n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

# 解説AC
near = nearlist(n)
print(bfs(s, t, n))


Measured memory_bytes: 178300
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
    ll n,m;
    cin>>n>>m;
    if(n>=m/2)cout<<m/2<<endl;
    else cout<<n+(m-n*2)/4<<endl;
    return 0;
}



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

Measured memory_bytes: 3712
n = int(input())
S = [input() for i in range(n)]
cnt = 0
a = 0
b = 0
ba = 0
for i in range(n):
    cnt += S[i].count("AB")
    if S[i].startswith("B") and S[i].endswith("A"):
        ba += 1
    elif S[i].startswith("B"):
        b += 1
    elif S[i].endswith("A"):
        a += 1
if ba >= 1:
    cnt += ba - 1
    if a >= 1:
        cnt += 1
        a -= 1
    if b >= 1:
        cnt += 1
        b -= 1
    cnt += min(a, b)
elif a >= 1 and b >= 1:
    cnt += min(a, b)
print(cnt)


Measured memory_bytes: 3828
n=input()
d=int(input())
m=len(n)
mod=10**9+7

DP=[[[0]*d for _ in range(2)] for _ in range(m+1)]
DP[0][0][0]=1

for i in range(1,m+1):
    for flag in range(2):
        num=9 if flag else int(n[i-1])
        for j in range(d):
            for k in range(num+1):
                DP[i][flag or k<num][(j+k)%d] +=DP[i-1][flag][j]
                DP[i][flag or k<num][(j+k)%d] %=mod

print((DP[-1][0][0]+DP[-1][1][0]-1)%mod)

Measured memory_bytes: 62812
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	if n == 3 {
		fmt.Println("2 3 25")
	} else {
		x := make([]int, 0, n)
		for i := 0; i*6+4 <= 30000 ; i++ {
			if len(x) >= n/4*4 {
				break
			}
			if i*6+4 <= 30000 {
				x = append(x, i*6+2)
				x = append(x, i*6+4)
			}
			if i*2*6+9 <= 30000 {
				x = append(x, i*2*6+3)
				x = append(x, i*2*6+9)
			}
		}
		for i := 1; i*6 <= 30000; i++ {
			if len(x) == n {
				break
			} else {
				x = append(x, i*6)
			}
		}
		fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
	}
}


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

int dp[200][200][200];
int a, b;
int c[200][200];
int dx[2] = { -1,0 }, dy[2] = { 0,-1 };
int saiki(int d, int e, int f, int g) {
	if (dp[d][e][f] != -1)return dp[d][e][f];
	for (int h = 0; h < 2; h++) {
		for (int i = 0; i < 2; i++) {
			int n = d + dx[h], m = e + dy[h];
			if (n < 0 || m < 0)continue;
			int x = f + dx[i], y = g + dy[i];
			if (x < 0 || y < 0)continue;
			int S = saiki(n, m, x, y);
			S += c[d][e]; S += c[f][g];
			if (d == f&&e == g)S -= c[d][e];
			dp[d][e][f] = max(dp[d][e][f], S);
		}
	}
	return dp[d][e][f];
}
signed main() {
	memset(dp, -1, sizeof(dp));
	scanf("%d%d", &a, &b);
	for (int d = 0; d < a; d++) {
		for (int e = 0; e < b; e++) {
			scanf("%d", &c[d][e]);
		}
	}
	dp[0][0][0] = c[0][0];
	printf("%d\n", saiki(a - 1, b - 1, a - 1, b - 1));
}

Measured memory_bytes: 31616