akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, bool> mp;
#define rep(i, n) for(int (i) = 0; (i) < (n) ; (i)++ )
#define pr(x) cout << (x) << endl

int main(void){
    int n, m, a, b, ok; cin >> n >> m;
    vector<vi> g(n); vector<vb> l(n,vb(n,0)); vb rm(n,0), vs(n,0);
    rep(i,m){
        cin>>a>>b; g[--a].push_back(--b);
        if(!l[b][a])l[a][b]=1; else {pr(2);pr(++a);pr(++b);return 0;}
    }

    auto update=[&](int s,mp& nx,bool undo){for (int t:g[s])swap(rm[t],nx[t]),rm[t]=undo?rm[t]:1;};

    auto f = [&](auto f, int s, int r) -> bool{
        for(int t:g[s])if(t!=r&&vs[t])return 0;
        if(l[s][r])return vs[s]=1;
        vs[s]=1,ok=0;mp nx;

        update(s,nx,0);
        for (int t:g[s])if(!nx[t]&&f(f,t,r)){ok=1;break;}
        update(s,nx,1);
        return vs[s]=ok;
    };

    rep(i, n){
        rm.assign(n,0),vs.assign(n,0);
        if (f(f,i,i)){
            pr(count(vs.begin(),vs.end(),1));
            rep(j,n)if(vs[j])pr(j+1);
            return 0;
        }
    }
    pr(-1);
    return 0;
}


Measured memory_bytes: 4092
#include <stdio.h>
int main() {
  int n,count = 0;
  long x;
  double tmp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%ld", &x);
    tmp = x/2;
    for (int j = 2; j <= tmp; j++) {
      if (x%j == 0) {
        count++;
        break;
      }
      tmp = x / (j + 1);
    }
  }
  printf("%d\n", n - count);
  return 0;
}



Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int h = sc.nextInt();
			int n = sc.nextInt();
			
			int[] aArray = new int[n];
			int[] bArray = new int[n];
			
			for(int i = 0 ; i < n ; i++ ) {
				aArray[i] = sc.nextInt();
				bArray[i] = sc.nextInt();
			}
			
			// counstruct dp
			// calc minimum magic points for hp = i
			int[] dp = new int[h+1];
			dp[0] = 0;
			for(int i = 1 ; i < h+1 ; i++ ) {
				
				int total = Integer.MAX_VALUE; 
				for(int j = 0 ; j < n ; j++) {
					int current = 0;
					if ( i - aArray[j] > 0 ) {
						current += dp[i - aArray[j]];
					}
					current += bArray[j];
					
					if ( current < total ) {
						total = current;
					}
				}
				dp[i] = total;				
			}

			System.out.println(dp[h]);

		}
			
	}
}

Measured memory_bytes: 26236
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
for i in range(l+1, 0, -1):
    if l % i == 0:
        d = True
        for item in c:
            if item % i != 0:
                d = False
        if d:
            print(i)
            break

Measured memory_bytes: 17836
m,k=gets.chomp.split.map(&:to_i)
if m==0
  if k==0
    puts "0 0"
  else
    puts -1
  end
elsif m==1
  if k==0
    puts "0 0 1 1"
  else
    puts -1
  end
elsif 2**m <= k
  puts -1
else
  a=[]
  0.upto(2**m-1) do |i|
    next if i == k
    a << i
  end
  a.each do |v|
    printf("%d ", v)
  end
  printf("%d ", k)
  a.reverse.each do |v|
    printf("%d ", v)
  end
  printf("%d\n",k)
end 

Measured memory_bytes: 5500
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
using namespace std;
const int N=2e5+10;
const ll P=1e9+7;
int dep[N],cou[N],n;
vector<int>g[N];
int d[N],num[N],cnt;
vector<pll>dp[N];
ll all[N],zero[N],one[N],ans;
ll pwr(ll x,ll y){
	if(!y)return 1;
	if(y&1)return pwr(x,y-1)*x%P;
	ll z=pwr(x,y>>1);
	return z*z%P;
}
void dfs(int x){
	int son=n+1;
	for(int i=g[x].size()-1;~i;i--){
		int k=g[x][i];
		dfs(k);
		if(d[son]<d[k])son=k;
	}
	if(son==n+1)num[x]=++cnt;
	else num[x]=num[son],d[x]=d[son]+1;
	dp[num[x]].pb(mp(1,1));
	if(g[x].size()==1)return;
	for(int i=0;i<d[x];i++)
		all[i]=zero[i]=1,one[i]=0;
	for(int i=g[x].size()-1;~i;i--){
		int k=g[x][i];
		for(int j=0;j<=d[k];j++){
			int p=j+d[son]-d[k];
			pll t=dp[num[k]][j];
			all[p]=all[p]*(t.fst+t.snd)%P;
			zero[p]=zero[p]*t.fst%P;
		}
	}
	for(int i=g[x].size()-1;~i;i--){
		int k=g[x][i];
		for(int j=0;j<=d[k];j++){
			int p=j+d[son]-d[k];
			pll t=dp[num[k]][j];
			one[p]=(one[p]+zero[p]*pwr(t.fst,P-2)%P*t.snd%P)%P;
		}
	}
	for(int i=0;i<d[x];i++){
		dp[num[x]][i].fst=(all[i]-one[i]+P)%P;
		dp[num[x]][i].snd=one[i];
	}
}
int main(){
	int i,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&k);
		g[k].pb(i);
		dep[i]=dep[k]+1;
		cou[dep[i]]++;
	}
	cou[0]++;
	d[n+1]=-1;//vector<>下标从0开始,所以d[]从0开始方便计算
	dfs(0);
	for(i=0;i<=d[0];i++){
		pll t=dp[num[0]][i];
		ans=(ans+t.snd*pwr(2,n+1-cou[d[0]-i])%P)%P;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 48248
#include <bits/stdc++.h>
using namespace std;
#include <cmath>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=1;
	for(ll i=1;i<=sqrt(n);i++){
		if(n%i==0){
			ans=max(i,ans);
		}
	}
	ll ans2=n/ans;
	cout <<ans+ans2-2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3660
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q

for i in range(Q):
    B[i], C[i] = map(int, input().split())


from collections import defaultdict

dic = defaultdict(int)
for a in A:
    dic[a] += 1

s = sum(A)

for i in range(Q):
    num = dic[B[i]]
    diff = num * (C[i] - B[i])
    # print("diff: ", diff)
    s += diff

    dic[C[i]] += dic[B[i]]
    dic[B[i]] = 0
    print(s)



Measured memory_bytes: 29868
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

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

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    double x;
    cin >> x;
    cout << fixed;
    cout.precision(10);
    cout << 2.0 * acos(-1.0) * x << '\n';
}


Measured memory_bytes: 3784
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=2000;
const int MAXVAL=2000;
const int MAXSUM=MAXN*MAXVAL;
const int MAXLL=(MAXSUM+1+63)/64;

int n;
int a[MAXN];

int sum;
ull b[MAXLL+1];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]);
	sum=0; REP(i,n) sum+=a[i];
	memset(b,0,sizeof(b)); b[0]|=1ULL<<0;
	REP(i,n) {
		int dj=a[i]/64,dk=a[i]%64;
		if(dk!=0) {
			for(int j=MAXLL-1;j>=0;--j) if(b[j]!=0) {
				ull high=b[j]>>(64-dk),low=b[j]<<dk;
				b[j+dj]|=low,b[j+dj+1]|=high;
			}
		} else {
			for(int j=MAXLL-1;j>=0;--j) if(b[j]!=0) {
				b[j+dj]|=b[j];
			}
		}
	}
	int hsum=(sum+1)/2;
	FORE(i,hsum,sum) if((b[i/64]>>(i%64))&1) { printf("%d\n",i); return; }
	assert(false);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 896
import numpy as np
p = 998244353

N,S = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
dp = np.zeros(S+1)
dp[0] = 1
for a in A:
  if S < a:
    dp *= 2
    dp %= p
    continue
  tmp = 2*dp
  dp = np.append(np.zeros(a),dp[:S-a+1])
  dp += tmp
  dp %= p
print(int(dp[S]))

Measured memory_bytes: 27568
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=700+10;
const int inf=0x3f3f3f3f;
int n,m;
int Ans=inf;
int cnt[2],s[2][maxn],vis[maxn],col[maxn];
int g[maxn][maxn];

inline void file() {
	freopen("ARC099E.in","r",stdin);
	freopen("ARC099E.out","w",stdout);
}

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline int calc(int p) { return p*(p-1)/2; }

int dfs(int u,int c) {
	vis[u]=1; col[u]=c;
	++cnt[c];
	For (v,1,n)
		if (g[u][v]) {
			if (col[v]==col[u]) return 0;
			if (vis[v]) continue;
			if (!dfs(v,c^1)) return 0;
		}
	return 1;
}

int main() {
//	file();
	n=read(); m=read();
	For (i,1,n) For (j,1,n) g[i][j]=1;
	For (i,1,n) g[i][i]=0;
	For (i,1,m) {
		int x=read(),y=read();
		g[x][y]=g[y][x]=0;
	}
	Set(col,-1); int p=0; s[p][0]=1;
	For (i,1,n)
		if (!vis[i]) {
			cnt[0]=cnt[1]=0;
			if (!dfs(i,0)) {
				puts("-1"); return 0;
			}
			Set(s[p^1],0);
			For (j,0,n)
				if (s[p][j]) s[p^1][j+cnt[0]]=s[p^1][j+cnt[1]]=1;
			p^=1;
		}
	For (i,1,n)
		if (s[p][i])
			chkmin(Ans,calc(i)+calc(n-i));
	printf("%d",Ans);
	return 0;
}

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

int main() {
	int N, C;
	cin >> N >> C;
	vector<int>Cake(C);
	int sum = 0;
	for (int i = 0; i < C; i++) {
		cin >> Cake.at(i);
		sum += Cake.at(i);
	}
	int ans = sum / (N + 1);
	if (sum % (N + 1) != 0) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3116
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return r'\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
u=UnionFind(n)
ans=0
p=list(map(lambda x:int(x)-1,input().split()))
for i in range(m):
  a,b=map(lambda x:x-1,map(int,input().split()))
  u.union(a,b)
for i in range(n):
  if u.same(i,p[i]):
    ans+=1
print(ans)


Measured memory_bytes: 14708
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll a, b, c;
	cin >> a >> b >> c;

	ll d = c - a - b;
	if (d>0 && d*d > 4*a*b){
			cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <set>
#include <map>
#include <numeric>
#include <string>

class union_find {
  mutable std::vector<intmax_t> c;

public:
  union_find(size_t n): c(n, -1) {}

  size_t find(size_t v) const {
    if (c[v] < 0) return v;
    return (c[v] = find(c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (-c[u] > -c[v]) std::swap(u, v);
    c[v] += c[u];
    c[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) const { return (find(u) == find(v)); }

  size_t size() const { return c.size(); }
  size_t size(size_t v) const {
    return -c[find(v)];
  }
};

int main() {
  size_t N;
  scanf("%zu", &N);

  size_t M = 1e5;
  union_find uf(M+M+N);
  for (size_t i = 0; i < N; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    uf.unite(M+M+i, x);
    uf.unite(M+M+i, M+y);
  }

  std::set<size_t> g;
  for (size_t i = 0; i < N; ++i) {
    g.insert(uf.find(M+M+i));
  }

  std::map<size_t, intmax_t> xp, yp, ip;
  for (size_t i = 0; i < M; ++i) {
    ++xp[uf.find(i)];
    ++yp[uf.find(M+i)];
  }
  for (size_t i = 0; i < N; ++i) {
    ++ip[uf.find(M+M+i)];
  }

  intmax_t res = 0;
  for (auto v: g) {
    intmax_t xx = xp.at(v);
    intmax_t yy = yp.at(v);
    intmax_t ii = ip.at(v);
    res += xx*yy - ii;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 14976
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let flip f x y = f y x
                   
let () =
  let _ = read_int () in
  let lst = read_list int_of_string |> List.sort (flip compare) in
  let rec iter e = function
      x :: y :: ys when x = y -> if e = 0 then iter x ys else e * x
    | x :: xs -> iter e xs
    | _ -> 0 in
  iter 0 lst |> string_of_int |> print_endline


Measured memory_bytes: 16640
n, k = list(map(int,(input().split(' '))))
d = set(list(map(int,(input().split(' ')))))
l = set(list(range(0,10)))

like = l -d 
#print(like)
#print(list(map(int,(str(10001)))))

for i in range(n,100001):
  #print(i)
  if like >= set(list(map(int,(str(i))))):
  #  print(list(like),list(map(int,(str(i)))))
    #print(i)
    break

print(i)    
#print(like >= set(list(map(int,(str(10000))))))

Measured memory_bytes: 3060
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
for i in range(1,n):
    arr1[i]=arr1[i]+arr1[i-1]
for i in range(1,m):
    arr2[i]=arr2[i]+arr2[i-1]
ma=0
for i in range(n):
    if arr1[i]<=k:
        ma=max(ma,bisect_right(arr2,k-arr1[i])+i+1)
for i in range(m):
    if arr2[i]<=k:
        ma=max(ma,bisect_right(arr1,k-arr2[i])+i+1)
print(ma)

Measured memory_bytes: 40580
import java.util.BitSet;
import java.util.Scanner;

class Solver {
    Solver(Scanner in){
        int N = in.nextInt();
        int M = in.nextInt();
        BitSet bits = new BitSet(N);
        bits.set(0, N);
        for (int i = 0; i < M; i++) {
            BitSet gate = new BitSet(N);
            gate.set(in.nextInt() - 1, in.nextInt());
            bits.and(gate);
        }
        System.out.println(bits.cardinality());
    }

    void solve() {

    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 346064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int k;

int x(int a) {
	rep(i, 0, k) {
		a *= 2;
	}
	return a;
}

int main() {
	int h, w;
	cin >> h >> w;
	string s;
	vector<vector<bool>> x(h + 2, vector<bool>(w + 2, false));
	rep2(i, 1, h) {
		cin >> s;
		rep(j, 0, w) {
			if (s[j] == '#') {
				x[i][j + 1] = true;
			}
		}
	}
	rep2(i, 1, h) {
		rep2(j, 1, w) {
			if (!x[i][j]) {
				continue;
			}
			if (!x[i - 1][j] && !x[i + 1][j] && !x[i][j - 1] && !x[i][j + 1]) {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

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

int main(){
    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    ll y = x/d;
    x -= min(y, k) * d;
    k -= min(y, k);
    if(k%2==0) cout << x << endl;
    else cout << abs(x-d) << endl;
        
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

//for binomial coefficients
const int MAX=510000;
vector<modint> fac(MAX,0);
vector<modint> finv(MAX,0);
vector<modint> inv(MAX,0);
void COMinit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(int i=2;i<MAX;i++){
    fac.at(i)=fac.at(i-1)*i;
    inv.at(i)=-inv.at(MOD%i)*(MOD/i);
    finv.at(i)=finv.at(i-1)*inv.at(i);
  }
}
modint COM(int n,int k){
  if(n<k) return 0;
  if(n<0 || k<0)  return 0;
  return fac.at(n)*finv.at(k)*finv.at(n-k);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,M,K;
  cin >> N >> M >> K;

  COMinit();
  modint ans=0;
  for(ll i=0;i<N;i++){
    for(ll j=0;j<M;j++){
      ans+=(i+1)*(j+1)*((i+1)-1+(j+1)-1)/2;
      ans+=(i+1)*(M-j)*((i+1)-1+(M-j)-1)/2;
      ans+=(N-i)*(j+1)*((N-i)-1+(j+1)-1)/2;
      ans+=(N-i)*(M-j)*((N-i)-1+(M-j)-1)/2;
      ans-=(i+1)*((i+1)-1)/2;
      ans-=(j+1)*((j+1)-1)/2;
      ans-=(N-i)*((N-i)-1)/2;
      ans-=(M-j)*((M-j)-1)/2;
    }
  }
  ans/=2;
  ans*=COM(N*M-2,K-2);
  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define int ll
string str;

int power(int a,int b,int M){ //returns a^b % M, O(logb)
  	 if (b==0) return 1;
    
   	int half = b/2;
   	int halfval;
    
   	halfval = (power(a,half,M))%M;
   	if (b%2 == 0) return (halfval * halfval) % M;
   	else return (((halfval * halfval) % M) * (a % M)) % M;
}



	

	
int32_t main(){
	fast;
	
	cin>>str;
	
	int ans = 0,prevones = 0;

	FOR(i,0,str.size()-1){
		if (str[i] == '1'){
			ans += (power(2,prevones,MOD) * power(3,str.size() - i - 1,MOD)) % MOD;
			ans %= MOD;
			prevones++;

		}
	}
	cout<<(ans + power(2,prevones,MOD)) % MOD;
	
	
	
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
    int a,b,c,d,i;

    while(scanf("%d%d",&a,&c)!=EOF){
        d=a+c;
        for(i=1;;i++){
            b=d/10;
            d=b;
            if(b==0){
                printf("%d\n",i);
                break;
                }
                }
                }
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const double pi=acos(-1);
const int maxn=2e5+5;

int main()
{
    int n;
    string s;
    cin>>n>>s;
    if(n%2)
        printf("No\n");
    else 
    {
        int flag=1;
        for(int i=0;i<n/2;i++)
            if(s[i]!=s[i+n/2])
             flag=0;
        if(flag)
            printf("Yes\n");
        else 
            printf("No\n");
    }
    return 0;
}


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

int main() {
    int N, K;
    std::cin >> N;
    std::cin >> K;

    std::vector<int> X(N);
    for (int &x : X) {
        std::cin >> x;
    }

    int moves = 0;
    for (int x : X) {
        moves += std::min(x, std::abs(x - K)) * 2;
    }
    std::cout << moves << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int n;
int ma[220][220];
int dis[220][220];
int vis[220];

void dfs(int x,int y)
{
	if(vis[x])
	{
		if(vis[x] != y)
		{
			cout << -1 << endl;
			exit(0);
		}
		return;
	}
	vis[x] = y;
	rep(i,0,n) if(ma[x][i] == 1) dfs(i,y^3);
}
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	string str;
	rep(i,0,n)
	{
		cin >> str;
		rep(j,0,n)
		{
			ma[i][j] = str[j] - '0';
			dis[i][j] = ma[i][j];
			if(ma[i][j] == 0)
			{
				dis[i][j] = 1e4;
			}
		}
	}
	int ans = 0;
	rep(k,0,n)
	{
		rep(i,0,n)
		{
			rep(j,0,n)
			{
				dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}


	rep(i,0,n)
	{
		if(!vis[i])
		dfs(i,1);
	}

	rep(i,0,n)
	{
		rep(j,0,n)
		{
			if(i == j)
				continue;

			ans = max(ans,dis[i][j]);
		}
	}
	cout << ans+1 << endl; 
	return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, K;
int a[110000];
int S(int n) {
    int res = 0;
    while (n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}
signed main() {
    int K;
    cin >> K;
    int keta = 1;
    int x = 0;
    {
        int low = 99;
        stack<int> stk;
        for (int i = 99; i >= 1; i--) {
            int cur = i;
            if (low * S(cur) >= cur * S(low)) {
                stk.push(cur);
                low = cur;
            }
        }
        while (!stk.empty()) {
            cout << stk.top() << endl;
            stk.pop();
            x++;
            if (x == K) goto end;
        }
    }
    while (true) {
        int low = keta * 1000 - 1;
        stack<int> stk;
        for (int i = 999; i >= 100; i--) {
            int cur = i * keta + keta - 1;
            if (low * S(cur) >= cur * S(low)) {
                stk.push(cur);
                low = cur;
            }
        }
        while (!stk.empty()) {
            cout << stk.top() << endl;
            stk.pop();
            x++;
            if (x == K) goto end;
        }
        keta *= 10;
    }
end:;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  int N;
  string S;

  cin >> N >> S;

  //奇数サイズでは，題意の文字列の繰り返しは起こらない
  if(N%2 == 1)
    cout << "No" << endl;
  else{
    int T_size = N/2;
    int i;
    for(i=0; i<T_size; i++)
      if(S[i] == S[i+T_size])
	continue;
      else{
	cout << "No" << endl;
	break;
      }
    if(i == T_size)
      cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	cin >> x;
	long long A[6209];
	for (int i = 0; i < 6209; i++)
	{
		A[i] = pow(i, 5);
	}
	for (int i = 0; i < 6209; i++)
	{
		for (int j = 0; j < 6209; j++)
		{
			if (A[i] + A[j] == (long long)x)
			{
				cout << i << " -" << j << endl;
				return 0;
			}
			else if (A[i] - A[j] == (long long)x)
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int f(int n, int k, string s){
	VI a; a.reserve(n+10);
	
	int sm =1;
	rep(i,n-1){
		if(s[i] == s[i+1]) sm++;
		else{ a.push_back(sm); sm =1; }
	}
	if(sm!=0) a.push_back(sm);
	vector<ll> sk(sz(a)+1);
	rep(i, sz(a)) sk[i+1] = sk[i]+a[i];
	//for(auto x :a) printf("%d, ",x); puts("");
	//for(auto x :sk) printf("%lld, ",x); puts("");
	
	ll mx=0;
	rep(i,sz(a)){
		int nk=0;
		if(s[0]=='1' && i%2==0 || s[0]=='0' && i%2==1 ) nk=k*2+1;
		else nk = k*2;
		//dbg(i,i+nk, sk[i+nk] - sk[i]);
		mx=max(mx, sk[min(i+nk, sz(a))] - sk[i]);
	}
	return mx;
}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,k;
	string s;
	cin >>n >>k >>s;
	
	auto z=f(n, k, s);
	cout << z <<"\n";
	return 0;
}

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

int main() {
    int arr[5];
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
        if(arr[i]==0)
        {
            cout<<i+1;
            break;
        }
    }
    // your code goes here
	return 0;
}


Measured memory_bytes: 3568
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sstream> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <queue> //C++
#include <map> //C++
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  max(x,y) ((x)>(y)?(x):(y))
#define  min(x,y) ((x)>(y)?(y):(x))


using namespace std; //C++


int main(void) {

	int i;

	/* 文字 */
	char moji;

	/* 文字を入力 */
	scanf("%c", &moji);

	/* アルファベットの小文字か大文字かを判定 */
	if ((moji >= 'a') && (moji <= 'z')) {
		printf("a\n");
	}
	else if ((moji >= 'A') && (moji <= 'Z')) {
		printf("A\n");
	}


	return 0;

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset((a), v, sizeof(a))
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
	int x; scanf("%d", &x);
	if (x <= 599) printf("8\n");
	else if (x <= 799) printf("7\n");
	else if (x <= 999) printf("6\n");
	else if (x <= 1199) printf("5\n");
	else if (x <= 1399) printf("4\n");
	else if (x <= 1599) printf("3\n");
	else if (x <= 1799) printf("2\n");
	else printf("1\n");
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

const int INF = 1e9;
typedef long long ll;

int main(void){
  int n;
  while(cin >> n && n != -1){
    string quaternary("");
    while(n != 0){
      quaternary.insert(quaternary.begin(), 1, (n % 4) + '0');
      n /= 4;
    }
    if(quaternary == "") quaternary = "0";
    cout << quaternary << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define puba push_back
#define pufro push_front
#define poba pop_back
#define pofro pop_front

using namespace std;
typedef long long ll;
const ll M=1e9+7;
const double PI=acos(-1);
const double EPS=1e-12;
const ll arrSize=2000005;
ll arr[arrSize];
int main(){
	int tc=1,kasus=1;
	//scanf("%d",&tc);
	while(tc--){
		int a,b;
		scanf("%d %d",&a,&b);
		if(a%2==0 || b%2==0){
			printf("No\n");
		}
		else{
			printf("Yes\n");
		}
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int n;
	cin >> n;
	
	vi v(n);
	for(auto& el : v) cin >> el;
	
	int ans = 0;
	for(int i = 1 ; i + 1 < n ; ++i)
	{
		vi a = { v[i - 1] , v[i] , v[i + 1] };
		SORT(a);
		ans += a[1] == v[i];
	}
	
	cout << ans << nl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;

int N,M;
bool conf[5010];
bool other;
vector<int> V[5010];
vector<int> ans;
void dfs(int n){
    conf[n]=true;
    for(int i=0;i<V[n].size();++i){
        if(conf[V[n][i]])continue;
        dfs(V[n][i]);
    }
    ans.PB(n);
    return ;
}

signed main(){
    cin>>N>>M;
    for(int i=0;i<M;++i){
        int a,b;
        cin>>a>>b;
        V[b].PB(a);
    }
    for(int i=1;i<=N;++i)if(!conf[i])dfs(i);
    for(int i=0;i<N;++i){
        cout<<ans[i]<<endl;
        if(i!=N-1){
            int it = find(V[ans[i+1]].begin(),V[ans[i+1]].end(),ans[i])-V[ans[i+1]].begin();
            if(it==V[ans[i+1]].size())other=true;
        }
    }
    cout<<other<<endl;
}

Measured memory_bytes: 4428
X = int(input().strip())
a = 1
b = 0
while True:
    if X == a**5 - b**5:
        print(a, b)
        break
    elif X == a**5 + b**5:
        print(a, -b)
        break
    elif a**5 - b**5 < 0:
        b = 0
        a += 1
    else:
        b += 1


Measured memory_bytes: 9120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, ans = 0;
	cin >> n;
	vector<int> l(2 * n);
	rep (i, 2 * n) cin >> l[i];
	sort(all(l));
	rep (i, n) ans +=l[2 * i];
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

#define ll long long 
#define endl "\n"

int main()
{
	int a, b, t;
	
	cin >> a >> b >> t;
	
	t += 0.5;
	
	int ans = b*(t/a);
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MN 500000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
pair<double,double> q[MN+5];
int n,L,t[MN+5],v[MN+5],top,tail;
double X[MN+5],Y[MN+5];
inline double C(pair<double,double> a,pair<double,double> b){return(a.second-b.second)/(a.first-b.first);}
inline double CY(int res,double Y,double X){return (q[res+1].second+Y+(X+L-q[res+1].first)/(q[res].first-q[res+1].first)*(q[res].second-q[res+1].second))/L;}
int main()
{
	n=read();L=read();q[top=tail=1]=make_pair(0.,0.);
	for(int i=1;i<=n;++i) t[i]=read(),v[i]=read(),X[i]=X[i-1]+v[i],Y[i]=Y[i-1]+1LL*t[i]*v[i];
	for(int i=1;i<=n;++i)
	{
		pair<double,double> s=make_pair(-X[i],-Y[i]); 
		while(tail<top&&q[tail+1].first>=s.first+L) ++tail;
		q[++top]=s;double yy=CY(tail,Y[i],s.first);
	//	cout<<q[tail+1].second+Y[i]<<" "<<q[tail].first<<" "<<q[tail].second<<" "<<q[tail+1].first<<" "<<q[tail+1].second<<endl;
		printf("%.10lf\n",yy);--top;q[tail]=make_pair(s.first+L,-Y[i]+yy*L);
		while(top>tail&&C(s,q[top])<C(q[top],q[top-1])) --top;
		q[++top]=s;
	}
	return 0;
}



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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int h, w; cin >> h >> w;

    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }

    for (int i = 0; i < w+2; ++i) {
        cout << '#';
    }

    cout << endl;

    for (int i = 0; i < h; ++i) {
        cout << '#' << a[i] << '#' << endl;
    }

    for (int i = 0; i < w+2; ++i) {
        cout << '#';
    }

    cout << endl;
}

Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=str(input())
    if '7' in n:
        print("Yes")
    else:
        print("No")
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()


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

ll n;

int main(void){
	scanf("%lld",&n);
	printf("%lld\n",(n-1LL)*(n)/2LL);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int m,n,vis[2333];
int main(){
	cin>>m>>n;
	for(int i=1,x;i<=n;i++)cin>>x,vis[x]=1;
	int mx=m+1,p=-1;
	for(int i=0;i<=1000;i++){
		if(!vis[i]){
            int t=abs(i-m);
            if(t<mx)mx=t,p=i;
            else if(t==mx&&i<p)p=i;
		}
	}
	cout<<p<<endl;
}


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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  string s;
  int q;cin>>s>>q;
  int i;
  vector<char> fro(0);
  vector<char> bac(0);
  bool rev=false;
  rep(i,q)
  {
    int t;cin>>t;
    if(t==1)
    {
      if(rev)rev=false;
      else rev=true;
    }
    else
    {
      int f;cin>>f;
      char c;cin>>c;
      if(f==1)
      {
        if(rev) bac.emplace_back(c);
        else fro.emplace_back(c);
      }
      else
      {
        if(rev) fro.emplace_back(c);
        else bac.emplace_back(c);
      }
    }
  }
  if(rev)
  {
    for(i=bac.size()-1;i>=0;i--)cout<<bac[i];
    reverse(all(s));
    cout<<s;
    for(i=0;i<fro.size();i++)cout<<fro[i];
    cout<<endl;
  }
  else
  {
    for(i=fro.size()-1;i>=0;i--)
    {
      cout<<fro[i];
    }
    cout<<s;
    for(i=0;i<bac.size();i++)cout<<bac[i];
    cout<<endl;
  }

}


Measured memory_bytes: 1024
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {

    var n = readLine.split(" ").map(_.toInt)
    while( n(0) != 0 || n(1) != 0) {
      val h = n(0)
      val w = n(1)

      for(i <- 0 to h-1) {
        for(j <- 0 to w-1) {
          if((i+j)%2==0)
            print("#")
          else
            print(".")
        }
        println()
      }
      println()
      n = readLine.split(" ").map(_.toInt)
    }
  }
}

Measured memory_bytes: 55920
import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        A, B = L[i], L[j]
        delta = A-B+1
        idx = bisect.bisect_left(L, delta)
        if idx >= j:
            break
        ans += j-idx

print(ans)

Measured memory_bytes: 3188
S = input()

s_ind = 0
e_ind = 0


for i, s in enumerate(S):
    if s == "A":
        s_ind = i
        break
        
for i in range(len(S)):
    if S[-(i+1)] == "Z":
        e_ind = len(S)-(i+1)
        break
        
print(e_ind - s_ind + 1)

Measured memory_bytes: 3516
import sys
from collections import defaultdict
input = sys.stdin.buffer.readline

n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

pre_dp = defaultdict(lambda: 0)
pre_dp[0] = 0

for i in range(1, n+1):
    cur_dp = defaultdict(lambda: 0)
    w_i, v_i = wv[i-1]

    keys = sorted(pre_dp.keys())
    for k in keys:
        cur_dp[k] = max(cur_dp[k], pre_dp[k])
        if k + w_i <= W:
            big = max(pre_dp[k + w_i], pre_dp[k] + v_i)
            cur_dp[k+w_i] = big
    pre_dp = cur_dp
ans = 0
for w, v in cur_dp.items():
    if w <= W:
        ans = max(ans, v)

print(ans)



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

using namespace std;

int main() {
  int N, A, B, P;
  cin >> N >> A >> B;
  vector<int> g(3);
  while (cin >> P) {
    if (P <= A)
      ++g[0];
    else if (P <= B)
      ++g[1];
    else
      ++g[2];
  }
  cout << *min_element(begin(g), end(g)) << endl;
  return 0;
}


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

bool bo;
int n,l,r,ans,q[1000101],po;
char s[1000101],t[1000101];

int main()
{
	scanf("%d%s%s",&n,s+1,t+1); bo=1;
	for (int i=1; i<=n; i++) bo&=(s[i]==t[i]);
	if (bo) {puts("0"); return 0;}
	t[0]=' ',l=ans=1,r=0,po=n;
	for (int i=n; i; i--)
		if (t[i]!=t[i-1])
		{
			po=(po>i?i:po);
			while (po&&s[po]!=t[i]) po--;
			if (!po) {puts("-1"); return 0;}
			while (l<=r&&q[l]-(r-l+1)+1>i) l++;
			q[++r]=po; if (i!=po) ans=(ans>r-l+2?ans:r-l+2);
		}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> d(n); for (int i = 0; i < n; ++i) cin >> d[i];

  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      res += d[i] * d[j];
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;


int main() {
  int dp[100010];
  int n;
  cin >> n;

  dp[0] = 0;
  for (int n=1; n<=100000; n++){
    dp[n] = 1000000;
    int power = 1;
    while (power <=n) {
      dp[n] = min(dp[n], dp[n-power]+1);
      power *= 6;
    }
    power =  1;
    while (power <=n) {
      dp[n] = min(dp[n], dp[n-power]+1);
      power *= 9;
    }
  }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
N = int(sys.stdin.readline().rstrip())
A = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 10**9 + 7
color = A.count(0)
ans = 1
cnt = [0] * N
for a in A:
    if a > 0:
        ans *= (cnt[a - 1] - cnt[a])
    cnt[a] += 1
    ans %= mod
for i in range(cnt[0]):
    ans *= 3 - i
print(ans % mod)

Measured memory_bytes: 13964
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var a = 0;

            int i = cin.ReadInt;
            if (i / 100 == 1)
            {
                a++;
            }
            i = i % 100;

            if (i / 10 == 1)
            {
                a++;
            }
            i = i % 10;

            if (i == 1)
            {
                a++;
            }

            WriteLine(a.ToString());
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 27604
#include<iostream>
using namespace std;
long long n,ans;
const long long maxn=1e6+5;
int prime[maxn];
void makeprime(int x){
	for(register int i=2;i<=x;i++){
		prime[i]=1;
	}
	for(register int i=2;i*i<x;i++){
		if(prime[i]){
			for(int j=i*i;j<=x;j+=i){
				prime[j]=0;
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	makeprime(1000000);
	cin>>n;
	for(register int i=1,x;i<n;i++){
		x=n-i;
		if(prime[x]!=0){
			ans+=2;
		}
		else {
			for(register int j=1;j*j<=x;j++){
				if(x%j==0){
					ans+=2;
					if(j*j==x) ans--;
				}
			}	
		}
	}
	cout<<ans;
}

Measured memory_bytes: 7544