akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

// ??±???????????¢?´¢
public class Main {
    static int w, h;
    static int[][] map;
    static int c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            w = sc.nextInt();
            h = sc.nextInt();
            if ((w | h) == 0) {
                break;
            }
            map = new int[h][w];
            int sx = 0;
            int sy = 0;
            c = 0;
            for (int i = 0; i < h; i++) {
                String line = sc.next();
                for (int j = 0; j < w; j++) {
                    if (line.charAt(j) == '@') {
                        sy = i;
                        sx = j;
                        map[i][j] = 0;
                    } else {
                        map[i][j] = line.charAt(j) == '.' ? 0 : 1;
                    }
                }
            }
            dfs(sy, sx);
            System.out.println(c);
        }
    }

    public static void dfs(int y, int x) {
        if (y < 0 || y >= h || x < 0 || x >= w) {
            return;
        }
        if (map[y][x] == 1) {
            return;
        }
        map[y][x] = 1;
        int[] d = new int[] { 0, 1, 0, -1, 0 };
        for (int i = 0; i < 4; i++) {
            dfs(y + d[i], x + d[i + 1]);
        }
        c++;
    }

}

Measured memory_bytes: 39228
#create date: 2020-07-07 11:02

import sys
stdin = sys.stdin
from heapq import heapify, heappush, heappop

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = list()
    for _ in range(n):
        a.append(ni())
    b = sorted(a, reverse=True)
    amax = b[0]
    asec = b[1]
    for ai in a:
        if ai == amax:
            print(asec)
        else:
            print(amax)


if __name__ == "__main__":
    main()

Measured memory_bytes: 19072
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int n, m, x;


int main(void) {
	cin >> n >> m >> x;
	vint c(n);
	vvint a(n, vint(m));
	int ans = INT_MAX;

	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}

	for (int i = 1; i < (1 << n); i++) {
		vint r(m);
		int cost = 0;
		rep(j, n) {
			if ((i>>j)& 1) {
				rep(k, m) {
					r[k] += a[j][k];
				}
				cost += c[j];
			}
		}
		if (*minmax_element(r.begin(), r.end()).first >= x) {
			ans = min(ans, cost);
		}
	}

	if (ans == INT_MAX) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;


}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }

        
  int main(){
      map<lint,lint> mp;
      lint N;
      lint g;
      lint count=0;
      cin >>N; 
      rep(i,N){
          cin>>g;
          mp[g]++;
      }
      for(auto x:mp){
          if(x.second%2==0)count++;
      }
      lint ans=mp.size();
      if(count%2==1)ans--;
      cout<<ans;
           }
  

  
     
  

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

using namespace std;

int main() {
	int res = 0;
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			res++;
		}
		else {
			res--;
		}
	}
	cout << res << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}

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

int main() {
  int N, A, B;
  /*
  Nは駐車時間
  Aは1時間ごとの料金
  Bは時間に関わらず一定料金
  */
  cin >> N >> A >> B;
  if (N*A-B >= 0) {
    cout << B << endl;
  }
  else if (N*A-B < 0) {
  	cout << N*A << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define LL long long
const int N=2e5+5;

int n;
vector<string> v;
vector<int> c[N][26];
LL ans;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s; cin>>s;
		reverse(s.begin(),s.end());
		v.pb(s);
	}
	sort(v.begin(),v.end());
	
	for(int i=0;i<n;i++)
	for(int j=0;j<26;j++)
	{
		c[i][j].resize(v[i].size());
		for(int k=v[i].size()-1;k>=0;k--)
			if(k!=v[i].size()-1 && c[i][j][k+1] || v[i][k]==j+'a') c[i][j][k]=1;
			else c[i][j][k]=0;
	}
	for(int i=1;i<n;i++)
	for(int j=0;j<26;j++)
	for(int k=0;k<c[i][j].size();k++)
		if(k<c[i-1][j].size()) c[i][j][k]+=c[i-1][j][k];
	
	for(int i=0;i<n;i++)
	{
		string s=v[i].substr(0,v[i].size()-1);
		int u1=upper_bound(v.begin(),v.end(),s)-v.begin();
		if(s.size()) s[s.size()-1]++; else s="|位巨佬！";
		int u2=lower_bound(v.begin(),v.end(),s)-v.begin();
		int last=v[i][v[i].size()-1]-'a';
		ans+=c[u2-1][last][v[i].size()-1];
		if(u1 && v[i].size()<=c[u1-1][last].size()) ans-=c[u1-1][last][v[i].size()-1];
	}
	cout<<ans-n<<'\n';
	
	return 0;
}

Measured memory_bytes: 293912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl
int main(){
    ll h , a;
    cin >> h >> a;

    ll ans = h/a;
    if(h%a != 0){ans++;}
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    int ans = LINF;
    for(int i = 1; i <= sqrt(n); i++)if(n%i == 0){
        int j = n/i;
        //cout << i << " " << j << endl;
        ans = min(ans, i+j-2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int absmin=999;
    for(int i=0;i<n-2;i++){
        int num=(s.at(i)-'0')*100+(s.at(i+1)-'0')*10+s.at(i+2)-'0';
        absmin=min(absmin,abs(num-753));
    }
    cout<<absmin<<endl;
}

Measured memory_bytes: 256
a=int(input())
l=list()

for i in range(a):
    k,n=input().split()
    n=int(n)
    if k=="S":
        n=n
    elif k=="H":
        n=n+13
    elif k=="C":
        n=n+26
    else:
        n=n+39
    l.append(n)

for j in range(1,14):
    if j not in l:
        print("S {}".format(j))
for j in range(14,27):
    if j not in l:
        print("H {}".format(j-13))
for j in range(27,40):
    if j not in l:
        print("C {}".format(j-26))
for j in range(40,53):
    if j not in l:
        print("D {}".format(j-39))



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

int main(){
  int n;
  long a[300000];
  cin>>n;
  for(int t=0;t<n;t++)cin>>a[t];

  long  sum2=0LL;
  for(int t=0;t<n;t++){
    sum2+=a[t];
  }
  long sum1=a[0];
       sum2-=a[0];
  long min=abs(sum2-a[0]);
  for(int t=0;t<n-1;t++){
    if(t!=0){
    sum1+=a[t];
    sum2-=a[t];
  }
    long temp=abs(sum1-sum2);
    if(temp<min)min=temp;
  }

  cout<<min<<"\n";
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int N;
  cin >> N;
  vi32 r(N + 5, -1e9);
  rep(i, N) {
    int a;
    cin >> a;
    int x = bis<int>(N + 5, -1, [&](int m) { return a > r[m]; });
    r[x] = a;
  }
  int ans = 0;
  rep(i, N + 1) if (r[i] != -1e9) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 768
import sys

readline = sys.stdin.readline

def flatten_2dim(array):
    return [item for sublist in array for item in sublist]


def dfs(i, j):
    global flag, grid
    grid[i][j] = '.'
    if i == H and j == W:
        fgrid = flatten_2dim(grid)
        flag = ('#' in fgrid)
    if grid[i][j+1] == '#':
        dfs(i, j+1)
    if grid[i+1][j] == '#':
        dfs(i+1, j)
    grid[i][j] = '#'


def main():
    global H, W, grid, flag
    H, W = map(int, readline().split())
    grid = []
    grid.append(['.']*(W+2))
    for _ in range(H):
        grid.append(['.'] + list(readline()[:-1]) + ['.'])
    grid.append(['.']*(W+2))
    flag = True
    dfs(1, 1)

    if flag:
        print('Impossible')
    else:
        print('Possible')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N,M = map(int,input().split())
from collections import defaultdict
INF = float('inf')
dic = defaultdict(lambda: INF)
for i in range(M):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    d = 0
    for k in c:
        d |= (1<<(k-1))
    dic[d] = min(dic[d], a)

dp = [INF] * (1<<N)
dp[0] = 0
for k,v in dic.items():
    for b in range((1<<N)-1):
        if dp[b] == INF: continue
        if b == (b|k): continue
        dp[b|k] = min(dp[b|k], dp[b]+v)
print(-1 if dp[-1]==INF else dp[-1])                

Measured memory_bytes: 3564
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * ABC157
 */
public class Main {

	public static void main(String[] args) throws Exception {
		Main main = new Main();

		try (Scanner scan = new Scanner(System.in)) {
			main.bingo(scan);
		}
	}

	private void bingo(Scanner scan) {
		int[][] a = IntStream.range(0, 3)
			.mapToObj(i -> IntStream.range(0, 3).map(i2 -> scan.nextInt()).toArray())
			.toArray(int[][]::new);
		int n = scan.nextInt();
		int[] b = IntStream.range(0, n).map(i -> scan.nextInt()).toArray();
		List<Pair<Integer, Integer>> hit = new ArrayList<>();

		for (int i : b) {
			for (int i2 = 0; i2 < a.length; i2++) {
				for (int i3 = 0; i3 < a[i2].length; i3++) {
					if (i == a[i2][i3]) {
						hit.add(new Pair<Integer, Integer>(i2, i3));
					}
				}
			}
		}

		// 横
		if (IntStream.range(0, 3).anyMatch(i -> hit.stream().filter(i2 -> i2.left == i).count() == 3)) {
			System.out.println("Yes");
			return;
		}
		// 縦
		if (IntStream.range(0, 3).anyMatch(i -> hit.stream().filter(i2 -> i2.right == i).count() == 3)) {
			System.out.println("Yes");
			return;
		}
		// 斜め (0, 0) -> (2, 2)
		if (hit.stream().filter(i -> i.left == i.right).count() == 3) {
			System.out.println("Yes");
			return;
		}
		// 斜め (0, 2) -> (2, 0)
		if (hit.stream().filter(i -> i.left == 2 - i.right).count() == 3) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
 	}

	@SuppressWarnings("unused")
	private void duplexPrinting(Scanner scan) {
		int n = scan.nextInt();

		System.out.println(n / 2 + n % 2);

	}

	@SuppressWarnings("unused")
	private static class Pair<T1, T2> {

		private T1 left;
		private T2 right;

		public Pair(T1 left, T2 right) {
			this.left = left;
			this.right = right;
		}

		public T1 left() {
			return left;
		}

		public T2 right() {
			return right;
		}
	}

	@SuppressWarnings("unused")
	private static class UnionFindTree {

		private List<Integer> parents;

		public static UnionFindTree initialize(int n) {
			return new UnionFindTree(n);
		}

		public UnionFindTree(int n) {
			parents = IntStream.range(0, n).boxed().collect(Collectors.toCollection(() -> new ArrayList<>()));
		}

		public int find(int index) {
			if (index == parents.get(index)) {
				return index;
			}
			// 自分の親の親は自分の親とできるため経路圧縮
			parents.set(index, find(parents.get(index)));
			return parents.get(index);
		}

		public void union(int x, int y) {
			int xParent = find(x);
			int yParent = find(y);
			parents.set(yParent, xParent);
		}

		public long size() {
			return parents.stream().map(i -> find(i)).distinct().count();
		}
	}

}


Measured memory_bytes: 28628
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int ans = 0;
	while (N > 0) {
		ans += (N % 10 == 2 ? 1 : 0);
		N /= 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

const ll MAX = 2000003;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll calcin(ll r,ll c){
  ll sum = 0;
  rep(i,r+1){
    sum += COM(c+i+1,c);
    sum %= mod;
  }
  //cout << sum << endl;
  return sum;
}


int main() {

  ll r1,r2,c1,c2;
  cin >> r1 >> c1 >> r2 >> c2;

  // 前処理
  COMinit();

  // 計算例
  vector<ll> vec1(r2+1),vec2(c2+1);
  ll ans = calcin(r2,c2) - calcin(r2,c1-1) - calcin(r1-1,c2) + calcin(r1-1,c1-1);
  ans += mod * 4;
  ans %= mod;
  cout << ans << endl;
}

Measured memory_bytes: 62720
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);

  int id;
  int s12, s23, s31;
  int l, r;

  while(n--){
    auto args=readln.split.to!(int[]);
    auto w=args[0], as=args[1..$];
    int[] p=[1, 2, 3];
    foreach(a; as){
      if(a==0) swap(p[0], p[1]);
      else swap(p[1], p[2]);
    }
    auto o1=p[0], o2=p[1], o3=p[2];
    if(o1==1 && o2==2 && o3==3) id++;
    if(o1==2 && o2==1 && o3==3) s12++;
    if(o1==1 && o2==3 && o3==2) s23++;
    if(o1==3 && o2==2 && o3==1) s31++;
    if(o1==2 && o2==3 && o3==1) l++;
    if(o1==3 && o2==1 && o3==2) r++;
  }

  if(id){
    writeln("yes");
  }else if(s12>=2 || s23>=2 || s31>=2){
    writeln("yes");
  }else if(l>=3 || r>=3){
    writeln("yes");
  }else if(l>=1 && r>=1){
    writeln("yes");
  }else if((l>=1 || r>=1) && s12>=1 && s23>=1){
    writeln("yes");
  }else if((l>=1 || r>=1) && s23>=1 && s31>=1){
    writeln("yes");
  }else if((l>=1 || r>=1) && s31>=1 && s12>=1){
    writeln("yes");
  }else{
    writeln("no");
  }
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}



Measured memory_bytes: 2488
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
namespace FastFourierTransform
{
	using C = complex< double >;

	void DiscreteFourierTransform(vector< C > &F, bool rev)
	{
		const int N = (int)F.size();
		const double PI = (rev ? -1 : 1) * acos(-1);
		for (int i = 0, j = 1; j + 1 < N; j++) {
			for (int k = N >> 1; k > (i ^= k); k >>= 1);
			if (i > j) swap(F[i], F[j]);
		}
		C w, s, t;
		for (int i = 1; i < N; i <<= 1) {
			for (int k = 0; k < i; k++) {
				w = polar(1.0, PI / i * k);
				for (int j = 0; j < N; j += i * 2) {
					s = F[j + k];
					t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
						F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
					F[j + k] = s + t, F[j + k + i] = s - t;
				}
			}
		}
		if (rev) for (int i = 0; i < N; i++) F[i] /= N;
	}

	vector< long long > Multiply(const vector<long long int > &A, const vector<long long int > &B)
	{
		int sz = 1;
		while (sz <= A.size() + B.size()) sz <<= 1;
		vector< C > F(sz), G(sz);
		for (int i = 0; i < A.size(); i++) F[i] = A[i];
		for (int i = 0; i < B.size(); i++) G[i] = B[i];
		DiscreteFourierTransform(F, false);
		DiscreteFourierTransform(G, false);
		for (int i = 0; i < sz; i++) F[i] *= G[i];
		DiscreteFourierTransform(F, true);
		vector< long long > X(A.size() + B.size() - 1);
		for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
		return (X);
	}
};
const int asize = 2e5+100;
vector<long long int> get_mp(const vector<int>v) {
	vector<long long int>sums(v.size()+1);
	for (int i = 0; i < v.size(); ++i) {
		sums[i+1]=sums[i]+v[i];
	}

	vector<long long int>a(asize);
	vector<long long int>b(asize);
	for (auto sum : sums) {
		a[sum]++;
		b[asize-sum-1]++;
	}
	vector<long long int> c= FastFourierTransform::Multiply(a,b);
	vector<long long int>ans(asize);
	for (int i = asize; i < 2 * asize-1; ++i) {
		if (c[i]) {
			ans[i - asize+1] += c[i];
		}
	}
	return ans;
}
vector<long long int>solve(vector<long long int>a, vector<long long int>b) {
	reverse(a.begin(),a.end());

	vector<long long >c= FastFourierTransform::Multiply(a,b);
	vector<long long int>ans(asize);
	ans[0]=c[asize-1];
	for (int i = 1; i < asize; ++i) {
		ans[i]=c[asize-1-i]+c[asize-1+i];
	}
	return ans; 
}

int main() {
	int N,M,Q;cin>>N>>M>>Q;
	vector<int>as(N),bs(M);
	for (int i = 0; i < N; ++i) {
		cin>>as[i];
	}
	for (int i = 0; i < M; ++i) {
		cin>>bs[i];
	}
	long long int aaa=static_cast<long long int>(N)*(N+1)/2;
	long long int bbb=static_cast<long long int>(M)*(M+1)/2;
	auto a_mp(get_mp(as));
	assert(aaa=accumulate(a_mp.begin(),a_mp.end(),0ll));
	auto b_mp(get_mp(bs));
	assert(bbb = accumulate(b_mp.begin(), b_mp.end(), 0ll));
	auto ans(solve(a_mp,b_mp));
	assert(abs(aaa*bbb-accumulate(ans.begin(),ans.end(),0ll))<1e9);
	while (Q--) {
		int n;cin>>n;
		cout<<ans[n]<<endl;
	}
	return 0;
}

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

int main(){
    using namespace std;
    unsigned long M;
    cin >> M;
    unsigned long a{0 - 2UL}, r{9};
    for(unsigned long i = 0, d, c; i < M; ++i){
        cin >> d >> c;
        a += c;
        for(unsigned long _ = 0; c % 9; ++_){
            r += d;
            if(r > 9){
                ++a;
                r -= 9;
            }
            --c;
        }
        if(!c)continue;
        unsigned long t{0};
        for(unsigned long _ = 0; _ < 9; ++_){
            r += d;
            if(r > 9){
                ++t;
                r -= 9;
            }
        }
        a += c / 9 * t;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//解説AC
namespace ABC_D
{
    class D063
    {
        static void Main(string[] args)
        {
            //string path = @"C:\Contest\CSharp\TaskSample\ABC_D063_b05";
            //System.IO.StreamReader sr = new System.IO.StreamReader(path);
            //System.Console.SetIn(sr);

            int[] a = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();
            int N = a[0], A = a[1], B = a[2];
            int[] h = new int[N];
            for (int i = 0; i < N; i++)
            {
                h[i] = int.Parse(Console.ReadLine());
            }

            int r = BinarySearch(h, A, B);
            Console.WriteLine(r);
        }

        static int BinarySearch(int[] h, int A, int B)
        {
            int s = 0;
            int t = int.MaxValue;

            while (s + 1 < t)
            {
                int mid = (s + t) / 2;
                if (Judge(h, mid, A, B))
                {
                    t = mid;
                }
                else
                {
                    s = mid;
                }
            }

            return t;
        }


        static bool Judge(int[] h, int T, int A, int B)
        {
            //全体ダメージ
            long d = (long)T * B;

            long sum = 0;
            for (int i = 0; i < h.Length; i++)
            {
                if (h[i] > d)
                {
                    sum += (long)Math.Ceiling((double)(h[i] - d) / (A - B));
                }
            }
            if (sum <= T) return true;
            else return false;
        }

    }
}


Measured memory_bytes: 17632
'use strict'
function main(input) {
  for(let i = 1; i < 10; i++) {
    for (let j = 1; j < 10; j++) {
      if(i * j == input) {
        console.log('Yes')
        return true
      }
    }
  }
  console.log('No')
  return true

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
D, N = map(int, input().split())

if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
else:
    if N == 100:
        ans = (100**D) * (N+1)
        print(ans)
    else:
        ans = (100**D) * N
        print(ans)


Measured memory_bytes: 38384
fn main() {
    let word: String = read();
    if word.chars().last().unwrap() == 's' {
        println!("{}es", word);
    } else {
        println!("{}s", word);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2180
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String S = in.nextLine();
        String regex = "2017";
        Pattern p = Pattern.compile(regex);

        Matcher m = p.matcher(S);
        String result = m.replaceFirst("2018");

        System.out.println(result);

        in.close();
    }
}


Measured memory_bytes: 21972
#include <stdio.h>

int main() {
  int N,M;
  scanf("%d %d",&N,&M);
  int A[N];
  float sum=0,count=0;
     for(int i=0;i<N;i++) {
        scanf("%d",&A[i]);
        sum+=A[i];
     }
     for(int i=0;i<N;i++) {
         if(A[i]>=sum/(4*M)) {
	   count++;
         }
       }
     if(count>=M) {
       printf("Yes");
     }else if(count<M) {
       printf("No");
     }
  return 0;
}
  

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

int main() {
  int x, y;
  int i = 1;
  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    if (x < y)
      cout << x << " " << y << endl;
    else
      cout << y << " " << x << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
d = [int(input()) for i in range(N)]
d.sort(reverse=True)

chk = 101
ret = 0
for i in range(len(d)):
    if d[i] < chk:
        chk = d[i]
        ret += 1
    elif d[i] > chk:
        break

print(ret)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Aug 29 21:20:28 JST 2020
 **/

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

struct UnionFind {
    int cnt;                  // 集合の数
    std::vector<int> number;  // 0以上のとき親のindex, 負のときは集合サイズ
    UnionFind(int n) : cnt(n), number(n, -1) {}
    int root(int x) { return number[x] < 0 ? x : number[x] = root(number[x]); }
    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (number[y] < number[x]) std::swap(x, y);
        // yをxにマージ
        number[x] += number[y];
        number[y] = x;
        cnt--;
    }
    bool is_same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -number[root(x)]; }
};

signed main() {
    Int n, m;
    std::cin >> n >> m;
    UnionFind uf(n);
    REP(i, m) {
        Int u, v;
        std::cin >> u >> v, u--, v--;
        uf.unite(u, v);
    }
    Int ans = -1;
    REP(i, n) { chmax(ans, (Int)uf.size(i)); }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3976
N = int(input())
W = []
for _ in range(N):
    W.append(input())
D = []
for i in range(N):
    if W[i] in D:
        print('No')
        exit()
    else:
        if i == 0:
            pass
        else:
            if D[-1][-1] != W[i][0]:
                print('No')
                exit()
        D.append(W[i])
print('Yes')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	long long a, b;
	cin >> a >> b;
	long long c = gcd(a, b);
	cout << a * b / c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n;
    double ans = 0.0;

    cin >> n;

    if(n%2==0){
        ans = 0.5;

    }else{
        ans = (double)(n+1)/((n-1) + (n+1));
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int r,c;
char s[55][55];
int d[55][55];
int mazebfs(){
	int sx=0,sy=0,gx=r-1,gy=c-1;
	int dx[4]={1,0,-1,0} ,dy[4]={0,1,0,-1};
	queue<p> que;
	rep(i,0,r){
		rep(j,0,c){
			d[i][j]=inf;
		}
	}
	que.push(p(sx,sy));
	d[sx][sy]=0;
	while(que.size()){
		p pf=que.front();
		que.pop();
		
		if(pf.first==r-1&&pf.second==c-1) break;
		rep(i,0,4){
			int nx=pf.first+dx[i],ny=pf.second+dy[i];
			if(nx>=0&&nx<r&&ny>=0&&ny<c&&s[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(p(nx,ny));
				d[nx][ny]=d[pf.first][pf.second]+1;
			}
		}
	}
	return d[r-1][c-1];
}
int main(){
	string s;
	cin>>s;
	ll b=753;
	ll a=114514;
	char z='0';
	rep(i,0,s.length()-2){
		ll x=(s[i]-z)*100+(s[i+1]-z)*10+(s[i+2]-z);
		a=min(a,abs(b-x));
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#C
import math
a, b, c, d = map(int, input().split())

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        x, y = y, x % y
    return x

s = b - a + 1
cc = b // c - (a - 1) // c
dd = b // d - (a - 1) // d
cd = c * d // gcd(c, d)
cd = b // cd - (a - 1) // cd
s -= cc + dd - cd
print(s)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  int K;
  cin>>s>>K;
  set<string>S;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<=5;j++){
      if(j==0)continue;
      string ss=s.substr(i,j);
      S.insert(ss);
    }
  }
  vector<string>ans;
  for(auto it:S)ans.push_back(it);
  sort(rng(ans));
  cout<<ans[K-1]<<endl;
  return 0;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
const ll mod = 1000000007;
const ll M = 1000000000000000000ll;
#define fi first
#define se second
#define pb push_back
inline ll add(ll a,ll b){return ((a%mod+b%mod)%mod);}
inline ll sub(ll a,ll b){return ((a%mod-b%mod+mod)%mod);}
inline ll mult(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
inline ll power(ll n,ll x){ll p=1;while(x!=0){if(x%2==0){n=mult(n,n);x=x/2;}p=mult(p,n);x--;}return p;}
inline ll recurmult(ll a,ll b){ll r = 0;while (b){if (b & 1)r = add(r, a);a = mult(2,a);b >>= 1;}return r%mod;}

int main()
{
    ios::sync_with_stdio(0);   
    cin.tie(0);   
    #ifndef ONLINE_JUDGE   
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif  
    ll n,k;
    cin>>n>>k;
    map<ll,ll>mp;
    while(k--)
    {
        ll d;
        cin>>d;
        for(ll i=1;i<=d;i++)
        {
            ll x;
            cin>>x;
            mp[x]=1;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(mp[i]==0)
            ans++;
    }
    cout<<ans<<"\n";

}

Measured memory_bytes: 3676
#include<stdio.h>
#include<stdlib.h>

#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;
  int n,i,j,k;
  int C[VMAX];

  scanf("%d",&n);
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<n+1;i++){
    scanf("%hd",&A[i]);
  }
  k=A[1];
  for(i=1;i<n+1;i++){
    if(k<A[i]){
      k=A[i];
    }
  }
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(i=1;i<=n;i++){
    C[A[i]]++;
  }

  for(i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if(i<n){
      printf("%d ",B[i]);
    }
    else{
      printf("%d\n",B[i]);
    }
  }
  return 0;
}



Measured memory_bytes: 9552
import sys


def resolve(in_):
    X, K, D = map(int, next(in_).split())

    c, a = X // D, X % D
    b = a - D

    if X >= 0:
        ans = X - K * D
        if ans <= b:
            if c % 2 == K % 2:
                ans = a
            else:
                ans = abs(b)
        elif ans <= a:
            ans = a
        else:
            pass
    else:
        ans = X + K * D
        if ans >= a:
            if c % 2 == K % 2:
                ans = a
            else:
                ans = abs(b)
        elif ans >= b:
            ans = abs(b)
        else:
            ans = abs(ans)
    return ans

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();

        int x;

        for(int i = 1; i <= a; i++) {
            if (i % 3 == 0) {
                System.out.printf(" %d", i);
            } else {
                x = i;

                do {
                    if (x % 10 == 3) {
                        System.out.printf(" %d", i);
                        break;
                    }
                    x /= 10;
                } while (x != 0);
            }
        }

        System.out.printf("\n");
    }
}



Measured memory_bytes: 37160
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    string s;
    while(cin >> n && n != 0) {
        string a[n] = {}, b[n] = {};
        for(int i = 0; i < n; i++) {
            cin >> a[i] >> b[i]; 
        }
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> s;
            bool x = true;
            for(int l = 0; l < n; l++) {
                if(a[l].compare(s) == 0) {
                    cout << b[l];
                    x = false;
                }
                
            }
            if(x) {
                    cout << s;
                }
        }
        cout << endl;
    } 
}



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

int main() {
  int N;
  string s;
  cin >> N;
  for(int i=0;i<N;i++){
    cin>>s;
    if(s=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    else if(i==N-1){
      cout<<"Three"<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
a, b, c, k = map(int, input().split())

ans = 0
if k >= a:
    ans = a
    k -= a
else:
    print(k)
    exit()

if k >= b:
    k -= b
else:
    print(ans)
    exit()

if k >= c:
    ans -= c
    print(ans)
else:
    ans -= k
    print(ans)


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) a[i]=i+1;
    vector<int> b(n),c(n);
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    ll u=0,q,w;
    do{
        if (a==b) q=u;
        if (a==c) w=u;
        u++;
    }while(next_permutation(all(a)));
    cout << abs(q-w) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr int MOD = 998244353;

ll N, K;


int main() {
  cin >> N;
  for(int i = 1; i*i <= N; ++i) {
    if(N % i == 0) {
      if(i <= 9 && N / i <= 9) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}


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

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;

  q.push(s);

  for(int i=0;i<n;i++)d[i] = INFTY;

  d[s] = 0;

  int u;

  while(!q.empty()){
    u = q.front(); q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v] != INFTY)continue;
      d[v] = d[u] +1;
      q.push(v);
    }
  }

  for(int i=0;i<n;i++){
    cout << i+1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }

}

int main(){
  int u,k,v;

  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j] = 0;
    }
  }

  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;  
}

Measured memory_bytes: 3116
n,k,q=map(int,input().split())
l=list(map(int,input().split()))
ans=10**10
for i in range(n):
    x=l[i]
    tmp=[]
    z=[]
    for j in range(n):
        if l[j]>=x:
            tmp.append(l[j])
        if l[j]<x or j==n-1:
            tmp.sort()
            if len(tmp)-k+1>0:
                z+=tmp[:len(tmp)-k+1]
            tmp=[]
    z.sort()
    if len(z)>=q:
        ans=min(ans,z[q-1]-x)
print(ans)

Measured memory_bytes: 74792
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll q;cin>>q;
    while(q){
        q--;
        ll a,b;
        cin>>a>>b;
        if(a>b){
            swap(a,b);
        }
        if(a==b&&a==1){
            cout<<0<<endl;
            continue;
        }
        ll l=1,r=inf;
        while(r-l>1){
            ll mid=(l+r)/2;
            if(mid*mid<=a*b-1){
                l=mid;
            }else r=mid;
        }
        ll d=l;
        //cout<<d<<' ';
        if(a==b){
            ll cnt=0;
            ll e=(a*b-1)/b;
            if(e>0&&(a*b-1)/e==b){
                if(d==(a*b-1)/d){
                    if(b-d==d-e)cnt+=2;
                }else{
                    if(b-d==d-e+1)cnt+=2;
                }
            }
            if((a*b-1)/d==d)cout<<2*d-1-cnt<<endl;
            else cout<<2*d-cnt<<endl;
        }else{
            ll cnt=0;
            ll e=(a*b-1)/b;
            if(e>0&&(a*b-1)/e==b){
                if(d==(a*b-1)/d){
                    if(b-d==d-e)cnt++;
                }else{
                    if(b-d==d-e+1)cnt++;
                }
            }
            if(d>=a)cnt++;
            if((a*b-1)/d==d)cout<<2*d-1-cnt<<endl;
            else cout<<2*d-cnt<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
const ll inf = 1e18;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<ll> a(n); rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    priority_queue<ll> que; que.push(a[0]);
    ll res = 0;
    rep(i,n-1){
        ll m = que.top();
        res += m;
        que.pop();
        que.push(a[i+1]);
        que.push(a[i+1]);
    }
    cout << res << endl; 
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string s, t;
  cin >> s >> t;

  reverse(all(s));
  reverse(all(t));

  rep(i, s.size() - t.size() + 1) {
    bool f = true;
    rep(j, t.size()) if (s[i + j] != '?' && s[i + j] != t[j]) f = false;

    if (f) {
      string ans = "";
      rep(j, i) ans += s[j];
      ans += t;
      REP(j, i + t.size(), s.size()) ans += s[j];
      reverse(all(ans));
      rep(j, ans.size()) if (ans[j] == '?') ans[j] = 'a';
      cout << ans << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
a, b, k = list(map(int, input().split()))

for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        a //= 2
        b += a
    else:
        if b % 2 == 1:
            b -= 1
        b //= 2
        a += b

print(a, b)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

struct edge{
	int to,co,inv;
};

vector<edge> vs[105];
int gone[105];

int n,m;
int st,gl;

int dfs(int no,int f){
	if(no==gl)return f;
	//printf("dfs .. %d %d\n",no,f);
	gone[no]=1;
	rep(i,vs[no].size()){
		edge& e = vs[no][i];
		int to = e.to;
		if(gone[to] || e.co==0)continue;
		int nf = dfs(to,min(f,e.co));
		if(nf==0)continue;
		
		e.co-=nf;
		vs[to][e.inv].co+=nf;
		return nf;
	}
	return 0;
}

int main(void){
	scanf("%d%d",&n,&m);
	st=0; gl=n-1;
	rep(i,m){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		int sa = vs[a].size(), sb = vs[b].size();
		vs[a].push_back((edge){b,c,sb});
		vs[b].push_back((edge){a,0,sa});
	}
	
	int ans = 0;
	for(;;){
		memset(gone,0,sizeof(gone));
		int f = dfs(st,INT_MAX);
		if(f==0)break;
		ans+=f;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1096
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
vector<vector<pair<int,int>>> tree;
vector<int> flag;
bool dfs(int u,int pre,int g,int num){
    if(u==g) return true;
    for(auto e:tree[u]){
        if(e.first==pre) continue;
        if(dfs(e.first,u,g,num)){
            flag[e.second]=flag[e.second]|(1<<num);
            return true;
        }
    }
    return false;
}

int main(){
    int N;cin>>N;
    tree.resize(N);
    REP(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        tree[a].push_back({b,i});
        tree[b].push_back({a,i});
    }
    int M;cin>>M;
    flag.resize(N-1,0);
    REP(i,M){
        int u,v;
        cin>>u>>v;
        u--;v--;
        dfs(u,-1,v,i);
    }
    vector<ll> dp(1<<M);
    dp[0]=1;
    REP(i,N-1) for(int j=(1<<M)-1;j>=0;--j){
        dp[j|flag[i]]+=dp[j];
    }
    cout<<dp[(1<<M)-1]<<endl;
}


Measured memory_bytes: 8576
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n,x,t = map(int, input().split())
    if n%x == 0:
        print((n//x)*t)
    else:
        print(((n//x)+1)*t)
            
    
if __name__ == '__main__':
	main()


Measured memory_bytes: 9608
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	ull n,k,memo = 0,memo2 = 0;
	cin >> n >> k;
	int a[n];
	rep(i,0,n){
		cin >> a[i];
		if(a[i] == k){
			cout << "POSSIBLE" << endl;
			return 0;
		}
		if(!i) memo2 = (ull)a[i];
		else memo2 = max(memo2,(ull)a[i]);
	}
	
	if(memo2 < k){
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	memo = a[0];
	rep(i,1,n){
		memo = gcd(memo,a[i]);
	}
	
	if(memo == 1){
		cout << "POSSIBLE" << endl;
	}
	else if(k % memo == 0){
		cout << "POSSIBLE" << endl;
	}
	else{
		cout << "IMPOSSIBLE" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
import sys
n, t = map(int,input().split())
src = [list(map(int,input().split())) for _ in range(n)]
new = []
for s in src:
    if s[1] <= t:
        new.append(s[0])
if len(new) == 0:
    print('TLE')
    sys.exit()
print(min(new))

Measured memory_bytes: 3060
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    long long int ans=0;
    for(long long int i=0;i<s.length();++i)
    {
    	if(s[i]!=t[i])
    		++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3776
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,l;
	while(scanf("%d%d",&n,&l)!=EOF)
	{
		string str[105];
		for(int i=0;i<n;i++)
		{
			cin>>str[i];
		}
		sort(str+0,str+n);
		for(int j=0;j<n;j++)
		{
			cout<<str[j];
		}
		cout<<endl;
	}
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int b[202020], w[202020];

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;

    int bb=0, ww=0;
    rep(i, s.size()) {
        if (s[i] == '#') bb++;
        else ww++;
    }


    int tb=0, tw=0, ans = 1e8;
    rep(i, s.size()) {
        if (s[i] == '#') tb++;
        if (s[i] == '.') tw++;

        // iを境目に
        ans = min(ans, tb+(ww-tw));
    }

    cout << min({ans,bb,ww}) << endl;
}


Measured memory_bytes: 640