akhauriyash/Code-Regression huggingface dataset:
// Problem: E - Bomber
// Contest: AtCoder - AtCoder Beginner Contest 176
// URL: https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

//=========================================================

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//=========================================================
#ifdef DEBUG
#define xtp xtp1
#else
#define xtp(x)
#endif
//=========================================================

#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define F first
#define S second
#define pb push_back
#define endl "\n"

#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define rSORT(a) sort(rALL(a))
#define REV(a) reverse(ALL(a))
#define sqr(x) ((x) * (x))

#define TEZ                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);

const long double PI = 3.1415926535897;
const int mod = 1000000007LL;
const int INF = 1e18;

signed main() {
	TEZ;

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

	vi r(h + 1, 0ll), c(w + 1, 0ll);

	int a, b;
	set<ii> el;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;

		r[a]++;
		c[b]++;

		el.insert({a, b});
	}

	vii rr, cc;
	for (int i = 1; i <= h; i++)
		rr.pb({r[i], i});

	for (int i = 1; i <= w; i++)
		cc.pb({c[i], i});

	rSORT(rr);
	rSORT(cc);

	int ro, co;
	ro = h - 1;
	co = w - 1;

	while (rr[ro].F < rr[0].F)
		ro--;
	while (cc[co].F < cc[0].F)
		co--;

	// random_shuffle(rr.begin(), rr.begin() + ro);
	// random_shuffle(cc.begin(), cc.begin() + co);
	vii u;
	// for (int i = ro; i >= max(0ll, ro - 10); i--) {
	// u.pb(rr[i]);
	// }
	// rr.insert(rr.begin(), u.begin(), u.end());

	// u.clear();
	// for (int i = co; i >= max(0ll, co - 1000); i--) {
	// u.pb(cc[i]);
	// }
	// cc.insert(cc.begin(), u.begin(), u.end());

	int jv = -100;
	for (int i = 0; i < min((int)rr.size(), 20ll); i++) {
		for (int j = 0; j < min((int)cc.size(), 300000ll); j++) {
			int jj = rr[i].F + cc[j].F;

			if (el.count({rr[i].S, cc[j].S})) jj--;

			jv = max(jj, jv);
		}
	}

	for (int i = 0; i < min((int)rr.size(), 300000ll); i++) {
		for (int j = 0; j < min((int)cc.size(), 20ll); j++) {
			int jj = rr[i].F + cc[j].F;

			if (el.count({rr[i].S, cc[j].S})) jj--;

			jv = max(jj, jv);
		}
	}

	cout << jv << endl;

	return 0;
}


Measured memory_bytes: 43688
#include<iostream>
#include <algorithm>
#include<queue>
#include<cmath>
#include<math.h>
using namespace std;


long long n;
int main() 
{
	cin >> n;
	cout << (n / 500 * 1000) + (n - n / 500*500) / 5 * 5 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
long long dif(long long a,long long b,long long c){
    long long vec[3]={a,b,c};
    sort(vec,vec+3);
    return vec[2]-vec[0];
}
int main(){
    long long h,w;
    cin >> h >> w;
    if(h%3==0 || w%3==0){
        cout << 0 << endl;
        return 0;
    }
    long long ans = h*w;
    long long pw,pw2;
    long long difs;
    pw = w/3;
    pw2= pw+1;
    if(h%2==0){
        ans = min(ans,abs(((w-pw)*(h/2))-pw*h));
        ans = min(ans,abs(((w-pw2)*(h/2))-pw2*h));
    }
    else{
        difs = dif(pw*h,(w-pw)*(h/2),(w-pw)*((h+1)/2));
        ans = min(ans,difs);
        difs = dif(pw2*h,(w-pw2)*(h/2),(w-pw2)*((h+1)/2));
        ans = min(ans,difs);
    }
    swap(h,w);
    pw = w/3;
    pw2= pw+1;
    if(h%2==0){
        ans = min(ans,abs(((w-pw)*(h/2))-pw*h));
        ans = min(ans,abs(((w-pw2)*(h/2))-pw2*h));
    }
    else{
        difs = dif(pw*h,(w-pw)*(h/2),(w-pw)*((h+1)/2));
        ans = min(ans,difs);
        difs = dif(pw2*h,(w-pw2)*(h/2),(w-pw2)*((h+1)/2));
        ans = min(ans,difs);
    }
    ans = min(ans,min(h,w));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
	return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;      //次のノードのポインタ        
  struct node *prev;      //前のノードのポインタ
};

typedef struct node * NodePointer; //node型のポインタ

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer i;
  for(i=nil->next; i!=nil && i->key!=key ;i=i->next){
  }    //keyが見つかったらbreak  iのメンバー変数が探しているkeyと一致
  return i;  
}

void init(){//新しいノードを作成
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){ //プリント curにNodepinter型のポインタを持たせる
  NodePointer cur = nil->next;
  int isf = 1;// 出力の空白処理
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  //削除するノードは　t         
  if(t == nil) return;//削除するノードがなかったらreturn
  t->prev->next = t->next; 
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
       deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
    if( t == nil ) return;
  deleteNode(t);
}

void delete(int key){       
  NodePointer t;
  t = listSearch(key);
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int a[101],n;

bool check(){
	sort(a+1,a+n+1);
	if(a[n] != a[n-1]) return false;
	for(int i=1;i<n;++i)
		if(a[i+1] > a[i] + 1)
			return false;
	if(a[n]&1){
		if(a[1] < (a[n]+1>>1)) return false;
		if(a[1] != (a[n]+1>>1) or a[2] != (a[n]+1>>1) or a[3] == (a[n]+1>>1)) return false;
		return true;
	}
	if(a[1] < (a[n]>>1)) return false;
	if(a[1] != (a[n]>>1)) return false;
	if(a[1] != (a[n]>>1) or a[2] == (a[n]>>1)) return false;
	return true;
}

int main(){
	scanf("%d",&n);
	for(int i=n;i;--i)scanf("%d",a+i);
	puts(check()?"Possible":"Impossible");
	return 0;
}

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

long int dp[3001][3001];


long long int func(int start,int end,int n,vector<long long int> &v)
{
    if(start>end)
    {
        return 0;
    }
    
    int turn=n-(end-start+1);
    
    if(turn%2==0)
    {
        turn=1;
    }
    else
    {
        turn=0;
    }
    
    if(dp[start][end]!=-1)
    {
        return dp[start][end];
    }
        
    if(turn==1)
    {
        dp[start][end]=max(v[start]+func(start+1,end,n,v),v[end]+func(start,end-1,n,v));
        return dp[start][end];
    }
    else if(turn==0)
    {
        dp[start][end]=min(func(start+1,end,n,v)-v[start],func(start,end-1,n,v)-v[end]);
        return dp[start][end];
    }
    
}

int main()
{
    
        int n;
        cin>>n;
        vector<long long int> v(n);
        for(int i=0;i<n;i++)
        {
            cin>>v[i];
        }
        
        int start=0;
        int end=n-1;
        
        memset(dp,-1,sizeof(dp));
        cout<<func(start,end,n,v);
        
        
    return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
struct edge{ int to,cost; };
vector<edge> nex[301]; // to, cost
int dist[301][301];
int ndis[301][301];
signed main(){
	int n,m,l;
	cin>>n>>m>>l;
	for(int i=0;i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		nex[x].pb((edge){y,z});
		nex[y].pb((edge){x,z});
		dist[x][y] = z;
		dist[y][x] = z;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if( i == j ){
				dist[i][j] = 0;
			}
			else if( dist[i][j] == 0 ){
				dist[i][j] = inf;
			}
		}
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if( dist[i][j] > dist[i][k] + dist[k][j] ){
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if( i == j ){
				ndis[i][j] = 0;
			}
			else if( dist[i][j] <= l ){
				ndis[i][j] = 1;
			}
			else{
				ndis[i][j] = inf;
			}
		}
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if( ndis[i][j] > ndis[i][k] + ndis[k][j] ){
					ndis[i][j] = ndis[i][k] + ndis[k][j];
				}
			}
		}
	}
	int q; cin>>q;
	for(int i=0;i<q;i++){
		int s,t;
		cin>>s>>t;
		if( ndis[s][t] == inf)cout<<-1<<endl;
		else cout<<ndis[s][t]-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 4352
# なぜかうまくいかない
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_right, bisect_left

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = [LIST() for i in range(N)]

# print(list(combinatins(L, 2)))
A = [n for n in range(N)]
ans = 0
for i in list(combinations(A, 2)):
    l, r = i
    a, b = L[r], L[l]
    c = (a[0] - b[0]) ** 2
    d = (a[1] - b[1]) ** 2
    ans += sqrt(c + d)

print(ans/ N * 2)

Measured memory_bytes: 5200
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll x, y;
  cin >> x >> y;
  set<ll> g1 = {1, 3, 5, 7, 8, 10, 12};
  set<ll> g2 = {4, 6, 9, 11};
  set<ll> g3 = {2};
  bool in_g1 = (g1.find(x) != g1.end()) && (g1.find(y) != g1.end());
  bool in_g2 = (g2.find(x) != g2.end()) && (g2.find(y) != g2.end());
  bool in_g3 = (g3.find(x) != g3.end()) && (g3.find(y) != g3.end());
  string ans = (in_g1 || in_g2 || in_g3) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
jc=[0]*n
for i in range(n):
    jc[i]+=i+1-a[i]
jcc=Counter(jc)
count=0
for j in range(n):
    count+=jcc[a[j]+j+1]
print(count)


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

typedef long long ll;

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    cout << A * min(B - 1, N) / B << "\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << "-->" << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
    #define mod 998244353
 
#define fi first
#define se second

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n>>k;
    vector<double> v(n);
    fo(i, n) {
        int x;
        cin >> x;
        v[i]=((x+1)*1.0)/2;
    }
    foo(i, 1, n)
        v[i] += v[i - 1];
    

        double ans = 0;
foo(i,k,n){
    ans = max(ans, v[i] - v[i - k]);
}
ans = max(ans, v[k - 1]);
cout << fixed << setprecision(12) << ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int counta = 1;
  int countb = 1;
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    counta *= 3;
    if (A.at(i) % 2 == 0){
      countb *= 2;
    }
  }
  cout << counta - countb << endl;
}
  

Measured memory_bytes: 3568
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var Si = ReadLine().Split();
            Write((char)(Si[0][0] + 'A' - 'a'));
            Write((char)(Si[1][0] + 'A' - 'a'));
            Write((char)(Si[2][0] + 'A' - 'a'));
        }
        


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 25848
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double a[10000],sum;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%lf",&a[i]);
        sum+=a[i];
    }
    sum/=n;
    double d=1000000;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]>sum&&(a[i]-sum)<d){
            d=a[i]-sum;
            ans=i;
        }
        if(a[i]<=sum&&(sum-a[i])<d){
            d=sum-a[i];
            ans=i;
        }
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 256
import numpy as np
import math
n,k = map(int,input().split())
ans = [0 for i in range(n+1)]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in a:
        if ans[j] == 0:
            ans[j] += 1

num = 0
for i in ans:
    num += i

print(n-num)

Measured memory_bytes: 27152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define el '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define all(x) x.begin(),x.end()
#define int long long
int inf = 1e18;

int32_t main()
{
    fastIO
    int t=1;
    //cin>>t;

    while(t--)
    {
       vector<string> v;
       v.pb("SUN");
       v.pb("MON");
       v.pb("TUE");
       v.pb("WED");
       v.pb("THU");
       v.pb("FRI");
       v.pb("SAT");
       string s;
       cin>>s;
       int i;
       for( i=0;i<v.size();++i)
       {
           if(v[i]==s)
           {
             break;
           }
       }
       cout<<((7-i));
    }
    return 0;
}
// always test the corner cases ALWAYS;


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n;
    cin >> n;
    map<ll, ll> m;
    rep1(i, n){
        ll a;
        cin >> a;
        m[a]++;
    }
    ll init = (n%2==0);
    for (ll i=init; i<n; i+=2){
        if (i==0){
            if (m[i]!=1){
                cout << 0 << endl;
                return 0;
            }
        }
        else if (m[i]!=2){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep1(i, n/2){
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 7540
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] A = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		A[0] = Integer.MAX_VALUE;

		int max = 0;
		int last_min_i = N;
		int max_start_i = N;
		int diff_max = 0;
		int cost = 0;
		for (int i = N; i >= 0; i--) {
			if (A[i] > max) {
				if (diff_max > 0) {
					int cost0 = 0;
					int cost1 = 0;
					for (int j = i + 1; j <= max_start_i; j++) {
						if (A[j] == max && j >= last_min_i) {
							cost0++;
						} else if (A[j] == max - diff_max) {
							if (cost0 > cost1) {
								cost0 = cost1;
							}
							cost1++;
						}
					}
					cost += Math.min(cost0, cost1);
				}
				max = A[i];
				max_start_i = i;
			} else if (A[i] == max) {
				//
			} else {
				if (max - A[i] == diff_max) {
					last_min_i = i;
				} else if (max - A[i] > diff_max) {
					diff_max = max - A[i];
					last_min_i = i;
					cost = 0;
				}
			}
		}

		System.out.println(cost);
	}
}


Measured memory_bytes: 33780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int n;
string s;
int a[] = {};
map<char,int> mp,tmp;
int main(){
    cin >> n;
    cin >> s; //入力
    for(int i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }
    //入力2
    for(int i = 1; i < n; i++){
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            a[s[j]]++;
        }
        for(char c = 'a'; c <= 'z'; c++){
            mp[c] = min(mp[c], a[c]);
        }
        for(char c = 'a'; c <= 'z'; c++){
            a[c] = 0; //初期化
        }
    }
    for(char c = 'a'; c <= 'z'; c++){
        while(mp[c]){
            cout << c;
            mp[c]--;
        }
    }
    cout << endl;
}



Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll power(ll x, ll n){
    if(n == 0) return 1LL;
    ll res = power(x * x % MOD, n/2);
    if(n % 2 == 1) res = res * x % MOD;
    return res;
}
ll bitcnt[1LL<<22] = {};
ll number[1LL<<22] = {};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[100010];
    rep(i,0,N) cin >> a[i];
    ll ans = 0;
    vector<ll> uq;
    rep(i,0,N) uq.push_back(a[i]);
    sort(uq.begin(), uq.end());
    uq.erase(unique(uq.begin(), uq.end()), uq.end());
    rep(i,0,N) number[a[i]]++;

    for(auto &e: uq){
        for(int bit = e; ; bit = (bit-1) & e) {
            bitcnt[bit] += number[e];
            if (!bit) break;
        }   
    }

    // rep(i,0,N){
    //     for(int bit = a[i]; ; bit = (bit-1) & a[i]) {
    //         bitcnt[bit]++;
    //         if (!bit) break;
    //     }
    // }
    // ll num[22] = {};
    // rep(p,0,22){
    //     rep(i,0,N){
    //         if((a[i]>>p)&1) num[p]++;
    //     }
    // }

    rep(bit,1,(1LL<<21)){
        ll cnt = __builtin_popcount(bit);
        ll nn = bitcnt[bit];
        ll val = (power(2, nn) - 1 + MOD) % MOD;
        if(cnt % 2 == 1){
            ans += val;
        }else{
            ans -= val;
        }
        ans %= MOD;

    }
    ans = (power(2,N) - 1 - ans + MOD*2) % MOD;
    print(ans);

}


Measured memory_bytes: 21024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int dp[50], g, price, a1, a5, b1, b5, c1, c5, inp;
	
	rep(i, 50) dp[i] = INF;
	
	rep(a, 25) rep(b, 16) rep(c, 10)
	{
		g = 2 * a + 3 * b + 5 * c;
		if (g > 50) continue;
		a1 = a % 5; a5 = a / 5;
		b1 = b % 4; b5 = b / 4;
		c1 = c % 3; c5 = c / 3;
		price = 380*a1 + 1520*a5 + 550*b1 + 1870*b5 + 850*c1 + 2244*c5;
		if (dp[g] > price) dp[g] = price;
	}
	
	while (cin >> inp, inp)
	{
		cout << dp[inp / 100] << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

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

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(){
    int d1,d2;
    scanf("%d %d" , &d1,&d2);
    
    if(d1 < d2){
    printf("a < b\n");
    }else if(d1 > d2){
    printf("a > b\n");
    }else{
    printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2588
from heapq import heappush, heappop, heapify
N, M = map(int, input().split())
aaa = list(map(lambda x: -x , map(int, input().split())))
heapify(aaa)
for _ in range(M):
    a = heappop(aaa)
    if a < 0:
        a *= -1
        a //= 2
        a *= -1
    heappush(aaa, a)
print(-sum(aaa))


Measured memory_bytes: 20272
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    string s; cin >> s;
    if (s == "zyxwvutsrqponmlkjihgfedcba") cout << -1 << ln;
    else{
        if(s.size()<26){
            for(char c='a'; c<='z'; c++){
                if(s.find(c) == s.npos){
                    s += c;
                    break;
                }
            }
            cout << s << ln;
        }else{
            vector<char> lst;
            while(!s.empty()){
                lst.push_back(s.back());
                s.erase(s.size()-1);
                sort(all(lst));
                auto iter = upper_bound(all(lst), s.back());
                if(iter == lst.end()) continue;
                s[s.size()-1] = *iter;
                cout << s << ln;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let x: i64 = input();
    let t: i64 = input();
    println!("{}", std::cmp::max(x - t, 0));
}


Measured memory_bytes: 4352
def sub():
    items = [int(input()) for _ in range(5)]
    ms = [e % 10 for e in items]

    minIdx = None
    minMod = 11
    for i, m in enumerate(ms):
        if m == 0:
            continue
        if m < minMod:
            minMod = m
            minIdx = i
    if minIdx is None:
        print(sum(items))
        return
    others = items[:minIdx] + items[minIdx+1:]
    cum = 0
    for a in others:
        m = a % 10
        if m == 0:
            cum = cum + a
        else:
            cum = cum + a + (10 - m)
    cum = cum + items[minIdx]
    print(cum)

sub()


Measured memory_bytes: 3064
n = int(input())
A = [int(i) for i in input().split()]

sortA = sorted(A)
mid = sortA[n//2 - 1]
midnext = sortA[n//2]

for i in range(n):
    if A[i] <= mid:
        print(midnext)
    else:
        print(mid)

Measured memory_bytes: 26772
import java.io.*;
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader mBufferedReader=new BufferedReader(new InputStreamReader(System.in));
    String str=mBufferedReader.readLine();
    char[] c=str.toCharArray();
    for(int i=0;i<c.length;i++){
      
      if(Character.isLowerCase(c[i])){
        System.out.print(Character.toUpperCase(c[i]));
      }else{
        System.out.print(Character.toLowerCase(c[i]));
      }
    }
    System.out.println();
   }
}


Measured memory_bytes: 24800
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
 ll n,k;
 vin a;
bool isok(int l){//最大値をlにできるか？
 
  int cnt=0;
  rep(i,0,n){
    cnt+=a[i]/l;
    if(a[i]%l!=0)cnt++;
    cnt--;
  }
 // cout<<cnt<<l<<endl;
  return cnt<=k;
}



int main() {
  //最大値の最小値は二分探索あるある。

  cin>>n>>k;
 a.resize(n);
  rep(i,0,n){
   cin>>a[i]; 
  }
  sort(all(a));
  int ng=0,ok=a[n-1];
  while(ok-ng>1){
    int mid=(ng-ok)/2+ok;
    if(isok(mid)){
      ok=mid;
    }
    else {
        ng=mid;
    }
  }
  cout<<ok<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 1e9
#define infll 1e15


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

double minh=10000000;
int minh_id=0;

int main(){
    int n;
    double t,a;
    vint h(10000);
    cin>>n;
    cin>>t>>a;
    rep(i,n){
        cin>>h[i];
        if(abs(a-(t-0.006*h[i]))<=minh){
            minh=abs(a-(t-0.006*h[i]));
            minh_id=i;
        }
    }
    cout<<minh_id+1<<endl;

    

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = s; i < (n); i++)
using namespace std;
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long ll;

const ll INF = 1LL << 60;
ll h[100010];
ll dp[100010];

int main(){
  ll n; cin >> n;
  rep(i, n) cin >> h[i];
  rep(i, 100010) dp[i] = INF;
  dp[0] = 0;
  rep2(i, 1, n){
    chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1792
int G(x,y){return y?G(y,x%y):x;}
main(x,y,z,t,T,f){for(;scanf("%d%d",&x,&y),y;printf("%d %d\n",z>f?z:f,t)){
y/=G(x,y);
for(z=0;y%2==0;y/=2)z++;
for(f=0;y%5==0;y/=5)f++;
if(y==1)t=0;else{x=1;t=0;do{x=x*10%y;t++;}while(x!=1);}
}exit(0);}

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

int main(){
    int cards[4][13] = {0};
    char mark;
    int rank,number;
    cin >> number;

    for(int i = 0; i < number; i++){
        cin >> mark >> rank;
        if(mark == 'S'){
            cards[0][rank - 1] = 1;
        }
        else if(mark == 'H'){
            cards[1][rank - 1] = 1;
        }
        else if(mark == 'C'){
            cards[2][rank - 1] = 1;
        }
        else if(mark == 'D'){
            cards[3][rank - 1] = 1;
        }
    }

    for(int i = 0; i < 4; i++){
        if(i == 0){
            mark = 'S';
        }
        else if(i == 1){
            mark = 'H';
        }
        else if(i == 2){
            mark = 'C';
        }
        else if(i == 3){
            mark = 'D';
        }
        for(int j = 0; j < 13; j++){
            if(cards[i][j] == 0){
                cout << mark << ' ' << j + 1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn bottom(x: usize) -> usize {
    x % 10
}

fn top(x: usize) -> usize {
    if x < 10 {
        x
    } else {
        top(x / 10)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut t = vec![vec![0; 10]; 10];
    for i in 1..n+1 {
        t[top(i)][bottom(i)] += 1;
    }
    let mut ans = 0;
    for i in 0..10 {
        for j in 0..10 {
            ans += t[i][j] * t[j][i];
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
N, M = map( int, input().split())
fromN = set([])
from1 = set([])
ans = 'IMPOSSIBLE'
for _ in range(M):
    a, b = map( int, input().split())
    a, b = a-1, b-1
    if a == 0:
        if b == N-1:
            ans = 'POSSIBLE'
            break
        else:
            from1.add(b)
    elif b == N-1:
        fromN.add(a)
if len( fromN & from1) != 0:
    ans = 'POSSIBLE'
print(ans)

Measured memory_bytes: 18996
s=gets.chomp.to_i
ary = [s]
i = 1
loop do
  i += 1
  if s % 2 == 0
    tmp = s / 2
    if ary.include?(tmp)
      ary << tmp
      break
    end
    ary << tmp
    s = tmp
  else
    tmp = 3*s + 1
    if ary.include?(tmp)
      ary << tmp
      break
    end
    ary << tmp
    s = tmp
  end
end

puts i

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

int main()
{
  int N, K;
  string S;
  
  cin >> N >> K;
  cin >> S;

  char t = S.at(K-1);
  switch (t)
  {
      case 'A':
        S.at(K-1) = 'a';
        break;
      case 'B':
        S.at(K-1) = 'b';
        break;
      case 'C':
        S.at(K-1) = 'c';
        break;
      default:
        break;
  }

  cout << S << endl;
}


Measured memory_bytes: 256
//06, 10, 2018, 09:13:45 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int N = 100;
pii p[N + 10];
int h[N + 10];
int n;

int can(int i, int j){
    int h0 = 1;

    for(int k = 0 ; k < n ; k++){
        if(h[k] != 0){
            h0 = abs(p[k].first - i) + abs(p[k].second - j) + h[k];
            break;
        }
    }

    for(int k = 0 ; k < n ; k++){
        if(h[k] == 0)
            continue;

        int hi = abs(p[k].first - i) + abs(p[k].second - j) + h[k];

        if(hi != h0){
            return -1;
        }
    }

    return h0;
}

bool ver(int H, int cx, int cy){
    for(int i = 0 ; i < n ; i++){
        if(max(H - (abs(cx - p[i].first) + abs(cy - p[i].second)), 0) != h[i]){
            return false;
        }
    }

    return true;
}

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

    scanf("%d", &n);
    
    for(int i = 0 ; i < n ; i++){
        scanf("%d %d %d", &p[i].first, &p[i].second, &h[i]);
    }

    for(int i = 0 ; i <= N ; i++){
        for(int j = 0 ; j <= N ; j++){
            int d = can(i, j);

            if(d != -1 && d > 0 && ver(d, i, j)){
                printf("%d %d %d\n", i, j, d);
                return 0;
            }
        }
    }

    assert(false);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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 int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    ll p;
    if(n/b==0) p = n;
    else p = b-1;
    cout << (a*p)/b - a *(p/b);
}

Measured memory_bytes: 3632
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
            
            ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3108
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    }
}

Measured memory_bytes: 61972
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    sd = sorted(d)
    print(sd[N//2] - sd[N//2-1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15220
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	hh := make([]int, n)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		hh[i] = getNextInt(scanner)
	}

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	seg := Segment{}

	seg.init(n + 1)

	for i := 0; i < n; i++ {
		mx := seg.max(0, hh[i])
		seg.maximize(hh[i], mx+aa[i])
	}

	fmt.Fprintln(writer, seg.bucket[seg.h-1][0])
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int64
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int64, 1)
	seg.bucket[0] = make([]int64, n)

	chunk := 2
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int64, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index int, value int64) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		parent := index / seg.chunk
		if seg.bucket[seg.i+1][parent] < value {
			seg.bucket[seg.i+1][parent] = value
		}
		index /= seg.chunk
	}
}

func (seg *Segment) max(l, r int) int64 {
	var max int64
	var i int
	for index := l; index < r; index += seg.unit[i] {
		for i < seg.h-1 && index%seg.unit[i+1] == 0 {
			i++
		}
		for i > 0 && index+seg.unit[i] >= r {
			i--
		}
		ii := index / seg.unit[i]
		if max < seg.bucket[i][ii] {
			max = seg.bucket[i][ii]
		}
	}

	return max
}


Measured memory_bytes: 11520
def equal(A,B,i,j):
	ret = True
	for row in xrange(i,i+len(B)):
		if A[row][j:j+len(B)] != B[row-i]:
			ret = False
	return ret

n,m = map(int,raw_input().split())
A = []
B = []
for i in xrange(n):
	A.append(raw_input())
for i in xrange(m):
	B.append(raw_input())


contained = False
for i in xrange(n-m+1):
	for j in xrange(n-m+1):
		if equal(A,B,i,j):
			contained = True
			break
		else:
		 	pass
	if contained: break

if contained: print 'Yes'
else: print 'No'

Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;



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

	ll M,N; cin >> N >> M;
	ll a[110000];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	while (true) {
		sort(a, a + N, greater<ll>());
		ll i = 1;
		a[0] /= 2;
		M--;
		while (i<N&&a[0] < a[i]&&M>0) {
			a[i] /= 2;
			M--;
			i++;
		}
		if (M==0) break;
	}
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		sum += a[i];
	}
	cout << sum;
}

Measured memory_bytes: 1024
template<class T> inline void chmax(T & a, const T b) { if (a < b) a = b; }
template<class T> inline void chmin(T & a, const T b) { if (a > b) a = b; }

#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n; cin >> n;
	map<string, int> S;
	for (int i = 0; i < n; i++) {
		string tmp; cin >> tmp;
		if (S.find(tmp) == S.end()) {
			S.insert({ tmp, 1 });
		}
		else {
			S.at(tmp) += 1;
		}
	}

	int maxv = 0;
	for (auto & a : S) {
		chmax(maxv, a.second);
	}

	for (auto & a : S) {
		if (a.second == maxv) {
			cout << a.first << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 25216
n=int(input())
b=list(map(int,input().split()))
A=[0]*n
for i in range(n-1,-1,-1):
  if i>=n//2:
    A[i]=b[i]
  else:
    a=0
    for j in range(2*i+1,n,i+1):
      a=(a+A[j])%2
    if b[i]==a:
      A[i]=0
    else:
      A[i]=1
print(sum(A))
for i in range(n):
  if A[i]==1:
    print(i+1,end=" ")


Measured memory_bytes: 7148
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lll long long
#define llf __float128
#define lld long double
using namespace std;
const int NR= 2e5 + 20 ,oo = 1e5 + 10, MOD = 1e9 + 7 ;
const long double pi = 2*acos(0.0);


int ans [ NR ] ;

int main () {
    lll x , y , z , i , n ;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0) ;
    cin >> n ;
    for ( x = 1 ; x * x < n ; x ++ )  {
        for ( y = 1 ; x * x + y * y + x * y < n ; ++ y )   {
            for ( z = 1 ; x * x + y * y + z * z + x * y + y * z + x * z <= n ; ++ z )  {
                ans [  x * x + y * y + z * z + x * y + y * z + x * z ] ++ ;
            }
        }
    }
    for ( i = 1 ; i <= n ; ++ i )   {
        cout << ans [ i ] << '\n' ;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
 
ll t[105];
 
int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	FOR(i, a, b)
	{
		t[i] = 1;
	}
	FOR(i, c, d)
	{
		if (t[i] == 1) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll arr[a],brr[b],crr[c];
	vll v;
	//vector<pair<ll,ll> > v,v1;
	for(ll i=0;i<a;i++)
		{
			cin>>arr[i];
			//v.pb(make_pair(arr[i],2));
		}
	for(ll i=0;i<b;i++)
		{
			cin>>brr[i];
			//v.pb(make_pair(brr[i],1));
		}
	for(ll i=0;i<c;i++)
		{
			cin>>crr[i];
			v.pb(crr[i]);
			//v.pb(make_pair(crr[i],0));
		}
	sort(arr,arr+a,greater<ll>());
	sort(brr,brr+b,greater<ll>());
	for(ll i=0;i<x;i++)
	{
		v.pb(arr[i]);

	}
	for(ll i=0;i<y;i++)
	{
		v.pb(brr[i]);

	}
	ll ans=0;
	sort(v.begin(),v.end(),greater<ll>());
	for(int i=0;i<x+y;i++)
		ans+=v[i];
	cout<<ans;



	return 0;
}

Measured memory_bytes: 8688
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();
    if(a<b){
      System.out.println("a < b");
    }
    else if(a>b){
      System.out.println("a > b");
    }
    else{
      System.out.println("a == b");
    }
  }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    string s,t;
    cin>>s>>t;
    sort(all(s));sort(all(t));
    vi a,b;
    int cnta=0,cntb=0;
    char S=s[0],T=t[0];
    rep(i,s.size()){
        if(S==s[i])cnta++;
        else{S=s[i];a.PB(cnta);cnta=1;}
        if(T==t[i])cntb++;
        else{T=t[i];b.PB(cntb);cntb=1;}
        if(i==s.size()-1){
            a.PB(cnta);
            b.PB(cntb);
        }
    }
    sort(all(a));sort(all(b));
    if(a.size()!=b.size())cout<<"No";
    else{
        rep(i,a.size()){
            if(a[i]!=b[i]){cout<<"No";return 0;}
        }
        cout<<"Yes";
    }
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int k;
	cin >> k;
	vector<int> v;
	int sum=0;
	for(int i=0; i<n; i++)
	{
		int a; cin >> a;
		v.push_back(a);
	}
		sort(v.begin(), v.end());
	if(k>1)
	{
		for(int i=0; i<k; i++)
			   {
			sum += v[i];

				}
	cout << sum << endl;
	}else
	{
		cout << v[0] << endl;
	}
	v.clear();
return 0;
}

Measured memory_bytes: 3612