akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

ll N, M, K;
ll asum[200010], bsum[200010];

// 二分探索
ll binary_search(ll key) {
  int left = -1;
  int right = M;

  /* どんな二分探索でもここの書き方を変えずにできる！ */
  while (right - left > 1) {
    int mid = left + (right - left) / 2;

    if (bsum[mid] > key) right = mid;
    else left = mid;
  }

  /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
  return right;
}

int main() {
  cin >> N >> M >> K;
  ll a[N], b[M];
  for (int i = 0; i < N; i++) cin >> a[i];
  for (int i = 0; i < M; i++) cin >> b[i];

  asum[0] = a[0];
  for (int i = 1; i < N; i++) asum[i] = a[i] + asum[i-1];
  bsum[0] = b[0];
  for (int i = 1; i < M; i++) bsum[i] = b[i] + bsum[i-1];

  ll ans = binary_search(K);
  for (int i = 0; i < N; i++) {
    if (asum[i] <= K) {
      ans = max(ans, i + 1 + binary_search(K - asum[i])); 
    }
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin>>s;
    cout<<((s[0]==s[1]&&s[1]==s[2]) || (s[3]==s[2]&&s[2]==s[1]) ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    for(int i = 0; i < k; i++) {
        cin >> d[i];
    }
    for(int i = n; ; i++) {
        int j = i;
        bool can = true;
        while(j > 0) {
            can &= find(d.begin(), d.end(), j % 10) == d.end();
            j /= 10;
        }
        if(can) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    n, p = map(int, input().split())
    pp = p
    if n == p == 0:
        break
    stones = [0] * n
    for i in range(1000000):
        er = i % n
        if p == 1 and stones[er] == pp - 1:
            print(er)
            break
        if p >= 1:
            stones[er] += 1
            p -= 1
        else:
            p += stones[er]
            stones[er] = 0

Measured memory_bytes: 7612
$ss = gets.chomp.split('').map &:to_s
t = gets.chomp.split('').map &:to_s

UNR = 'UNRESTORABLE'

def is_p(s,t)
  s.each_with_index do |v, i|
    next if v === '?'
    return false if v != t[i]
  end
  return true
end

def exchange(t, start)
  ss = $ss.dup
  t.each_with_index do |tt, i|
    ss[start + i] = tt
  end
  return ss
end

if $ss.size < t.size
  puts UNR
  exit
end

oks = []
($ss.size - t.size + 1).times do |i|
  if is_p($ss[i..i+t.size-1], t)
    oks << exchange(t, i).join.gsub(/\?/, 'a')
  end
end

if oks.size.zero?
  puts UNR
  exit
end

puts oks.sort.first


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
const int N = 230;
int n, m;
char a[N][N];
int o;
int f[2][N][N][N];
int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
	for(int j = m; j; j--) {
		for(int i = 1; i <= n; i++) {
			for(int k = i; k <= n; k++) if(a[k][j] == a[i][j]) {
				f[o][j][i][k] = j;
				if (a[i][j] == a[i][j + 1]) {
					f[o][j][i][k] = max(j, f[o][j + 1][i][k]);
				}
			} else break;
		}
	}
	for(int ans = 0; ans <= 20; ans++) {
		if (f[o][1][1][n] == m) {
			printf("%d\n", ans); return 0;
		}
		memset(f[1 - o], 0, sizeof f[1 - o]);
		for(int j = 1; j <= m; j++) {
			for(int i = 1; i <= n; i++) {
				for(int z = i; z <= n; z++) {
					int g = f[o][j][i][z];
					if (f[o][j][i][z] > 0 && f[o][j][i][z] < m)
						g = max(g, f[o][ f[o][j][i][z] + 1 ][i][z]);
					if (i != z) {
						int l = i, r = z - 1, ret = l;
						while (l <= r) {
							int mid = l + r >> 1;
							if (f[o][j][i][mid] >= f[o][j][mid + 1][z]) {
								ret = mid, l = mid + 1;
							} else r = mid - 1;
						}
						g = max(g, min(f[o][j][i][ret], f[o][j][ret + 1][z]));
						ret ++;
						if (ret < z)
							g = max(g, min(f[o][j][i][ret], f[o][j][ret + 1][z]));
					}
					f[1 - o][j][i][z] = g;
				}
				int e = j;
			}
		}
		o = 1 - o;
	}
}


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

using namespace std;

long long  a[300010] = {};

int main(){
    int n;
    unsigned long long ans = 0;
    cin >> n;

    for(int i = 0;i < n*3;i++)cin >> a[i];
    sort(a,a+(n*3));
    for(int i = n*3-2; i >= n;i-=2){
        ans += a[i];
        //cout << a[i] <<endl;
    }
    cout << ans << endl;

    return 0;
}

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

const int64_t mod=1e9+7;
int64_t a,b,fac[100005];

int main()
{
    cin>>a>>b;
    fac[0]=1;
    for(int64_t i=1;i<=1e5;i++)
        fac[i]=fac[i-1]*i%mod;
    if(abs(a-b)>=2)
        cout<<0;
    else
    if(a==b)
        cout<<2LL*fac[a]*fac[b]%mod;
    else
        cout<<fac[a]*fac[b]%mod;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x,a,b;
	cin >> a >> b >> x;
	if (a > x ){
		cout << "NO" << endl;
	}else if ( (a+b) >= x){
		cout << "YES" << endl ;
	}else if ((a+b)<x){
		cout << "NO" << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define MOD 1000000007

int modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = modPow(2, n) - 1;
    //cout << ans << endl;
    ll tmp_a = 1, tmp_b = 1;

    for (int i = n; i > n - a; i--) {
        tmp_a *= i;
        tmp_a %= MOD;
    }
    for (int i = n; i > n - b; i--) {
        tmp_b *= i;
        tmp_b %= MOD;
    }
    //cout << tmp_b << endl;

    ll div_a = 1, div_b = 1;
    for (int i = a; i > 0; i--) {
        div_a *= i;
        div_a %= MOD;
    }
    for (int i = b; i > 0; i--) {
        div_b *= i;
        div_b %= MOD;
    }

    tmp_a *= modPow(div_a, MOD - 2);
    tmp_b *= modPow(div_b, MOD - 2);

    ans = ((ans % MOD) - (tmp_a % MOD) - (tmp_b % MOD)) % MOD;
    if (ans < 0) ans += MOD;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

R = [0] * N
R[0] = sum(A)
for i in range(1, len(A), 2):
  R[0] -= A[i] * 2

for i in range(len(A)-1):
  R[i + 1] = A[i] * 2 - R[i]
  
print(*R)

Measured memory_bytes: 14204
using System;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            char b = a[0];
            char c = a[1];
            char d = a[2];
            if (b == c && c == d)
                Console.WriteLine("No");
            else
                Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11092
from itertools import permutations
from numpy import sqrt
def dist(x,y):
    return sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2)

N = int(input())

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

ans = 0
l = 0
for way in permutations(range(0,N)):
    l += 1
    for i in range(N-1):
        ans += dist(d[way[i]],d[way[i+1]])
    
print(ans/l)

Measured memory_bytes: 14392
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	int n,x,l,pos=0,ans=1;
    cin>>n>>x;
    rep(i,n){
        cin>>l;
        pos+=l;
        if(pos<=x)ans++;
    }
    cout<<ans<<endl;
}

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

vector<pair<string, int>> ps;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	rep(i, n) {
		string a; int b; cin >> a >> b;
		ps.pb({a, b});
	}
	string t; cin >> t;
	int ans = -1; 
	for(auto& e:ps) {
		if(ans != -1) ans += e.se;
		if(e.fi == t) ans = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	vector<int> h(100001);
	cin >> n;
	for (int i = 0; i < n; i++)cin >> h[i];

	vector<int> dp(100001);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++)
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int d, n; cin >> d >> n;
    int ans = n;
    rep(i, d) ans *= 100;
    if(n == 100) ans += ll(pow(100, d));
    cout << ans << endl;
}

Measured memory_bytes: 3696
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int M = sc.nextInt();
	    
	    Queue <Integer> A = new PriorityQueue <Integer>();
	    
	    for (int i=0; i<M; i++){
	    	int ai=sc.nextInt();
	    	int bi=sc.nextInt();
	    	
	    	if (ai==1){
	    		A.add(bi);
	    	}
	    	else if (bi==N){
	    		A.add(ai);
	    	}	
	    }
	    sc.close();
	    
	    
	    int size = A.size();
	    boolean ans = false;
	  
	    if (size>1) {
	    	
	    	for (int i=0; i<size-1; i++){
	    		int temp=A.poll();
	    		if (temp==A.peek()){
	    			ans = true;
	    			break;
	    		}
	    	}
	    }
	    if (ans==false)
	    	System.out.println("IMPOSSIBLE");
	    
	    else if  (ans==true)
	    	System.out.println("POSSIBLE");
	    	
	}

}


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

using namespace std ;
bool checkPal (string s ) {
	for(  int i = 0  , j = s.size()-1 ; i < j ; i++ , j-- ) {
//cout << i << " " << j << endl ; 
//cout << s[i] << " " << s[j] << endl ; 
		if( s[i] != s[j] )
			return false ; 
	}
	return true ; 
}
int main () {
	ios_base::sync_with_stdio; 
	cin.tie(0) ; 
	cout.tie(0)  ; 
	
	string s ; 
	cin >> s;  
	string a , b ; 
	for ( int i = 0 ;  i < (s.size()-1)/ 2 ; i ++ ) {
		a.push_back(s[i]);  
	}
	for ( int i = (s.size()+3)/2-1 ; i < s.size() ; i ++ ) 
		b.push_back(s[i]) ; 
//	cout << a << endl <<  b << endl ; 
	if (checkPal(a) && checkPal(b) && checkPal(s) )
		cout << "Yes" << endl ; 
	else
		cout << "No" << endl ; 
	
	
}


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

void solve(long long n, std::vector<long long> a) {
    vector<ll> ans;
    rep(i, n) {
        if (i % 2 == 0) {
            ans.push_back(a[i]);
        } else {
            ans.insert(ans.begin(), a[i]);
        }
    }
    if (n % 2 == 0) {
        rep(i, n) { cout << ans[i] << " "; }
    } else {
        rep(i, n) { cout << ans[n - 1 - i] << " "; }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long n;
    scanf("%lld", &n);
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }
    solve(n, std::move(a));
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
using namespace std;
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	int l=1;
	ll ans=0,sum=0;
	for(int r=1;r<=n;r++){
		scanf("%d",&a[r]);
		while((sum^a[r])!=sum+a[r])sum^=a[l],l++;
		sum^=a[r];
		ans+=(r-l+1);
	}
	printf("%lld\n", ans);
	return 0;
}
/*
Sample Input 3
19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1
Sample Output 3
37
*/

Measured memory_bytes: 1024
import collections

N = int(input())
S = str(input())

num_open = 0
num_close = 0

q = collections.deque([])

for i in range(N):
  if S[i] == "(":
    q.append("(")
  if S[i] == ")":
    if len(q) == 0:
      num_close += 1
    else:
      q.pop()

num_open = len(q)
str_close = "(" * num_close
str_open =  ")" * num_open


ans = str_close + S + str_open

print(ans)


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

using ll = long long;
#define REP(i,n) for(int i = 0;i < n;i++)
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{";
	for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i];
	cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n";
	for (auto& vec : arr)cout << "  " << vec << ",\n";
	cout << "}";
	return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll k;cin >> k;

  if(k % 2 == 0){
  	cout << -1 << '\n';
  	return 0;
  }

  ll ten = 1;
  ll tmp = 0;
  int cnt = 1;
  for(int i = 0;i < 1e7;i++){
  	ll add = (7 * ten) % k; 
  	tmp = (tmp + add) % k;
  	ten = (ten * 10) % k;
  	if(tmp == 0){
  		cout << cnt << '\n';
  		return 0;
  	}
  	cnt++;
  }
  cout << -1 << '\n';

}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n - 1; i++) cin >> c[i];

    int ans = 0;
    for(int i = 0; i < n; i++) {
        int idx = a[i] - 1;
        ans += b[idx];
        if(i < n && a[i + 1] - 1 - idx == 1) ans += c[idx];
    }

    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, M, ans=0;
	int a[200005], b[200005];
	vector<int> v[200005];

	cin >> N >> M;
	rep(i,M){
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	ll d[200005];
	Fill( d, INF );
	queue<pll> que;
	que.emplace(0, 1);
	d[1] = 0;
	while( !que.empty() ){
		auto p = que.front();
		que.pop();
		//if( !chmin<ll>( d[p.Y], p.X ) ) continue;
		if( p.X > 2 ) continue;
		for(auto t: v[p.Y]){
			if( d[t] > p.X + 1 ){
				que.emplace( p.X + 1, t );
				d[t] = p.X + 1;
			}
		}
	}

	ans = d[N];
	cout << (ans>2 ? "IMPOSSIBLE" : "POSSIBLE") << endl;

	return 0;
}


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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;
    cin >> A >> B >> C >> N;
    cout << (A-C)*(B-N) << endl;
//    vector<int> X();

//    for(int i = 0; i < ; i++){}
//    for(int j = 0; j < ; j++){}

//    cout <<  << endl;
}

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

money = 1000
stock = 0
for day in range(N-1):
    today_price = A[day]
    tommorow_price = A[day+1]
    if today_price < tommorow_price:
        div,mod = divmod(money, today_price)
        stock += div
        money = mod
    elif today_price > tommorow_price:
        money += today_price * stock
        stock = 0
money += A[N-1] * stock
print(money)

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int& k : l)
    cin >> k;
  sort(l.begin(), l.end());
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 2; j < n; ++j) {
      int k = lower_bound(l.begin() + i + 1, l.begin() + j, l[j] - l[i] + 1) - l.begin();
      ret += max(0, j - k);
    }
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    string s, t;
    cin >>s >> t;
    cout << t << s << endl;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(W):
        print('#', end='')
    print()
    for i in range(H - 2):
        print('#', end='')
        for j in range(W - 2):
            print('.', end='')
        print('#')
    for i in range(W):
        print('#', end='')
    print('\n')



Measured memory_bytes: 7008
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	VVI A;
	A.resize(3, VI(3, 0));
	for (int y = 0; y < 3; y++) {
		for (int x = 0; x < 3; x++)cin >> A[y][x];
	}
	int N;
	cin >> N;
	vector<vector<bool>> check;
	check.resize(3, vector<bool>(3, false));
	for (int n = 0; n < N; n++) {
		int b;
		cin >> b;
		for (int y = 0; y < 3; y++) {
			for (int x = 0; x < 3; x++) {
				if (A[y][x] == b)check[y][x] = true;
			}
		}
	}
	for (int x = 0; x < 3; x++) {
		if (check[0][x] && check[1][x] && check[2][x])goto YES;
	}
	for (int y = 0; y < 3; y++) {
		if (check[y][0] && check[y][1] && check[y][2])goto YES;
	}
	if (check[0][0] && check[1][1] && check[2][2])goto YES;
	if (check[0][2] && check[1][1] && check[2][0])goto YES;
	goto NO;
YES:
	cout << "Yes\n";
	return 0;
NO:
	cout << "No\n";
	return 0;
}

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

int a, b, n;
char c;
 
int main() {
	int i;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> c, a += c == 'R', b += c == 'B';
	if (a > b) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i,s,e) for(int i=s;i<e;i++)
#define drep(i,s,e) for(int i=s;i>e;i--)
#define ll long long
using namespace std;
stack<int> v;
int main(){
    ios_base::sync_with_stdio(0);
    ll n;
    cin>>n;
    n++;
    while(n>1){
        if(n%2){
            v.push(1);
            n--;
        }
        else{
            v.push(2);
            n/=2;
        }
    }
   /*while(!v.empty())
   {
     cout<<v.top();
       v.pop();
   }
    return 0; */ 
   int k=1;
   deque<int> ans;
    while(!v.empty()){
        int u=v.top();
        v.pop();
        if(u==1)
            ans.push_front(k);
        else
            ans.pb(k);
        k++;
    }
    cout<<2*(k-1)<<endl;
    for(int i=1;i<k;i++)
        cout<<i<<' ';
    while(!ans.empty()){
        cout<<ans.front()<<' ';
        ans.pop_front();
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int arr[26][55];
int ans[26];
int n;
int minone(int x){
    int s=100;
    for(int i=0;i<n;i++){
        s=min(s,arr[x][i]);
    }
    return s;
}
void p(int x,int t){
    for(int i=0;i<t;i++)
        printf("%c",x+'a');
}
int main(){
    scanf("%d",&n);
    memset(arr,0,sizeof(arr));
    memset(ans,0,sizeof(ans));
    char str[55];
    for(int i=0;i<n;i++){
        scanf("%s",str);
        for(int j=0;str[j]!='\0';j++){
            arr[str[j]-'a'][i]++;
        }
    }
    for(int i=0;i<26;i++){
        ans[i]=minone(i);
    }
    for(int i=0;i<26;i++){
        if(ans[i]!=0){
            p(i,ans[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 128
N=int(input())
c=str(input())
rnum=c.count('R')
wnum=c.count('W')

rnum_front=c.count('R', 0, rnum)
wnum_back=c.count('W', N-wnum, N)

if rnum > wnum:
    print(wnum-wnum_back)
else:
    print(rnum-rnum_front)


Measured memory_bytes: 9288
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M, P = map(int, input().split())

edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, -c+P])


def bellnabFord(edges, src, N):
    inf = float('inf')
    dist = [inf for i in range(N)]
    dist[src] = 0

    for i in range(2*N):
        for s, d, c in edges:
            if s != inf and dist[d] > dist[s]+c:
                dist[d] = dist[s]+c
                if i >= N: #N回目以降の更新では-infに。(数字の大きさに影響されない)
                    dist[d] = -float('inf')

            if i == N-1:
                prev = dist[-1]
    return (prev, dist[-1])


prev, dist = bellnabFord(edges, 0, N)
if prev != dist:
    ans = -1
else:
    ans = max(0, -dist)
print(ans)

Measured memory_bytes: 74548
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

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

    for (int i = X - K + 1; i <= X + K - 1; i++) {
        if (-1000000 <= i  && i <= 1000000) {
            cout << i << ' ';
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n,m,max,i,j,a[1000];

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

}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
const int oo = 1e6;
bool sortbysec(const pair<int, int>& a,
	const pair<int, int>& b)
{
	return (a.second < b.second);
}
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int len = b.length();
  	int lena = a.length();
	if (a[lena - 1]  == b[0] && b[len - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#include<climits>
#define MOD 1000000007

vector<int> dsu;

int fin(int x){
    if(x == dsu[x])
        return x;
    return dsu[x] = fin(dsu[x]);
}

void uni(int x, int y){
    int xroot = fin(x);
    // cout << "got xroot" << endl;
    int yroot = fin(y);
    // cout << "got yroot" << endl;
    // cout << "for " << x << ' ' << y << " " << xroot << ' ' << yroot << endl;
    if(xroot != yroot){
        dsu[xroot] = yroot;
    }
}

signed main() {
    int n;
    cin >> n;
    dsu.resize(n);
    for(int i = 0; i < n; i++)
        dsu[i] = i;
    int m;
    cin >> m;
    
    for(int i = 0; i < m; i++){
        int x,y;
        cin >> x >> y;
        uni(x - 1, y - 1);
        // cout << "Temp" << endl;
        // copy(dsu.begin(), dsu.end(), ostream_iterator<int>(cout, " "));
        // cout << endl;
    }
    // cout << "2" << endl;
    for(int i = 0; i < n; i++){
        fin(i);
    }
    unordered_map<int, int> mp;
    for(const auto& ele : dsu){
        mp[ele]++;
    }
    int ans = INT_MIN;
    for(const auto& pr : mp){
        ans = max(ans, pr.second);
    }
    // copy(dsu.begin(), dsu.end(), ostream_iterator<int>(cout, " "));
    // cout << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12064
#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits>

using namespace std;

const double MinAngVelPerMin = 2 * M_PI / 60.0;
const double HourAngVelPerMin = 2 * M_PI / (12.0 * 60.0);
const double DEG_TO_RAD = M_PI / 180.0;
const double RAD_90 = M_PI / 2;
const double RAD_180 = M_PI;
const double RAD_270 = M_PI * 1.5;
const double RAD_360 = M_PI * 2;

struct Pt {
public:
	double x;
	double y;

	Pt() {
		this->x = 0;
		this->y = 0;
	}

	Pt(double x, double y) {
		this->x = x;
		this->y = y;
	}
};

Pt GetPt(double angle, int hypo) {
	Pt pt = Pt();

	angle = fmod(angle, RAD_360);

	if (angle >= 0 && angle <= RAD_90) {
		angle = RAD_90 - angle;
		pt.x = cos(angle) * hypo;
		pt.y = sin(angle) * hypo;
	}
	else if (angle > RAD_90 && angle <= RAD_180) {
		angle -= RAD_90;
		pt.x = cos(angle) * hypo;
		pt.y = -sin(angle) * hypo;
	}
	else if (angle > RAD_180 && angle <= RAD_270) {
		angle = RAD_90 - (angle - RAD_180);
		pt.x = -cos(angle) * hypo;
		pt.y = -sin(angle) * hypo;
	}
	else {
		angle -= RAD_270;
		pt.x = -cos(angle) * hypo;
		pt.y = sin(angle) * hypo;
	}

	return pt;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout.precision(numeric_limits<double>::max_digits10);

	int hourHandLen, minHandLen, hour, min;

	cin >> hourHandLen >> minHandLen >> hour >> min;

	Pt minHandPt = GetPt(MinAngVelPerMin * min, minHandLen);
	Pt hourHandPt = GetPt(HourAngVelPerMin * ((hour * 60) + min), hourHandLen);

	double xDiff = (hourHandPt.x - minHandPt.x);
	double yDiff = (hourHandPt.y - minHandPt.y);

	double dist = sqrt((xDiff * xDiff) + (yDiff * yDiff));

	cout << dist << endl;

	return 0;
}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
#define ll long long


using namespace std;

map <int, int> mp;

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, x;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> x;
        mp[x]++;
    }
    cin >> m;
    for(i = 1; i <= m; i++) {
        cin >> x;
        mp[x]--;
        if(mp[x] < 0) {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 9728
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSplittingPile solver = new CSplittingPile();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSplittingPile {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long sum = 0;
            for (long x : a) {
                sum += x;
            }

            long answer = Long.MAX_VALUE;
            long first = 0;
            for (int i = 0; i < n - 1; i++) {
                first += a[i];
                sum -= a[i];

                answer = Math.min(answer, Math.abs(first - sum));
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<long long> arr;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n, m, k;
    cin >> n >> m >> k;

    for(int rows = 0; rows * 2 < n; ++rows){
        if(k >= rows * m && (k - rows * m) % (n - rows * 2) == 0 && (k - rows * m) / (n - rows * 2) <= m){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
    int a,b;
    char op;
    while(1)
    {
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?')
        {
            break;
        }
        switch(op)
        {
            case '+':
      printf("%d\n",a+b);
      break;
    case '-':
      printf("%d\n",a-b);
      break;
    case '*':
      printf("%d\n",a*b);
      break;
    case '/':
      printf("%d\n",a/b);
      break;
        }
    }
}



Measured memory_bytes: 2148
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
using dd = long double;
int main() {
  ll N, K;
  cin >> N >> K;

  vector<ll> log(N);
  for (ll i = 0; i < N; i++) {
    cin >> log[i];
  }
  ll l = 1;
  ll r = 1e9;

  while ((r - l) > 1) {
    ll mid = (l + r) / 2;
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      if (log[i] <= mid){
        continue;
      }
      sum += (log[i] / mid) + (log[i] % mid == 0 ? -1 : 0);
    }
    if (sum > K) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  ll l_sum = 0;
  for (ll i = 0; i < N; i++) {
    if (log[i] <= l){ 
      continue;
    }
    l_sum += (log[i] / l) + (log[i] % l == 0 ? -1 : 0);
  }

  if (l_sum <= K){ 
    cout << l << endl;
  } else {
    cout << r << endl;
  }
}

Measured memory_bytes: 4744
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define numarr 10
#define inf 100000000
using namespace std;

int main() {
	int i, j, k, p, N, A, B, C, a, b, c, abc[3], anum, bnum, MP, MP_min = inf, l[numarr], la[numarr], lb[numarr], count, gacount, gbcount, gccount;
	cin >> N >> A >> B >> C;
	for (i = 0; i < N; i++)
	{
		cin >> l[i];
	}
	for (i = 1; i < pow(2, N); i++)
	{
		a = 0;
		gacount = -10;
		anum = 0;
		count = 0;
		for (p = 0; p < N; p++)
		{
			if ((i >> p) % 2)
			{
				a += l[p];
				anum++;
				gacount += 10;
			}
			else
			{
				la[count] = l[p];
				count++;
			}
		}
		count = 0;
		for (j = 1; j < pow(2, N - anum); j++)
		{
			gbcount = -10;
			bnum = 0;
			b = 0;
			for (p = 0; p < N - anum; p++)
			{
				if ((j >> p) % 2)
				{
					b += la[p];
					bnum++;
					gbcount += 10;
				}
				else
				{
					lb[count] = la[p];
					count++;
				}
			}
			count = 0;
			for (k = 1; k < pow(2, N - anum - bnum); k++)
			{
				gccount = -10;
				c = 0;
				for (p = 0; p < N - anum - bnum; p++)
				{
					if ((k >> p) % 2)
					{
						c += lb[p];
						gccount += 10;
					}
				}
				abc[0] = a;
				abc[1] = b;
				abc[2] = c;
				
				sort(abc, abc + 3, greater<int>());
				MP = 0;
				MP += abs(abc[0] - A);
				MP += abs(abc[1] - B);
				MP += abs(abc[2] - C);
				MP += gacount;
				MP += gbcount;
				MP += gccount;
				MP_min = min(MP, MP_min);
			}
		}
	}
	cout << MP_min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
long long a[3010],b[3010],dp[3010][6010];
pair<long long,long long> p[3010];
int main(){
	int i,j,n,t;
	cin >> n >> t;
	for(i=0;i<n;i++){
		cin >> a[i] >> b[i];
		p[i] = {a[i],b[i]};
	}
	sort(p,p + n);
	for(i=0;i<n;i++){
		a[i] = p[i].first,b[i] = p[i].second;
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=6001;j++){
			dp[i][j] = -100000000000;
		}
	}
	dp[0][0] = 0;
	for(i=1;i<=n;i++){
		for(j=0;j<=6001;j++){
			dp[i][j] = max(dp[i][j],dp[i - 1][j]);
		}
		for(j=0;j<t;j++){
			dp[i][j + a[i - 1]] = max(dp[i][j + a[i - 1]],dp[i - 1][j] + b[i - 1]);
		}
	}
	long long mx = 0;
	for(i=0;i<=6001;i++){
		mx = max(dp[n][i],mx);
	}
	cout << mx << endl;
}
	

Measured memory_bytes: 141696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll dp[2010][2010] , jc[5000010];
ll Pow(ll x , ll y)
{
	ll res = 1;
	while (y)
	{
		if (y & 1)
		{
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		y >>= 1;
	}
	return res;
}
ll getc(int n , int r)
{
	return (jc[n] * Pow(jc[n - r] * jc[r] % mod , mod - 2)) % mod;
}
int main()
{
	int n , k;
	scanf("%d%d" , &n , &k);
	jc[0] = 1;
	for (int i = 1; i <= 5000000; i++)
	{
		jc[i] = (jc[i - 1] * i) % mod;
	}
	if (k == 1)
	{
		printf("1\n");
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = 1;
		for (int j = 1; j <= i; j++)
		{
			dp[i][j] = dp[i - 1][j];
			dp[i][j] += dp[i][j - 1] * (n - j + 1) % mod
			* getc((n - j + 1) * (k - 1) + n - i - 1 , k - 2) % mod;
			dp[i][j] %= mod;
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	printf("%lld\n" , dp[n][n]);
	return 0;
}

Measured memory_bytes: 70784
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include <bits/stdc++.h>
using namespace std ;
 
 
typedef long long                ll;
typedef long double              ld;
typedef unsigned long long       ull;
typedef pair <int,int>           pii;
typedef pair <ll,ll>             pll;
typedef vector <int>             vi;
typedef vector <ll>              vll;
typedef vector <vector <int> >   vvi;
 
inline int    Int(){int x; cin >> x; return x;}
inline ll     Long(){ll x; cin >> x; return x;}
inline float  Float(){float x; cin >> x; return x;}
inline double Double(){double x; cin >> x; return x;}
inline void   Yes(){cout << "Yes" << endl;}
inline void   No(){cout << "No" << endl;}
inline void   YES(){cout << "YES" << endl;}
inline void   NO(){cout << "NO" << endl;}
 
const int N             =(int)2e5 + 5;
const int maxN          =(int)1e6 + 6;
const ll  Mod           =(ll)1e9 + 7;
const int inf           =(int)2e9;
const ll  Inf           =(ll)1e18;
 
#define     T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b > e); i =i+1-2*(b > e))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
#define     biday       return 0 
 
 
int main()
{
	ll N,i,cnt=0;
	cin >> N;
    
        ll x = 100;
	for(i = 1; ; i++)
	{
		if(x>=N)break;
		cnt++;
        x = x+((x*1)/100);
	}
	cout << cnt << endl;
    

    biday;
}
 
//...............BYE BYE................

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


Measured memory_bytes: 256
#include <cstdio>
#define ll long long
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=2e3+5,B=4e6+5,mod=1e9+7;
int n,k,i,j,ans,f[N][N],fac[B],inv[B];
int fgm(int a,int n)
{
	int ret=1,bsc=a;
	for (;n>0;n>>=1,bsc=(ll)bsc*bsc%mod)
	if (n&1) ret=(ll)ret*bsc%mod;
	return ret;
}
int C(int n,int m)
{
	if (n<m) return 0;
	if (!m || !(n-m)) return 1;
	return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
//	freopen("leftmost.in","r",stdin);
//	freopen("leftmost.out","w",stdout);
	scanf("%d%d",&n,&k);
	if (k==1) {
		printf("1\n"); return 0;
	}

	fac[1]=fac[0]=inv[1]=inv[0]=1; 
	rep(i,2,n*k) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n*k]=fgm(fac[n*k],mod-2);
	down(i,n*k-1,2)	inv[i]=(ll)(i+1)*inv[i+1]%mod;
	
	f[0][0]=1;
	rep(i,0,n)
		rep(j,i,n)
		{
			if (i>0) f[i][j]=f[i-1][j];
			if (j>0 && i<j) f[i][j]=(f[i][j]+(ll)f[i][j-1]*C(j*(k-1)+i-1,k-2) )%mod;
		}
	ans=(ll)f[n][n]*fac[n]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 46336
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<string, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

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



Measured memory_bytes: 3216
from _collections import deque

SENIAL = 1000000000
def mergeSort(A,left,right):
    if left + 1 < right:
        middle = (left + right) // 2
        mergeSort(A, left, middle)
        mergeSort(A, middle, right)
        merge(A,left,right,middle)
    
def merge(A,left,right,middle):
    global count        
    L = deque(A[left:middle])
    R = deque(A[middle:right])
    L.append(SENIAL)
    R.append(SENIAL)
    for i in range(left,right):
        if L[0] < R[0]:
            A[i] = L.popleft()
        else:
            A[i] = R.popleft()
            count += len(L) -1 
count = 0     
input()
A = list(map(int,input().split()))
mergeSort(A,0,len(A))
print(count)

Measured memory_bytes: 30280
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
#define MAX 100
#define NONE -1
int main()
{
  int N,data[MAX][MAX];
  string s;
  for(int i=0;i<MAX;i++)for(int j=0;j<MAX;j++)data[i][j]=NONE;
  for(int i=0;cin>>s;i++){
    int j=0;
    string words=" ,.";
    int k=0,start=0;
    for(;k<s.size();k++){
      if(words.find(s[k])!=string::npos){
	data[i][j]=atoi( s.substr(start,k-start).c_str() );
	j++;
	start=k+1;
      }
    }
    data[i][j]=atoi( s.substr(start,k-start).c_str() );
    N=i+1;
  }

  int dp[MAX][MAX]={0};
  dp[0][0]=data[0][0];
  for(int i=1;i<=N/2;i++){
    for(int j=0;data[i][j]!=NONE;j++){
      dp[i][j]=dp[i-1][j]+data[i][j];
      if(j>0 && dp[i][j]<dp[i-1][j-1]+data[i][j])dp[i][j]=dp[i-1][j-1]+data[i][j];
    }
  }
  for(int i=N/2+1;i<N;i++){
    for(int j=0;data[i][j]!=NONE;j++){
      dp[i][j]=dp[i-1][j]+data[i][j];
      if(j<MAX && dp[i][j]<dp[i-1][j+1]+data[i][j])dp[i][j]=dp[i-1][j+1]+data[i][j];
    }
  }

  cout<<dp[N-1][0]<<endl;
}

Measured memory_bytes: 0
// Problem : 
// 			B - Making Triangle
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_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;
#define X first
#define Y second
#define endl '\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a) for(auto x: a) cout<<x<<" "; cout<<endl;
#define pxy(a,n,m) rep(i,0,n) {rep(j,0,m) cout<<a[i][j]<<" "; cout<<endl;}

//--------------------------------------------//

const long long MOD=LLONG_MAX;
void solve()
{
	int n,ans=0;
	cin>>n;
	int a[n];
	rep(i,0,n) cin>>a[i];
	rep(i,0,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if(a[i]==a[j] or a[i]==a[k] or a[j]==a[k]) continue;
				int b[3];
				b[0]=a[i];
				b[1]=a[j];
				b[2]=a[k];
				sort(b,b+3);
				if(b[0]+b[1]>b[2]) ans++;
			}
		}
	}
	cout<<ans<<endl;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1; 
	//cin>>t;
	while(t--) solve();
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    n = N // (A + B)
    m = N % (A + B)
    if m > A:
        print(A * n + A)
    else:
        print(A * n + m)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
    int a,b,di;
    int rect=0, rhom=0;
    
    while (scanf("%d,%d,%d", &a,&b,&di) != EOF){
        if (a*a+b*b == di*di) rect++;
        if (a==b) rhom++;
    }
    printf("%d\n%d\n", rect,rhom);

    return 0;
}

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

bool plime(int x){
	if(x==2) return true;
	if(x%2==0) return false;
	for(int i=3;i<=sqrt(x);i+=2) if(x%i==0) return false;
	return true;
}

int main(){
	int n,x,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(plime(x)) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {

	string s;
	cin >> s;
	ll N = s.size();

	ll l = 0;
	ll r = N - 1;

	ll ans = 0;

	while (l < r) {
		if (s[l] == s[r]) { l++; r--; }
		else if (s[l] == 'x') { l++; ans += 1; }
		else if (s[r] == 'x') { r--; ans += 1; }
		else { ans = -1; break; }
	}

	cout << ans;

	
	

	system("PAUSE");
}


Measured memory_bytes: 760