akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception{
      Scanner scn = new Scanner(System.in);
      int h = scn.nextInt();
      int w = scn.nextInt();
      char[][] a = new char[h][w];
      for(int i=0; i<h; ++i){
        String str = scn.next();
        for(int j=0; j<w; ++j){
          a[i][j] = str.charAt(j);
        }
      }
      int[] hh = new int[h];
      int c = 0;
      for(int i=0; i<h; ++i){
        int count = 0;
        for(int j=0; j<w; ++j){
          if(a[i][j]=='.'){
            count = count + 1;
          }
        }
          if(count != w){
          	hh[c] = i;
            c = c + 1;
          }
      }
      int[] ww = new int[w];
      int d=0;
      for(int j=0; j<w; ++j){
        int count = 0;
        for(int i=0; i<h; ++i){
          if(a[i][j]=='.'){
            count = count + 1;
          }
        }
          if(count != h){
          	ww[d] = j;
            d = d + 1;
          }
      }
      for(int i=0; i<c; ++i){
        for(int j=0; j<d; ++j){
        	System.out.print(a[hh[i]][ww[j]]);	
        }
        System.out.println();
      }
    }
}


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

const int MAX = 100000;

typedef struct tree {
	int cost;
	bool use;
	int treeNum;
	bool DFSread;
	vector<int> edge;
} Tree;

void setTreeNum(Tree t[], int n, int num) {
//	cout << "木" << n << ":" << num << "番" << endl;
	t[n].treeNum = num;
	t[n].DFSread = true;
	for (int i = 0;i < t[n].edge.size();i ++) {
		if (t[t[n].edge[i]].DFSread) continue;
		setTreeNum(t, t[n].edge[i], num);
	}
	t[n].DFSread = false;
}

int getMinimum(Tree t[], int n) {
	int ret = n, tmp;
	t[n].DFSread = true;
	for (int i = 0;i < t[n].edge.size();i ++) {
		if (t[t[n].edge[i]].DFSread) continue;
		tmp = getMinimum(t, t[n].edge[i]);
		if (t[ret].cost > t[tmp].cost) {
			ret = tmp;
		}
	}
	t[n].DFSread = false;
	return ret;
}

int main() {
	int N, M;
	static pair<int, int> a[MAX]; // コスト記憶用
	cin >> N >> M;
	static Tree t[MAX];
	for (int i = 0;i < N;i ++) {
		cin >> t[i].cost;
		t[i].treeNum = -1;
		t[i].use = false;
		t[i].DFSread = false;
		a[i] = make_pair(t[i].cost, i);
	}
	int x, y;
	for (int i = 0;i < M;i ++) {
		cin >> x >> y;
		t[x].edge.push_back(y);
		t[y].edge.push_back(x);
	}
	
	int num = 0; // 木の数
	int64_t cost = 0; // 最終コスト
	for (int i = 0, tmp;i < N;i ++) {
		// 木ごとにナンバリングすることで所属を確定させていくよ！DFSとかで良いかな
		if (t[i].treeNum == -1) { // 未確定木を発見したら
			setTreeNum(t, i, num); // ナンバリングのお時間だ！
			tmp = getMinimum(t, i); // そして最小値の頂点を接続用に使うのでコストとして計算
			cost += t[tmp].cost;
			t[tmp].use = true;
			num ++;
		}
	}
//	cout << "木の数:" << num << endl;
	
	if (num > (N + 2) / 2) {
		cout << "Impossible";
		return 0;
	}
	
	sort(a, a+N); // さっきのコストを記憶してた分がここで生きるよ
	for (int i = 0, c = num - 2;c > 0;i ++) {
		if (t[a[i].second].use == false) { // コスト最小順に見た奴が使われてないなら
			cost += a[i].first; // そのコストを足してしまおう
			c --;
		}
	}
	if (num == 1) cout << 0;
	else cout << cost;
	return 0;
}
/*
まず、impossibleかどうか先に判定してしまおう
これは、森に何本の木があるかで判定できる
木同士を1個つなぐ度に2本の頂点が使用されるので、
N本の木を繋ぐためには2(N-1)個の頂点が必要である
言い換えると、頂点がNならば木の個数は(N+2)/2個以下でないといけない
逆に頂点がNの時木の個数が(N+2)/2個以下ならば必ず1個の木にできる

次に、使用する頂点を選ぶ
選ぶ頂点の数は、木の個数をAとしたときに2(A-1)個であり、しかもそれは全ての木から最低でも1個は選ぶ必要がある
逆に、全ての木から1個ずつ選べば後は一番コストの小さい頂点から順に選べば良いことが分かる

全ての木からまず1個ずつの頂点を選び、次にA-2個の任意頂点を選べば良いわけだ
当然だが頂点はコスト最小順かつまだ使われていない奴
後は分かるな？

あ、注意点
木の数が1本の時のみ、全ての木から1個ずつの～の下りが不要になる
よってこの時は0返しておけばいい
*/

Measured memory_bytes: 8064
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
tune = {}
times = []
for i in range(n):
    title, time = input().split()
    time = int(time)
    tune[title] = i
    times.append(time)
x = input()
ind = tune[x]
print(sum(times[ind+1:]))

Measured memory_bytes: 66028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x) //counts no of zeroes in binary rep
#define zrobits(x)      __builtin_ctzll(x) // count no of zeroes to right of first set bit
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

const int sz = 1e5 + 2;
// pbds works as set data structure. USE pbds.find_by_order() to get element randomly. it returns iterator
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int pwmd(int a, int b) {
	if (a == 1)
		return 1;
	if (b == 0)
		return 1;
	int ans = pwmd(a, b >> 1);
	ans = (ans * ans);
	if (b & 1)
		return (ans * a);
	else
		return ans;
}



int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int k = 0; cin >> k;
	int dp[sz]; // dp[i] stores the frequency of sequences which has gcd i
	memset(dp, 0, sizeof(dp));
	int ans = 0;
	int n = 3;
	// iterate reverse because we need to subtract the frequency of sequence related to multiples of i
	for (int i = k; i >= 1; --i) {
		dp[i] = pwmd(k / i, n);
		//remove the count of 2*i,3*i,4*i......
		for (int j = 2 * i; j <= k; j += i)
			dp[i] = (dp[i] - dp[j]);
		ans = (ans + (dp[i] * i ));
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N ;
  vector <int> vec(N);
  for (int i = 0; i < N ; i++){
    cin >> vec.at(i) ;
  }
  
  sort(vec.begin(),vec.end());
  /*for (int i = 0 ; i < N ; i++){
    cout << vec.at(i) << endl;
  }*/
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < N; i++){
    if (i%2 == 0 ) alice += vec.at(N-1-i);
    else bob += vec.at(N-1-i);
  }
  cout << alice-bob << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = in.nextInt();
        }

        int l = 0, r = n - 1;
        int s1 = 0, s2 = 0;
        while (l <= r) {
            if (s1 <= s2) {
                s1 += w[l++];
            } else {
                s2 += w[r--];
            }
        }

        System.out.println(Math.abs(s1 - s2));
    }
}


Measured memory_bytes: 21844
import std.stdio,
	   std.string,
	   std.conv,
	   std.algorithm,
	   std.range,
	   std.math;

void main()
{
auto n = readln.chomp.to!int;
auto a = readln.split.to!(long[]);
writefln("%s %s %s", a.reduce!(min), a.reduce!(max), a.sum);
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	map<int, int> mp;
	for( auto k : a ){
		mp[k] += 1;
		mp[k-1] += 1;
		mp[k+1] += 1;
	}
	int ans = 0;
	for( auto k : mp ){
		ans = max(ans, k.second);
	}
	cout << ans << endl;
	return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for(i = 0; i < n; i++)
#define Fo(i, k, n) for(i=k; i < n; i++)

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}
template<typename... T>
void write(T&&... args) {
	((cout << args << " "), ...);
	cout << endl;
}

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> arr(n, 0);
	for(int i = 0; i < n; i++) cin >> arr[i];
	
	sort(arr.begin(), arr.end());
	
	vector<int> minis;
	for(int i = 0; i < k; i++) {
		minis.push_back(arr[i]);
	}
	int mini = accumulate(minis.begin(), minis.end(), 0);
	
	/*5 3
	 * 50 100 80 120 80
	 * */
	
	cout << mini << endl;
	
	return 0;
}



Measured memory_bytes: 3596
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

K = len(bin(np.max(A))) - 2

ans = 0
mod = 10 ** 9 + 7
N %= mod

for i in range(K):
    bit = np.count_nonzero(A >> i & 1) % mod
    ans += pow(2, i, mod) * bit * (N - bit)
    ans %= mod
    
print(ans)

Measured memory_bytes: 49952
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 1000000007;
int main() {
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  bool kk[8];
  for(int i = 0; i < 8; i++) {
    kk[i] = false;
  }
  int cou = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 8; j++) {
      if(a[i] < 400 * (j+1)) {
        kk[j] = true;
        break;
      }
    }
    if(a[i] >= 400 * (8)) cou++;
  }
  int min = 0;
  int max = 0;
  for(int i = 0; i < 8; i++) {
    if(kk[i])min++;
  }
  max = min + cou;
  if(min == 0) min = 1;

  cout << min << " " << max << endl;





}


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

using namespace std;

int main() {
  int h[10];
  for (int i=0; i<10; ++i) {
    cin >> h[i];
  }
  sort(begin(h), end(h));
  cout << h[9] << "\n";
  cout << h[8] << "\n";
  cout << h[7] << "\n";
}


Measured memory_bytes: 3156
import sys
input = sys.stdin.buffer.readline


N, M = map(int, input().split())
class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
        self.u = n
    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        self.u -= 1
        return True
    def same(self, x, y):
        return self.root(x) == self.root(y)
    def size(self, x):
        return -self.d[self.root(x)]
    def num_union(self):
        return self.u

uf = UnionFind(N)
G = [[] for _ in [0]*N]
for _ in [0]*M:
    a, b = map(int, input().split())
    a -= 1; b -= 1
    uf.unite(a, b)

print(uf.num_union()-1)



Measured memory_bytes: 18632
import itertools

def main() -> None:
    S = input()
    for i in itertools.product(["+","-"], repeat=3):
        ans=""
        for j in range(3):
            ans+=S[j]+i[j]
        ans += S[-1]
        num = eval(ans)
        if num == 7:
            print(ans + "=7")
            exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math
N = int(input())
lst = [int(input()) for _ in range(5)]

#print(lst)
#print(min(lst),N//min(lst))
'''
if min(lst) >= N:
    print(5)
else:
    print(N//min(lst)+5)
'''

print(math.ceil(N/min(lst))+4)

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:

	long long f(vector<long long> d, vector<long long> c){
		int m = d.size();
		long long ret = -1;
		long long s =0;
		for(int i=0; i < m; i++){
			ret += c[i];
			s += d[i] * c[i];
		}
		if(s < 10)return ret;
		vector<long long> nd(2), nc(2);
		nd[0] = 1;
		nc[0] = s/10;
		nd[1] = s % 10;
		nc[1] = 1;
		return f(nd, nc) + ret;

	}
	void solve() {
		int m;
		cin >> m;
		vector<long long> d(m, 0), c(m, 0);
		for(int i=0; i < m; i++)cin >> d[i] >> c[i];
		cout << f(d, c) << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n;
  cin >> n;
  vector<string> s(n);
  for(ll i = 0; i < n; i++){
    cin >> s[i];
    sort(all(s[i]));
  }

  map<string, ll> mp;
  ll ans = 0;
  for(ll i = 0; i < n; i++){
    ans += mp[s[i]];
    mp[s[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=998244353;

//for(i=0; i<N; i++) cin >> a[i];



int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX];
  
    
  for(i=0; i<=N; i++) cin >> a[i];
  
  if(N==0) {
    pt(2*(a[0]==1)-1);
    return 0;
  }
  
  if(a[0]>0) { pt(-1); return 0; }
  
  ll c[MAX]={}, f[MAX];
  f[0]=1;
  for(i=1; i<=N; i++) f[i]=INF;
  for(i=1; i<=N; i++) {
    f[i]=f[i-1]*2-a[i];
    if(f[i]<0) { pt(-1); return 0; }
    if(f[i]>INF) break;
  }
  
  f[N]=0;
  for(i=N; i>=0; i--) c[i]=min(f[i], c[i+1])+a[i];
  for(i=0; i<=N; i++) if(f[i]*2<c[i+1]) { pt(-1); return 0; }
  
  ll ans=0;
  for(i=0; i<=N; i++) ans+=c[i];
  pt(ans);
  
}
 
 




Measured memory_bytes: 6004
def canSort(num, mylist):
    num1, num2, count = 0, 0, 0
    
    for i in range(1,num):
        if mylist[i] < mylist[i - 1]:
            count += 1
            
            if num1 == 0:
                num1 = i
            else:
                num2 = i
                
    if count > 2:
        return False
    
    if count == 0:
        return True
    
    if count == 2:  
        (mylist[num1 - 1], mylist[num2]) = (mylist[num2], mylist[num1 - 1])   
    elif count == 1:  
        (mylist[num1 - 1], mylist[num1]) = (mylist[num1], mylist[num1 - 1]) 
    
    for i in range(1,num):
        if mylist[i] < mylist[i - 1]:
            return False
    
    return True

N = int(input())
mylist = list(map(int, input().split(None,N)[:N]))
num = len(mylist)

if canSort(num, mylist):
    print("YES")
else:
    print("NO")

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

const int mod = 1000000007;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    mint sum = 0;
    rep(i, 60) {
        int sum0 = 0;
        int sum1 = 0;
        rep(j, N) {
            if (A[j] & (1ULL << i)) {
                sum1++;
            } else {
                sum0++;
            }
        }
        mint tmp = sum1;
        tmp *= sum0;
        rep(j, i) tmp *= 2;
        sum += tmp;
    }
    cout << sum << endl;
    return 0;
}


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

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

//status unsolved

int main(){
    long long M=1e18;
    int n;
    cin>>n;

    long long a[n];
    rep(i,n){
        cin>>a[i];
        if(a[i]==0){
            a[0]=0;
        }
    }
    long long ans=a[0];
    rep2(i,n-1){
        if(ans>((long double)M/a[i])){
            cout<<"-1"<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 4400
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int n, k, i;
	long double ans = 0;
	cin >> n >> k;

	for (i = 1; i <= n; i++) {
		if (i < k) {
			ans += (1/(long double)n) * pow((long double)0.5,ceil(log2((long double)k / i)));
		}
		else {
			ans += 1 / (long double)n;
		}
	}

	cout << setprecision(12) << ans << endl;

}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct vec
{
    double x, y;
    vec (const double& x0 = 0, const double& y0 = 0) : x(x0), y(y0) {}
    vec operator + (const vec& t) const {return vec(x+t.x, y+t.y);}
    vec operator - (const vec& t) const {return vec(x-t.x, y-t.y);}
    vec operator * (const double& t) const {return vec(x*t, y*t);}
    vec operator / (const double& t) const {return vec(x/t, y/t);}
    const double len2 () const {return x*x + y*y;}
    const double len () const {return sqrt(len2());}
    vec norm() const {return *this/len();}
    vec rotate_90_c () {return vec(y, -x);}
};

double dot(const vec& a, const vec& b) {return a.x*b.x + a.y*b.y;}
double crs(const vec& a, const vec& b) {return a.x*b.y - a.y*b.x;}

vec lin_lin_int(const vec& p0, const vec& v0, const vec& p1, const vec& v1)
{
    double t = crs(p1-p0, v1) / crs(v0, v1);
    return p0 + v0 * t;
}

vec circle(const vec& a, const vec& b, const vec& c)
{
    return lin_lin_int((a+b)/2, (b-a).rotate_90_c(), (a+c)/2, (c-a).rotate_90_c());
}

int n;
vec pot[60];

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lf%lf", &pot[i].x, &pot[i].y);
    random_shuffle(pot+1, pot+n+1);
    vec o;
    double r2 = 0;
    for(int i=1; i<=n; i++)
    {
        if((pot[i]-o).len2() > r2)
        {
            o = pot[i], r2 = 0;
            for(int j=1; j<i; j++)
            {
                if((pot[j]-o).len2() > r2)
                {
                    o = (pot[i]+pot[j])/2, r2 = (pot[j]-o).len2();
                    for(int k=1; k<j; k++)
                    {
                        if((pot[k]-o).len2() > r2)
                        {
                            o = circle(pot[i], pot[j], pot[k]), r2 = (pot[k]-o).len2();
                        }
                    }
                }
            }
        }
    }
    printf("%.10lf\n", sqrt(r2));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
 
int main(){
	int n;
	cin >> n;
	pair<ll, ll> p[n];
	for(int i=0; i<n; i++){
		cin >> p[i].first >> p[i].second;
	}
 
	int ans=n;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) continue;
			ll x=p[i].first-p[j].first, y=p[i].second-p[j].second;
			int cnt=0;
			for(int k=0; k<n; k++){
				for(int l=0; l<n; l++){
					if(p[k].first-p[l].first==x && p[k].second-p[l].second==y){
						cnt++;
					}
				}
			}
			ans=min(ans, n-cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long sub(long);

int main() {
  long N;
  cin >> N;
  cout << sub(N) << endl;
  return 0;
}

long sub(long N){
long ans;
    if(N==1){
        ans = 1;
    }else{
        long temp = N/2;
        ans = sub(temp)*2 + 1;
    }
    return ans;
}

Measured memory_bytes: 256
(h, w) = input().split(" ")
(h, w) = (int(h), int(w))

s = []
for _ in range(h):
    s += [input()]

for i in range(h):
    s2 = ""
    for j in range(w):
        if s[i][j] == '#':
            s2 += "#"
            continue
        
        mines = 0
        for y in range(-1, 2):
            for x in range(-1, 2):
                ni = i+y
                nj = j+x
                if ni < 0 or ni >= h or nj < 0 or nj >= w:
                    continue
                
                if s[i+y][j+x] == '#':
                    mines += 1
        s2 += str(mines)
    print(s2)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <set>
using namespace std;
int main(void){
    int n, day = 0, comp, cnt = 0;
    int used[1000];
    queue<int> nx[1000];
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            int a;
            cin >> a;
            nx[i].push(--a);
        }
    }
    comp = n*(n-1)/2;
    while(comp > 0){
        day++;
        fill(used, used+n, false);
        bool flg = false;
        for(int i=0;i<n;i++){
            if(++cnt >= 10000000){
                cout << n*(n-1)/2 << endl;
                return 0;
            }
            if(used[i] || nx[i].empty())continue;
            int t =  nx[i].front();
            if(used[t])continue;
            if(nx[t].front() == i){
                nx[i].pop();
                nx[t].pop();
                used[i] = used[t] = true;
                flg = true;
                comp--;
                //cout << " __ " << i << " vs " << t << endl;
            }
        }
        if(!flg){
            cout << -1 << endl;
            return 0;
        }
        //cout << day << " " << comp << endl;
    }
    cout << day << endl;

}


Measured memory_bytes: 4736
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#define ll long long
using namespace std;



int main(){
  vector<ll> A(9);
  vector<ll> A_s(9,0);
  for(int j=0;j<9;j++){
    cin>>A[j];
  }
  ll N;
  cin>>N;
  vector<ll> b(N);
  for(int i=0;i<N;i++){
    cin>>b[i];
  }

  for(int k=0;k<N;k++){
    for(int l=0;l<9;l++){
      if(b[k]==A[l]) A_s[l]=1;
    }
  }
  if((A_s[0]==1&&A_s[1]==1&&A_s[2]==1)||(A_s[3]==1&&A_s[4]==1&&A_s[5]==1)
  ||(A_s[6]==1&&A_s[7]==1&&A_s[8]==1)||(A_s[0]==1&&A_s[3]==1&&A_s[6]==1)
  ||(A_s[1]==1&&A_s[4]==1&&A_s[7]==1)||(A_s[2]==1&&A_s[5]==1&&A_s[8]==1)
  ||(A_s[0]==1&&A_s[4]==1&&A_s[8]==1)||(A_s[2]==1&&A_s[4]==1&&A_s[6]==1)){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;


    return 0;
}


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

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_CAKE_MAX		8										// 最大ケーキ数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 個数取得
	int liACnt, liBCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liACnt, &liBCnt);

	// 判定
	int liRet = D_ON;
	if (liACnt > D_CAKE_MAX) {
		liRet = D_OFF;
	}
	if (liBCnt > D_CAKE_MAX) {
		liRet = D_OFF;
	}

	// 結果セット
	if (liRet == D_ON) {
		sprintf(lc1Out, "Yay!\n");
	}
	else {
		sprintf(lc1Out, ":(\n");
	}

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


M = 10**9+7
n = int(input())
p = list(map(int, input().split()))
g1 = [None]*(n+10)
v = 1
g1[0] = 1
for i in range(1,len(g1)):
    v *= i
    v %= M
    g1[i] = v
    
def init(bit, values):
    for i,v in enumerate(values):
        add(bit,i+1,v)
#a1 ~ aiまでの和 O(logn)
def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN)
def add(bit,i,x):
    if i==0:
        raise RuntimeError
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return


index = [i for i,num in enumerate(p) if num==0]
used = [False]*n
for i in range(n):
    if p[i]>0:
        used[p[i]-1] = True
nl = []
for i in range(n):
    if not used[i]:
        nl.append(i+1)
nl.sort()
scores = [0]*(n+1) # scores[i]: nlのうちiより大きいものの個数
v = len(nl)
cur = 0
for i in range(1,n+1):
    if nl and cur<len(nl) and nl[cur]<i:
#     if nl and nl[cur]<i:
        cur += 1
        v -= 1
    scores[i] = v
ans = 0
bit = [0]*(n+1)
s = set(index)
val = 0
pp = len(index) # 欠損の個数
ss = sum(nl)
num = 0
inv2 = pow(2, M-2, M)
for i in range(n):
    if p[i]==0:
        ans += (g1[pp-1] * (ss - pp - val - pp*(num)*inv2)) * g1[n-i-1]
        num += 1
    else:
        ans += (g1[pp] * (p[i]-query(bit, p[i])-1) - g1[pp-1]*num*(len(nl)-scores[p[i]])) * g1[n-i-1]
        add(bit, p[i], 1)
        val += scores[p[i]]
    ans %= M
#     print(ans, val)
print((ans + g1[pp])%M)

Measured memory_bytes: 222452
N,M = map(int,input().split())
PS = [list(map(str,input().split())) for i in range(M)]
A_num = [0]*N
W_num = [0]*N
w=0
#print(PS)
for j in range(M):
    #print(A_num)
    if PS[j][1] == 'WA'and A_num[int(PS[j][0])-1]==0:
        W_num[int(PS[j][0])-1]+=1 
    if PS[j][1]== 'AC' and A_num[int(PS[j][0])-1]==0:
        A_num[int(PS[j][0])-1]=1
s = sum(A_num)
for k in range(N):
    if A_num[k] == 0:
        W_num[k]=0
w = sum(W_num)
print(s,w)

Measured memory_bytes: 33680
n = input()

sm = 0
if int(n) <= 9:
    sm = n
elif len(n)%2 != 0:
    for i in range(0, len(n)-1, 2):
        sm += 9*10**i
    sm += int(n)-10**int(len(n)-1)+1
else:
    for i in range(0, len(n)-1, 2):
        sm += 9*10**i
        
print(sm)

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int N,Q;
int A[100005];
int num[100005];

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>A[i];
        num[A[i]]++;
    }
    cin>>Q;
    int ans=0;
    for(int i=0;i<=100000;++i)ans+=i*num[i];
    while(Q--){
        int B,C;
        cin>>B>>C;
        ans-=B*num[B];
        ans+=C*num[B];
        num[C]+=num[B];
        num[B]=0;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, -1, 0, 0};
int dx[4]={0, 0, 1, -1};

int32_t main(){
    vector<int> v(3);
    REP(i, 3) cin >> v[i];
    SORT(v);
    int cnt=0;
    while(v[1]<v[2]){
        v[0]++; v[1]++;
        cnt++;
    }
    while(v[0]<v[1]){
        v[0]+=2;
        cnt++;
    }
    if(v[0]>v[1]){
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
S = input()
case =True
while(case == True):
    if len(S) <5:
        case = False
    
    elif S[0:5] == 'dream': #check 'dreamer' and 'dream'
        if S[0:10] == 'dreamerase':
            S = S[5:]
        elif S[0:7] == 'dreamer':
            S = S[7:]
        else:
            S = S[5:]

    elif S[0:5] == 'erase': #check 'erase' and 'eraser'
        if len(S) > 5 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    
    else:
        case =False

if len(S) == 0:
    print('YES')
else:
    print('NO')
#print(S)

Measured memory_bytes: 3188
n = int(input())
f = [list(input().split()) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

result = []
for i in range(1, 2**10):
    b = format(i, "010b")
    r = 0
    for j in range(n):
        c = 0
        for s in range(10):
            if b[s]=="1" and f[j][s]=="1":
                c += 1
        r += p[j][c]
    result.append(r)
print(max(result))

Measured memory_bytes: 3064
#include <stdio.h>
#define N 8

int row[N],col[N],dpos[2*N],dneg[2*N];
int X[N][N];

void calc(){
  int i;
  for(i=0; i<N; i++){
    row[i] = -1;
    col[i] = -1;
  }
  for(i=0; i<2*N-1; i++){
    dpos[i] = -1;
    dneg[i] = -1;
  }
}

void print(){
  int i,j;

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(X[i][j]){
        if(row[i] != j) return;
      }
    }
  }

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(row[i]==j) printf("Q");
      else {
        printf(".");
      }
    }
    printf("\n");
  }
}

void condition(int i){
  int j;
  if(i==N){
    print();
    return ;
  }
  for(j=0; j<N; j++){
    if(col[j] == 1 || dpos[i+j] == 1 || dneg[i-j + N-1] == 1) continue;

    row[i] = j;
    col[j] = dpos[i+j] =dneg[i-j+N-1] = 1;

    condition(i+1);

    row[i] = col[j] = dpos[i+j] = dneg[i-j + N-1] =-1;
  }
}

int main(){
  int i,j,k,c,r;
  calc();

  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      X[i][j] = 0;
    }
  }

  scanf("%d",&k);

  for(i=0; i<k; i++){
    scanf("%d%d",&r,&c);
    X[r][c] = 1;
  }
  condition(0);

  return 0;
}



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

int main(){
    int n;
    cin >> n;
    int f[n], p[n][11];
    rep(i, n){
        int tmp = 0;
        rep(i, 10){
            int a;
            cin >> a;
            tmp += a * (1<<i);
        }
        f[i] = tmp;
    }

    rep(i, n) rep(j, 11) cin >> p[i][j];


    ll ans = - 1e+9 - 7;
    for(int bit = 1; bit < (1<<10); bit++){
        ll res = 0;
        rep(i, n){
            int cnt = __builtin_popcount(bit & f[i]);
            res += p[i][cnt];
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!.split(" ")[0]
    if(s == "SUN"){
        println(7)
    } else if (s == "MON"){
        println(6)
    } else if (s == "TUE"){
        println(5)
    } else if (s == "WED"){
        println(4)
    } else if (s == "THU"){
        println(3)
    } else if (s == "FRI"){
        println(2)
    } else if (s == "SAT"){
        println(1)
    }
}


Measured memory_bytes: 36156
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
 
using namespace std;
 
int main(){
 
    int n;
    cin >> n;

    string s,t;
    cin >> s >> t;

    for(int i = 0;i<n;i++){
        if(s.substr(i,n-i) == t.substr(0,n-i)){
            cout << n + i;
            return 0;
        }
    }
    cout << 2*n;

}

Measured memory_bytes: 256
### constant

D_E = 0
D_W = 1
D_N = 2
D_S = 3

### subroutines

def hv2nd(hv, n)
  h, v = hv.split('-')
  (h.ord - 'a'.ord) * n + (v.to_i - 1)
end

def sig_stop?(tm, k, direc)
  return false if k.nil?
  p = (tm / k) & 1
  dhv = (direc & 2) >> 1
  p == dhv
end

### main

while true
  m, n = gets.strip.split(' ').map{|s| s.to_i}
  break if m == 0 && n == 0

  d = gets.strip.to_i

  ns = gets.strip.to_i
  sigs = []
  ns.times.each do
    hv, k = gets.strip.split(' ')
    sigs[hv2nd(hv, n)] = k.to_i
  end

  mn = m * n

  edges = mn.times.map{[]}
  nbrs = mn.times.map{[nil] * 4}

  for n0 in (0...mn)
    x = n0 % n
    y = n0 / n
    if x < n - 1
      n1 = n0 + 1
      edges[n0][n1] = d
      edges[n1][n0] = d
      nbrs[n0][D_E] = n1
      nbrs[n1][D_W] = n0
    end
    if y < m - 1
      n1 = n0 + n
      edges[n0][n1] = d
      edges[n1][n0] = d
      nbrs[n0][D_S] = n1
      nbrs[n1][D_N] = n0
    end
  end

  nc = gets.strip.to_i
  nc.times.each do
    hv1, hv2 = gets.strip.split(' ')
    n1 = hv2nd(hv1, n)
    n2 = hv2nd(hv2, n)

    edges[n1][n2] = edges[n2][n1] = nil
    nbrs[n1][nbrs[n1].index(n2)] = nil
    nbrs[n2][nbrs[n2].index(n1)] = nil
  end

  nj = gets.strip.to_i
  nj.times.each do
    hv1, hv2, d0 = gets.strip.split(' ')
    n1 = hv2nd(hv1, n)
    n2 = hv2nd(hv2, n)
    di = d0.to_i

    edges[n1][n2] += di
    edges[n2][n1] += di
  end

  shv, ghv = gets.strip.split(' ')
  snd = hv2nd(shv, n)
  gnd = hv2nd(ghv, n)
  #puts "#{snd}->#{gnd}"

  ss = [0, snd, D_E]
  q = [ss]
  visited = {ss.join(',') => true}
  gtime = nil

  while ! q.empty?
    time0, n0, direc0 = q.shift
    if n0 == gnd
      gtime = time0
      break
    end

    for direc1 in (0..3)
      n1 = nbrs[n0][direc1]
      next if n1.nil? || (direc1 ^ 1) == direc0

      time1 = time0 + edges[n0][n1]
      s1 = [time1, n1, direc1]
      s1key = s1.join(',')

      next if ! visited[s1key].nil? || sig_stop?(time1, sigs[n1], direc1)

      id1 = q.find_index{|s| s[0] > time1}
      if id1.nil?
        q << s1
      else
        q.insert(id1, s1)
      end

      visited[s1key] = true
    end
  end
  #p times

  puts gtime
end

Measured memory_bytes: 24024
n=int(input())
a=list(map(int,input().split()))
num=[0]*n
ans=0
for i in range(n):
    num[a[i]-1]+=1
def cul(num1):
    if num1>=2:
        return ((num1-1)*num1)//2
    else:
        return 0
for i in range(n):
    ans=ans+cul(num[i])
for i in range(n):
    print(ans-num[a[i]-1]+1)


Measured memory_bytes: 32296
def main():
    N = list(str(input()))
    if len(N) == 1:
        print(int(N[0]))
    else:
        if all(n == "9" for n in N[1:]):
            print(int(N[0])+9*(len(N)-1))
        else:
            print((int(N[0])-1)+9*(len(N)-1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<double,P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

vector<ll> factrial, inverse;  //階乗と逆元を保持

ll mod_power(ll x, ll n) {  //繰り返し二乗法
    x %= MOD;
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

void init(ll n) {
    factrial.resize(n+1);
    inverse.resize(n+1);
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;
        inverse[i] = mod_power(factrial[i], MOD - 2);
    }
}

ll nCk(ll n, ll k) {
    if(n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(k == 1){
        cout << 0 << endl;
        return 0;
    }
    SORT(a);
    init(n);
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(i <= n-k){
            ans += (-nCk(n-1-i,k-1)*a[i]%MOD+MOD)%MOD;
        }
        if(i >= k-1){
            ans += nCk(i,k-1)*a[i]%MOD;
        }
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
//Harjot Singh Student NIT JALANDHAR	

#include<bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
const int mod =1e9+7;
int main()
{


  int n,m;
  cin>>n>>m;
  char arr[n][m];
  for(int i=0;i<n;i++)
  	for(int j=0;j<m;j++)
  		cin>>arr[i][j];
  	
    
  	int dp[n][m];
  	dp[0][0]=arr[0][0]=='.'?1:0;
  	for(int i=1;i<n;i++)
  	{
  		dp[i][0]=arr[i][0]=='.'?dp[i-1][0]:0;
  	}
  	for(int i=1;i<m;i++)
  		dp[0][i]=arr[0][i]=='.'?dp[0][i-1]:0;

  	for(int i=1;i<n;i++)
  		for(int j=1;j<m;j++)
  		{
  			if(arr[i][j]=='.')
  				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
  			else
  				dp[i][j]=0;
  		}

     cout<<dp[n-1][m-1]%mod<<endl;

      	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
typedef pair<int,int> pi;
unsigned hash[N];
char s[N];
int ls[N], rs[N], n;

int t[N][26];
int g[N][26];
int cnt=1;
int C[26];
long long ans=0;
pi f[N];
inline void ins(int r,int l){
	int u=1;
	for(int i=r;i>=l;i--)C[s[i]-'a']++;
	for(int i=r;i>=l;i--){
		if(i==l){
			ans+=g[u][s[l]-'a'];
		}
		for(int j=0;j<26;j++)if(C[j])g[u][j]++;
		u=t[u][s[i]-'a']==0?(t[u][s[i]-'a']=++cnt):t[u][s[i]-'a'];
		// cout << u << ":";
		C[s[i]-'a']--;
	}
	// puts("");
//	g[u][s[i+1]-'1']++;
}

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++){
		ls[i] = rs[i-1]+1;
		scanf("%s",s+ls[i]);
		rs[i] = ls[i] + strlen(s+ls[i]) - 1;
	//	ins(rs[i], ls[i]);
		f[i] = pi(rs[i]-ls[i]+1,i);
	//	cout << ans << endl;
	}
	sort(f+1,f+n+1);
	for(int i=n;i;i--){
		ins(rs[f[i].second],ls[f[i].second]);
		// cout << f[i].second << ":" << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 207356
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

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

	int mini = min_element(all(a)) - a.begin();
	int i = mini;
	int j = mini;
	int rest = 0;
	int count = 0;

	while (i != 0) {
		if (i - k + 1 <= 0) {
			rest += abs(i - k + 1);
			count++;
			break;
		}
		i = i - k + 1;
		count++;
	}
	while (j != n - 1) {
		if (j + k - 1 >= n - 1) {
			rest += j + k - 1 - n + 1;
			count++;
			break;
		}
		j = j + k - 1;
		count++;		
	}
	if (rest >= k-1) {
		count--;
	}
	cout << count << endl;

}

Measured memory_bytes: 640
N = int(input())
K = int(input())
N = str(N)
dp = [[[0]*2 for _ in range(K+1)] for _ in range(len(N)+1)]
dp[0][0][1] = 1  # 初期化, まだ崩れていないという認識
# 遷移を考える
for i in range(len(N)):
    x = int(N[i])  # 上からi桁目を考える
    for j in range(K):
        # 崩れているものを増やしていく
        dp[i+1][j+1][0] += dp[i][j][0]*9  # 非ゼロを増やした
        dp[i+1][j][0] += dp[i][j][0]  # ゼロを使った
        # 崩れていないものについて
        if x > 0:
            dp[i+1][j][0] += dp[i][j][1]  # 0を使って崩す
            dp[i+1][j+1][0] += dp[i][j][1]*(x-1)  # x未満の数字を使って(jが増える)崩した場合
            dp[i+1][j+1][1] += dp[i][j][1]  # xをそのまま埋め込んで崩れていない状態を選んだ場合
        else:
            # 崩さない場合は、0を埋め込むしかないのでjは増えない
            dp[i+1][j][1] += dp[i][j][1]  # 0を埋め込む
    dp[i+1][K][0] += dp[i][K][0]
    dp[i+1][K][not x>0] += dp[i][K][1]
print(sum(dp[len(N)][K]))


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  int s = 0;
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (s + v.at(i) <= x) {
      s += v.at(i);
      c++;
    }
    else break;
  }
  if (s < x && c == n) cout << n - 1 << endl;
  else cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<pair<int, int>> bom(m);
	for (int i = 0; i < m; ++i) {
		cin >> bom[i].first >> bom[i].second;
		bom[i].first--; bom[i].second--;
	}

	map<int, int> row_map, col_map;
	for (int i = 0; i < m; ++i) {
		row_map[bom[i].first]++; col_map[bom[i].second]++;
	}

	int row_max = 0, col_max = 0;
	for (auto kv : row_map) row_max = max(row_max, kv.second);
	for (auto kv : col_map) col_max = max(col_max, kv.second);

	ll row_max_cnt = 0, col_max_cnt = 0;
	for (auto kv : row_map) if (kv.second == row_max) row_max_cnt++;
	for (auto kv : col_map) if (kv.second == col_max) col_max_cnt++;

	ll pat = row_max_cnt * col_max_cnt;
	ll bom_max_cnt = 0;
	for (int i = 0; i < m; ++i)
		if (row_map[bom[i].first] == row_max && col_map[bom[i].second] == col_max)
			bom_max_cnt++;

	int ans = row_max + col_max;
	if (bom_max_cnt >= pat) --ans;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 33220
/**
 *      ABC 92 A
 *      author  : kyomukyomupurin
 *      created : 2018-08-30 17:13:16
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;

const long MOD = 1000000007;


int main(){
    string S,T;
    cin>>S>>T;
    bool flag = false;
    if(S.size() == T.size()-1){
        flag = true;
        for(ll i=0;i<S.size();i++){
            if(S[i]!=T[i])flag=false;
        }
    }
    cout<<(flag? "Yes":"No")<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, M;

ll count_max(vector<queue<ll>>& A, vector<bool>& already)
{
  vector<ll> cnt(M, 0);
  for (ll i = 0; i < N; ++i) {
    while (true) {
      if (already.at(A.at(i).front())) {
        A.at(i).pop();
      }
      else {
        cnt.at(A.at(i).front()) += 1;
        break;
      }
    }
  }
  ll res = 0, index;
  for (ll i = 0; i < M; ++i) {
    if (res < cnt.at(i)) {
      index = i;
      res = cnt.at(i);
    }
  }
  already.at(index) = true;
  return res;
}

int main()
{
  cin >> N >> M;
  ll ans = INF;
  vector<bool> already(M, false);
  vector<queue<ll>> A(N);
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < M; ++j) {
      ll a;
      cin >> a;
      a -= 1;
      A.at(i).push(a);
    }
  }
  for (ll i = 0; i < M; ++i) {
    ans = min(ans, count_max(A, already));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main(){
    string x,y;
    cin>>x>>y;
    int n = x.size();
    int m = y.size();

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(x[i-1]==y[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    string ans ="";
    while(n!=0 && m!=0){
        if(dp[n-1][m]==dp[n][m])    n--;
        else if(dp[n][m-1]==dp[n][m])   m--;
        else{
            n--;
            m--;
            ans+=x[n];
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

Measured memory_bytes: 35456
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  bool c=false,f=false;
  string s;
  cin >> s;
  REP(i,s.length()){
    if (!c){
      if (s[i]=='C') c=true;
    } else {
      if (s[i]=='F') f=true;
    } 
  }
  Yn(f);
}

Measured memory_bytes: 256
num = []
for i in input().split():
    if i == "+":
        a = num.pop()
        b = num.pop()
        num.append(a+b)
    elif i == "-":
        a = num.pop()
        b = num.pop()
        num.append(b-a)
    elif i == "*":
        a = num.pop()
        b = num.pop()
        num.append(a*b)
    else:
        num.append(int(i))
print(num[0])


Measured memory_bytes: 5600
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let a = line[0];
    let b = line[1];
    let c = line[2];


    println!("{}", cmp::min(b/a, c));
}


Measured memory_bytes: 4352
n, m = gets.split.map(&:to_i)
lights = m.times.map { gets.split.map(&:to_i)[1..-1] }
ps = gets.split.map(&:to_i)

ans = (2**n).times.count do |switches|
  m.times.all? { |i| lights[i].count { |s| switches[s - 1] == 1 } % 2 == ps[i] }
end
puts ans

Measured memory_bytes: 1788
s = int(input())
l = [s]
max=s
 
while 1:
  if s %2 == 0:
    l.append(s/2)
    s = int(s/2)
  else:
    l.append(3*s + 1)
    s = 3*s+1
    max = s
  
  if any(l.count(i) >= 2 for i in range(s+1)):
    print(len(l))
    break

Measured memory_bytes: 3060