akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+10,M=3e3;
ll n,cnt,ans;
ll a[N],b[N],prime[M],vis[M];
map <ll,ll> mp,vt;
void init(){
	for(ll i=2;i<=3000;i++){
		if(!vis[i]) prime[++cnt]=i;
		for(ll j=1;j<=cnt && i*prime[j]<=3000;j++){
			vis[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}
void solve(ll pos,ll x){
	ll u=1,v=1;
	for(ll i=1;i<=cnt && prime[i]<=x;i++){
		if(x%prime[i]==0){
			ll tot=0;
			while(x%prime[i]==0) tot++,x/=prime[i];
			tot%=3;
			if(tot==1) u*=prime[i],v*=prime[i]*prime[i];
			else if(tot==2) u*=prime[i]*prime[i],v*=prime[i];
		}
		if(x==1) break;
	}
	if(x>1){
		ll px=sqrt(x);
		if(px*px==x) u*=x,v*=px;
		else u*=x,v*=x*x;
	}
	a[pos]=u,b[pos]=v;
	mp[u]++;
}
int main(){
	init();
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) scanf("%lld",&a[i]),solve(i,a[i]);
	for(ll i=1;i<=n;i++){
		if(!vt[a[i]]){
			vt[a[i]]=1,vt[b[i]]=1;
			if(a[i]==b[i]) ans++;
			else ans+=max(mp[a[i]],mp[b[i]]);
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
 
using namespace std;
 
string e[16];
bool dp[5010][1<<12];
 
int main() {
  int n, m;
  while (cin >> n >> m, n) {
    REP(i,n) cin >> e[i];
    string str, in;
    REP(i,m) { cin >> in; str += in; }
    memset(dp, false, sizeof(dp));
    REP(i,5010) dp[i][0] = true;
    int res = 0;
    REP(i,str.size()) {
      REP(k,n) {
        int len = e[k].size();
        if (str.substr(i, len) != e[k]) continue;
        REP(j,1<<n) if (dp[i][j] && (~(j >> k) & 1))
          dp[i+len][j|(1<<k)] = true;
      }
      res += dp[i+1][(1<<n)-1];
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 23116
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    string rs(s);
    reverse(rs.begin(), rs.end());
    llint n = s.size();
    string suba = s.substr(0, n / 2),rsuba = s.substr(0, n / 2),subb=s.substr((n+1)/2,n/2),rsubb=s.substr((n+1)/2,n/2);
    reverse(rsuba.begin(), rsuba.end());
    reverse(rsubb.begin(), rsubb.end());
    if((s==rs) && (suba==rsuba) && (subb==rsubb)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int R;

int main() {
    cin >> R;

    string ans;
    if (R < 1200) {
        ans = "ABC";
    } else if (R < 2800) {
        ans = "ARC";
    } else {
        ans = "AGC";
    }

    cout << ans << endl;
}

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

int main()
{
    long long pow = 1;
    int N;
    cin >> N;
    for (int i = 0; i < N;i++){
        pow *= i+1;
        pow %= 1000000007;
    }
    cout << pow << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var arr=[];
for(var j=0;j<2;j++){
   var N=Arr[j].split(" ").map(Number);
   var n=N.shift();
   var i=0;
   while(n!=i){
      var h=N.shift();
      var m=N.shift();
      arr.push(h*60+m);
      i++;
   }
}
arr.sort(function(a,b){return a-b;});
var memo="";
var result=[];
arr.forEach(function(v){
   var h=Math.floor(v/60);
   var m=v%60;
   if(m<10)m="0"+m;
   if(v!==memo)result.push(h+":"+m);
   memo=v;
});
console.log(result.join(" "));

Measured memory_bytes: 8628
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			String strs[]=new String[a];
			for(int i=0;i<a;i++) {
				String str=scan.next();
				char ch[]=str.toCharArray();
				Arrays.sort(ch);
				strs[i]=String.valueOf(ch);
			}
			Arrays.sort(strs);
			long cnt=0;
			long hoge=1;
			for(int i=1;i<a;i++) {
				String str1=strs[i-1];
				String str2=strs[i];
				if(str1.equals(str2)) {
					hoge++;
				}
				else {
					cnt+=hoge*(hoge-1)/2;
					hoge=1;
				}
			}
			cnt+=hoge*(hoge-1)/2;
			System.out.println(cnt);
		}
}

Measured memory_bytes: 51288
n=int(input())
a=list(map(int,input().split()))

rem=-1
while True:
    a=sorted(a)
    if a[0]==rem:
        print(a[0])
        break
    rem=a[0]
    for i in range(1,n):
        a[i]%=rem
        if a[i]==0:
            a[i]+=rem

Measured memory_bytes: 87680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	while(1) {
		int N, M;
		int D[10010], P[10010];
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
		rep(i, N) scanf("%d %d", &D[i], &P[i]);

		vector<pair<int, int>> v;
		rep(i, N) v.pb(mp(P[i], D[i]));
		sort(all(v)); reverse(all(v));

		ll ans = 0;
		ll cnt = M;
		for(auto t : v) {
			int E = t.fi, dist = t.se;
			if(cnt - dist >= 0) cnt -= dist;
			else if(cnt > 0) {
				ll m = dist - cnt;
				cnt = 0;
				ans += m * E;
			}else {
				ll m = dist;
				ans += m * E;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
long long a,b,n;
long long s,e;
int main(){
    cin>>a>>b>>n;
    if(a%n==0){
    	s=a/n;
	}else{
		s=a/n+1;
	}
    e=b/n;
    cout<<e-s+1;
    return 0;
}

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

int main()
{
    int n, i, count=0;
    cin>>n;
    int arr[n];

    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }

    for(i=0; i<n-2; i++)
    {
        if(arr[i]<=arr[i+1] && arr[i+1]<=arr[i+2])
            count++;
        else if(arr[i]>=arr[i+1] && arr[i+1]>=arr[i+2])
            count++;
    }

    cout<<count;
}


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

vector<int>a,b,c,d;
int n,m,q;
int ans=0;
void dfs(vector<int>A)
{
if(A.size()==n+1)
{
int temp=0;
for(int i=0;i<q;i++)
{
    if(A[b[i]]-A[a[i]]==c[i])temp+=d[i];
}ans =max(ans,temp);return;

}
A.push_back(A.back());
while(A.back()<=m)
{
dfs(A);
A.back()++;

}

}

int main()
{

cin>>n>>m>>q;
a=b=c=d=vector<int>(q);
for(int i=0;i<q;i++)
cin>>a[i]>>b[i]>>c[i]>>d[i];

dfs(vector<int>(1,1));
cout <<ans;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	vector<ll> cnt(13, 0);
	cnt[0]++;
	ll N; cin >> N;
	REP(_, N)
	{
		ll a; cin >> a;
		cnt[a]++;
	}

	if (cnt[0] > 1)
	{
		std::cout << 0 << std::endl;
		return 0;
	}

	if (cnt[12] > 1)
	{
		std::cout << 0 << std::endl;
		return 0;
	}

	for (ll i = 1; i < 12; ++i)
	{
		if (cnt[i] > 2)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	
	ll res{0};
	REP(bits, 1ll<<11)
	{
		vector<ll> c{0};
		
		if (cnt[12] == 1)
			c.push_back(12);
		
		for (ll ti = 1; ti < 12; ++ti)
		{
			ll tmp = cnt[ti];

			if (tmp == 2)
			{
				c.push_back(ti);
				c.push_back(ti+abs(12-ti)*2);
			}
			else if (tmp == 1)
			{
				if (bits & (1ll << (ti-1)))
					c.push_back(ti);
				else
					c.push_back(ti+abs(12-ti)*2);
			}
		}

		ll tmp{INF};

		ll M = c.size();
		REP(i, M)REP(j, M)
		{
			if (i == j) continue;
			ll d = abs(c[i] - c[j]);
			tmp = min(tmp, min(d, 24-d));
		}

		res = max(res, tmp);
	}

	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = set()
e = set()
p = False
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        if b in e:
            p = True
            break
        s.add(b)
    if b == n:
        if a in s:
            p = True
            break
        e.add(a)

if p: print('POSSIBLE')
else: print('IMPOSSIBLE')


Measured memory_bytes: 18936
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
using namespace std;

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

int main() {
  string W;
  string T;
  cin >> W;
  int count = 0;
  while(true) {
    cin >> T;
    if(T == "END_OF_TEXT") break;
    bool f = true;
    if(T.size() != W.size()) f = false;
    else {
      for(int i = 0; i < W.size(); i++) {
        if(T[i] >= 'A' && T[i] <= 'Z') {
          if(T[i] - 'A' != W[i] - 'a') {
          f = false;
          break;
          }
        } else if(T[i] >= 'a' && T[i] <= 'z') {
          if(T[i] != W[i]) {
            f = false;
            break;
          }
        }
      }
    }
    if(f) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3164
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #define int long long
#define ll long long
#define endl '\n'
#define all(v) v.bg(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define boolv vector<bool>
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define ac accumulate
#define F first
#define bg begin
#define me max_element
#define S second
#define ub upper_bound
#define bs binary_search
#define lb lower_bound
#define ull unsigned long long

const ll mod = 1e9 + 7;
const int N = 1e3 + 4;
template <typename... T>
void read(T &... args)
{
    ((cin >> args), ...);
}

template <typename... T>
void write(T &&... args) //rvalue references
{
    ((cout << args), ...);
}

void vjudge()
{
#ifndef ONLINE_JUDGE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
const int MAX = 2e4 + 5;
const int INF = 1e9 + 5;
void solve(int test)
{
    string n;
    read(n);
    int sum = 0;
    for (int i = 0; i < n.size(); i++)
        sum += (n[i] - '0');
    (sum % 9 == 0) ? write("Yes\n") : write("No\n");
}

int32_t main()
{
    vjudge();
    int t = 1;
    // read(t);
    for (int i = 1; i <= t; i++)
        solve(i);
}


Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,sum=0;
    cin>>a>>b;
    for(int i=0;i<b;i++)
    {
        cin>>c;
        sum+=c;
    }
    if(sum>a)cout<<-1<<endl;
    else cout<<a-sum<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Aug  2 21:38:01 JST 2020
 **/

struct Mo {
    int width;
    struct Query {
        int l, r, idx;
        Query(int l_, int r_, int idx_) : l(l_), r(r_), idx(idx_) {}
    };
    std::vector<Query> query;
    std::vector<bool> v;

    Mo(int n) : width((int)sqrt(n)), v(n) {}
    void add(int l, int r) {
        int idx = query.size();
        query.emplace_back(l, r, idx);
    }
    template <class F, class G, class H> void run(const F& add, const G& del, const H& rem) {
        std::sort(query.begin(), query.end(), [&](const Query& a, const Query& b) {
            int ablock = a.l / width, bblock = b.l / width;
            if (ablock != bblock) return ablock < bblock;
            if (ablock & 1) return a.r < b.r;
            return a.r > b.r;
        });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if (v[idx])
                add(idx);
            else
                del(idx);
        };
        for (Query& q : query) {
            while (nl > q.l) push(--nl);
            while (nr < q.r) push(nr++);
            while (nl < q.l) push(nl++);
            while (nr > q.r) push(--nr);
            rem(q.idx);
            while (nl > q.l) push(--nl);
        }
    }
};

signed main() {
    Int n, Q;
    std::cin >> n >> Q;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    Mo mo(n);
    REP(q, Q) {
        Int l, r;
        std::cin >> l >> r, l--;
        mo.add(l, r);
    }
    Int cur = 0;
    std::vector<Int> cnt(n), ans(Q);
    mo.run(
        [&](Int i) {
            if (cnt[a[i]]++ == 0) cur++;
        },
        [&](Int i) {
            if (--cnt[a[i]] == 0) cur--;
        },
        [&](Int i) { ans[i] = cur; });
    REP(q, Q) std::cout << ans[q] << "\n";
}


Measured memory_bytes: 21504
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()
c = Counter(a)
a = sorted(a)

isprime = {a[i]:True for i in range(n)}

for i in range(n): 
    if not isprime[a[i]]: continue
    j = 2
    while a[i]*j < a[-1]+1:
        if isprime.get(a[i]*j) == True:
            isprime[a[i]*j] = False
        j += 1

ensem = list(c.values())
key = list(c.keys())
diff = len([i for i in range(len(c)) if ensem[i] != 1 and isprime[key[i]]])
print(list(isprime.values()).count(True)-diff)

Measured memory_bytes: 135432
#include<bits/stdc++.h>
using namespace std;
int i,j;
#define rep(i,n) for(i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,W,w,v,x,ans=0;
    vector<ll> a[4],A[4];
    cin>>n>>W;
    cin>>w>>v;
    x=w;
    a[0].push_back(v);
    rep(i,n-1) cin>>w>>v,a[w-x].push_back(v);
    rep(i,4) sort(a[i].begin(),a[i].end(),greater<ll>());
    rep(i,4){
        ll y=0;
        rep(j,a[i].size()) y+=a[i][j],A[i].push_back(y);
    }
    int B[4];
    rep(B[0],A[0].size()+1)rep(B[1],A[1].size()+1)rep(B[2],A[2].size()+1)rep(B[3],A[3].size()+1){
        ll value=0,weghit=0;
        rep(i,4) if(B[i]>0) weghit+=(x+i)*B[i],value+=A[i][B[i]-1];
        if(weghit<=W) ans=max(ans,value);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll q; cin >> q;
    ll ans = 0;
    // multiset<ll> left, right;
    priority_queue<ll> left;
    priority_queue<ll, vector<ll>, greater<ll>> right;
    rep(i,q){
        ll t; cin >> t;
        if(t == 1){
            ll a,b; cin >> a >> b;
            ans += b;
            ll l, r;
            if(left.size() == 0 && right.size() == 0){
                left.push(a);
                right.push(a);
            }
            else{
                l = left.top();left.pop();
                r = right.top();right.pop();
                if(a <= l){
                    left.push(a);
                    left.push(a);
                    right.push(l);
                    right.push(r);
                    ans += l-a;
                }
                else if(r <= a){
                    right.push(a);
                    right.push(a);
                    left.push(r);
                    left.push(l);
                    ans += a-r;
                }
                else{
                    left.push(a);
                    left.push(l);
                    right.push(a);
                    right.push(r);
                }
            }
            
        }
        else{
            cout << left.top() << " " << ans << "\n";
        }
    }
}

Measured memory_bytes: 4588
// by ul {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

int N, M, n;
// unordered_map<int, int> m;
int m[(1<<12)];

void input() {
    RI(N, M);
    n = (1<<N);
}

void solve() {
    REP(i, n) m[i] = 1e9;
    m[0] = 0;
    REP(i, M)
    {
        int a, b;
        RI(a, b);
        int mask = 0;
        REP(j, b) {
            int t; RI(t); t--;
            mask |= (1 << t);
        }

        REP(i, n) {
            m[i | mask] = min(m[i | mask], m[i] + a);
        }

        // for(auto p:m) {
        //     int x = p.first, y = p.second;
        //     if(m.count(x | mask) == 0) {
        //         m[x | mask] = y + a;
        //     } else {
        //         m[x | mask] = min(m[x | mask], y + a);
        //     }
        // } 
    }

    printf("%d\n", m[n - 1] >= 1e9? -1: m[n-1]);
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}


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

int next(int now,int last, multimap<int, int> &m) {
	auto it = m.lower_bound(now);
	if (it->second == last) it++;
	return it->second;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> count(N + 1, 0);
	multimap<int, int> m;

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		m.emplace(a, b);
		m.emplace(b, a);
		count[a]++;
		count[b]++;
	}

	int check = 0;
	int start = -1, end = -1;
	for (int i = 1; i <= N; i++) {
		if (count[i] % 2 == 1) {
			check = 0;
			break;
		}
		if (count[i] >= 6){
			check += 3;
		}
		if (count[i] == 4){
			if (start == -1) start = i;
			else end = i;
			check++;
		}
	}

	if (check >= 3) {
		cout << "Yes" << endl;
	} else if (check <= 1) {
		cout << "No" << endl;
	}
	else {
		int endcount = 0;
		auto it = m.lower_bound(start);
		for (int i = 0; i < 4; i++) {
			int tmp, now, last;
			now = it->second;

			last = start;
			while (true) {

				if (now == start) break;
				if (now == end) {
					endcount++;
					break;
				}
				tmp = now;
				now = next(now, last, m);
				last = tmp;
			}
			it++;
		}

		if (endcount == 4) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}

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

using namespace std;

int main() {
  int a;
  std::cin >> a;
  std::bitset<8> ls{};
  int u = 0;
  while (std::cin >> a) {
    if (a < 3200) {
      ls.set(a / 400);
    } else {
      u++;
    }
  }
  std::cout << std::max(static_cast<int>(ls.count()), 1) << " "
            << ls.count() + u << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
using ll = long long;

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		ll a, b; cin >> a >> b;
		ll r = (ll)sqrt(a * b), ans = r * 2;
		if (a != b)ans--;
		if (a * b <= r * r)ans--;
		if (a * b <= r * (r + 1))ans--;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// ABC 148-C
// 2019.12.22 bal4u

#include <stdio.h>

typedef long long ll;

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

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

int main()
{
	int A, B;
	
	scanf("%d%d", &A, &B);
	printf("%lld\n", lcm(A, B));
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010
ll n,k;
vll g[M];
ll dfs(ll u,ll p){
	ll rem=1,col;
	if(p==-1)col=k-1;
	else col=k-2;
	for(auto v:g[u]){
		if(v==p)continue;
		rem=(rem*col)%md,col--;
	}
	for(auto v:g[u]){
		if(v==p)continue;
		rem=(rem*dfs(v,u))%md;
	}
	return rem;
}
int main(){
	IOS;
	cin>>n>>k;
	rep(i,0,n-1){
		ll a,b;cin>>a>>b;a--,b--;
		g[a].pb(b),g[b].pb(a);
	}
	ll ans=dfs(0,-1);
	cout<<(k*ans)%md;
	return 0;
}



Measured memory_bytes: 31488
/**
*	created: 10.08.2020 15:47:23
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n,-1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y);
        par[x] += par[y]; par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);}
    int size(int x) {return -par[root(x)];}
};

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    UnionFind uf(n);
    rep(i,m) {
        int a, b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n) if (uf.same(p[i]-1,i)) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include<iostream>
using namespace std;
int main(){
 int a, b, c, t;
 cin >> a >> b >> c;
 if ( a > b ){
 t = a; a = b; b = t;
} 
 if ( b > c ){
 t = b; b = c; c = t;
}
 if ( a > b ){
 t = a; a = b; b = t;
}
cout << a << " " << b << " " << c << endl;
return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}

int acc[111111][4];
string S;
signed main(){
    cin>>S;
    int N=S.size();

    rep(i,N){
        if(S[i]=='A')acc[i+1][0]++;
        else if(S[i]=='B')acc[i+1][1]++;
        else if(S[i]=='C')acc[i+1][2]++;
        else acc[i+1][3]++;
        rep(j,4)acc[i+1][j]+=acc[i][j];
    }

    int ei=mpow(3,acc[N][3]);
    rep(i,3)ei=ei*mpow(3,mod-2)%mod;

    int ans=0;
    rep(i,N){
        int uku=ei;
        if(S[i]=='B')uku=uku*3%mod;
        if(S[i]=='A'||S[i]=='C')continue;

        add(ans,acc[i][0]*(acc[N][2]-acc[i+1][2])%mod*uku%mod*9%mod);
        add(ans,acc[i][0]*(acc[N][3]-acc[i+1][3])%mod*uku%mod*3%mod);
        add(ans,acc[i][3]*(acc[N][2]-acc[i+1][2])%mod*uku%mod*3%mod);
        add(ans,acc[i][3]*(acc[N][3]-acc[i+1][3])%mod*uku%mod);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 21248
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[100010];
ll b[100010];
ll h,n;
int main(){
	scanf("%lld%lld",&n,&h);
	rep(i,0,n)scanf("%lld%lld",a+i,b+i);
	sortdown(a,n);
	sortdown(b,n);
	ll ans=0,crr=0;
	while(h>0&&b[crr]>a[0]){
		h-=b[crr];
		crr++;
		ans++;
	}
	printf("%lld",h>0?ans+(h+a[0]-1)/a[0]:ans);
}

Measured memory_bytes: 2684
# -*- coding: utf-8 -*-
"""
Created on Mon Mar  4 22:49:08 2019

@author: yuta
"""

A,B,K = list(map(int,input().split()))
def main(a,b,k):
    yaku = []
    min_ab = min(a,b)
    count = 0
    for i in range(1,(min_ab+1)):
        if a % i == 0 and b % i == 0:
            yaku.append(i)
    print(yaku[len(yaku)-k])
main(A,B,K)

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> p(N);
    rep(i, N) {
        cin >> p[i];
        p[i]--;
    }
    vector<vector<int>> G(N);
    int x, y;
    rep(i, M) {
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    vector<int> group(N);
    int tmp = 1;
    rep(i, N) {
        if (group[i]) continue;
        queue<int> q;
        q.push(i);
        while(!q.empty()) {
            int now = q.front(); q.pop();
            if (group[now]) {
                continue;
            }
            group[now] = tmp;
            rep(j, G[now].size()) q.push(G[now][j]);
        }
        tmp++;
    }
    int ans = 0;
    rep(i, N) {
        if (group[p[i]] == group[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9432
#include<stdio.h>
#define N 10000
#define M 1010

int main(void){
  int i,num,j;
  int n,m,a;
  int h[M],p[M],q[M];
  int swp,sf;
  int cur[N];

  for(i=0;;i++){
    scanf("%d%d%d",&n,&m,&a);
    if(n==0 && m==0 && a==0) break;

    cur[i]=a;

    for(j=0;j<m;j++) scanf("%d%d%d",&h[j],&p[j],&q[j]);

    for(;;){
      sf=1;
      for(j=0;j<m-1;j++)
        if(h[j]<h[j+1]){
          sf=0;
          swp=h[j]; h[j]=h[j+1]; h[j+1]=swp;
          swp=p[j]; p[j]=p[j+1]; p[j+1]=swp;
          swp=q[j]; q[j]=q[j+1]; q[j+1]=swp;
        }
      if(sf==1) break;
    }

    for(j=0;j<m;j++)
      if(cur[i]==p[j]) cur[i]=q[j];
      else if(cur[i]==q[j]) cur[i]=p[j];
  }

  num=i;

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

  return 0;
}

Measured memory_bytes: 376
#include <iostream>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#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()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string tones[12] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
  int component[5][3] = {{4,7,-1},{4,7,10},{4,7,11},{3,7,-1},{3,7,10}};
  string compo[5] = {"","7","M7","m","m7"};
  int tension[12] = {0,1,2,3,4,5,6,-1,1,8,9,10};
  string tens[12] = {"","(-9)","(9)","(+9)","(-11)","(11)","(+11)","(-5)","(+5)","(-13)","(13)","(+13)"};

  map<set<int>, vector<string> > mp;
  REP(i, 12) {
    REP(j, 5) {
      vector<int> tmp;
      tmp.push_back(i);
      REP(k, 3) {
        if (component[j][k] == -1) break;
        tmp.push_back((i+component[j][k])%12);
      }
      map<set<int>,bool> memo;
      REP(k,12) {
        vector<int> tmp2(tmp);
        if (k == 0);
        else if (k == 7 || k == 8)   // +-5
          tmp2[2] = (tmp2[2]+tension[k]+12)%12;
        else
          tmp2.push_back((i+tension[k])%12);
        set<int> tmpset(ALL(tmp2));
        if (memo[tmpset]) continue;
        memo[tmpset] = 1;
        string s = tones[i];
        s += compo[j];
        s += tens[k];
        mp[tmpset].push_back(s);
        // cout << s << endl;
        // FOR(it, tmpset) cout << tones[*it] << " ";
        // cout << endl;
      }
    }
  }
  map<string, int> mp2;
  REP(i, 12) {
    mp2[tones[i]] = i;
  }
  int N;
  cin >> N;
  while(N--) {
    int n;
    cin >> n;
    set<int> se;
    REP(i,n) {
      string s;
      cin >> s;
      se.insert(mp2[s]);
    }
    vector<string> v = mp[se];
    if (v.size() == 0) {
      cout << "UNKNOWN" << endl;
    } else {
      REP(i, v.size()) {
        if (i) cout << " ";
        cout << v[i];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 0
N = int(input())
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = 10
lst_joisino = [None] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                return -float("INF")
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print(dfs(0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int n,a[Maxn];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	bool check=true;
	if (a[1]!=0) check=false;
	for (int i=1;i<n;i++)
		if (a[i+1]-a[i]>1) check=false;
	if (!check) printf("%d\n",-1);
	else
	{
		long long ans=0;
		for (int i=2;i<=n;i++)
			if (a[i]-a[i-1]==1) ++ans;
			else ans+=a[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	long n,m,x,y;
	cin >> n >> m >> x >> y;
	vector<long> xs(n),ys(m);
	for (long ni=0;ni<n;++ni) {
		cin >> xs[ni];
	}
	for (long mi=0;mi<m;++mi) {
		cin >> ys[mi];
	}
	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());
	bool war = true;
	for (long z=x+1;z<=y;++z) {
		if (xs[n-1]<z && z<=ys[0]) {
			war = false;
		}
	}
	if (war) {
		cout << "War" << endl;
	} else {
		cout << "No War" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    string s; cin>>s;
    sort(all(s));
    if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
char c[1010][1010];
ll n,m,a,b;
void put(ll y,ll x,string type){
    if(type=="a")c[y][x]='<',c[y][x+1]='>';
    if(type=="b")c[y][x]='^',c[y+1][x]='v';
}
void out(){
    if(a+b>0){
	cout<<"NO"<<endl;
	return;
    }
    cout<<"YES"<<endl;
    lol(i,n){
	lol(j,m){
	    cout<<c[i][j];
	}cout<<endl;
    }
}
bool fillrect(){
    bool res=0;
    for(ll i=0;i+1<n;i+=2){
	for(ll j=0;j+1<m;j+=2){
	    if(a>=2){
		put(i,j,"a");
		put(i+1,j,"a");
		a-=2;
	    }
	    else if(b>=2){
		put(i,j,"b");
		put(i,j+1,"b");
		b-=2;
	    }
	    else if(a){
		put(i,j,"a"); a--; res=1;
	    }
	    else if(b){
		put(i,j,"b"); b--;
	    }
	}
    }
    return res;
}
void fillright(){
    for(ll i=0;i+1<n;i+=2){
	if(b){put(i,m-1,"b"); b--;}
    }
}
void fillunder(){
    for(ll j=0;j+1<m;j+=2){
	if(a){put(n-1,j,"a"); a--;}
    }
}

void Fee(){
    fillrect();
    out();
}
void Feo(){
    fillright();
    fillrect();
    out();
}
void Foe(){
    fillunder();
    fillrect();
    out();
}
void Foo(){
    fillright();
    fillunder();
    if(fillrect()==1 and b==1){
	put(n-3,m-3,"b");
	put(n-1,m-3,"a");
	put(n-3,m-2,"a");
	put(n-2,m-1,"b");
	c[n-2][m-2]='.';
	a=b=0;
    }
    out();
}
int main(){
    cin>>n>>m>>a>>b;
    lol(i,n)lol(j,m)c[i][j]='.';
    if(n==1&&m==1)out();
    else if(n==1){
	fillunder();
	out();
    }
    else if(m==1){
	fillright();
	out();
    }
    else if(n%2==0 and m%2==0)Fee();
    else if(n%2==0 and m%2==1)Feo();
    else if(n%2==1 and m%2==0)Foe();
    else if(n%2==1 and m%2==1)Foo();
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
vll a(5);

void input() { 
  rep(i,5){
    cin >> a[i];
  }
}

void solve() {
  rep(i,5){
    if (a[i]==0){
      cout << i+1 << endl;
    }
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 3548
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


def main():
    N = int(input())

    div = divisor(N)

    result = []
    for d in div:
        result.append(N // d + d - 2)
    print(min(result))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3924
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

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

    cout << (b-a) * (b-a+1) / 2 - b << endl;

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r", stdin);
    //freopen("output.txt","w",stdout);
    int n,m; cin>>n>>m;
    m/=1000; bool b =false;
    int x=0,y=0,z=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(n-i-j<0) continue;
            int k = n-i-j;
            if(i+5*j+10*k==m)
            {
                x=i;y=j;z=k;
                b=true;
                break;
            }
        }
    }

    if(!b) cout<<-1<<" "<<-1<<" "<<-1;
    else cout<<z<<" "<<y<<" "<<x;
}

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

int main(){
    string s;
    cin >> s;
    int a = s.size();
    int count=0;
    int half=a/2;
    for(int i=0;i<half;i++){
        if(s[i]!=s[a-i-1]){
                count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
<?php  

$stdin = trim(fgets(STDIN));  
$number = array();
$number = explode(" ",$stdin);
$a1 = (int)$number[0];
$a2 = (int)$number[1];
$b1 = (int)$number[2];
$b2 = (int)$number[3];
$c1 = ($a1 > $b1) ? $a1 : $b1;
$c2 = ($a2 < $b2) ? $a2 : $b2;
$c3 = (int)($c2 - $c1); 
if($c3 < 0){
	echo "0";
}else{
	echo $c2 - $c1 ;
}
?>

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

#define ll long long;

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

	int a,b,c;
	cin>>a>>b>>c;
	swap(a, b);
	swap(a, c);	
	cout<<a<<" "<<b<<" "<<c ;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

ull n,m;
int H, W;


signed main(void)
{
	while (1) {
		cin >> n >> m;
		vector<int> connect[500];
		if (n == 0) break;
		rep(i, m) {
			int a, b;
			cin >> a >> b;
			a--; b--;
			connect[a].push_back(b);
			connect[b].push_back(a);
		}
		bool a1[500] = {0};
		rep(i, connect[0].size()) {
			int& v = connect[0][i];
			a1[v] = true;
			rep(j, connect[v].size()) {
				a1[connect[v][j]] = true;
			}
		}
		int cnt = 0;
		REP(i,1, n) {
			if (a1[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1372
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
//priority_queue<long long, vector<long long>, greater<long long>> pq;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


const double pi = acos(-1.0);

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  double r;
  cin >> r;
  cout << 2 * pi * r << endl;
  return 0;
}

Measured memory_bytes: 3788
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,M; cin>>N>>M;
  vector<ll> vec(N,0);
  rep(i,M){
    ll a,b; cin>>a>>b; a--; b--;
    vec[a]++; vec[b]++;
  }
  rep(i,N) if(vec[i]%2==1) {cout<<"NO"<<'\n'; return 0;}
  cout<<"YES"<<'\n';
  
  return 0;
}

Measured memory_bytes: 3960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, m, max, hoge, array[];
		
		while(!(string = reader.readLine()).equals("0 0")){
			n = Integer.valueOf(string.split(" ")[0]);
			m = Integer.valueOf(string.split(" ")[1]);
			
			array = new int[n];
			for(int i = 0; i < n; i++) array[i] = Integer.valueOf(reader.readLine());
			
			max = 0;
			for(int i = 0; i < n - m + 1; i++){
				hoge = 0;
				for(int j = i; j < i + m; j++) hoge += array[j];
				if(hoge > max) max = hoge;
			}
			
			System.out.println(max);
		}
		
		reader.readLine();
	}
}

Measured memory_bytes: 37424
/**
 * CatChecker - Accepted
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import static java.lang.Integer.parseInt;

public class Main {

	static Set<String> cat = new HashSet<>();
	static Set<String> rabbit = new HashSet<>();

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		cat.add("");
		cat.add("mew");

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			System.out.println(isCat(line) ? "Cat" : "Rabbit");
		}
	}

	static boolean isCat(String S) {

		if (cat.contains(S)) return true;
		if (rabbit.contains(S)) return false;

		if (S.charAt(0) == 'm'
				&& S.charAt(S.length() - 1) == 'w'
				&& S.indexOf('e') > 0) {
			boolean ret = false;
			for (int i = 1; i < S.length() - 1; i++) {
				if (S.charAt(i) == 'e') {
					ret = isCat(S.substring(1, i)) & isCat(S.substring(i + 1, S.length() - 1));
					if (ret) {
						cat.add(S);
						return true;
					}
				}
			}
		}

		rabbit.add(S);
		return false;
	}
}

Measured memory_bytes: 177716