akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll ten[20];

ll solve(ll val,int digit,bool first){
    if(digit==0){
        if(val==0) return 1;
        else return 0;
    }
    if(digit==1){
        if(val==0) return 10;
        else return 0;
    }

    if(abs(val)%10==0){
        ll c=10;
        if(first) c--;
        return c*solve(val/10,digit-2,false);
    }

    ll res=0;

    ll tar=abs(val)%10;
    ll d=10-tar;
    if(val<0) tar*=(-1);
    ll minus=tar-tar*ten[digit-1];
    res+=d*solve((val-minus)/10,digit-2,false);

    tar=10-abs(val)%10;
    ll e=10-tar;
    if(val<0) tar*=(-1);
    ll plus=tar-tar*ten[digit-1];
    if(first) e--;
    res+=e*solve((val+plus)/10,digit-2,false);

    return res;
}

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

  ll D;
  cin>>D;

  ten[0]=1;
  for(int i=1;i<19;i++) ten[i]=ten[i-1]*10ll;

  ll ans=0;
  for(ll i=1;i<=18;i++) ans+=solve(D,i,true);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int32_t main(){

int n,m;cin>>n>>m;
int v[n][m];
int dp[n+1][m+1]={};
char c;
for(int i=0;i<n;i++){
   for(int j=0;j<m;j++){
      cin>>c;
      if(c=='.')v[i][j]=0;
      else v[i][j]=1;
   }
}
dp[0][0]=1;
for(int i=1;i<=n;i++)if(!v[i-1][0])dp[i][1]=1;else break;
for(int i=1;i<=m;i++)if(!v[0][i-1])dp[1][i]=1;else break;
// for(int i=0;i<=n;i++)cout<<dp[i][0]<<" ";
for(int i=2;i<=n;i++){
   for(int j=2;j<=m;j++){
      if(v[i-1][j-1]==0){
         dp[i][j]=dp[i-1][j]+dp[i][j-1];
      }
      dp[i][j]%=mod;
   }
}
// for(int i=1;i<=n;i++){
//    for(int j=1;j<=m;j++)cout<<dp[i][j]<<" ";
//    cout<<endl;
// }
cout<<dp[n][m]<<endl;

}

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

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

  vector<string> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  map<string,int> hin;

  for (auto x : A) {
    if (hin.count(x)) {

    } else {
      hin[x];
    }
  }

  cout << hin.size() << endl;
}

Measured memory_bytes: 25048
#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];
}
sort(d.begin(), d.end());
int ans=d[n/2]-d[n/2-1];
cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <cstdio>

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

const int maxn=100000;

int n,v[maxn+10],cnte[maxn+10],cnto[maxn+10];

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      v[i]=read();
    }
  for(int i=2; i<=n; i+=2)
    {
      ++cnte[v[i]];
    }
  for(int i=1; i<=n; i+=2)
    {
      ++cnto[v[i]];
    }
  int ef=0,es=0,of=0,os=0;
  for(int i=1; i<=maxn; ++i)
    {
      if(cnte[i]>cnte[ef])
        {
          es=ef;
          ef=i;
        }
      else if(cnte[i]>cnte[es])
        {
          es=i;
        }
    }
  for(int i=1; i<=maxn; ++i)
    {
      if(cnto[i]>cnto[of])
        {
          os=of;
          of=i;
        }
      else if(cnto[i]>cnto[os])
        {
          os=i;
        }
    }
  if(ef!=of)
    {
      printf("%d\n",n-cnte[ef]-cnto[of]);
    }
  else
    {
      if(cnte[es]>cnto[os])
        {
          printf("%d\n",n-cnte[es]-cnto[of]);
        }
      else
        {
          printf("%d\n",n-cnto[os]-cnte[ef]);
        }
    }
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
     
     
int main(){
 
	int a,p; sd(a); sd(p);

	p = p + 3 * a;

	pd(p/2);          
           
     
     
        
    return 0;
}


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

using namespace std;

int N, M;
int dp[100000];

int inf = 100000000;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> As(M);
  vector<int> nMatches = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int A;
  for (int i = 0; i < M; ++i) {
    cin >> A;
    As[i] = A;
  }

  for (int i = 1; i <= N; ++i) {
    dp[i] = -inf;
    for (int j = 0; j < M; ++j) {
      int index = i - nMatches[As[j]];
      if (index >= 0 && dp[index] >= 0) {
	dp[i] = max(dp[i], dp[index] + 1);
      }
    }

  }

  int max_digits = dp[N];
  sort(As.begin(), As.end(), greater<int>());
  int rest = N;
  string ans = "";
  for (int i = max_digits; i > 0; --i) {
    for (int m = 0; m < M; m++) {
      if (rest - nMatches[As[m]] >= 0 && dp[rest - nMatches[As[m]]] == (i - 1)) {
	rest -= nMatches[As[m]];
	ans += to_string(As[m]);
	break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main (){
  char S[100],a[50],l;
  scanf("%s",S);
  l=strlen(S);
  
  for(int i=0;i<(l)/2;i++){
    a[i]=S[i];
  }
  
  for(int i=0;i<l-1-i;i++){
    if(S[i]==S[l-i-1]){
    }else{
      printf("No");
      return 0;
    }
  }
  
  l = (l-1)/2;
  for(int i=0;i<l-1-i;i++){
    if(a[i]==a[l-i-1]){
    }else{
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}


Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, x = rm()
x /= a
if a*b / 2 >= x:
    a = 2*x / b
    print(90 - math.degrees(math.atan(a/b)))
else:
    x = a*b - x
    b = 2*x / a
    print(math.degrees(math.atan(b/a)))













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

int main() {
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 3916
#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>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<double>u(n); rep(i, n)cin >> u[i];
	sort(u.begin(), u.end());
	double sum = u[0];
	for (int i = 1; i < n; i++) {
		sum = (sum + u[i]) / 2;
	}
	cout << fixed << setprecision(10)<<sum << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            var A = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = A[0];
            long M = A[1];
            var X = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            if(N>=M){
                Console.WriteLine("0");
                return;
            }
            Array.Sort(X);
            var dist = new long[M-1];
            for(var i=1;i<M;i++){
                dist[i-1] = X[i] - X[i-1]; 
            }
            Array.Sort(dist);
            long sum = 0;
            for(var i=0;i<M-N;i++){
                sum += dist[i];
            }
            System.Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 17888
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n;
inline bool Check(int x)
{
    for(ri int i=2;i*i<=x;i++) if(x%i==0) return 0;
    return 1;
}
signed main()
{
    n=read();
    for(ri int i=11;n;i+=10)
    {
        if(Check(i)) printf("%lld ",i), n--;
    }
    puts("");
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b) {
  if(b==0) return a;
  return gcd(b,a%b);
 }
int main(){
  ll n;
  cin >>n;
  ll a[n],g1[n],m[n];
  for(ll i=0;i<n;i++) cin >>a[i];
  ll g=a[0];
  g1[0]=a[0];
  for(ll i=1;i<n;i++){
    g=gcd(a[i],g);
    g1[i]=g;
  }
  g=a[n-1],m[n-1]=a[n-1];
  for(ll i=n-2;i>=0;i--){
     g=gcd(a[i],g);
     m[i]=g;
  }
  ll ans=-1;
  for(ll i=0;i<n;i++){
    if(i==0) ans=max(ans,m[i+1]);
    else if(i==n-1) ans=max(ans,g1[i-1]);
    else ans=max(ans,gcd(g1[i-1],m[i+1]));
  }
  cout <<ans<<endl;
}


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

using namespace std;

int sum_digits(int a, int b) {
  int sum = 0;
  while (a) {
    sum += a % 10;
    a /= 10;
  }

  while (b) {
    sum += b % 10;
    b /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int min_sum = 10005;
  for (int i = 1; i < n / 2 + 1; i++) {
    int a = i;
    int b = n - i;
    int sum_dig = sum_digits(a, b);
    min_sum = min(sum_dig, min_sum);
  }
  cout << min_sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  int cnt = 0;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    int t;
    cin >> t;
    if (t%2 == 1 && i%2 == 0) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

int main(void){

    int n, a, b;

    scanf("%d", &n);

    for(a = 1; a <= 9; a++){
        for(b = 1; b <= 9; b++){
            if(n == a*b){
                printf("Yes");
                break;
            }
        }
        if(n == a*b && b <= 9){
            break;
        }
    }
    if(a == 10){
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int n;
double sum, x;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    while(n--)  cin >> x, sum += 1 / x;
    cout << fixed << setprecision(14) << 1 / sum;
    return 0;
}


Measured memory_bytes: 256
def inpl(): return input().split()
def get_str(bl): return 'POSSIBLE' if bl else 'IMPOSSIBLE'

n, m = map(int, inpl())
M = list(tuple(map(int, inpl())) for _ in range(m))#[(a, b), ..., (a, b)]
X = list(tuple((a, b)) for a, b in M if a == 1)
Y = list(tuple((a, b)) for a, b in M if b == n)
XB = set(list(b for _, b in X))
YA = set(list(a for a, _ in Y))
print(get_str(len(XB & YA) > 0))

Measured memory_bytes: 52688
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll x){ cout << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

ll INF = 1e9+7;

int main(){
    ll A[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll K;
    ii(K);
    oie(A[K-1]);
    return 0;
}

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

#define lint long long

const int N = 4e5 + 10;

int a[N];
int nxt[N], pos[N];
int vis[N];

int main (void) {
	int n; lint k;
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	if (n == 1) {
		if (k & 1) printf("%d\n", a[1]);
		else puts("");
		return 0;
	}

	memcpy(a + n + 1, a + 1, sizeof(int) * n);
	for (int i = 1; i <= 2 * n; i++) {
		if (pos[a[i]]) nxt[pos[a[i]]] = i;
		pos[a[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (nxt[i] > n) nxt[i] -= n;
	}
	int loop = 1, cur = 0;
	pos[1] = 0;
	while (cur != n) {
		cur ++;
		if (cur >= nxt[cur]) {
			cur = nxt[cur];
			pos[++ loop] = cur;
		} else {
			cur = nxt[cur];
		}
	}
	k %= loop;
	if (k != 0) {
		vector<int> v;
		for (int i = pos[k] + 1; i <= n; i++) {
			if (!vis[a[i]]) {
				v.push_back(a[i]);
				vis[a[i]] = 1;
			} else {
				while (v.back() != a[i]) {
					vis[v.back()] = 0;
					v.pop_back();
				}
				vis[v.back()] = 0;
				v.pop_back();
			}
		}
		for (int i = 0, sz = v.size(); i < sz; i++) {
			printf("%d%c", v[i], "\n "[i != sz - 1]);
		}
	}
}

Measured memory_bytes: 7924
#include <iostream>
using namespace std;
int main(void){
    int left = 0, right, ans = 0;
    string s;
    cin >> s;
    right = s.length() - 1;
    while(left < right){
        if(s[left] == s[right]){
            left++;
            right--;
        }else if(s[left] != 'x' && s[right] != 'x'){
            ans = -1;
            break;
        }else if(s[left] == 'x'){
            left++;
            ans++;
        }else{
            right--;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#だいくすとらお試し
def dk(ed, dis, from, i, to, v)
  max = 1000000000
  
  d = v.times.map{max}
  check = Array.new(v,false)
  
  d[from] = 0
  
  v.times{|i|
    now = 0
    nowd = max
    v.times{|j|
      #p check[j],nowd,d[j]
      if nowd>d[j]&&!check[j] then
        nowd = d[j];
        now = j;
      end
    }
    break if nowd==max
    
    #p from
    #p 'now'+now.to_s
    
    check[now] = true
    ed[now].size.times{|j|
      nextt = ed[now][j]
      nextd = d[now]+dis[now][j]
      #p nextt,nextd
      d[nextt] = nextd if nextd<d[nextt]
    }
  }
  
  d[i] = max
  
  return to.map{|t|d[t]}
end



N,M,R=gets.split.map(&:to_i)
r = gets.split.map{|w|w.to_i-1}

edge = N.times.map{[]}
dist = N.times.map{[]}
M.times.map{
  a,b,c = gets.split.map(&:to_i)
  edge[a-1] << b-1
  edge[b-1] << a-1
  dist[a-1] << c
  dist[b-1] << c
}

#p dist

co = R.times.map{|i| dk(edge,dist,r[i],i,r,N)}

#p co

min = 1000000000
R.times.to_a.permutation(R).each{|t|
  cost = 0
  #p t
  (t.size-1).times{|i|
    #p co[t[i]][t[i+1]]
    cost += co[t[i]][t[i+1]]
  }
  min = cost if min>cost
}

puts min

Measured memory_bytes: 4092
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    # comb init
    # mod = 1000000007
    nmax = 2 * 10 ** 6 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    K = int(input())
    S = input().rstrip('\n')
    N = len(S)

    ans = 0
    for k in range(K+1):
        ans = (ans + (pow(25, K-k, mod) * comb(N+K, N+k))%mod)%mod
    print(ans)



if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c, d , e, k;
  cin >> a >> b >> c >> d >> e >> k;
  string ans = "Yay!";
  if ( (b-a) > k) ans = ":(";
  if ( (c-a) > k ) ans = ":(";
  if ( (d-a) > k ) ans = ":(";
  if ( (e-a) > k ) ans = ":(";
  if ( (c-b) > k ) ans = ":(";
  if ( (b-d) > k ) ans = ":(";
  if ( (e-b) > k ) ans = ":(";
  if ( (d-c) > k ) ans = ":(";
  if ( (e-c) > k ) ans = ":(";
  if ( (e-d) > k ) ans = ":(";
  
  cout << ans << endl;
}

  
  

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
n,k=map(int,input().split())
tmp=0
ans=0
if k==0:
    print(n*n)
    quit()
for i in range(k,n):
    tmp=n//(i+1)
    ans+=(i+1-k)*tmp
    if n%(i+1)-k+1>0:
        ans+=n%(i+1)-k+1
print(ans)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n,m,i,j,x,y,z;
	   string a[1000];
	cin>>n>>m;
	   for(i=1;i<=n;i++)
	   cin>>a[i];
	     sort(a,a+n+1);
	     for(i=1;i<=n;i++)
	      cout<<a[i];
	      cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
using namespace std;

const int kMaxN = 1e5 + 5;

typedef long long ll;

int n, m;
ll a[kMaxN];
vector<int> G[kMaxN], S;
bool vis[kMaxN];

int DFS(int x, vector<int> &vec) {
  vec.push_back(a[x]);
  vis[x] = true;
  for (int nxt : G[x])
    if (!vis[nxt])
      DFS(nxt, vec);
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%d", a + i);
  for (int i = 0, x, y; i < m; ++i) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (m == n - 1)
    return puts("0"), 0;
  int need = (n - m - 1) << 1;
  if (n < need) {
    return puts("Impossible"), 0;
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i)
    if (!vis[i]) {
      --need;
      vector<int> v;
      DFS(i, v);
      sort(v.begin(), v.end());
      ans += v[0];
      for (int i = 1; i < v.size(); ++i)
        S.push_back(v[i]);
    }
  sort(S.begin(), S.end());
  for (int i = 0; i < need; ++i)
    ans += S[i];
  printf("%lld\n", ans);
  return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {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 a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    string s,t;cin>>s>>t;
    vvi a(26);
    vi b(26,0);
    for(int i=0;i<s.size();++i){
      a[s[i]-'a'].push_back(i);
    }
    int i=-1;
    int k=0;
    for(char c:t){
        int j=c-'a';
        if (a[j].empty()){cout << -1;return 0;}
        auto it=lower_bound(a[j].begin(),a[j].end(),i+1);
        if (it==a[j].end()){
            ++k;
            i=a[j][0];
        }else{
            i=*it;
        }
    }
    cout << (ll)k*s.size()+i+1;
    return 0;
}



Measured memory_bytes: 1228
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    print(int(-N**0.5)**2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def other_kind(k):
	if k == 'S':
		return 'W'
	elif k == 'W':
		return 'S'
	else:
		return 1/0



def mk_next(kind, say, pre_kind):
	if kind == 'S':
		if say == 'o':
			return pre_kind
		else:
			return other_kind(pre_kind)
	else:
		if say == 'o':
			return other_kind(pre_kind)
		else:
			return pre_kind


def main():
	n = int(input())
	#b , c = tin()
	s = input()
	for pre in ['W','S']:
		for cc in ['W','S']:
			ret = [0]*n
			pk = pre
			kind = cc
			for i, c in enumerate(s):
				next = mk_next(kind, c, pk)
				#pa((kind,pk,c,next))
				ret[i] = kind
				pk = kind
				kind = next
			if pre == ret[-1] and cc == mk_next(ret[-1], s[-1], ret[-2]):
				#pa((kind,s[-1],pk,cc, mk_next(kind, s[-1], pk) ))
				print(''.join(ret))
				return
	return -1
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 79980
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;

void solve(){
    ll n;
    cin >> n;
    ll x[n+1];
    for(ll i=0;i<n+1;i++) x[i]=0;
    for(ll i=2;i<=n;i++){
        ll a;
        cin >>a;
        x[a]++;
    }
    for(ll i=1;i<=n;i++){
        kaku(x[i]);
    }
}

int main(){
    solve();
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

ll g(ll n) {return n * (n+1) / 2;}


int main()
{   
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vll a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vll sa(n+1), sb(m+1);
    rep(i, n) sa[i+1] = sa[i] + a[i];
    rep(i, m) sb[i+1] = sb[i] + b[i];

    int ans = 0;
    rep(i, n+1) {
        if(sa[i] > k) continue;
        auto itr = upper_bound(all(sb), k-sa[i]);
        int x = itr - sb.begin(); --x;
        ans = max(ans, i+x);
        //cout << i << " " << k-sa[i] << " " << x << endl;
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 9556
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int n,u,v;
vector<int> gr[100001];
pair<ll,ll> dp[100001];
void dfs(int x,int par){
   if(x!=1 && gr[x].size()==1)
   {
       dp[x].first=1;
       dp[x].second=1;
       return;
   }
   long long wh=1,bl=1;
   for(auto k : gr[x]){
    if(k==par)
         continue;
         dfs(k,x);
         wh=(wh%mod*dp[k].first%mod)%mod;
         bl=(bl%mod*(dp[k].second+dp[k].first)%mod)%mod;
   }
   dp[x].first=bl;
   dp[x].second=wh;
}
int main(){
cin>>n;
for(int i=1;i<n;i++){
    cin>>u>>v;
    gr[u].push_back(v);
    gr[v].push_back(u);
}
if(n==1){
    cout<<2<<"\n";
    return 0;
}
dfs(1,0);

cout<<(dp[1].first%mod+dp[1].second%mod)%mod<<"\n";

}


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

const int MAX_N = 40, MAX_AB = 10, INF = 1000000000;
int dp[MAX_N + 1][MAX_N * MAX_AB + 1][MAX_N * MAX_AB + 1];

int main() {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i] >> C[i];
    
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= MAX_N * MAX_AB; j++) {
            for (int k = 0; k <= MAX_N * MAX_AB; k++) {
                dp[i][j][k] = INF;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int a = 0; a <= MAX_N * MAX_AB; a++) {
            for (int b= 0; b <= MAX_N * MAX_AB; b++) {
                if (dp[i][a][b] == INF) continue;
                dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b]);
                dp[i + 1][a + A[i]][b + B[i]] = min(dp[i + 1][a + A[i]][b + B[i]], dp[i][a][b] + C[i]);
            }
        }
    }

    int res = INF;
    for (int a = 1; a <= MAX_N * MAX_AB; a++) {
        for (int b = 1; b <= MAX_N * MAX_AB; b++) {
            if (a * Mb == b * Ma) {
                res = min(res, dp[N][a][b]);
            }
        }
    }
    if (res == INF) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 25984
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int N;
	static long A[], B[];

	static class Pair {
		int x;
		int y;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new long[N];
		B = new long[N];
		ArrayList<Pair> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			Pair p = new Pair(sc.nextInt(), sc.nextInt());
			list.add(p);
		}

		list.sort((p, q) -> p.y - q.y);

		long t = 0;
		for (int i = 0; i < N; i++) {
			Pair p = list.get(i);
			t += p.x;
			if (t > p.y) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

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

int main()
{
    int N, K, Q;
    std::cin >> N >> K >> Q;
    std::vector<int> p(N);
    for (int turn = 0; turn < Q; ++turn)
    {
        int A;
        std::cin >> A;
        p[A-1] += 1;
    }
    for (int i = 0; i < N; ++i)
    {
        if (Q - p[i] >= K)
        {
            std::cout << "No" << std::endl;
        }
        else
        {
            std::cout << "Yes" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
sum[3<<17],cnt[3<<17];
N,i,acc,t,k,x;
char f[10],buf[2200000],*p;
main()
{
	read(0,buf,2200000);
	p=buf;
	for(;;)
	{
		k=*p++;
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(i=0;i<N;i++)
	{
		x=0;
		for(;;)
		{
			k=*p++;
			if(k<'0')break;
			x=x*10+k-'0';
		}
		++sum[cnt[x]++];
	}
	i=0;
	p=buf;
	for(t=N;t;t--)
	{
		while(acc>=i*t)acc+=sum[i++];
		cnt[t]=i-1;
	}
	for(i=1;i<=N;i++)
	{
		if(!cnt[i])
		{
			*p++='0';
		}
		else
		{
			if(cnt[i-1]!=cnt[i])
			{
				k=0;
				t=cnt[i];
				while(t)
				{
					f[k++]=t%10;
					t/=10;
				}
				acc=k;
			}
			else k=acc;
			while(k--)*p++=f[k]+'0';
		}
		*p++='\n';
	}
	write(1,buf,p-buf);
}

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

int main() {
  int n,ans=0;
  cin >> n;
  for(int i=1;i<=n;i+=2) {
    int a=0;
    for(int j=1;j*j<=i;j++) {
      if(i%j==0) {
        a++;
        if(j*j!=i) a++;
      };
    };
    if(a==8) ans++;
  };
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int n, mod(998244353);
  cin >> n;
  array<int, 2> infos[n];
  long long dp[n+1];
  for (int i = 0; i < n; ++i)
    cin >> infos[i][0] >> infos[i][1];
  sort(infos, infos + n, greater<array<int, 2>>());
  dp[0] = 1;
  stack<pair<int, int>> st;
  st.push({0, INT_MAX});
  for (int i = 1; i <= n; ++i) {
    while (st.top().second < infos[i-1][0] + infos[i-1][1]) st.pop();
    dp[i] = (dp[st.top().first] + dp[i-1]) % mod;
    st.push({i, infos[i-1][0]});
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int H, W, M, h, w, ans{};
  cin >> H >> W >> M;
  vector<pair<int, int>> ch(H + 1), cw(W + 1);
  for (int i = 1; i <= H; ++i) ch[i] = {0, i};
  for (int i = 1; i <= W; ++i) cw[i] = {0, i};
  set<pair<int, int>> s;
  while (cin >> h >> w) {
    ++ch[h].first;
    ++cw[w].first;
    s.insert({h, w});
  }
  sort(rbegin(ch), rend(ch));
  sort(rbegin(cw), rend(cw));
  for (auto [nh, ih] : ch) {
    for (auto [nw, jw] : cw) {
      if (nh + nw <= ans) break;
      ans = max(ans, nh + nw - (int)s.count({ih, jw}));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 22004
//package AtCoderDp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int a[]=new int[n+1];
        int b[]=new int[n+1];
        int c[]=new int[n+1];
        for(int i=1;i<=n;i++){
            StringTokenizer st=new StringTokenizer(br.readLine());
            a[i]=Integer.parseInt(st.nextToken());
            b[i]=Integer.parseInt(st.nextToken());
            c[i]=Integer.parseInt(st.nextToken());
        }
        int dp[][]=new int[n+1][4];
        dp[n][1]=a[n];
        dp[n][2]=b[n];
        dp[n][3]=c[n];
        for(int i=n-1;i>=1;i--){
            dp[i][1]=Math.max(dp[i+1][2],dp[i+1][3])+a[i];
            dp[i][2]=Math.max(dp[i+1][1],dp[i+1][3])+b[i];
            dp[i][3]=Math.max(dp[i+1][1],dp[i+1][2])+c[i];
        }
        System.out.println(Math.max(dp[1][1],Math.max(dp[1][2],dp[1][3])));
    }
}


Measured memory_bytes: 54308
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <string>
#include <tuple>
#include <climits>
#include <cmath>
#include <map>
#include <functional>
using namespace std;
typedef unsigned long long int ull;
const int INF = 987654321;
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
ull arr[200000];
int main(){
    ull tot = 0;
    int n;
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%llu",&arr[i]);
        tot ^= arr[i];
    }
    for(int i = 0;i<n;i++){
        printf("%llu ",tot^arr[i]);
    }
    printf("\n");

}

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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
void solve(void)
{
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
}
int main(void)
{
    solve();
}

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    ll zero = 0;
    if(k>a){
        cout << "0 " << max(zero,b-k+a) << endl;
    }else{
        cout << a-k << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string foundword = Console.ReadLine();
            string input;
            int count = 0;
            

            while((input=Console.ReadLine())!= "END_OF_TEXT")
            {
                foreach (var i in input.Split(' '))
                {
                    bool judge = true;
                    if (i.Length != foundword.Length) continue;
                    for (int j = 0; j < foundword.Length; j++)
                    {
                        if ('A' <= foundword[j] && foundword[j] <= 'Z')
                        {
                            if (i[j] != foundword[j] && (i[j] - ('a' - 'A')) != foundword[j])
                            {
                                judge = false;
                                break;
                            }
                        }
                        else if (i[j] != foundword[j] && (i[j] + ('a' - 'A')) != foundword[j])  
                        {
                            judge = false;
                            break;
                        }
                    }
                    if (judge) count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9164
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
class Main {
    public static void main(String args[] ) throws Exception {
//        int testCases = Integer.parseInt(br.readLine());
//        while(testCases-- >0){
//
//        }
        double in = GetInput.getInt();
        System.out.println(Math.PI*2*in);
    }
}

class GetInput {
    static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

    static char[] getCharArray() {
        char[] charArray;
        try {
            StringBuilder string = getInputString();
            charArray = new char[string.length()];
            for (int i = 0; i < string.length(); i++) {
                charArray[i] = string.charAt(i);
            }
            return charArray;
        } catch (Exception e) {
            e.printStackTrace();
        }
        charArray = new char[0];
        return charArray;
    }

    static int[] getArrayInt() {
        String[] string;
        int[] array;
        try {
            string = bufferedReader.readLine().split("\\s+");
            array = new int[string.length];
            for (int i = 0; i < string.length; i++) {
                array[i] = Integer.parseInt(string[i]);
            }
            return array;
        } catch (IOException e) {
            e.printStackTrace();
        }

        int[] arra = new int[2];
        return arra;
    }

    static int getInt() {
        try {
            String string = bufferedReader.readLine();
            return Integer.parseInt(string);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return 0;
    }

    static StringBuilder getInputString() {
        try {
            StringBuilder string = new StringBuilder();
            string.append(bufferedReader.readLine());
            return string;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new StringBuilder();
    }

    static long getLongInput() {
        try {
            String string = bufferedReader.readLine();
            return Long.parseLong(string);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return 0;
    }

    static long[] getLongArrayInput() {
        String[] string;
        long[] array;
        try {
            string = bufferedReader.readLine().split("\\s+");
            array = new long[string.length];
            for (int i = 0; i < string.length; i++) {
                array[i] = Long.parseLong(string[i]);
            }
            return array;
        } catch (IOException e) {
            e.printStackTrace();
        }

        long[] arra = new long[2];
        return arra;
    }
}



Measured memory_bytes: 32964
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	int ones = 0, twos = 0, threes = 0;
	int arr[n];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];

		if (arr[i] == 1)ones++;
		else if (arr[i] == 2)twos++;
		else threes++;
	}
	int mones = ones + twos + threes;
	int mtwos = twos + threes;
	int mthrees = threes;
	double dp[n + 1][n + 1][n + 1];
	memset(dp, 0, sizeof(dp));
	int i, j, k;
	for (k = 0; k <= mthrees; k++)
	{
		for (j = 0; j <= mtwos - k; j++)
		{
			for (i = 0; i <= mones - j - k; i++)
			{
				if (i + j + k == 0)continue;
				else
				{
					dp[i][j][k] = (double)n / (i + j + k);
					if (i > 0)
						dp[i][j][k] += (double)(dp[i - 1][j][k] * i) / (i + j + k);
					if (j > 0)
						dp[i][j][k] += (double)(dp[i + 1][j - 1][k] * j) / (i + j + k);
					if (k > 0)
						dp[i][j][k] += (double)(dp[i][j + 1][k - 1] * k) / (i + j + k);
				}
			}
		}
	}
	cout << fixed << setprecision(9) << dp[i-1][j-1][k-1];
	return 0;
}

Measured memory_bytes: 213376
n, m = map(int, input().split())
DB = []

for i in range(n):
  DD = list(map(int, input().split()))
  DD.pop(0)
  DB.append(DD)

fav = set(DB[0])
for i in range(n):
  fav = fav & set(DB[i])
print(len(fav))

Measured memory_bytes: 3060
n=int(raw_input())
N=map(int,raw_input().split())
a=[0]*(10**5+10)
for i in N:
    if i==0:
        a[i]+=1
        a[i+1]+=1
    else:
        a[i-1]+=1
        a[i]+=1
        a[i+1]+=1
print max(a)


Measured memory_bytes: 11304
if __name__ == "__main__":

    h1, a1, h2, a2 = map(int, input().split())
    t1 = (h1 + a2 - 1)//a2
    t2 = (h2 + a1 - 1)//a1
    if t1 < t2:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 9132
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 100000LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

char s[100001];
int main() {
	scanf("%s", s);
	int g = 0, p = 0;
	for (int i=0;s[i];i++)
	{
		if (s[i] == 'g')g++;
		else p++;
	}
	printf("%d", (g - p) / 2);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int answer = 0, k, h, w;

char arr[6][6];

int main(){
    
    int black = 0;
    cin >> h >> w >> k;
    vector<int> v1;
    for(int i = 0; i < h; i++){
    	for(int j = 0; j < w; j++){
    		cin >> arr[i][j];
    	}
    }

    int n = h + w;

    for(int i = 0; i < ( 1 << n ); i++){
    	int black = 0;
        for(int k = 0; k < h; k++){
            for(int l = 0; l < w; l++){
            	if ( ( i & ( 1 << k ) ) != 0 || ( i & ( 1 << l + h ) ) != 0){
            		continue;
            	}
            	else{
            		if(arr[k][l] == '#'){
            			black++;
            		}
            	}
            }
        }
        if(black == k){
        	answer++;
        }         
    }
    cout << answer;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    string s = "";
    while(n > 0){
        n--;
        ll rem = n%26;
        s += 'a'+rem;
        n /= 26;
        //cout << n << " " << rem << nl;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ld double
#define ll long long
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
#define fi first
#define se second
#define Dracarys  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf (ll)1e16

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

void solve(){
    ll h,w;
    cin>>h>>w;
    
    ll dp[h+2][w+2],arr[h+2][w+2];
    memset(dp,0,sizeof(dp));
    memset(arr,0,sizeof(arr));
    
    string s;
    for (ll i=1;i<=h;i++){
        cin>>s;
        for (ll j=1;j<=w;j++){
            if (s[j-1]=='#')
            arr[i][j]=1;
        }
    }
    
    ll cnt=0;
    for (ll i=1;i<=w;i++){
        if (arr[1][i]&&(!arr[1][i-1]))
        cnt++;
        dp[1][i]=cnt;
    }
    
    cnt=0;
    for (ll i=1;i<=h;i++){
        if (arr[i][1]&&(!arr[i-1][1]))
        cnt++;
        dp[i][1]=cnt;
    }
    
    for (ll i=2;i<=h;i++){
        for (ll j=2;j<=w;j++){
            if (arr[i][j]){
                ll ex1=0,ex2=0;
                if (!arr[i][j-1])
                ex1=1;
                if (!arr[i-1][j])
                ex2=1;
                dp[i][j]=min(dp[i][j-1]+ex1,dp[i-1][j]+ex2);
            }
            else
            dp[i][j]=min(dp[i][j-1],dp[i-1][j]);
        }
    }
    
    cout<<dp[h][w]<<"\n";
}

int main() {
    
    Dracarys
    
    ll t=1;
    //cin>>t;
    while(t--){ solve(); }
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
#define pp pair<int,int> 
const int INF = 1001001001;
//int 2×10の9乗

//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n){
    //rep(j,m) cin >> a[i][j]; 
  //}
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  int neg=0;
  rep(i,n){
    ans += abs(a[i]);
    if(a[i]<0) neg++;
  }
  if(neg%2==1){
    int minx=INF;
    rep(i,n) minx=min(minx,abs(a[i]));
    ans -= minx*2;
  }
   cout << ans << endl;
}    

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
typedef pair<ll,ll>pi;
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0)
#define bitseT(y,pos) (1<<pos)|y
#define bitchecK(y,pos) ((1<<pos)&y)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(ll i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define N 100005
bool prime[N+5];
vector<ll>v;
void sieve()
{
    prime[0]=prime[1]=true;
    for(ll i=4;i<=N;i+=2)
    {
        prime[i]=true;
    }
    for(ll i=3;i*i<=N;i+=2)
    {
        if(prime[i]==false)
        {
            for(ll j=i*i;j<=N;j+=2*i)
                prime[j]=true;
        }
    }
}
ll sum[N+5];
int main()
{
    IOS;
    sieve();
    for(ll i=1;i<=N;i++)
    {
        sum[i]=sum[i-1];
        if(prime[i]==false){
//                cout<<i<<" "<<(i+1)/2<<endl;
            if(prime[((i+1)/2)]==0)
            {
                sum[i]++;
//                cout<<"I = "<<i<<endl;
            }
        }
    }
    ll q;cin>>q;
    for(ll cs=1;cs<=q;cs++)
    {
        ll l,r;cin>>l>>r;
        cout<<sum[r]-sum[l-1]<<endl;
    }
}


Measured memory_bytes: 1536
#define _GLIBCXX_DEBUG
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>//"geometry.cpp"
#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include<functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include<cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

int w[100000];
long long x[100000],c[100000];

int main(){
	int n;
	long long l,t;
	cin>>n>>l>>t;
	for(int i=0;i<n;++i){
		cin>>x[i]>>w[i];
		c[i]=(x[i]+(3-2*w[i])*(t%l)+l)%l;
	}
	sort(c,c+n);
	long long d=0;
	for(int i=1;i<n;++i){
		if(w[0]!=w[i]){
			++d;
		}
	}
	d*=((2*t)/l);
	d%=n;
	if(w[0]==1){
		for(int i=1;x[i]<x[0]+((2*t)%l)&&i<n;++i){
			if(w[i]!=w[0]){
				++d;
			}
		}
	}else{
		for(int i=n-1;x[i]>x[0]+l-((2*t)%l);--i){
			if(w[i]!=w[0]){
				++d;
			}
		}
	}
	d%=n;
	d=(n+(3-2*w[0])*d)%n;
	long long c0=(x[0]+(3-2*w[0])*(t%l)+l)%l;
	int j0;
	if(w[0]==1){
		j0=lower_bound(c,c+n,c0)-c;
	}else{
		j0=upper_bound(c,c+n,c0)-1-c;
	}
	for(int i=0;i<n;++i){
		cout<<c[(j0-d+i+n)%n]<<endl;	
	}
}

Measured memory_bytes: 3200