akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;

ll x, y, cnt;

int main() {
  cin >>x >>y;
  while(x * 2 <= y) {
    x *= 2;
    cnt ++;
  } cout <<cnt + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;

    return 0;
}

Measured memory_bytes: 256
def collatz(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1
    
s = int(input())
a = [s]
pre= s
m = 2

while True:
    next = collatz(pre)
    if next not in a:
        m += 1
        a.append(next)
        pre = next
    else:
        break

print(m)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n;
    cin >> n;
    out(3 * n * n);
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
inline ll exponentiation(ll base, ll exp)
{
	ll t = 1;
	while (exp > 0)
	{

		
		if (exp % 2 != 0)
			t = (t * base) % N;

		base = (base * base) % N;
		exp /= 2;
	}
	return t % N;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0),cin.tie(0);
	ll n;
	cin >> n;
	set<ll> arr;
	f(i, 0, n)
	{
		ll temp;
		cin >> temp;
		arr.insert(temp);
	}
	if (arr.size() == n)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
 
int main(){
    int i,x;
    i = 1;
    while(true){
        cin >> x;
        if(x == 0) break;
        cout << "Case " << i << ": " << x << endl;
        i += 1;
    }
 
    return 0;
}


Measured memory_bytes: 3116
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

kisu = A[0::2]
gusu = A[1::2]

CK = Counter(kisu)
CG = Counter(gusu)
CKM = CK.most_common(2)
CGM = CG.most_common(2)

if len(CKM) == 1 and len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2
    else:
        ans = 0
elif len(CKM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CGM[1][1]
    else:
        ans = n // 2 - CGM[0][1]
elif len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CKM[1][1]
    else:
        ans = n // 2 - CKM[0][1]
else:
    if CKM[0][0] == CGM[0][0]:
        ans1 = n // 2 - CKM[1][1] + n // 2 - CGM[0][1]
        ans2 = n // 2 - CGM[1][1] + n // 2 - CKM[0][1]
        ans = min(ans1, ans2)
    else:
        ans = n - (CKM[0][1] + CGM[0][1])

print(ans)


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

int main() {
  int a,b,c,d,e,f;
  string op;
  cin >> f ;
	a = f/1000;
    b = (f%1000)/100;
  	c = (f%100)/10;
  	d = (f%10)/1;

  
  if (a==b){
  	if(b==c){
    cout<<"Yes"<<endl;
    }
    /*lse if(b==d){
    cout<<"Yes"<<endl;
    }*/
    else{
    cout<<"No"<<endl;
    }
  }
  else if(b==c){
  	if(c==d){
    cout<<"Yes"<<endl;
    }
    else{
    cout<<"No"<<endl;
    }
  }
  /*else if(a==c&&a==d){
  cout<<"Yes"<<endl;
  }*/
  else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int n;
ll dp[101][4][4][4],ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	dp[0][3][3][3]=1;
	for (int len=1;len<n+1;++len)
		for (int i=0;i<4;++i)
			for (int j=0;j<4;++j)
				for (int k=0;k<4;++k)
					for (int l=0;l<4;++l)
					{
						if (j==0 && k==2 && l==1) continue;
						if (j==2 && k==0 && l==1) continue;
						if (j==0 && k==1 && l==2) continue;
						if (i==0 && k==2 && l==1) continue;
						if (i==0 && j==2 && l==1) continue;
						dp[len][j][k][l]+=dp[len-1][i][j][k];
						dp[len][j][k][l]%=MOD;
					}
	for (int i=0;i<4;++i)
		for (int j=0;j<4;++j)
			for (int k=0;k<4;++k)
				ans+=dp[n][i][j][k],ans%=MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


typedef struct _state{
  int from,vis;
  double cost;
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];

main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    int ti[n];
    rep(i,n)cin>>ti[i];

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<state> Q;
    state st;
    st.cost=0;
    st.vis=0;
    st.from=a;
    Q.push(st);

    double cost[1<<n][m];
    rep(i,1<<n)rep(j,m)cost[i][j]=1<<26;
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(cost[cti][from]<=ccost)continue;
      cost[cti][from]=ccost;
      if(from==b){
	ans=ccost;
	break;
      }

      rep(i,n){
	if(cti>>i&1)continue;
	rep(j,V[from].size()){
	  int to=V[from][j].first;
	  int cc=V[from][j].second;
	  double ncost=ccost+1.0*cc/ti[i];
	  st.from=to;
	  st.vis=cti|1<<i;
	  st.cost=ncost;
	  Q.push(st);
	}
      }
    }
    if(ans<0)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}

Measured memory_bytes: 8200
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll n; cin >> n;
    ll ans = 0;
    rep(i, 1, n) ans += i;
    cout << ans << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	if(m == 0){
    		System.out.println("0" + " " + "0");
    		System.exit(0);
    	}
    	int[] iAry = new int[m];
    	String[] sAry = new String[m];
     	int[] ans = new int[2];
    	for(int i = 0; i < m; i++){
    		iAry[i] = sc.nextInt();
    		sAry[i] = sc.nextLine().trim();
    	}
    	sc.close();
    	int[] wrong = new int[n];
    	boolean[] isCorrect = new boolean[n];
    	for(int i = 0; i < m; i++){
    		int p = iAry[i]-1;
    		if(isCorrect[p]) continue;
    			if(sAry[i].equals("AC")){
    				ans[0]++;
    				isCorrect[p] = true;
    				ans[1] += wrong[p];
    			}else{
    				wrong[p]++;
    			}
    	}
    	System.out.println(ans[0] + " " + ans[1]);
    }
}

Measured memory_bytes: 159556
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1000000001;

int main(){
	int n,q; scanf("%d%d",&n,&q);
	int x[5000],y[5000];
	rep(i,n) scanf("%d%d",x+i,y+i);

	vector<int> X(x,x+n),Y(y,y+n);
	X.push_back(-INF); sort(X.begin(),X.end()); X.erase(unique(X.begin(),X.end()),X.end());
	Y.push_back(-INF); sort(Y.begin(),Y.end()); Y.erase(unique(Y.begin(),Y.end()),Y.end());

	static int dp[5001][5001];
	rep(i,n){
		dp[lower_bound(Y.begin(),Y.end(),y[i])-Y.begin()][lower_bound(X.begin(),X.end(),x[i])-X.begin()]++;
	}
	rep(i,5000) rep(j,5000) dp[i+1][j+1]+=dp[i+1][j]+dp[i][j+1]-dp[i][j];

	while(q--){
		int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		x1=lower_bound(X.begin(),X.end(),x1)-X.begin();
		y1=lower_bound(Y.begin(),Y.end(),y1)-Y.begin();
		x2=upper_bound(X.begin(),X.end(),x2)-X.begin()-1;
		y2=upper_bound(Y.begin(),Y.end(),y2)-Y.begin()-1;
		printf("%d\n",dp[y2][x2]-dp[y2][x1-1]-dp[y1-1][x2]+dp[y1-1][x1-1]);
	}

	return 0;
}

Measured memory_bytes: 98856
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a + W < b) {
			System.out.println(b - (a + W));
		} else if(a > b + W) {
			System.out.println(a - (b + W));
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 21972
package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	fmt.Println(3 * (n - gcd(n, x)))
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, k[111];
char a[111][22];
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%s", a[i]);
		k[i] = strlen(a[i]);
		for(int j = 1; j < i; j++){
			if(k[j] != k[i]) continue;
			for(int q = 0; q < k[j]; q++){
				if(a[i][q] != a[j][q]) break;
				if(q == k[j] - 1) return !puts("No");
			}
		}
		if(i > 1 && a[i][0] != a[i - 1][k[i - 1] - 1]) return !puts("No");
	}
	puts("Yes");
	return 0;
}

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

int main()
{
	int cnt[26] = { 0 };

	while (true) {
		char c;
		cin >> c;

		if (cin.eof())
			break;

		if (islower(c)) {
				//ASCIIコード
			cnt[c - 'a']++;
		}
		else if (isupper(c)) {
			cnt[c - 'A']++;
		}
	}

	for (int i = 0; i < 26; i++) {
		cout << (char)(i + 'a') << " : " << cnt[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
from math import ceil
K, A, B = map(int, input().split())
b = 1

if B - A > 2:
    b += min(A - 1, K)
    K -= min(A - 1, K)
    if K == 0:
        print(b)
        exit()
    n = K // 2
    b += n * (B - A)
    b += K % 2
    print(b)
else:
    b += K
    print(b)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    int ans;
    if( (x / d) > k )
        ans = x - k * d;
    else
    {
        int y = x % d;
        k -= (x - y) / d;
        k %= 2;
        if(k & 1)   ans = d - y;
        else        ans = y;
    }
    cout << ans;
}

Measured memory_bytes: 3588
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

#define GOZEN 200
#define GOGO 300

int main(){
	string className;
	int gozenIn = 0, gogoIn = 0;

	while (cin >> className >> gozenIn >> gogoIn){
		cout << className << " " << (gozenIn + gogoIn) << " " << (gozenIn*GOZEN + gogoIn*GOGO) << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
n = int(input())
hB = set()
tA = set()
cAB = 0
for i in range(n):
    s = input()
    cAB += s.count('AB')
    if s[0] == 'B': hB.add(i)
    if s[-1] == 'A': tA.add(i)
if len(hB&tA)>0:
    if len(hB)-len(hB&tA)>0 or len(tA)-len(hB&tA)>0:
        print(cAB+min(len(hB),len(tA)))
    else:
        print(cAB+min(len(hB),len(tA))-1)
else:
    print(cAB+min(len(hB),len(tA)))

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

int main() {
  
  string s;
  cin >> s;
  
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    if(s.at(i) == '1')
      ans++;
  }
  
  cout << ans << endl;
  
}

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

using namespace std;
int main()
{
    int i,n,haga,sum=0,m,c=0;
    cin>>n>>m;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    haga=ceil(sum/(4.0*(double)m));
    for(i=0;i<n;i++)
    {
        if(arr[i]>=haga)
            c++;
    }
    if(c>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

   return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll mod=1e+9+7;
int main(void){
    int n;cin>>n;
    map<pair<ll,ll>,int> mp;
    int zero=0;
    rep(i,n){
        ll a,b;cin>>a>>b;
        if(a==0&&b==0){
            zero++;
            continue;
        }
        ll g=gcd(a,b);//片方が0だともう片方の絶対値が出てくる
        a/=g;b/=g;
        /*if(b<0||(b==0&&a<0)){
            b*=-1;a*=-1;//第3象限と第4象限の座標をそれぞれ第1象限と第2象限にまとめる
        }*/
        mp[{a,b}]++;
    }
    vector<ll> s(2*n+1,1);
    rep(i,n*2){
        s[i+1]=s[i]*2;
        s[i+1]%=mod;
    }
    ll res=1;
    for(auto& p:mp){
        ll a=p.first.first,b=p.first.second;
        int x=p.second,y=mp[{-a,-b}],z=mp[{-b,a}],t=mp[{b,-a}];
        if(x==-1||y==-1||z==-1||t==-1)continue;//すでに見られている
        ll tmp=1;
        tmp+=s[x+y]-1;tmp%=mod;
        tmp+=s[z+t]-1;tmp%=mod;
        res*=tmp;res%=mod;
        mp[{-b,a}]=-1;mp[{-a,-b}]=-1;mp[{a,b}]=-1;mp[{b,-a}]=-1;
        //cout<<a<<" "<<b<<" "<<x<<" "<<t<<" "<<res<<endl;
    }
    res+=zero;
    res=(res+mod-1)%mod;
    cout<<res<<endl;
}

Measured memory_bytes: 56232
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int W, H;
  while (cin >> W >> H, W) {
    vs v(H);
    rep(i, H) cin >> v[i];
    vvi dp(H, vi(W));
    int b = 0, w = 0;
    rep(i, H) rep(j, W) {
      dp[i][j] = 2 * (v[i][j] == 'B') + (v[i][j] == 'W');
      b -= v[i][j] == 'B';
      w -= v[i][j] == 'W';
    }
    rep(_, W * H) rep(i, H) rep(j, W) {
      if (v[i][j] != '.') continue;
      if (i > 0) dp[i][j] |= dp[i - 1][j];
      if (j > 0) dp[i][j] |= dp[i][j - 1];
      if (i < H - 1) dp[i][j] |= dp[i + 1][j];
      if (j < W - 1) dp[i][j] |= dp[i][j + 1];
    }
    rep(i, H) rep(j, W) {
      b += dp[i][j] == 2;
      w += dp[i][j] == 1;
    }
    cout << b << ' ' << w << endl;
  }
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct info {int value, home; };
bool operator < (info a, info b) {return a.value < b.value; }
int r, c, n, tn, home[MAXN], pr[MAXN * 2];
info a[MAXN * 2];
int check(int x, int y) {
	if (x != 0 && x != r && y != 0 && y != c) return 0;
	if (x == 0) return r * 2 + c * 2 - y;
	if (x == r) return r + y;
	if (y == 0) return x;
	return 2 * r + c - x;
}
bool valid(int l, int r) {
	if (l > r) return true;
	int tmp = pr[l];
	if (tmp > r || tmp < l) return false;
	else return valid(l + 1, tmp - 1) && valid(tmp + 1, r);
}
int main() {
	read(r), read(c), read(tn);
	for (int i = 1; i <= tn; i++) {
		int x, y, tmp, tnp;
		read(x), read(y);
		tmp = check(x, y);
		read(x), read(y);
		tnp = check(x, y);
		if (tmp == 0 || tnp == 0) continue;
		n++;
		a[n * 2] = (info) {tmp, n};
		a[n * 2 - 1] = (info) {tnp, n};
	}
	if (n == 0) {
		printf("YES\n");
		return 0;
	}
	sort(a + 1, a + 2 * n + 1);
	for (int i = 1; i <= 2 * n; i++)
		if (home[a[i].home] == 0) home[a[i].home] = i;
		else {
			pr[i] = home[a[i].home];
			pr[home[a[i].home]] = i;
		}
	if (valid(1, 2 * n)) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    long long int A[100][100];
    long long int B[100][100];
    long long int C[100][100] = {0};
    int n, m, l;
    cin >> n >> m >> l;

    for(int row=0;row<n;row++){
        for(int col=0;col<m;col++){
            cin >> A[row][col];
        }
    }

    for(int row=0;row<m;row++){
        for(int col=0;col<l;col++){
            cin >> B[row][col];
        }
    }

    for(int row=0;row<n;row++){
        for(int col=0;col<l;col++){
            for(int k=0;k<m;k++){
                C[row][col] += A[row][k]*B[k][col];
            }
        }
    }

    for(int row=0;row<n;row++){
        for(int col=0;col<l;col++){
            if(col == l-1) {
                cout << C[row][col] << endl;
            } else cout << C[row][col] << " ";
        }
    }
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	string s;
	cin >> s;
	if(s.back() == '3'){
		cout << "bon";
	}
	else if(s.back() <= '1' || s.back() == '6' || s.back() == '8')
		cout << "pon";
	else
		cout << "hon";

	return 0;
}



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

int main() {
  string s;
  cin >> s;
  set<char> st;
  for (int i = 0; i < s.size(); i++) {
    st.insert(s.at(i));
  }
  for (int i = 0; i < 26; i++) {
    if (!st.count(i + 'a')) {
      char c = i + 'a';
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 3744
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p,int r) {
	int x, i, j, t;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

int main() {
	int i, q;

	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &A[i]);

	q = partition(0, n - 1);

	for (i = 0; i < n; i++) {
		if (i)printf(" ");
		if (i == q)printf("[");
		printf("%d", A[i]);
		if (i == q)printf("]");
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n[4];
  vector<int> v;
  for(int i = 0; i < 3; i++) scanf("%d", &n[i]);
  for(int i = 0; i < 3 - 1; i++){
    for(int j = i + 1; j < 3; j++) v.push_back(abs(n[i] - n[j]));
  }
  sort(v.begin(), v.end());
  cout << v[0] + v[1] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    long answer = 0;
    String[] input = sc.nextLine().split(" ");
    int[] nodeCount = new int[n + 1];
    long[] maxNodeCount = new long[n + 1];
    long[] minNodeCount = new long[n + 1];
    for(int i = 0; i <= n; i++){
      nodeCount[i] = Integer.parseInt(input[i]);
    }
    int idx = n;
    maxNodeCount[idx] = nodeCount[idx];
    minNodeCount[idx] = nodeCount[idx];
    idx--;
    while(idx >= 0){
      maxNodeCount[idx] = maxNodeCount[idx + 1] + nodeCount[idx];
      idx--;
    }
    minNodeCount[0] = 1;
    for (int i = 1; i <= n; i++){
      minNodeCount[i] = Math.min((minNodeCount[i -1] - nodeCount[i - 1]) * 2, maxNodeCount[i]);
      if(minNodeCount[i] < nodeCount[i]){
        System.out.print(-1);
        return;
      }
    }
    if(minNodeCount[n] != nodeCount[n]){
      System.out.print(-1);
      return;
    }
    for(long cnt : minNodeCount){
      answer += cnt;
    }
    System.out.print(answer);
  }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

vector<pair<pii, int> > ans;

void solve(){
	int l;
	int n = 20;
	cin >> l;
	for(int i = n - 1; i >= 1; i--) {
		if (l == 1) {
			ans.pb(mp(mp(i, i + 1), 0));
			continue;
		} else if (l % 2 == 0) {
			ans.pb(mp(mp(i, i + 1), 0));
			ans.pb(mp(mp(i, i + 1), l / 2));
		} else {
			ans.pb(mp(mp(i, i + 1), 0));
			ans.pb(mp(mp(i, i + 1), l / 2));
			ans.pb(mp(mp(1, i + 1), l - 1));
		}
		l /= 2;
	}
	printf("%d %d\n", n, SZ(ans));
	REP(i, 0, SZ(ans)) {
		printf("%d %d %d\n", ans[i]._1._1, ans[i]._1._2, ans[i]._2);
	}
	
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

char f[10][21];
int n, w[10], s[10], a[10], b[10];
bool u[10];
double maxg;

void dfs(int x, int tw, int m, double g) {
  if (m == n) {
    if (maxg < g) {
      maxg = g;
      for (int i=0; i<n; i++) {
        b[i] = a[i];
      }
    }
    return;
  }
  if (x>=n) {
    return;
  }
  if (!u[x] && tw <= s[x]) {
    u[x] = true;
    tw += w[x];
    a[m] = x;
    dfs(0, tw, m+1, g + w[x]*(m+1));
    tw -= w[x];
    u[x] = false;
  }
  dfs(x+1, tw, m, g);
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      scanf("%s %d %d", f[i], &w[i], &s[i]);
    }
    for (int i=0; i<n; i++) {
      u[i] = false;
    }
    maxg = -DBL_MAX;
    dfs(0, 0, 0, 0.);
    for (int i=n-1; i>=0; i--) {
      printf("%s\n", f[b[i]]);
    }
  }
  return 0;
}

Measured memory_bytes: 1012
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        String output = "No";
        if(N%2 == 0){
            String first = S.substring(0,N/2);
            String second = S.substring(N/2);
            if(first.equals(second)){
                output = "Yes";
            }
        }
        System.out.println(output);
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
    
        if(a == b && b == c){System.out.println(1);}
		else if(a != b && a != c && b != c){System.out.println(3);}
		else{System.out.println(2);}
	}
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n) - 1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9)+1;
const LL LLINF = LL(1e18)+1;
long double eps = 1.0E-14;

void solve()
{
    string S, T; cin >> S >> T;
    std::cout << T<<S << endl;

}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

int main() {
	// your code goes here
	int a,b,c,d;
	int arr[101];
	cin>>a>>b>>c>>d;
	memset(arr,0,sizeof(arr));
	for(int i=a+1;i<=b;i++)
	arr[i]++;
	for(int i=c+1;i<=d;i++)
	arr[i]++;
	int count=0;
	for(int i=0;i<101;i++)
	if(arr[i]==2)
	count++;
	cout<<count;
	return 0;
}


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

int main(){
  int X,maxn = 1;

  cin >> X;
  
  int cnt;
  for(int i=2;pow(i,2)<=X;++i){
    cnt = 3;
    while(true){
      if(pow(i,cnt) > X){
	if(maxn < pow(i,cnt - 1)){
	  maxn = pow(i,cnt - 1);
	}
        
	break;
      }
      ++cnt;
    }
  }

  cout << maxn << endl;
  return 0;
}


Measured memory_bytes: 256
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=998244353;         
const int N=3e3+4;

//dp[i][j] tells the no. of subset formed considering the first i eleements 
//so that their sum is j.

int dp[N][N];

int main()
{
	int n,s;

	scn(n); scn(s);

	//dp[0][0]=1;

	int ans=0;

	for(int i=1;i<=n;i++)
	{
		int val; scn(val);

		for(int j=0;j<=s;j++)
		{
			dp[i][j]=dp[i-1][j];

			if(j-val>=0)
			{
				dp[i][j]+=dp[i-1][j-val];

				if(dp[i][j]>=mod)
				dp[i][j]-=mod;
			}
		}

		dp[i][val]+=i;

		ans=(ans+dp[i][s])%mod;
	}

	pri(ans);

    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
	int N,M;
	int pi,ti;
	vector<int> fp;
	vector<vector<int>> ordt;
	vector<map<int,int>> ordp;
	vector<int> t;
	cin >> N >> M;

	for (int i=0; i<N; i++) {
		vector<int> tmp(0);
		ordt.push_back(tmp);
	}
	for (int i=0; i<M; i++) {
		cin >> pi >> ti;
		fp.push_back(pi);
		ordt[pi-1].push_back(ti);
		t.push_back(ti);
	}

	for (auto itr=ordt.begin(); itr!=ordt.end(); ++itr) {
		sort(itr->begin(), itr->end());
		map<int,int> tmp;
		for (auto jtr=itr->begin(); jtr!=itr->end(); ++jtr) {
			tmp[*jtr] = jtr-(itr->begin())+1;
		}
		ordp.push_back(tmp);
	}

	for (int i=0; i<M; i++) {
		cout << setfill('0') << right << setw(6) << fp[i];
		cout << setfill('0') << right << setw(6) << ordp[fp[i]-1][t[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 19180
import numpy as np

MOD = 1000000007


class Combination:
    def __init__(self, n):
        self.n = n
        self.fac, self.facinv = self.make_fact(n, MOD)

    def cumprod(self, arr,MOD):
        L = len(arr); Lsq = int(L**.5+1)
        arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
        for n in range(1,Lsq):
            arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
        for n in range(1,Lsq):
            arr[n] *= arr[n-1,-1]; arr[n] %= MOD
        return arr.ravel()[:L]
    
    def make_fact(self, U,MOD):
        x = np.arange(U,dtype=np.int64); x[0] = 1
        fact = self.cumprod(x,MOD)
        x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
        fact_inv = self.cumprod(x,MOD)[::-1]
        return fact,fact_inv


    def nck(self, n, k):
        if k == 0 or n == k:
            return 1
        return self.fac[n] * self.facinv[k] % MOD * self.facinv[n-k] % MOD;

    def get(n):
        return self.fac[n]
    
    def getinv(n):
        return self.facinv[n]

if __name__ == "__main__":
    X,Y = map(int, input().split())
    cb = Combination(1000010)
    if (X+Y) % 3 != 0:
        print(0)
        exit(0)
    if X > Y:
        if X > 2*Y:
            print(0)
            exit(0)
    else:
        if Y > 2*X:
            print(0)
            exit(0)
    a = (2 * Y - X) // 3
    b = (2 * X - Y) // 3
    print(cb.nck(a+b, a))


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

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

    vector<long long> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end(), greater<long long>());
    
    vector<long long> list;
    long long ans = 0;
    list.push_back(a[0]);
    ans += a[0];
    list.push_back(a[1]);
    
    int cnt = 0, idx = 1;
    for (int i = 2; i < n; i++){
        ans += list[idx];
        list.push_back(a[i]);
        cnt += 1;

        if (cnt == 2){
            cnt = 0;
            idx += 1;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6892
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define gc getchar_unlocked
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define debug(x) cout << #x << "=" << x << endl
#define debug2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define setz(x) memset(x, 0, sizeof(x))
#define seto(x) memset(x, 1, sizeof(x))
#define PI 3.1415926535897932384626

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef vector<pii> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef set<int> si;

auto ONLINE = []() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
};

void solve() {
  /// write your code here
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1\n";
    return;
  }
  ll s = 7;
  ll cnt = 1;
  while(true) {
    if(s % k == 0) {
      break;
    }
    cnt++;
    s = (s % k) * 10 + 7;
  }
  cout << cnt << "\n";
}

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


Measured memory_bytes: 3592
#include<iostream>

using namespace std;

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

	int i;
	if(b-a+1 <= k*2){
		for(i=a; i<=b; i++)
			cout << i << endl;
	}

	else{
		for(i=a; i<a+k; i++)
			cout << i << endl;
		for(i=b-k+1; i<=b; i++)
			cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

bc = 0
wc = 0

bc_list = []
wc_list = []

S.each_char do |s|
  if s == '#'
    bc += 1
  else
    wc += 1
  end

  bc_list << bc
  wc_list << wc
end

ans = Float::INFINITY

(N + 1).times do |i|
  lwrb = if i == 0
           bc
         elsif i == N
           wc
         else
           bc_list[i - 1] + wc - wc_list[i - 1]
         end

  ans = lwrb if ans > lwrb
end

puts ans


Measured memory_bytes: 5444
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
const ll INF = 1e15;

typedef pair<ll,ll> P;
struct edge{
    int to,cost;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,n;
    cin >> v >> n;
    ll d[v];
    vector<vector<edge>> G(v);
    rep(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b,c});
    }
    rep(i,v) if(i+1<v) G[i+1].push_back({i,0});
    priority_queue<P,vector<P>,greater<P>> pq;
    rep(i,v) d[i]=INF;
    d[0]=0;
    pq.push(P(0,0));
    while(!pq.empty()){
        P p=pq.top();
        pq.pop();
        int c = p.second;
        if(d[c]<p.first) continue;
        rep(i,G[c].size()){
            edge e = G[c][i];
            if(d[e.to] > d[c]+e.cost){
                d[e.to] = (ll)(d[c] + e.cost);
                pq.push({d[e.to],e.to});
            }
        }
    }
    
    if(d[v-1]<INF) cout << d[v-1] << endl;
    else cout << -1 << endl;
}



Measured memory_bytes: 7932
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

long long a, b, x, ts;

long long pow5(long long x) {
    return x * x * x * x * x;
}

int main() {
    scanf("%lld", &x);
    a = -65, b = -65;
    ts = pow5(a) - pow5(b);
    while (ts != x) {
        if (ts > x) {
            ++b;
        } else {
            ++a;
        }
        ts = pow5(a) - pow5(b);
    }
    printf("%lld %lld\n", a, b);
    return 0;
}

Measured memory_bytes: 3824
// AOJ 2299:   Tiles are Colorful
// 2017.12.10

#include <stdio.h>
#include <string.h>

int m, n;
char map[501][503];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int rpos['Z'+1], cpos['Z'+1];
int sr[501], sc[501];

int calc()
{
	int r, c, i, r2, c2, a, ans = 0;
	for (r = 0; r < m; r++) for (c = 0; c < n; c++) 
		if ((sr[c] + sc[r]) && map[r][c] == '.' ) {
			memset(rpos, -1, sizeof(rpos));

		    for (i = 0; i < 4; i++) {
				r2 = r, c2 = c;
				while (1) {
					r2 += mv[i][0], c2 += mv[i][1];
					if (r2 < 0 || r2 >= m || c2 < 0 || c2 >= n) break;
					if (map[r2][c2] == '.') continue;

	                a = map[r2][c2];
					if (rpos[a] >= 0) {
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
						r2 = rpos[a], c2 = cpos[a];
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
	                    ans += 2;
					} else rpos[a] = r2, cpos[a] = c2;
					break;
				}
            }
        }

	return ans;
}

int main()
{
	int r, c, t, ans;
	char buf[10];

    fgets(buf, 10, stdin);
	sscanf(buf, "%d%d", &m, &n);
	for (r = 0; r < m; r++) {
		fgets(map[r], 503, stdin);
		for (c = 0; c < n; c++) {
			if (map[r][c] != '.') sr[c]++, sc[r]++;
		}
	}
	ans = 0; while (t = calc()) ans += t;
	printf("%d\n", ans);
	return 0;
}

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

int main(void) {
	int C1, C2, i, j, len;
	char S[100010];
	scanf("%s", &S);
	len = strlen(S);

	C1 = 0;
	j = len - 1;
	for (i=len-2;i>=0;i--) {
		if (S[i] != S[j]) {
			C1++;
			j = i;
		}
	}

	C2 = 0;
	j = 0;
	for (i=1;i<len;i++) {
		if (S[i] != S[j]) {
			C2++;
			j = i;
		}
	}
	printf("%d\n", (C1>C2)?C2:C1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 n,m;
    int64 ans = 0;
    cin >> n >> m;
    ans += min(n, m/2);
    m = max(0LL, m - ans * 2);
    ans += m / 4;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a*b);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{

    int N;
    cin >> N;
    if (N % 1000 == 0)cout << 0;
    
    else cout << 1000 - (N %1000);
    return 0;
}



Measured memory_bytes: 3620
def main():
    n = int(input())
    S = list(map(int, input().split()))
    
    q = int(input())
    T = list(map(int, input().split()))
    
    res = 0
    for i in T:
        if i in S:
            res += 1
    print(res)
    

if __name__ == '__main__':
    main()
    


Measured memory_bytes: 6544
from itertools import product

N, M = map(int, input().split())
lights = []
for _ in range(M):
    t = list(map(int, input().split()))
    lights.append(t[1:])
cond = list(map(int, input().split()))
ans = 0
for pat in product([True, False], repeat=N):
    flag = True
    for c, l in zip(cond, lights):
        if sum([pat[idx - 1] for idx in l]) % 2 != c:
            flag = False
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n, m;
	cin >> n >> m;
	int a[n];
	rep(i, n) cin >> a[i];

	for(int i = 1; i <= m; i++) {
		rep(j, n - 1) {
			if(a[j] % i > a[j + 1] % i) swap(a[j], a[j + 1]);
		}
	}

	rep(i, n) cout << a[i] << endl;
	return 0;
}



Measured memory_bytes: 3164
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
D = inp()
n = len(s)
#dp[i][j][k]: i上から桁目まででそれまでの和をDで割ったあまりがj,k=0:Nと一緒 k=1:Nより小さいことが確定
dp = [[[0 for i in range(2)] for j in range(D)] for k in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
    nd = int(s[i])
    for j in range(D):
        for k in range(2):
            for d in range(10):
                ni = i+1; nj = (j+d)%D; nk = k
                if k == 0:
                    if d > nd: continue
                    elif d < nd: nk = 1
                dp[ni][nj][nk] += dp[i][j][k] % mod
# pprint.pprint(dp)
print((sum(dp[n][0])-1)%mod)

Measured memory_bytes: 131276
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<long long >where;
int n, k, a, b;
long long solve(long long start , long long end){
    long long  r = upper_bound(where.begin(), where.end(), end)-where.begin();
    long long l = lower_bound(where.begin(), where.end(), start)-where.begin();
    
    long long  aveng = r - l;
   
    if(start == end){
        if(aveng)return 1 * aveng * b;
        return a;
    }
    
    
    long long ch1 ;
    if(aveng)
    ch1 = (end - start + 1) * aveng * b;
    else return  a;
   
    long long ch2 = solve(start, (end + start)/ 2) + (solve((end + start)/ 2 + 1, end));
    

    return min(ch1, ch2);
    
}
int main(void){
 int n;
 string s;
 cin >> n >> s;
 int w,r;
 int cnt = 0;
 for(int i = 0; i < s.length();i++)w += (s[i] == 'W'),r += (s[i] == 'R');
 
 for(int i = 0; i < r; i++){
     if(s[i] != 'R')cnt++;
 }
 cout << cnt;
 
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int func(int x){
  string y=to_string(x);
  vector<char> a(y.size());
  vector<char> b(y.size());
  for(int i=0;i<y.size();i++){
    a.at(i)=y.at(i);
    b.at(i)=y.at(i);
  }
  reverse(b.begin(),b.end());
  int c=0;
  for(int i=0;i<y.size();i++){
    if(a.at(i)!=b.at(i))
      c=1;
  }
  if(c==0)
    return 1;
  return 0;
  
}
int main(){
  int A,B,count=0;
  cin>>A>>B;
  for(int i=A;i<B+1;i++){
    if(func(i)==1)
      count++;
  }
  cout<<count<<endl;
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int calc(int N){
    int c = 0;
    while(N){
        c++;
        N /= 10;
    }
    return c;
}

signed main(){

    int N; cin >> N;
    int ans = 0;
    FOR(i, 1, N + 1) if(calc(i) % 2) ans++;
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y;
  cin >> x >> y;
  if(x < y) {
    if(y < 0) {
      cout << y-x << endl;
    } else if(y == 0) {
      cout << y-x << endl;
    } else if(x < 0) {
      cout << abs(abs(y)-abs(x))+1 << endl;
    } else if(x == 0) {
      cout << y-x << endl;
    } else {
      cout << y-x << endl;
    }
  } else {
    if(x < 0) {
      cout << abs(abs(y)-abs(x))+2 << endl;
    } else if(x == 0) {
      cout << abs(abs(y)-abs(x))+1 << endl;
    } else if(y < 0) {
      cout << abs(abs(y)-abs(x))+1 << endl;
    } else if(y == 0) {
      cout << abs(abs(y)-abs(x))+1 << endl;
    } else {
      cout << abs(abs(y)-abs(x))+2 << endl;
    }
  }
  return 0;
}


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

int main() {
	
	int a[100],n;
	cin>>n;
	
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	
	int sw = 0;
	bool flag = true;
	for(int i; flag; i++){
		flag = false;
		for(int j=n-1; j>i; j--){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
			        sw++;
				flag = true;
			}
		}
	}
	
	for(int i=0; i<n ; i++){
		if(i) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	
	return 0;
}

Measured memory_bytes: 1160