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

long long f(long long x){
  if(x < 0){
    x = x * (-1);
  }
  return x; 
}

int main(){
  long long n;
  cin >> n;
  long long k;
  cin >> k;

  long long c = n % k;

  long long ans;
  ans = min(c, (k - c));
  cout << ans << endl;


}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 200005
#define inf INT32_MAX
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,int> pr;
typedef pair<pair<int,int>, int> tup;

inline void solve()
{
	string s;
	cin >> s;
	int otv = 0;
	fore(i, 0, s.size() / 2)
	{
		if (s[i] != s[s.size() - i - 1])
			otv++;
	}
	cout << otv;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}




Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
proset=[0,0,0]
for i in range(n):
    if p[i]<=a:
        proset[0]+=1
    elif a<p[i]<=b:
        proset[1]+=1
    else:
        proset[2]+=1
print(min(proset))


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
//input
int main(void)
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int r = 0, w = 0;
    for (int i = 0; i < N; i++)
    {
        if (s[i] == 'R')
        {
            r++;
        }
        /*else
        {
            w++;
        }*/
    }
    int ans = 0;
    for (int i = 0; i < r; i++)
    {
        if (s[i] == 'W')
        {
            ans++;
        }
    }
    //ans = max(w, r);

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


Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
    int A, B, C; cin >> A >> B >> C;
    if(A==B && B==C) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool dp[5010][5010];
int long long n,k;
int long long a[5010];

bool nec(int i){
    ll kk=a[i];a[i]=0;
    rep(c,n+1){rep(cc,k+1){dp[c][cc]=false;}}
    dp[0][0]=true;
    
    for(ll j=0;j<n;j++){
        for(ll l=k-1;l>=0;l--){
            if(l-a[j]>=0&&dp[j][l-a[j]]==true){
                dp[j+1][l]=true;
            }else if(dp[j][l]==true){
                dp[j+1][l]=true;
            }
        }
    }
    bool flag=0;
    for(ll g=max(k-kk,0ll);g<k;g++){
        if(dp[n][g]==true){
            flag=1;
            break;
        }
    }
    a[i]=kk;
    bool ans=false;
    if(flag==1){ans=true;}
    
    return ans;//trueなら必要
}

int main(){

    cin>>n>>k;
    rep(i,n){cin>>a[i];}
    sort(a,a+n);
    ll ans=0;
    if(nec(0)){cout<<0<<endl;}
    else if(nec(n-1)==false){cout<<n<<endl;}
    else{
        int l=0;int r=n-1;
        while(r-l>1){
            int m=(l+r)/2;
            if(nec(m)){
                r=m;
            }else{
                l=m;
            }
        }
        cout<<l+1<<endl;
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 24704
n = int(input())
p = [int(x) for x in input().split()]
q = sorted(p)
dif = 0
for i in range(n):
    if p[i] != q[i]:
        dif += 1
if dif == 0 or dif == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main() {
    int n, d;
    cin >> n >> d;
    int ans, amari;
    ans = n / (d * 2 + 1);
    amari = n % (d * 2 + 1);
    if (amari == 0) {
        cout << ans;
    }
    else
    {
        cout << ans + 1;
    }

    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
d=[abs(a-b) for a,b in zip(l,l[1:])]
m=sum(d)
for i in range(n):
    print(m+abs(l[i]-l[i+2])-(d[i]+d[i+1]))


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

int main(){
	int n,check=0;

	cin >>n;
	int array[n+1][3];
	int calc[n][3];

	for(int i=0;i<3;i++)array[0][i]=0;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<3;j++){
			cin >>array[i][j];
			calc[i-1][j]=array[i][j]-array[i-1][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			if(calc[i][0]<calc[i][1]+calc[i][2])check=0;
			else if(calc[i][0]==calc[i][1]+calc[i][2])check=1;
			else if((calc[i][0]-(calc[i][1]+calc[i][2]))%2==0)check=1;
			if(check==0)break;
		}
		if(check==0)break;
	}
	if(check==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 2560
def calc(K,d,p):
    sum = 0
    if(K > d):
        sum = p * d
    else:
        sum = p * K
    
    return sum,d


def resolve():
    data = [int(i) for i in input().split()]
    sum = 0
    K = data[3]
    for i in range(3):
        add,count= calc(K,data[i],1 - i)
        sum += add
        K -= count
        if(K <= 0):
            break    
    print(sum)
resolve()

Measured memory_bytes: 9132
#include <stdio.h>
#include <string.h>

int main(void)
{
        int n;
        scanf("%d", &n);
        while (n--) {
                int a, b, c;
                scanf("%d%d%d", &a, &b, &c);
                if ((a*a + b*b == c*c) ||
                    (b*b + c*c == a*a) ||
                    (c*c + a*a == b*b))  
                        puts("YES");
                else
                        puts("NO");
        }

        return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=2e5+5;
const int mod=998244353;
ll f[N];
ll qpow(ll a,ll n){
	ll re=1;
	while(n>0){
		if(n&1){
			re*=a;
			re%=mod;
		}
		a*=a;
		a%=mod;
		n>>=1;
	}
	return re;
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	f[0]=1;
	for(ll i=1;i<=n;i++){
		f[i]=1ll*f[i-1]*i;
		f[i]%=mod;
	}
	ll ans=0;
	for(int i=0;i<=k;i++){
		ans+=1ll*m*qpow(m-1,n-1-i)%mod*f[n-1]%mod*qpow(f[i],mod-2)%mod*qpow(f[n-1-i],mod-2)%mod;
		ans%=mod;
//		de(ans);
	}
	printf("%lld",ans);
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,M,Q;
  cin>>N>>M>>Q;
  Vec<V> sum = Vec<V>(N+1,V(N+1,0));
  rep(i,M){
    int l,r;
    cin>>l>>r;
    sum[l][r]++;
  }
  for(int i=1;i<=N;++i)
    for(int j=1;j<=N;++j)
      sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];

  while(Q--){
    int res,l,r;
    cin>>l>>r;
    res=sum[r][r]-sum[r][l-1]-sum[l-1][r]+sum[l-1][l-1];
    out(res);
  }
  
  return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int n;
int h[200005],a[200005];
int dp[200005];
int tree[4*200005];

void updatee(int s,int e,int idx,int SE,int val){
    if(s>SE || e<SE)return;
    if(s==e){
        tree[idx]=val;
        return;
    }
    int mid=(s+e)/2;
    updatee(s,mid,idx*2+1,SE,val);
    updatee(mid+1,e,idx*2+2,SE,val);
    tree[idx]=max(tree[idx*2+1],tree[idx*2+2]);
}

int gett(int s,int e,int idx,int S,int E){
    if(s>E || e<S)return 0;
    if(s>=S && e<=E)return tree[idx];
    int mid=(s+e)/2;
    return max(gett(s,mid,idx*2+1,S,E),gett(mid+1,e,idx*2+2,S,E));
}

signed main(){
    FASTER;
    cin>>n;
    int mxH=0;
    for(int i=0;i<n;i++)cin>>h[i],mxH=max(mxH,h[i]);
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        dp[h[i]]=gett(0,mxH-1,0,0,h[i]-1)+a[i];
        updatee(0,mxH-1,0,h[i],dp[h[i]]);
        ans=max(ans,dp[h[i]]);
    }
    cout<<ans;
    
}


Measured memory_bytes: 12396
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
}



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

using namespace std;

typedef long long ll;

int main() {
    ll a, b;
    cin >> a >> b;
    if (a > 0){
        cout << "Positive" << endl;
    }else if (a * b <= 0){
        cout << "Zero" << endl;
    }else if ((b - a + 1) % 2 == 0){
        cout << "Positive" << endl;
    }else{
        cout << "Negative" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		if (s.length < 6) {
			System.out.println("No");
			return;
		}
		if (s[2] == s[3] && s[4] == s[5]) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a); i<(b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()
#define rs resize
#define DBG(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

const ld PI = acos(-1.0);
template<class T> using min_queue =
priority_queue<T, vector<T>, greater<T>>;
template<class T> int sz(const T &x) {
    return (int) x.size(); // copy the ampersand(&)!
}

template<class T> ostream& operator<<(ostream &os, vector<T> &v) {
    os << "\n[";
    for(T &x : v) os << x << ',';
    return os << "]\n";
}

struct pairhash {
    public:
    template<typename T1, typename T2>
    size_t operator()(const pair<T1, T2> &p) const {
        size_t lhs = hash<T1>()(p.x);
        size_t rhs = hash<T2>()(p.y);
        return lhs ^ (rhs+0x9e3779b9+(lhs<<6)+(lhs>>2));
    }
};

void run() {
	ll H, W;
	cin >> H >> W;
	vector<vector<bool>> G(H, vector<bool>(W, false));
	for (ll i = 0; i < H; i++) {
		string line;
		cin >> line;
		for (ll j = 0; j < W; j++) {
			G[i][j] = line[j] == '#';
		}
	}
	vvi R(H, vi(W, 100000));
	R[0][0] = G[0][0];
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			if (i > 0) {
				if (G[i-1][j] || !G[i][j]) {
					R[i][j] = min(R[i][j], R[i-1][j]);
				} else {
					R[i][j] = min(R[i][j], R[i-1][j]+1);
				}
			}
			if (j > 0) {
				if (G[i][j-1] || !G[i][j]) {
					R[i][j] = min(R[i][j], R[i][j-1]);
				} else {
					R[i][j] = min(R[i][j], R[i][j-1]+1);
				}
			}
		}
	}
	cout << R[H-1][W-1] << endl;
}

signed main() {
    // DON'T MIX "scanf" and "cin"!
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);
    run();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll x,y;
    cin>>x>>y;
    ll cnt=0;
    while(y>=x){
        x=x*2;
        cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a = 10, b = 10, loop = 0;
  cin >> n;
  vector<int> v(n), p(n), q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    v[i] = i + 1;
  }
  for (int i = 0; i < n; i++) cin >> q[i];
  do {
    bool flag_p = true, flag_q = true;
    if(a == 10) {
      for(int i = 0; i < n; i++) {
        if(v[i] != p[i]) {
          flag_p = false;
          break;
        }
      }
      if(flag_p) a = loop;
    }
    if(b == 10) {
      for(int i = 0; i < n; i++) {
        if(v[i] != q[i]) {
          flag_q = false;
          break;
        }
      }
      if(flag_q) b = loop;
    }
    if(a != 10 && b != 10) break;
    loop++;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(a-b);
}

Measured memory_bytes: 3572
def comb(n, r, p):
    numer = 1
    denom = 1

    for i in range(n-r+1, n+1):
        numer = numer * i % p
    for i in range(1, r+1):
        denom = denom * i % p
    return numer * pow(denom, p-2, p)

def main():
    p = pow(10, 9) + 7
    n, a, b = map(int, input().split())
    print(((pow(2, n, p) - comb(n, a, p) - comb(n, b, p) - 1)) % p)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE=3000;
const int SIZE2=5010;
const int SIZE3=400;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string S;
ut N,M,K,X,L,W,H;
// ut A,B,C,D,E,F,G,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL x[2],vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
VI v[2];
bool DP[4000][2];
bool able(int now){

}
signed main(){
	string a,b;
	cin >> a>> b;
	sort(ALL(a));
	sort(ALL(b),greater<char>());
	if(a<b)
			cout << "Yes" << endl;
	else cout <<"No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);

    ll st = 20190430;
    ll in = y * 10000 + m * 100 + d;

    if (st < in) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

void DispArg(int elem[], int num)
{
    int i;

    printf("%d", elem[0]);
    for (i = 1; i < num; i++) {
        printf(" %d", elem[i]);
    }
    printf("\n");

    return;
}

int main(void)
{
    int i, j, k;
    int num;
    int tmp;
    int elem[100];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d", &elem[i]);
    }

    DispArg(elem, num);

    for (i = 1; i < num; i++) {
        for (j = i; j > 0; j--) {
            if (elem[j] < elem[j-1]) {
                tmp       = elem[j];
                elem[j]   = elem[j-1];
                elem[j-1] = tmp;
            }
            else {
                break;
            }
        }
        DispArg(elem, num);
    }

    return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;

#define INF 1e9

int dfs(int nowobject, int size, vector<vector<int> > &all_pairs, vector<bool> &used, int dist){
  if(dist >= INF){ return INF; }
  
  used[nowobject] = true;
  int mindist = INF;
  bool endflag = true;
  
  for(int i = 0; i < size; i++){
    if(!used[i]){
      endflag = false;
      int tmp = dfs(i, size, all_pairs, used, dist + all_pairs[nowobject][i]);
      if(mindist > tmp){ mindist = tmp; }
    }
  }
  
  if(endflag){ mindist = dist; }
  used[nowobject] = false;
  return mindist;
}


int main(void){
  while(true){
    int w, h;
    cin >> w >> h;
    if(w == 0 && h == 0){ break; }

    // ?????????????????±?????\???
    const int C = -1, F = -2;
    int robot;
    string s;
    vector<vector<int> > map(h, vector<int>(w));
    vector<pair<int, int> > object; 
    for(int i = 0; i < h; i++){
      cin >> s;
      for(int j = 0; j < w; j++){
        if(s[j] == '.'){ map[i][j] = C; }
        else if(s[j] == 'x'){ map[i][j] = F; }
        else{
          if(s[j] == 'o'){ robot = object.size(); }
          map[i][j] = object.size();
          object.push_back(make_pair(i, j));
        }
      }
    }

    // ???????????§???????????°??????bfs??????????????¨??????????±???????
    const int x[4] = {-1, 0, 1, 0};
    const int y[4] = {0, -1, 0, 1};
    vector<vector<int> > all_pairs(object.size(), vector<int>(object.size(), INF));
    for(int i = 0; i < object.size(); i++){ all_pairs[i][i] = 0; }
    for(int i = 0; i < object.size(); i++){
      vector<vector<bool> > used(h, vector<bool>(w, false));
      queue<pair<pair<int, int>, int> > q;
      used[object[i].first][object[i].second] = true;
      q.push(make_pair(object[i], 0));

      while(!q.empty()){
        pair<int, int> now = q.front().first;
        int dist = q.front().second + 1;
        q.pop();

        // ??????????????????
        for(int j = 0; j < 4; j++){
          pair<int, int> next = make_pair(now.first + x[j], now.second + y[j]);
          // ?????¢???????£???????????????????????????¶????????¶???????????£??????????????§?????¢?´¢???????????£?????´???????????????
          if(next.first < 0 || h <= next.first || next.second < 0 || w <= next.second
             || map[next.first][next.second] == F || used[next.first][next.second]){
            continue;
          }

          // ????????´???or?????????????????¶???????????£????????????????????§????????¢????¨????
          if(0 <= map[next.first][next.second]){ all_pairs[i][map[next.first][next.second]] = dist; }

          // ?????\????????????
          q.push(make_pair(next, dist));
          used[next.first][next.second] = true;
        }
      }
    }

    // 10!???????????????????????¨??¨??????
    vector<bool> used(object.size(), false);
    int result = dfs(robot, object.size(), all_pairs, used, 0);

    // ???????????????
    if(result == INF){ cout << -1 << endl; }
    else{ cout << result << endl; }
  }
  
  return 0;
}

Measured memory_bytes: 1240
N = int(input())
INF = float('inf')
d = [1000] * 26
a = ord('a')
for i in range(N):
    k = input()
    tmp = [0] * 26
    for j in k:
        tmp[ord(j) - a] += 1

    for j in range(26):
        d[j] = min(d[j], tmp[j])

t = ''
for i in range(26):
    t += chr(i + a) * d[i]

print(t)



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

int main(){
  string S; cin >> S;
  
  bool OK = true;
  for(int i = 0; i < S.size()-1; i++){
      if(S.at(i) == S.at(i+1)) OK = false;
  }
  if(OK) cout << "Good" << endl;
  else cout << "Bad" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);

void solve(){
    ll n,k,d;
    cin >> n >> k >> d;
    n = abs(n);
    ll temp = n-k*d;
    ll ans=0;
    if(n/d>=k){
        ans=n-d*k;
    }
    else {
        ll moves=n/d;
        moves=k-moves;
        if(moves%2==0){
            ans=n%d;
        }
        else {
            ans=abs(n%d-d);
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ll t=1;
    //cin >> t;
    while(t--) {
        solve();
     
    }

}


//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    for(int i = a; i < min(a + k,  b+1); ++i)cout << i << endl;
    for(int i = max(a+k, b-k+1); i <= b; ++i)cout << i << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int n, m;
int ck[100010],cnt[100010];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) cnt[i] = 1;
	ck[1] = 1;
	for (int i = 0, x, y; i < m; i++) {
		scanf("%d%d", &x, &y);
		ck[y] |= ck[x];
		cnt[y]++;
		cnt[x]--;
		if (cnt[x] == 0) ck[x] = 0;
	}
	int res = 0;
	for (int i = 1; i <= n; i++) res += ck[i];
	printf("%d", res);
	return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;
#define DOUBLE fixed<<setprecision(15)

const double pi = acos(-1.0);
typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    long double a,b,x;
    cin >> a >> b >> x;
    long double ans;
    if(a*a*b/2 <= x){
        //ans = atan(2*b/a - 2*x/(a*a*a));
        ans = atan(2 * (a * a * b - x) / (a * a * a));
        //cout << "000" << endl;
    }

    else {
        //ans = pi/2 - atan(2*x / (a*b*b));
        ans = atan(a*b*b / (2*x));
        //cout << "111" << endl;
    }
    //cout << DOUBLE << ans << endl;
    cout << DOUBLE << ans*180 / pi << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int main(){
	// int t;
	// while(){
		// int cnt=0, tmp=0;
		// while(1){
		// 	if(mp[tmp])
		// }
		scanf("%d",&n);
		ll tmp=0, ans=-1;
		for(int i=0; i<n+2; ++i){
			tmp*=10;
			tmp+=7;
			tmp%=n;
			if(tmp%n==0){
				ans=i+1;
				break;
			}
		}
		cout<<ans<<endl;
	// }
}

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

int main(){
	string s;
	cin >>s;
	if(s=="Sunny") s = "Cloudy";
	else if(s=="Cloudy") s = "Rainy";
	else s = "Sunny";
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

int main() {
  int h, a;
  cin >> h >> a;
  if (h % a == 0) {
    cout << h / a << endl;
  } else {
    cout << h / a + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n;
	int i ,j ,k ,t ;
	int namelen ,kanbanlen ;
	int cnt  = 0 ;
	char name[ 26 ] ,kanban[ 201 ] ;
	cin >> n ;
	cin >> name ;
	namelen=strlen(name);
	for( i = 0 ; i < n ; i++ )
	{
		cin >> kanban ;
		kanbanlen=strlen(kanban);
		for( j = 0 ; j < kanbanlen ; j++ )
		{
			for( k = 1 ; j + ( namelen - 1 ) * k < kanbanlen ; k++ )
			{
				for( t = 0 ; t < namelen ; t++ )
				{
					if( kanban[ j + t * k ] != name[ t ] )
					{
						goto one ;
					}
				}
				cnt++ ;
				goto two ;
				one : ;
			}
		}
		two : ;
	}
	cout << cnt << endl ;
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
    long long a,b,c,ans=0;
    cin>>a>>b>>c;
    if(b>=a){
        cout<<1<<endl;
        return 0;
    }
    if(c>=b){
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>0){
        ans++;
    }
    cout<<((a-b)/(b-c)+ans)*2+1<<endl;
}

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

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

    static class DNumberOfAmidakuji {
        final long mod = (long) (1e9 + 7);

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt(), w = in.nextInt(), K = in.nextInt();
            long dp[][] = new long[h + 10][w + 10];
            dp[0][0] = 1;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    for (int k = 0; k < 1 << (w - 1); ++k) {
                        boolean ok = true;
                        for (int l = 0; l < w - 2 && ok; ++l) {
                            if ((k >> l & 1) == 1 && (k >> (l + 1) & 1) == 1) ok = false;
                        }
                        if (ok) {
                            if ((k >> j & 1) == 1) {
                                dp[i + 1][j + 1] += dp[i][j];
                                dp[i + 1][j + 1] %= mod;
                            } else if (j > 0 && (k >> (j - 1) & 1) == 1) {
                                dp[i + 1][j - 1] += dp[i][j];
                                dp[i + 1][j - 1] %= mod;
                            } else {
                                dp[i + 1][j] += dp[i][j];
                                dp[i + 1][j] %= mod;
                            }
                        }
                    }
                }
            }
            out.println(dp[h][K - 1]);
        }

    }

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

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

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

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

    }
}



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

int H, W;

const int di[] = {1, -1, 0, 0};
const int dj[] = {0, 0, 1, -1};

int main(void){
	cin >> H >> W;
	vector<vector<char>> m(H+2, vector<char>(W+2));
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			cin >> m[i][j];
		}
	}
	bool ans = true;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if(m[i][j] == '#'){
				if(m[i-1][j] == '.' && m[i+1][j] == '.' && m[i][j-1] == '.' && m[i][j+1] == '.') ans = false;
			}
		}
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3588
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[]
for i in range(M):
  L.append(list(map(int,input().split())))
#print(L)
bad=[]
for i in range(M):
  ori=L[i][0]-1
  dest=L[i][1]-1
 # print(ori,dest)
  if H[ori] <= H[dest]:
    bad.append(ori)
  if H[ori] >= H[dest]:
    bad.append(dest)

deletes=set(bad)
print(N-len(deletes))
#print(ans)
#print(len(ans))

Measured memory_bytes: 37812
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  vector<bool> prime(60000,true);

  for(i=2;i<60000;i++)
    if(prime[i])
      for(j=2;i*j<60000;j++)
        prime[i*j]=false;

  vi ans(60000,0);

  for(i=2;i<60000;i++)
    if(prime[i])
      for(j=i;j<60000;j++)
        if(prime[j] && i+j<60000)
          ans[i+j]++;

  while(1){
    cin>>n;
    if(n==0)break;
    cout<<ans[n]<<endl;
  }
}

Measured memory_bytes: 3088
#include<stdio.h>
void get_f(int top[],int height);
void get_s(int top[],int height);
int main(void){
  int i,height[10];
  int top[3]={0,0,0};

  for(i=0;i<10;i++){
    scanf("%d",&height[i]);
  }

  for(i=0;i<10;i++){
    if(top[0]<height[i])
      get_f(top,height[i]);
    else if(top[1]<height[i])
      get_s(top,height[i]);
    else if(top[2]<height[i])
      top[2]=height[i];
  }

    for(i=0;i<3;i++)
      printf("%d\n",top[i]);

    return 0;
}
void get_f(int top[],int height){
  top[2]=top[1];
  top[1]=top[0];
  top[0]=height;
}
void get_s(int top[],int height){
  top[2]=top[1];
  top[1]=height;
}

Measured memory_bytes: 1816
#include<stdio.h>
int main(void)
{
	int x,ama;
	
	while(1) {
		if(scanf("%d",&x)==EOF){
			break;
		}
		ama=x%39;
		if(ama==0) {
			ama=39;
		}
		if(ama<10) {
				printf("3C0%d\n",ama);
		}
		else {
			printf("3C%d\n",ama);
		}
	}	
	return 0;
}

Measured memory_bytes: 1024
/*input
20000
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 30000
#define INF 0x3f3f3f3f


int N = 42 , n;
int32_t main(){
	IOS;
	cin >> n;
	vector<int> sol;
	int sum = 0;
	REP(i , 1 , MAX + 1){
		if(sol.size() == n - 1) break;
		else if(__gcd(i , N) != 1) sol.pb(i) , sum += i;
	}
	// cout << sol.back() << endl;
	// return 0;
	REP(i , 1 , MAX + 1){
		if(__gcd(i , N) != 1 && i <= sol.back()) continue;
		if((sum + i) % 2 == 0 && (sum + i) % 3 == 0 && (sum + i) % 7 == 0
			 /*&& (sum + i) % 5 == 0*/ && __gcd(sum , i) != 1){
			sol.pb(i);
			break;
		}
	}
	// while(sol.size() < n);
	for(auto to : sol) cout << to << " "; cout << endl;
    return 0;
}

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

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

long long knapsack(int *w, int *v, vector<vector<long long>> &dp, int i, int maxw){
    if(maxw <= 0)return 0;
    if( i < 0)return 0;
    
    if(dp[i][maxw] != -1)return dp[i][maxw];
    
    if(w[i] <= maxw){
        dp[i][maxw] = max(knapsack(w, v, dp, i - 1, maxw), knapsack(w, v, dp, i-1, maxw - w[i]) + v[i]);
    }else{
        dp[i][maxw] = knapsack(w, v, dp, i - 1, maxw);
    }
    return dp[i][maxw];
}

int main() {
    int n;
    cin>>n;
    int maxw;
    cin>>maxw;
    vector<long long> t(100001, -1);
    vector<vector<long long>> dp(101, t);
    int w[n];
    int v[n];
    for(int i = 0 ; i < n ; i++) {
        cin>>w[i]>>v[i];
    }
    cout<<knapsack(w, v, dp, n - 1, maxw);
	return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define loop(x) for(int i=0;i<x;i++)
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define dd fflush(stdout)
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mt make_tuple //use tie
#define eb emplace_back
typedef tuple<int,int,int> State;//use in dijkstra

// ll power(ll x,ll y,ll mod){
//  ll ans=1;
//  while(y>0){
//   if(y&1){
//     ans=ans*x;
//   }
//   x=x*x;
//   y=y/2;
//  }
//  return ans;
// }
ll a[100000+1];
ll n,k;
int solve(int start,int turn){
   if(start==k)
    return 1;
   else if(start>k)
    return 0;

  int ans=0;
   for(int i=0;i<n;i++){
    ans=(ans|solve(start+a[i],turn^1));
   }
   return ~ans;
}
int main(){
    IOS;   
   cin>>n>>k;
   loop(n)cin>>a[i];
   int dp[k+2][2];
    dp[0][0]=0;
    dp[0][1]=0;
   for(int i=1;i<=k;i++){
       dp[i][0]=0;
        dp[i][1]=0;
      for(int p=0;p<n;p++){
        if(i-a[p]>=0)
        {
        dp[i][0]=(dp[i][0]|(dp[i-a[p]][1]^1));
        dp[i][1]=(dp[i][1]|(dp[i-a[p]][0]^1));
        }
      }
   }
   if(dp[k][0]==1)
   cout<<"First"<<endl;
   else
   cout<<"Second"<<endl;
  
}
// https://atcoder.jp/contests/dp/tasks/dp_d
// https://codeforces.com/contest/1131/problem/C
 
//csjosh

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

    else if(b%3==0){
        cout<<"Possible"<<endl;
    }
    
    else if(((a+b)%3)==0){
        cout<<"Possible"<<endl;
    }
    else if(a+b<3){
        cout<<"Impossible"<<endl;
    }
    
    else  {
    cout<<"Impossible"<<endl;
    
    
    }
    }


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    if (2 * K > (N - 1) * (N - 2)) return !printf("-1\n");
    set<pii> ans;
    for (int i = 1; i <= N; i++)
        for (int j = i + 1; j <= N; j++) {
            ans.insert(make_pair(i, j));
        }
    int cnt = 0;
    for (int i = 1; i < N && cnt < K; i++) {
        for (int j = i + 1; j < N && cnt < K; j++) {
            ans.erase(make_pair(i, j));
            cnt++;
        }
    }
    printf("%d\n", (int)ans.size());
    for (auto i : ans)
        printf("%d %d\n", i.first, i.second);

    return 0;
}


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

int main(){
  
  string S;
  cin >>S;
  
  string m;
  m = S.substr(5,2);
  
  if(m=="01"||m=="02"||m=="03"||m=="04"){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, w;
    cin >> n >> w;
    int v = 1e5;
    vector<long long>dp(v + 1, INT_MAX);
    dp[0] = 0;
    int weight, value;
    for(int i = 0; i < n; i++){
        cin >> weight >> value;
        for(int j = v-value; j >= 0; j--){
            dp[j+value] = min(dp[j+value], dp[j] + weight );
        }
    }
    for(int i = v; i >= 0; i--){
        if(dp[i] <= w){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

struct request {
	int a;
	int b;
	int c;
};

int mycmp_b(const void *p, const void *q) {
	return ((request *)p)->b - ((request *)q)->b;
}

int mycmp_c(const void *p, const void *q) {
	return ((request *)p)->c - ((request *)q)->c;
}
	

int main(int argc, char *argv[])
{
	int i, j;
	int N;
	int M;
	int cut;
	int count = 0;
	int temp_flag = 0;

	cin >> N >> M;

	struct request req[M];
	char flags[N];

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

	for (i = 0; i < M; i++) {
		cin >> req[i].a >> req[i].b;
		req[i].c = req[i].b - req[i].a;
	}

	qsort(req, M, sizeof(struct request), mycmp_c);
	qsort(req, M, sizeof(struct request), mycmp_b);

	for (i = 0; i < M; i++) {
		temp_flag = 0;
		for (j = req[i].a - 1; j <= req[i].b - 2; j++) {
			if (flags[j] == 1) {
				temp_flag = 1;
				break;
			}
		}
		if (temp_flag == 1)
			continue;
		else {
			flags[req[i].b - 2] = 1;
			count++;
		}
	}

	cout << count << "\n";		
	
	return 0;
}


Measured memory_bytes: 2684
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Int](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = 1)
    })
    time.sum
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 58736
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
int main() {
  int N; cin >> N;
   
  int val[N];
  rep(i,N) {
    cin >> val[i];
  }
  
  int bene[N];
  
  rep(i,N){
    int a; cin >> a;
    bene[i] = val[i] - a;
  }
  int ans=0;
  rep(i,N) {
    if (bene[i] >0) ans += bene[i];
  }
  cout << ans << endl;
  return 0;
}

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;
using ll = long long;

void solve()
{
   string s,t; cin>>s>>t;
   ll ans=0;
   rep(i,s.size())
   {
    if(s[i]!=t[i]) ans++;
   }
   cout<<ans;
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
  //  cin>>t;
    while(t--)
        {solve();}
    return 0;
}

Measured memory_bytes: 3884
#include <iostream>
#include <string>
#include <cstdio>

int main()
{
	int datasets;
	scanf("%d\n", &datasets);
	
	for (int i=0; i<datasets; i++) {
		std::string str;
		getline(std::cin, str);
		//std::cout << str << std::endl;
		int offset = 0;
		while (true) {
			int pos = str.find("Hoshino", offset);
			if ( pos != std::string::npos ) {
				str.replace(pos, 7, "Hoshina");
				offset = pos + 7;
			} else {
				break;
			}
		}
		std::cout << str << std::endl;
	}
	
	return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  cin >> N;
 int fourflag=0;
  int j = 0;
  while (j < N) {
    string c;
    cin >> c;
    if(c == "Y"){
    fourflag++;
    }    
    j++;
  }
 if(fourflag ==0){
  cout << "Three" << endl; 
 }else{
 cout << "Four" << endl;
 }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int a,b;
	cin >> a >> b;
	int ans=0;
	if(b==1){
		cout << 0 << endl;
		return 0;

	}
	if(a==b){
		cout << 1 << endl;
		return 0;
	}
	FOR(i,100){
		if((a-1)*(ans-1)+a>=b){
			cout << ans << endl;
			return 0;
		}
		ans++;
	}
}

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


int main(){
	double x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3 = (y1-y2) + x2;
	int y3 = -(x1-x2) + y2;
	int x4 = -(y2-y1) + x1;
	int y4 = (x2-x1) + y1;
	cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
(defun count2div (n)
    (labels ((f (n i)
                (if (not (zerop (rem n 2))) i
                    (f (floor n 2) (1+ i)))))
        (f n 0)))

(defun main ()
    (let* ((n (read))
           (a-list (loop for i below n collect (read))))
        (format t "~A~%" (count2div (reduce #'gcd a-list)))))

(main)

Measured memory_bytes: 15840
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll N;
	cin>>N;
	ll t=1;
	while(t*(t+1)/2<N){
		t++;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256