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

#define ll long long
#define pii pair<ll,ll>
#define fr first
#define sc second
#define pb push_back
#define all(x) (x).begin(),(x).end()

ll OO = 1e9 + 10;
ll mod = 1e9 + 7;

const ll N = 101;
const ll Inf = 1e9 + 7;

typedef vector<ll> Row ;
typedef vector<Row> Matrix ;

Matrix Const(ll n,ll m,ll val){
    return Matrix(n,Row(m,val));
}

Matrix Mul(const Matrix& A,const Matrix& B)
{
    assert(A[0].size()==B.size());
    Matrix Res = Const(A.size(),B[0].size(),Inf);
    for(ll i=0;i<A.size();i++)
        for(ll j=0;j<B[0].size();j++)
            for(ll k=0;k<A[0].size();k++)
                Res[i][j]+=(A[i][k]*B[k][j])%mod,Res[i][j]%=mod;
    return Res;
}
Matrix Power(const Matrix& A,ll p)
{
    if(p==1)    return A;
    if(p&1)     return Mul(A,Power(A,p-1));
    return Power(Mul(A,A),p>>1);
}
int main() {
    ll n,m;
    cin >> n >> m;
    Matrix G = Const(n,n,0);
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin >> G[i][j];
        }
    }
    G = Power(G,m);
    ll ans=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            ans = (ans + G[i][j])%mod;
        }
    }
    cout << ans;
}
/*

*/


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long P, string S){
    if (P == 2 || P == 5) {
        ll answer = 0;
        rep(i,0,N) {
            if ((S[i] - '0') % P != 0) continue;
            answer += i+1;
        }
        cout << answer << endl;
        return;
    }
    vector<vector<int>> remainders(N+1, vector<int>(10));
    rep(i,1,10) remainders[1][i] = i % P;
    rep(i,2,N+1) {
        rep(j,0,10) {
            remainders[i][j] = (remainders[i-1][j] * 10) % P;
        }
    }
    // sum of remainders of string s from right
    vector<int> remaindersSum(N+1);
    rrep(i,0,N) {
        remaindersSum[i] = (remaindersSum[i+1] + remainders[N - i][S[i] - '0']) % P;
    }
    vector<int> cnt(P);
    cnt[0]++;
    rep(i,0,N) cnt[remaindersSum[i]]++;
    ll answer = 0;
    rep(i,0,P) {
        if (cnt[i] <= 1) continue;
        answer += ((ll)cnt[i] * (cnt[i]-1) / 2);
    }
    cout << answer << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long P;
    scanf("%lld",&P);
    string S;
    cin >> S;
    solve(N, P, S);
    return 0;
}


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

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            a[i][j] = '.'
            break

for i in range(1,w):
    for j in range(h):
        if a[j][i] == '#':
            a[j][i] = '.'
            break

def check():
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                return 0;
    return 1;

if check():
    print ("Possible")
else :
    print ("Impossible")


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#define f first
#define s second

using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef long long ll;
typedef pair<int,int> P;

mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B[0].size();j++){
	C[i][j]=(C[i][j]+A[i][k]*B[k][j]);
      }
    }
  }
  return C;
} 

mat pow(mat A,ll n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++)B[i][i]=1;
  while(n>0){
    if(n&1)B=mul(B,A);
    A=mul(A,A);
    n>>=1;
  }
  return B;
}

/*
mat identity(int n) {
  mat A(n, vec(n));
  for (int i = 0; i < n; ++i) A[i][i] = 1;
  return A;
}

mat mul(const mat &A, const mat &B) {
  mat C(A.size(), vec(B[0].size()));
  for (int i = 0; i < C.size(); ++i)
    for (int j = 0; j < C[i].size(); ++j)
      for (int k = 0; k < A[i].size(); ++k)
        C[i][j] += A[i][k] * B[k][j];
  return C;
}

mat pow(const mat &A, int e) {
  return e == 0 ? identity(A.size())  :
     e % 2 == 0 ? pow(mul(A, A), e/2) : mul(A, pow(A, e-1));
}
*/
int main(void){

  int n,m,z,s,d;
  vector<P>G;

  while(cin >> n >> m >> z,n|m|z){
    G.clear();
    G.push_back(P(1,1));
    for(int i=0;i<m;i++){
      cin >> s >> d;
      G.push_back(P(s,d));
      G.push_back(P(d,s));
    }

    mat A(G.size(),vec(G.size()));
 
    for(int i=0;i<G.size();i++){
      for(int j=0;j<G.size();j++){
	if(i==j || !j || G[i].f==G[j].s)A[i][j]=0;
	else A[i][j]=(G[i].s==G[j].f);
      }
    }
    
    A=pow(A,z);

    bool fg=false;
    for(int i=0;i<A.size();i++){
      if(G[i].s==n && A[0][i])fg=true;
    }

    if(fg)cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;

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

    int a, b;
    cin >> a >> b;
    int result = a-2*b;
    result = result < 0 ? 0 : result;
    cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String[] alphas = base.split("");

        Scanner sc = new Scanner(System.in);
        int plus = sc.nextInt();
        String[] raw = sc.next().split("");
        String result = "";
        for (String c : raw) {
            int num = Arrays.binarySearch(alphas, c);
            num += plus;
            if(num > 25) num = num - 26;
            result += alphas[num];
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 148280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

const int P1 = 1e9 + 103;
const int P2 = 1e9 + 289;
const int PV = 1e9 + 7;

int N, K;
int dp[10010];
string s[2020];
char buf[100010];

char ans[10010];
pii sans[10010];
int dl;
int min_index[10010];

pair<string, int> X[2020];
int main() {
	scanf("%d%d", &N, &K);
	for(int i=1;i<=N;i++) {
		scanf("%s", buf);
		s[i] = (string)buf;
		X[i] = make_pair(s[i], i);
	}
	sort(X+1, X+1+N);
	
	for(int i=0;i<=K;i++) dp[i] = -1;
	dp[0] = N+1;
	for(int i=N;i;i--) {
		int x = szz(s[i]);
		for(int j=K;j>=x;j--) if(dp[j] == -1) {
			if(dp[j-x] != -1) dp[j] = i;
		}
	}
	for(int i=0;i<10010;i++) min_index[i] = N + 1, ans[i] = 'z' + 1;
	min_index[0] = 0;
	
	for(int L=0;L<=K;L++) {
		if(min_index[L] == N + 1) continue;
		int idx = min_index[L];
		for(int a=1;a<=N;a++) {
			int j = X[a].Se;
			if(j <= idx) continue;
			int lj = szz(X[a].Fi);
			if(L + lj > K || dp[K-L-lj] <= j) continue;
			int fd = -1, op = 0;
			for(int k=0;k<lj;k++) {
				if(ans[L+k+1] != X[a].Fi[k]) {
					if(ans[L+k+1] > X[a].Fi[k]) op = 1;
					else op = -1;
					fd = k + 1;
					break;
				}
			}
			
			if(op == -1) break;
			if(op == 0) {
				if(min_index[L+lj] > j) {
					min_index[L+lj] = j;
				}
			}
			else {
				for(int b=L+fd;b<=L+lj;b++) min_index[b] = N + 1, ans[b] = X[a].Fi[b-L-1];
				for(int b=L+lj+1;b<=K;b++) min_index[b] = N + 1, ans[b] = 'z' + 1;
				min_index[L+lj] = j;
			}
		}
	}
	for(int i=1;i<=K;i++) printf("%c", ans[i]); puts("");
	
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	const int MAX = 256;
	char t[MAX], p[MAX],temp[MAX];
	cin.getline(t, MAX);
	cin.getline(p, MAX);
	strcpy(temp, t);
	strcat(t, temp);
	if (strstr(t, p))
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 3068
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    S=[int(input()) for i in range(n)]

    from functools import reduce
    from fractions import gcd

    def lcm(A, B):
        return A * B // gcd(A, B)


    print(reduce(lcm, S))
resolve()

Measured memory_bytes: 63980
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


int cnt[65][2];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int ans = 0;
	rep(i, n)rep(j, 60) {
		bool tmp = (bool)(a[i] & (1LL << j));
		cnt[j][tmp]++;
	}
	for (int i = 59; i >= 0; i--) {
		ans *= 2; ans %= MOD;
		ans += cnt[i][0] * cnt[i][1] % MOD;
	}
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>


int main(){

	long int list = 0;
	int buf,i;
	for (i = 0; 28 > i; i++){ scanf("%d", &buf); list |= 1 << buf-1; }
	for (i = 0; 30 > i; i++){ if (! (list &1<<i)) printf("%d\n",i+1); }
}

Measured memory_bytes: 1028
-- O(n^2)
check :: String -> Bool
check [] = True
check (x:xs)
  | l == 0    = check xs
  | otherwise = False
  where l = length $ filter (== x) xs

main :: IO ()
main = do
  str <- getLine
  if check str
    then putStrLn "yes"
    else putStrLn "no"

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

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

fastio _fast_io;

const int mod = 1e9 + 7;
int n, k;
const int N = 2e5 + 10;
ll a[N];

int main() {
    ll res = 1;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    bool neg = false;
    sort(a, a + n);
    int l = 0, r = n - 1;
    if (k & 1) {
        res = a[n - 1];
        --k;
        --r;
        if (res < 0)
            neg = true;
    }
    while (k) {
        ll x = a[l] * a[l + 1];
        ll y = a[r] * a[r - 1];
        if ((x > y) ^ neg) {
            l += 2;
            res = (res * (x % mod)) % mod;
        } else {
            r -= 2;
            res = (res * (y % mod)) % mod;
        }
        k -= 2;
    }
    res = (res + mod) % mod;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 5140
/*input
aabbaa
2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
#define version 20190814
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	string s;
	ll k;
	cin>>s>>k;

	{
		string t=s;
		sort(ALL(t));
		if(t[0]==t.back()){
			cout<<k*SZ(s)/2<<'\n';
			return 0;
		}
	}

	ll ans=0;

	int l=0;
	for(int i=0;i<SZ(s);i++){
		if(s[i]==s[l]);
		else{
			if(i==l+1);
			else{
				if(l==0&&s[0]==s.back())
					ans+=(i-l)/2;
				else ans+=(i-l)/2*k;
			}
			l=i;
		}
	}
	if(s[0]==s.back()) ans+=(SZ(s)-l)/2;
	else ans+=(SZ(s)-l)/2*k;
	if(s[0]==s[SZ(s)-1]){
		int l=0,r=0;

		while(s[l]==s[0]) l++;
		while(s[SZ(s)-1-r]==s[0]) r++;
		ans+=(r+l)/2*(k-1);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
using namespace std;

long long n, k;
vector<long long> edge[100005];
vector<bool> used;

long long solve();

int main() {
  cin >> n >> k;
  for(int i = 0; i < n - 1; ++i) {
    long long x, y;
    cin >> x >> y;
    --x, --y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  used.assign(n, 0);
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = k, start = 0;
  queue<long long> qu;
  for(int i = 0; i < n; ++i)
    if(edge[i].size() == 1) {
      start = i;
      qu.push(i);
      break;
    }
  while(qu.size() > 0) {
    long long now = qu.front();
    qu.pop();
    used[now] = 1;
    bool ch = 0;
    for(int i = 0; i < edge[now].size(); ++i)
      if(!used[edge[now][i]]) {
        ans *= (k - i - 2 + ch + (start == now));
        ans %= N;
        qu.push(edge[now][i]);
      }
      else
        ch = 1;
  }
  return ans;
}

Measured memory_bytes: 7284
#include <stdio.h>
typedef long long ll;
int main()
{
    int n,sum=1;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    for(int i=1;i<n;i++){
        if(s[i-1]!=s[i]){
            sum++;
        }
    }
    printf("%d",sum);
}


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

typedef unsigned long long ull;
ull a,b;
string s;

int main(){

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

    cin>>a>>s;
    b=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
    cout<<a*b/100<<endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

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

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

ll power(int m, int n) { // m^n（繰り返し自乗法）
    if (n == 0) return 1;
    if (n % 2 == 1) return power(m, n-1) * m % mod;
    ll r = power(m, n/2);
    return r * r % mod;
}

ll inv(ll a, ll b) { // 逆元を利用してa/bのmodを返す
    return a * power(b, mod-2) % mod;
}

int n; // 変数
int a[MAX];
ll sum = 0;
ll ans = 0;

int main() {
// input
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
// solve
    rep(i, n) {
        ans += (sum - a[i]) % mod * a[i] % mod;
        ans %= mod;
        sum -= a[i];
    }
// output
    cout << ans << "\n";
}

Measured memory_bytes: 4416
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl a(n);
    map<ll,ll> mp;
    ll mx = 0, mn = INF;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
        mx = max(mx,a[i]);
        mn = min(mn,a[i]);
    }
    bool flag = true;
    if(mp.size() > 2){
        flag = false;
    }else if(mp.size()==2){
        if(mx - mn >= 2) flag = false;
        else{
            ll y = mp[mx];
            ll x = n - mp[mx];
            if(2 * (mx - x) <= y) flag = true;
            else flag = false;
            if(mx <= x) flag = false;
        }
    }else{
        if(n/a[0] >= 2 || a[0] == n-1) flag = true;
        else flag = false;
    }
    if(flag) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 7296
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    L=[i for i in range(102) if i not in p]
    l=[abs(i-x) for i in L]
    key=l.index(min(l))
    print(L[key])
else:
    print(x)

Measured memory_bytes: 9192
# include <iostream>
# include <vector>
# include <map>
typedef long long ll;
using namespace std;

int main () {

    ll n, in;
    vector <ll> v;
    map <ll, ll> m;
    cin >> n;
    while (n--) {
        cin >> in;
        v.push_back(in);
        m[in]++;
    }
    vector <ll> comb(v.size(), 0);
    ll combinations(0);
    for (auto itr : m) {
        combinations += itr.second * (itr.second - 1) / 2;
    }

    for (ll i = 0; i < comb.size(); i++) {
        comb[i] = combinations - (m[v[i]] - 1);
    }
    for (ll i: comb) {
        cout << i << "\n";
    }
    return 0;
}

Measured memory_bytes: 12656
#include<iostream>
using namespace std;
#define int long long
#define MOD (long long)(1e9+7)
#define MAX_V (long long)(1e5*2+100)

long long MAX_VAL;
long long fac[MAX_V], mmi[MAX_V], temp[MAX_V];

inline void factorial(){
	fac[0] = fac[1] = 1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

inline long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

inline void modular_multiplicatibe_inverse(){
	mmi[MAX_VAL-1] = power_mod(fac[MAX_VAL-1],MOD-2);
	for(long long i = MAX_VAL-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

inline long long combination(long long n, long long r){
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	int H, W, A, B, ans = 0;
	cin>>H>>W>>A>>B;
	MAX_VAL = max(W+H-A-2,A+W-1)+2;
	factorial();
	modular_multiplicatibe_inverse();

	for(int i = B+1; i <= W; ans%=MOD,i++)
		ans += combination(i+H-A-2,H-A-1)*combination(A+W-i-1,W-i)%MOD;
	
	cout<<ans<<endl;

}

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

class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        long N = cin.Long();
        long K = cin.Long();

        long ans;
        if(K % 2 == 0) {
            long tmp = N / K;
            long tmp2 = N / (K / 2) - N / K;
            ans = tmp * tmp * tmp + tmp2 * tmp2 * tmp2;
        }
        else {
            long tmp = N / K;
            ans = tmp * tmp * tmp;
        }
        Console.WriteLine(ans);
        Console.ReadLine();
    }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
def resolve():

    S=list(input())
    if 'N' in S and 'S' in S and 'W' in S and 'E' in S:
        print('Yes')
    elif 'N' in S and 'S' in S and 'W' not in S and 'E' not in S:
        print('Yes')
    elif 'N' not in S and 'S' not in S and 'W' in S and 'E' in S:
        print('Yes')
    else:
        print('No')

resolve()

Measured memory_bytes: 38256
#入力
S = input()
T = input()

#比較
p = 0

if S[0]  == T[0]:
    p = p + 1
if S[1]  == T[1]:
    p = p + 1
if S[2]  == T[2]:
    p = p + 1

#出力
print(p)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {0, -1, 0, 1, 1, 1, -1, -1};
int dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};

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

  string s;
  cin >> s;

  if(s.size() == 3) reverse(all(s));
  cout << s << endl;
}


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

const int N = 1e5 + 5;
int cache[N];

int main() {
    vector< int> v;
    v.emplace_back(1);
    for (int x = 6; x < N; x *= 6) {
        v.emplace_back(x);
    }
    for (int x = 9; x < N; x *= 9) {
        v.emplace_back(x);
    }

    sort(v.begin(), v.end());

    cache[0] = 0;
    for(int i = 1; i < N; i++) {
        cache[i] = N;
        for(int x: v) {
            if(x > i) break;
            cache[i] = min(cache[i], cache[i - x] + 1);
        }
    }
    int n;
    scanf("%d", &n);
    cout << cache[n] << endl;

}

Measured memory_bytes: 640
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
#define dump(x) cerr<<#x<<"="<<x<<endl

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

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

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,R;
    cin>>n>>m>>R;
    
    vector<vector<ll>> d(n+1,vector<ll>(n+1,1000000000));
    vector<ll> r(R);
    
    rep(i,R) cin>>r[i];
    
    rep(i,m){
        ll x,y; cin>>x>>y;
        ll c; cin>>c;
        d[x][y]=min(d[x][y],c);
        d[y][x]=min(d[y][x],c);
    }
    sort(ALL(r));
    rrep(i,n) d[i][i]=0;
    
    rrep(k,n){
        rrep(i,n){
            rrep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
    ll ans=1000000000;
    do{
        ll tmp=0;
        rep(i,R-1){
            tmp+=d[r[i]][r[i+1]];
            dump(r[i]);
        }
        ans=min(ans,tmp);
    }while(next_permutation(ALL(r)));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
# define INF 1000005
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}


int32_t main()
{
    c_p_c();
    int n;
    cin>>n;
    int now=26;
    int len=1;
    while(n>now){
        n-=now;
        now*=26;
        len++;
    }
    string ans(len,'0');
    n--;
    for(int i=len-1;i>=0;i--){
        ans[i]=n%26+'a';
        n/=26;

    }
    cout<<ans;
    


 
    
      return 0;
       }
        
        

        























Measured memory_bytes: 3640
#include <iostream>
#include <vector>

using namespace std;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int &a:A) cin >> a;
    
    int ans = 0;
    for(int i=0; i<N;){
        int j = i;
        while(A[i]==A[j] && j<N) j++;
        ans += (j-i)/2;
        i = j;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# print('input >>')
A, B, C, D = map(int,(input().split()))

takahashi = A
aoki = C

while takahashi > 0 and aoki > 0:
    aoki -= B 
    takahashi -= D

if aoki <= 0:
    print('Yes')
else:
    print('No')

# print('-----output-----')

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, T, c, t;
  cin >>n >>T;
  int cost=1001;
  
  for(int i=0; i<n; i++){
    cin >>c >>t;
    if(t<=T){
      if(c<cost){
        cost=c;
      }
    }
  }
  if(cost ==1001){
    cout <<"TLE" <<endl;
  }
  else{
    cout <<cost <<endl;
  }
}

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

int main(){
  int A, B;
  cin >> A >> B;
  long long product = (long long)A*B;
  int temp = max(A, B);
  int tmp;
  B = min(A, B);
  A = temp;
  while (B != 0) {
    temp = A % B;
    A = B;
    B = temp;
  }
  cout << product / A << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main(){
	string str;
	while(cin >> str != '\0'){
		for(int i=0;i<str.size();i++){
			if(str[i]!='@'){
				cout << str[i];
			}else{
				int r=str[i+1]-'0';
				char ey=str[i+2];
				for(int j=0;j<r;j++){
					cout << ey;
				}
				i+=2;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char ** argv){
    int N;
    cin >> N;
    vector<vector<int>> V(N, vector<int>(3));
    for(int i = 0; i < N;++i){
        cin >> V[i][0] >> V[i][1] >> V[i][2];
    }
    vector<vector<int>> dp(N, vector<int>(3));
    for(int i = 0; i < 3; ++i)
        dp[0][i] = V[0][i];

    for(int i = 1; i < N; ++i){
        for(int j = 0; j < 3; ++j){
            for(int k = 0; k < 3; ++k){
                if(k != j){
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + V[i][j]);   
                }
            }
        }
    }
    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << "\n";
    return 0;
}

Measured memory_bytes: 11136
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define o 300011
using namespace std;
ll total,edgecnt,num[4],ans;
int n,m,ui,vi,tot;
int color[o],head[o],nxt[o],point[o],remain[o];
bool vis[o],cir,g[o];


void addedge(int x,int y){
	tot++;nxt[tot]=head[x];head[x]=tot;point[tot]=y;remain[tot]=1;
	tot++;nxt[tot]=head[y];head[y]=tot;point[tot]=x;remain[tot]=-1;
}

void dfs(int now){
	vis[now]=true;
	total++;
	num[color[now]]++;
	for(int tmp=head[now];tmp;tmp=nxt[tmp]){
		if(g[tmp])continue;
		g[tmp]=g[tmp^1]=true;
		edgecnt++;
		int v=point[tmp];
		if(vis[v]){
			if(color[v]!=(color[now]+remain[tmp]+3)%3) cir=true;
		}
		else{
			color[v]=(color[now]+remain[tmp]+3)%3;
			dfs(v);
		}
	}
}
void clear(){
	total=0;edgecnt=0;
	num[1]=num[2]=num[0]=0;
	cir=false;
}
int main(){
	tot=1;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&ui,&vi);
		addedge(ui,vi);
	}
	for(int i=1;i<=n;i++)
	if(!vis[i]){
		clear();
		dfs(i);
		if(cir){
			ans+=total*total;
			continue;
		}
		if(!num[0]||!num[1]||!num[2]){
			ans+=edgecnt;
			continue;
		}
		ans+=num[0]*num[1];
		ans+=num[0]*num[2];
		ans+=num[1]*num[2];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 8832
#include <iostream>

using namespace std;

int main(void)
{
	int a, b, c;
	
	std::cin >> a >> b >> c;
	
	if( a < b && b < c )
		std::cout << "Yes" << std::endl;
	
	else 
		std::cout << "No" << std::endl;
	
	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

ll a[N],b[N];
map <ll, int> m;

int main()
{
	ll n,ans=0,x;
	scanf("%lld",&n);
	REP(i,n)
	{
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
	sort(b,b+n);
	REP(i,n)
		m[b[i]]=i%2;
	REP(i,n) if (m[a[i]]!=i%2) ans++;
	ans/=2;
	printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 8064
transport = [0]*5
N = int(input())
for i in range(5):
    transport[i] = [0]*2
    transport[i][1], transport[i][0] = i, int(input())

transport = sorted(transport)
if N % transport[0][0] == 0:
    time = N // transport[0][0]
else:
    time = N // transport[0][0] + 1
time +=4
print("{}".format(time))


Measured memory_bytes: 3060
size = STDIN.gets
size_l = size.split(" ")[0].to_i
size_r = size.split(" ")[1].to_i
line = "########################"

def calc(matrix, vector)
  answer = []
  for i in 0..matrix.length - 1 do
    line = matrix[i]
    sum = 0
    for j in 0..line.length - 1 do
      sum += line[j] * vector[j]
    end
    answer << sum
  end
  return answer
end

# get matrix
# puts line
matrix = []
for i in 1..size_l do
  line = STDIN.gets.split(" ")
  num_line = []
  for j in 0..line.length - 1 do
    num = line[j].to_i
    num_line << num
  end
  matrix << num_line
end

# print matrix

# get vector
vector = []
for i in 1..size_r do
  num = gets.to_i
  vector << num
end

# print vector

answer = calc(matrix, vector)
puts answer

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

int main(){
    int n;
    cin >> n;
    int a=0,b=0;
    vector<int>num(n);
    rep(i,n) cin >> num[i];
    sort(num.begin(),num.end());
    reverse(num.begin(),num.end());
    rep(i,n){
        if(i%2==0) a+=num[i];
        else b+=num[i];
    }
    cout << a-b << endl;
    return 0;
}

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

int main(){
	int n,m,p;
	while(cin>>n>>m>>p,n||m||p){
		int c,g=0,x,i;
		for(i=0;i<n;i++){
			cin>>x;
			g+=x;
			if(i+1==m) c=x;
		}
		g*=(100-p);
		if(c) cout<<g/c<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1164
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

vector<long long int> factors[1100000];
long long int A[110000];

int main(){
	for(int i = 2; i <= 1000100; i++){
		if(factors[i].size() == 0){
			for(int j = i; j <= 1000100; j += i){
				factors[j].push_back(i);
			}
		}
	}
	int N;
	cin >> N;
	map<long long int, long long int> m;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		long long int hoge = A[i];
		for(long long int num : factors[A[i]]){
			long long int cnt = 0;
			while(hoge % num == 0){
				cnt += 1;
				hoge /= num;
			}
			m[num] = max(m[num], cnt);
		}
	}
	long long int S = 1;
	for(P p : m){
		for(int i = 0; i < p.second; i++){
			S *= p.first;
			S %= MOD;
		}
	}
	long long int ans = 0;
	for(int i = 0; i < N; i++){
		ans += S * rev_mod(A[i]) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 73088
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <cstdint>

int main()
{
	std::uint16_t w, n;
	std::cin >> w;
	std::cin >> n;

	std::vector<std::uint16_t> vnumbers(w);
	std::iota(vnumbers.begin(), vnumbers.end(), 1);

	for (int i = 0; i < n; ++i) {
		std::uint16_t a, b;
		char comma;
		std::cin >> a >> comma >> b;
		std::swap(vnumbers[a - 1], vnumbers[b - 1]);
	}

	std::copy(vnumbers.begin(), vnumbers.end(),
			std::ostream_iterator<std::uint16_t>(std::cout, "\n"));

	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int a,b,i,len,t;
    char s[1000];
    while(scanf("%d %d",&a,&b)!=EOF){
            getchar();
            gets(s);
        len=strlen(s);
    t=0;
    if(len!=a+b+1){
        printf("No\n");
    }
    else{
            if(s[a]!='-'){
                printf("No\n");
            }
            else{
        for(i=0;i<len;i++){
                if(i==a){
                    i++;
                }
            if(s[i]<'0'||s[i]>'9'){
                t++;
            }
        }
        if(t!=0){
            printf("No\n");
        }
        else printf("Yes\n");
    }
    }
    }
    return 0;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int count = 0; 
    for(int i = 0; i < 100; ++i){
    if(A <= i && i < B && C <= i && i < D) count ++;
    } 
    cout << count << endl; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    int a = 0, b = 0;
    for(int i = 0; i<3; i++){
        char c;
        cin>>c;
        c=='A'?(a++):(b++);
    }
    if(a==0 || b==0) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int t;
   double r,s=0;
   cin>>r;
   for(t=1; t<=r; t++)
   {
       if(t%2!=0)
        s++;
   }
   double d= s/r;
   printf("%0.7lf",d);
  return 0;
}

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

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

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

    if(n >= k * 2 - 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
s=list(input())
k=int(input())

if len(set(s))==1:
  print((len(s)*k)//2)
  exit()

t=[1]
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    t[-1]+=1
  else:
    t.append(1)
    
ans=0
for i in t:
  ans+=(i//2)*k

if s[0]==s[-1]:
  ans+= ((t[0]+t[-1])//2 - (t[0]//2+t[-1]//2))*(k-1)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=64,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

vll g[M];
pll rng[M][LG];
ll n,m,q;

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> m;
    For(i,0,m)
    {
        ll u,v;
        cin >> u >> v;
        u--;v--;
        g[u].PB(v);g[v].PB(u);
    }
    cin >> q;
    For(i,0,q)
    {
        ll v,d,c;
        cin >> v >> d >> c;
        v--;
        For(j,0,d+1)
            rng[v][j]={i+1,c};
    }
    For(rep,0,10)
    {
        For(x,0,n)
        {
            for (ll y:g[x])
            {
                For(i,0,10)
                {
                    smax(rng[y][i],
                    rng[x][i+1]);   
                }
            }       
        }   
    }
    For(i,0,n) cout << rng[i][0].Y << '\n';
}    

Measured memory_bytes: 110964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX_N = 1<<17;
ll n,dat[2*MAX_N-1];

void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=0;
}

void update(ll k,ll a){
  k+=n-1;
  dat[k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=max(dat[k*2+1],dat[k*2+2]);
  }
}

ll query(ll a,ll b,ll k,ll l,ll r){
  if(r<=a||b<=l)return 0;
  if(a<=l&&r<=b)return dat[k];
  else{
    ll v1=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(v1,vr);
  }
}

int main(){
  cin>>n;
  ll nn=n;
  ll ans=0;
  init(n);
  for(ll i=0,x;i<nn;i++){
    cin>>x;
    ll p=query(0,x,0,0,n);
    update(x-1,p+x);
    ans=max(ans,p+x);
  }

  cout<<nn*(nn+1)/2-ans<<endl;
  
  return 0;
}

Measured memory_bytes: 5116
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int a, b;
    cin >> a >> b;
    if (a < b){
        for (int i = 0; i < b; i++){
            cout << a;
        }
        cout << endl;
    }
    else {
        for (int i = 0; i < a; i++){
            cout << b;
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> suml(n, 0), sumr(n, 0);
    suml[0] = a[0];
    Rep(i, 1, n) suml[i] += suml[i - 1] + a[i];
    sumr[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--)
        sumr[i] = sumr[i + 1] + a[i];
    vector<int> L(n);
    L[0] = a[0] % 2;
    Rep(i, 1, n)
    {
        int cost = a[i] % 2;
        if (a[i] == 0)
            cost = 2;
        L[i] = min(L[i - 1] + cost, suml[i]);
    }
    //rep(i, n) cout << i << " " << L[i] << endl;
    vector<int> R(n, 0), M(n, 0);
    R[n - 1] = a[n - 1] % 2;
    M[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--)
    {
        int cost1 = a[i] % 2, cost2 = (a[i] + 1) % 2;
        if (a[i] == 0)
            cost1 = 2;
        R[i] = min(R[i + 1] + cost1, sumr[i]);
        M[i] = min(M[i + 1] + cost2, R[i]);
    }
    //rep(i, n) cout << i << " " << R[i] << endl;
    //rep(i, n) cout << i << " " << M[i] << endl;
    int ans = min(L[n - 1], M[0]);
    Rep(i, 1, n) ans = min(ans, L[i - 1] + M[i]);
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

int main(void)
{
	int n;

	cin >> n;

	if (n / 10 == 9 || n % 10 == 9)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func sqrtInt(n int) int {
	if n < 0 {
		panic("negative value")
	}
	f := math.Sqrt(float64(n))
	return int(f)
}

func main() {
	var n int
	fmt.Scanln(&n)
	for i := sqrtInt(n); i > 0; i-- {
		if n%i == 0 {
			fmt.Println(i + (n / i) - 2)
			break
		}
	}
}

Measured memory_bytes: 512
S = input().strip()
K = input().strip()

if len(K) <= 3:
    k = int(K)
else:
    k = 1000

if len(S) == 1:
    print(S)
elif len(S) == sum([int(i) for i in S]):
    print(1)
else:
    for i in S:
        k -= 1
        if (k == 0) or (i != "1"):
            print(i)
            break


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

int main()
{
	int N;
	cin >> N;
	vector<long long> A( N + 1 );
	for( int i = 0; i < N + 1; i++ ) {
		cin >> A[i];
	}

	vector<long long> asum( N + 1 );
	for( int i = N; i >= 0; i-- ) {
		if( i == N ) asum[i] = A[i];
		else asum[i] = asum[i + 1] + A[i];
	}
	long long ans = 0;
	vector<long long> B( N + 1 );
	for( int i = 0; i < N + 1; i++ ) {
		if( i == 0 ) {
			B[i] = 1 - A[i];
			if( B[i] < 0 ) {
				ans = -1;
				break;
			}
			ans += A[i] + B[i];
		}
		else if( i == N ) {
			B[i] = 0;
			if( A[i] + B[i] < B[i - 1] || B[i - 1] * 2 < A[i] + B[i] ) {
				ans = -1;
				break;
			}
			ans += A[i] + B[i];
		}
		else {
			long long l = B[i - 1] - A[i];
			long long h = B[i - 1] * 2 - A[i];
			h = min( h, asum[i + 1] );
			if( h < l || h < 0 ) {
				ans = -1;
				break;
			}
			B[i] = h;
			ans += A[i] + B[i];
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 5632
// https://atcoder.jp/contests/abc151/tasks/abc151_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

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

void solve() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) { cin >> S[i]; }
    vector<vector<bool>> path(H, vector<bool>(W));
    REP(h, H) {
        REP(w, W) {
            if (S[h][w] == '.') {
                path[h][w] = true;
            }
        }
    }
    auto ok = [&](int h, int w) {
        if (h < 0 || h >= H || w < 0 || w >= W) {
            return false;
        }
        return true;
    };

    // 外部変数のH、W、pathを参照
    auto bfs = [&](int h, int w) {
        queue<tuple<int, int, int>> q;
        // 位置と移動回数
        q.emplace(h, w, 0);
        // 元の通路情報を汚さないようにコピーする
        auto pa = path;
        pa[h][w] = false;
        int maxv = 0;

        while (!q.empty()) {
            int now_h, now_w, now_cnt;
            tie(now_h, now_w, now_cnt) = q.front();
            maxv = max(maxv, now_cnt);
            q.pop();
            REP(i, 4) {
                int next_h = now_h + dy[i];
                int next_w = now_w + dx[i];
                if (ok(next_h, next_w) && pa[next_h][next_w]) {
                    // 行った場所は壁扱いにして再度訪問不可
                    pa[next_h][next_w] = false;
                    q.emplace(next_h, next_w, now_cnt + 1);
                }
            }
        }
        return maxv;
    };

    // 開始位置、終了位置
    int ans = 0;
    REP(h, H) {
        REP(w, W) {
            if (path[h][w]) {
                ans = max(ans, bfs(h, w));
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3652
import Control.Applicative ((<$>))
import qualified Control.Monad as Monad (replicateM)

type Hands = [String]
type Points = [Int]

main = do
    n <- read <$> getLine
    hs <- map words <$> Monad.replicateM n getLine
    putStrLn . unwords $ show <$> cardGame hs

cardGame :: [Hands] -> Points
cardGame hs = foldr1 (\x acc -> zipWith (+) x acc) $ map oneGame hs

oneGame :: Hands -> Points
oneGame [a,b]
    | result == LT = [0,3]
    | result == EQ = [1,1]
    | result == GT = [3,0]
    where result = a `compare` b

Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rep(i, n) {
        if (a[i]!=(i+1-cnt)) cnt++;
    }
    if (cnt==n) cnt = -1;
    
    
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024