akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int h, w, d;
  cin >> h >> w >> d;

  vector<vector<int>> a(h, vector<int>(w));
  vector<P> ver(h*w); 

  rep(i,h) rep(j,w) {
    cin >> a[i][j];
    a[i][j]--;
    ver[a[i][j]] = make_pair(i, j);
  }
  vector<ll> cum(h*w+1, 0);

  for (int i = 0; i + d < h * w; i++) {
    int x = ver[i].first, y = ver[i].second;
    int nx = ver[i + d].first, ny = ver[i + d].second;
    int cost = abs(x - nx) + abs(y - ny);
    cum[i + d] = cum[i] + cost;
  }
  
  int q;
  cin >> q;

  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << cum[r - 1] - cum[l - 1] << endl;
  }
  return 0;
} 

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

#define task "B"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,b[83];
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	rep(i,1,9) rep(j,1,9) b[i*j]=1;
	cin >> n;
	if (n>81||(!b[n])) cout << "No";
	else cout << "Yes";

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int n;
multiset<int>S;
main()
{
  cin>>n;
  for(int i=0;i<n;i++)
  {
    int c,x;cin>>c>>x;
    if(c==1)cout<<S.count(x)<<endl;
    else if(c==0)S.insert(x),cout<<S.size()<<endl;
    else if(c==2)S.erase(x);
    else
    {
      int y;cin>>y;
      auto a=S.lower_bound(x),b=S.upper_bound(y);
      for(auto it=a;it!=b;it++)cout<<*it<<endl;
    }
  }
}



Measured memory_bytes: 12344
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9

using namespace std;

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

int main() {
    ll N, K;
    cin >> N >> K;
    
    ll ans = 0;
    if (K != 0) {
        for (ll i = K + 1; i <= N; ++i) {
            ans += (N / i) * (i - K);
            if (N % i >= K) {
                ans += (N % i) - K + 1;
            }
        }
    } else {
        ans = N * N;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 daymax=100010;
const int LOG=17;
int n;
vector<ll> x;
ll l;
ll table[100010][20];

void fill(vector<ll> v){
    //table[i][k] : iの2^k日で行けるindex
    table[n-1][0]=-1;
    rep(i,n-1){
        int idx=lower_bound(ALL(v),v[i]+l+1)-v.begin();
        idx--;
        table[i][0]=idx;
    }
    for(int k=0;k<LOG;k++){
        for(int i=0;i<n;i++){
            if(table[i][k]<0) table[i][k+1]=-1;
            else table[i][k+1]=table[table[i][k]][k];
        }
    }
}

int can_go(int day,int pos){
    //day日でposからどこまで行けるか
    if(day==0) return pos;
    int ret=pos;
    for(int i=LOG-1;i>=0;i--){
        if((day>>i)&1){
            ret=table[ret][i];
        }
        if(ret<0) break;
    }
    
    if(ret<0) ret=n-1;
    // cout<<"Day : "<<day<<" pos "<<pos<<" can go "<<ret<<endl;
    return ret;
}

int f(int a,int b){
    int lw=0,hi=daymax;
    while(hi-lw>0){
        int mid=(lw+hi)/2;
        if(can_go(mid,a)>=b) hi=mid;
        else lw=mid+1;
    }
    return hi;
}

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

    //ダブリングテーブル構築して殺せそう
    cin>>n;
    x.resize(n);
    rep(i,n) cin>>x[i];
    cin>>l;

    fill(x);
    // rep(i,n){
    //     rep(j,5){
    //         cout<<table[i][j]<<' ';
    //     }cout<<endl;
    // }

    vector<int> ans;
    int q;cin>>q;
    while(q--){
        int a,b;cin>>a>>b;a--,b--;
        if(a>b) swap(a,b);
        ans.push_back(f(a,b));
    }
    for(auto x:ans){
        cout<<x<<endl;
    }
    return 0;
}


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

int main(){
    double D, T, S;
    cin >> D >> T >> S;

    double time=D/S;
    if(time <= T) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
#include <string.h>
#define bufsize 1<<22
char ibuf[bufsize];
char *ptr=ibuf;

void readint(int *i)
{
    *i=0;
    while(*ptr>='0')
    {
        *i=*i*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
}

int h,w;
#define obs(i,j) ptr[i*(w+1)+j]=='@'

main()
{
    fread(ibuf,1,bufsize,stdin);

    int k,sx,sy,tx,ty;
    readint(&h);
    readint(&w);
    readint(&k);
    readint(&sx);
    readint(&sy);
    readint(&tx);
    readint(&ty);
    sx--,sy--,tx--,ty--;

    struct po {int x,y;};
    struct po qu[1<<20];
    struct po *beg=qu,*end=qu+1;
    beg->x=sx,beg->y=sy;
    unsigned int dist[1<<20];
    memset(dist,-1,sizeof(dist));
    dist[sx*w+sy]=0;
    while(beg!=end)
    {
        int x=beg->x,y=beg->y;
        unsigned int d=dist[x*w+y];
        ++beg;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a++,z+=w;
            if(a==h||obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b++,z++;
            if(b==w||obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a--,z-=w;
            if(a<0||obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b--,z--;
            if(b<0||obs(a,b)||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
    }
    puts("-1");
}


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

int main() {
    int N;
    cin >> N;
    map<char, long long int> Head;
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        Head[S[0]]++;
    }
    long long int ans = 0;
    vector<long long int>Human(5);
    Human[0] = Head['M'], Human[1] = Head['A'], Human[2] = Head['R'],Human[3] = Head['C'], Human[4] = Head['H'];
    for(int i = 0; i < 3; i++) {
        for(int j = i+1; j < 4; j++) {
            for(int k = j+1; k < 5; k++) {
                ans += (Human[i] * Human[j] * Human[k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,k = map(int,input().split())

for i in range(1,k+1):
    if n - k + 1 >= i:
        print(( cmb(n-k+1,i) * cmb(k-1,i-1) ) % (10**9+7))
    #青を分けようとするけど赤玉の隙間がたらないとき
    else:
        print(0)


Measured memory_bytes: 3944
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

vector<bool> knapsack(vector<int>& items) {
    int n = items.size();
    vector<vector<bool>> dp(n + 1, vector<bool>(8001, false));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 8000; j++) {
            dp[i + 1][j] = dp[i + 1][j] || dp[i][j];
            if (dp[i][j] && j + items[i] <= 8000) {
                dp[i + 1][j + items[i]] = true;
            }
        }
    }
    return dp.back();
}

int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;
    int cut = 0;
    while (cut < s.length() && s[cut] == 'F') {
        x--;
        cut++;
    }
    s = s.substr(cut);
    x = abs(x);
    y = abs(y);
    vector<int> vertical, horizontal;
    bool isVertical = false;
    int now = 0;
    while (now < s.length()) {
        if (s[now] == 'T') {
            isVertical = !isVertical;
            now++;
        } else {
            int len = 0;
            while (s[now] == 'F' && now < s.length()) {
                len++;
                now++;
            }
            if (isVertical) {
                vertical.push_back(len);
            } else {
                horizontal.push_back(len);
            }
        }
    }
    int sum_vertical = accumulate(vertical.begin(), vertical.end(), 0);
    int sum_horizontal = accumulate(horizontal.begin(), horizontal.end(), 0);
    auto dp_vertical = knapsack(vertical);
    auto dp_horizontal = knapsack(horizontal);
    bool ok_vertilal = false;
    bool ok_horizontal = false;
    for (int i = 0; i <= 8000; i++) {
        if (abs(sum_vertical - 2 * i) == y && dp_vertical[i]) {
            ok_vertilal = true;
            break;
        }
    }
    for (int i = 0; i <= 8000; i++) {
        if (abs(sum_horizontal - 2 * i) == x && dp_horizontal[i]) {
            ok_horizontal = true;
            break;
        }
    }
    if (ok_vertilal && ok_horizontal) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3072
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N = nextInt();
		long C = nextLong();
		long K = nextLong();
		long[] T = new long[N];
		for(int i=0;i<N;i++){
			T[i]=nextLong();
		}

		Arrays.sort(T);
		long limit=T[0]+K;
		long n=1;
		long ans =0;
		for(int i=1;i<N;i++){
			if(limit >=T[i]){
				if(n%C==0){
					ans+=(n+C-1)/C;
					n=0;
					limit=T[i]+K;
				}
				n++;
			}else{
				ans+=(n+C-1)/C;
				n=1;
				limit=T[i]+K;
			}
		}
		ans+=(n+C-1)/C;

		System.out.println(ans);
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 37060
# ABC144C - Walk on Multiplication Table
def min_div_pairs_sum(x: int) -> int:
    ret = 1 << 60
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            ret = min(ret, i + x // i)
    return ret


def main():
    N = int(input())
    ans = min_div_pairs_sum(N) - 2
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
    int a,b;
    cin>>a>>b;
    if (a<b) {
        cout<<"a < b"<<endl;
    } else if (a>b) {
        cout<<"a > b"<<endl;
    } else {
        cout<<"a == b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
from itertools import product

N = int(input())
c = product(range(2), repeat=N)
d = [[] for _ in range(N)]

for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        d[i].append((x, y))


ans = 0
for l in c:
    o = [None]*N
    is_conflict = False
    for i, j in enumerate(l):
        if j==0:continue
        for x, y in d[i]:
            if (o[x-1]!=None and o[x-1]!=y) or l[x-1]!=y:
                is_conflict = True
                break
            o[x-1] = y
        if is_conflict == True:
            break
    else:
        ans = max(ans, sum(l))

print(ans)

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

int main(void) {
    long n, k;
    cin >> n >> k;
    vector<long> p(n+1);
    for(long i=1; i<=n; i++)
        cin >> p[i];

    for(long i=1; i<=n; i++)
        p[i] += p[i-1];

    long m = 0;
    for(long i=k; i<=n; i++)
        m = max(m, p[i] - p[i-k]);

    printf("%.16f\n", 0.5*(m+k));
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define Rrep(i,n) for(int i=((int)n-1); i>=0; i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e15
#define MOD 10e9+7

typedef vector<int> vint;
typedef long long ll;



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

        int x;
        cin>>x;

        if(x>=30){cout<<"Yes"<<endl;}
        else{cout<<"No"<<endl;}


        return 0;
}


Measured memory_bytes: 3640
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	int a[2500];
	int ans = 0;
	cin >> n;
	REP(i,1, n*2+1) cin >> a[i];
	
	for(int i = 1; i < n*2; i+=2){
		ans += (a[i+1] - a[i]) + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll l,r; cin>>l>>r;
	const int MOD=2019;
	if(r-l>=3000)
	{
		cout<<0<<'\n';
	}
	else
	{
		ll ans=MOD+1000;
		for(ll i=l;i<=r;i++)
		{
			for(ll j=i+1;j<=r;j++)
			{
				ans=min(ans,(i*j)%MOD);
			}
		}
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine;
import scala.reflect.ClassTag;
object Main {
    def main(args: Array[String]): Unit = {
        val line = readLine.split(" ").map(_.toInt);
        val n = line(0);
        val q = line(1);
        val que = new Queue[(String, Int)](n);
        for (i <- 0 until n) {
            val proc = readLine.split(" ");
            que.enqueue((proc(0), proc(1).toInt));
        }
        process(que, q);
    }
    def process(que: Queue[(String, Int)], q: Int): Unit = {
        def _process(total: Int, ret: List[String]): List[String] = {
            if (que.isEmpty) {
                ret
            } else {
                val (name, time) = que.dequeue;
                if (time <= q) {
                    val newTotal = total + time;
                    _process(newTotal, "%s %d".format(name, newTotal) :: ret);
                } else {
                    val newTotal = total + q;
                    que.enqueue((name, time - q));
                    _process(newTotal, ret);
                }
            }
        }
        println(_process(0, Nil).reverse.mkString("\n"));
    }
}
class Queue[A](size: Int)(implicit m: ClassTag[A]) {
    private val arr = m.newArray(size);
    private var leftPtr = 0;
    private var rightPtr = 0;
    private var cnt = 0;
    def isEmpty: Boolean = cnt == 0;
    def isFull: Boolean = cnt == size;
    def enqueue(e: A): Unit = if (isFull) {
        throw new RuntimeException("queue full")
    } else {
        arr(rightPtr) = e;
        cnt += 1;
        rightPtr = if (rightPtr + 1 == size) 0 else rightPtr + 1;
    }
    
    def dequeue: A = if (isEmpty) {
        throw new NoSuchElementException("queue empty");
    } else {
        val e = arr(leftPtr);
        cnt -= 1;
        leftPtr = if (leftPtr + 1 == size) 0 else leftPtr + 1;
        e;
    }
}


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

signed main(){
    int A,B;
    cin >> A >> B;
    if(A < 10 && B < 10){
      cout << A * B << endl;
    }
    else{
      cout << "-1" << endl;
    }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	char b;
	cin >> b;
	if (b == 'A') cout << 'T' << endl;
	else if (b == 'T') cout << 'A' << endl;
	else if (b == 'C') cout << 'G' << endl;
	else cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int h,w,k,x1,yy1,x2,y2;
int cx[]={0,0,1,-1};
int cy[]={1,-1,0,0};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w>>k>>x1>>yy1>>x2>>y2;
    char arr[h+1][w+1];
    int dist[h+1][w+1];
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            cin>>arr[i][j];
        }
    }
    memset(dist,-1,sizeof(dist));
    dist[x1][yy1]=0;
    queue<pair<int,int> > q;
    q.push(mp(x1,yy1));
    while (!q.empty()){
        pair<int,int> cur=q.front();
        q.pop();
        for (int i=0;i<4;i++){
            int dx=cur.first;
            int dy=cur.second;
            for (int j=0;j<k;j++){
                dx+=cx[i];
                dy+=cy[i];
                if (dx<1 || dy<1 || dx>h || dy>w) break;
                if (arr[dx][dy]=='@') break;
                if (dist[dx][dy]!=-1 && dist[dx][dy]<dist[cur.first][cur.second]+1) break;
                if (dist[dx][dy]!=-1 && dist[dx][dy]<=dist[cur.first][cur.second]+1) continue;
                dist[dx][dy]=dist[cur.first][cur.second]+1;
                q.push(mp(dx,dy));
            }
        }
    }
    cout<<dist[x2][y2];
}


Measured memory_bytes: 12376
//
//  DPC-yo-5-a.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/24.
//

#include <stdio.h>
#include <iostream>
#include <cmath>

#define INF 100000

using namespace std;

int main()
{
    int n;
    int a[110];
    
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    
    double ave=0;
    
    for(int i=0;i<n;i++) ave+=a[i];
    
    ave/=(double)n;
    
    double dist=INF;
    int ans=-1;
    
    for(int i=0;i<n;i++)
    {
        if(abs(ave-a[i])<dist)
        {
            dist=abs(ave-a[i]);
            ans=i;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
A, B = mi()

print(A*B)

Measured memory_bytes: 9140
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.first*a.first + a.second*a.second) > (b.first*b.first + b.second*b.second);
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)


int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, Q;
    cin >> N >> Q;
    vector<ll> S(N), T(N), X(N);
    vector<tuple<ll, ll, ll> > U;
    REP(i, N) {
        cin >> S[i] >> T[i] >> X[i];
        U.push_back(make_tuple(S[i]-X[i], 1, X[i]));
        U.push_back(make_tuple(T[i]-X[i], -1, X[i]));
    }
    sort(U.begin(), U.end());
    
    multiset<ll> V;
    int l = 0;
    REP(i, Q) {
        int D;
        cin >> D;
        for (;l < U.size();l++) {
            if (get<0>(U[l]) > D) break;
            if (get<1>(U[l]) > 0) {
                V.insert(get<2>(U[l]));
            } else {
                V.erase(get<2>(U[l]));
            }
        }
        if (V.size() == 0) cout << -1 << endl;
        else cout << *V.begin() << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int h, w, k; cin>>h>>w>>k;
    if(w==1){
        cout << 1 << endl;
        return 0;
    }
    ll dp[110][10];
    memset(dp, 0, sizeof(dp));
    dp[0][1]=1;
    for(int i=2; i<=w; i++) dp[0][i]=0;

    for(int i=1; i<=h; i++){
        for(int bit=0; bit<(1<<w-1); bit++){
            bool can_make=true;
            for(int k=0; k<w-1; k++){
                if((1<<k)&bit && (1<<k+1)&bit) can_make=false;
            }

            if(can_make){
                for(int k=w-2; k>=0; k--){
                    if((1<<k)&bit){
                        if(k==w-2){
                            dp[i][1]+=(dp[i-1][2])%MOD;
                            dp[i][2]+=(dp[i-1][1])%MOD;
                        }
                        else if(k==0){
                            dp[i][w]+=(dp[i-1][w-1])%MOD;
                            dp[i][w-1]+=(dp[i-1][w])%MOD;
                        }
                        else{
                            dp[i][w-k]+=(dp[i-1][w-k-1])%MOD;
                            dp[i][w-k-1]+=(dp[i-1][w-k])%MOD;
                        }
                    }
                    else{
                        if(w==3 && k-1>=0 && ((!((1<<k)&bit)) && (!((1<<k-1)&bit)))){
                            dp[i][1]+=(dp[i-1][1])%MOD;
                            dp[i][2]+=(dp[i-1][2])%MOD;
                            dp[i][3]+=(dp[i-1][3])%MOD;
                            k--;
                            /*
                            cout << bit << " " << k << endl;
                            cout << i << "   " << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;
                            */
                        }
                        else if(k==w-2){
                            if((!((1<<k)&bit)) && (!((1<<k-1)&bit))){
                                dp[i][1]+=(dp[i-1][1])%MOD;
                                dp[i][2]+=(dp[i-1][2])%MOD;
                            }
                            else dp[i][1]+=(dp[i-1][1])%MOD;
                        }
                        else if(k==0){
                            dp[i][w]+=(dp[i-1][w])%MOD;
                        }
                        else{
                            if((!((1<<k)&bit)) && (!((1<<k-1)&bit))){
                                dp[i][w-k]+=(dp[i-1][w-k])%MOD;
                            }
                        }
                    }
                    for(int j=1; j<=w; j++) dp[i][j]%=MOD;
                }
            }
        }
    }

    /*
    for(int i=0; i<=h; i++){
        for(int j=1; j<=w; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    cout << dp[h][k]%MOD << endl;
}

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

public class Main {
    static int sum(List<Integer> bamboos){
        int ans = 0;
        for(int x:bamboos) ans += x;
        return ans;
    }
    static int magicPoint(List<Integer> bamboos, int target){
        if(bamboos.isEmpty()) return 1000000;
        return 10 * (bamboos.size()-1) + Math.abs(sum(bamboos)-target);
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int[] allBamboos = new int[N];
        for(int n=0; n<N; n++) allBamboos[n] = sc.nextInt();

        int ans = 1000000;

        for(int i=1; i<65536; i++){
            List<Integer> aBamboos = new ArrayList<>();
            List<Integer> bBamboos = new ArrayList<>();
            List<Integer> cBamboos = new ArrayList<>();
            for(int n=0; n<N; n++){
                switch((i>>(2*n)) & 3){
                    case 1:
                        aBamboos.add(allBamboos[n]); break;
                    case 2:
                        bBamboos.add(allBamboos[n]); break;
                    case 3:
                        cBamboos.add(allBamboos[n]); break;
                }
            }
            if(aBamboos.isEmpty() && bBamboos.isEmpty() && cBamboos.isEmpty()) break;
            int mp = magicPoint(aBamboos,A)+magicPoint(bBamboos,B)+magicPoint(cBamboos,C);
            //System.err.printf("%8s %7d %7d %7d %7d\n", Integer.toString(i, 4), mp, magicPoint(aBamboos,A), magicPoint(bBamboos,B), magicPoint(cBamboos,C));
            ans = Math.min(ans, mp);
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 42884
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() 
{
    int64_t X, N;
    std::cin >> X >> N;

    std::vector<bool> Ps(102);
    for (int64_t i = 1; i <= N; ++i) {
        int64_t idx;
        std::cin >> idx;
        Ps.at(idx) = true;
    }

    if (N == 0) {
        std::cout << X << std::endl;
        return 0;
    }

    int64_t ans = 0;
    int64_t count = 0;
    while (true) {
        if (X-count >= 0) {
            if (!Ps.at(X-count)) {
                ans = X-count;
                break;
            }
        }
        if (X+count <= 101) {
            if (!Ps.at(X+count)) {
                ans = X+count;
                break;
            }
        }
        count++;
    }

    std::cout << ans << std::endl;

    return 0;
}

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

int main() {
	
	while(true){
		int n=0,m=0,a=0;
		cin >> n >> m >> a;
		if(n==0&&m==0&&a==0){
				break;
		}
		
		int amida[101][1001]={{0}};
		
		for(int i=0;i<m;i++){
			int h=0,p=0,q=0;
			cin >> h >> p >> q;
			amida[p][h]=1;
		}
		
		for(int j=1000;j>0;j--){
			if(amida[a][j]==1) a++; //????????????
			else if(amida[a-1][j]==1) a--; //???
		}
		
		cout << a << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1560
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int color[100001];
vector<pii> adj[100001];

void dfs(int x, int c) {
    color[x] = c;
    for (auto it : adj[x]) {
        int nx = it.first, w = it.second;
        if (color[nx] == -1) {
            if (w % 2) dfs(nx, 1 - c);
            else dfs(nx, c);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int n; cin >> n;
    memset(color, -1, sizeof(color));
    for (int i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w;
        adj[u].emplace_back(v, w);
        adj[v].emplace_back(u, w);
    }
    
    dfs(1, 0);
    
    for (int i = 1; i <= n; i++) {
        cout << color[i] << '\n';
    }
    
    return 0;
}


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

using namespace std;

const int N = 1e5 + 2;

int n, a[N];

int main(){
      scanf("%d", &n);

      for(int i = 1; i <= n; i ++){
            scanf("%d", &a[i]);
      }

      sort(a + 1, a + n + 1);

      cout << a[n] << " ";

      int mx = 2e9, ind = 0;

      for(int i = 1; i < n; i ++){
            if(mx > abs(a[i] - (a[n] / 2))){
                  mx = abs(a[i] - (a[n] / 2));
                  ind = i;
            }
            if(mx > abs(a[i] - ((a[n] + 1) / 2))){
                  mx = abs(a[i] - ((a[n] + 1) / 2));
                  ind = i;
            }
      }

      cout << a[ind] << endl;
}


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

int main()
{
    int k,n;
    double sum=0;
    cin>>n>>k;
    vector<double> p(n+1); //累積和
    for(int i=1;i<=n;i++){
        double a;
        cin>>a;
        a=(a+1)/2;
        sum+=a;
        p[i]=sum;
    }
    double ans=0;
    rep(i,n-k+1){
        ans=max(ans,p[i+k]-p[i]);
    }
    printf("%.10f",ans);
}

Measured memory_bytes: 4856
S = input()
countermax = 0
counter = 0
for s in S:
    if s == 'A' or s == 'C' or s == 'G' or s == 'T':
        counter += 1
    else:
        if countermax < counter:
            countermax = counter
            counter = 0
if countermax < counter:
    countermax = counter

print(countermax)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll k,a,b;cin>>k>>a>>b;
  if(b-a<3){
    cout<<k+1<<endl;
    return 0;
  }

  ll ans=0;
  if(k-2+1>=a){//2回以上残してa枚にできる
    k-=a-1;
    ans=a;
    ans+=(b-a)*(k/2);
    if(k%2==1)ans++;
    cout<<ans<<endl;
  }else{
    cout<<k+1<<endl;
  }
}

Measured memory_bytes: 256
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()]
    p1, p2 = 0, K
    for i in range(N-K):
        if A[p1] < A[p2]:
            print('Yes')
        else:
            print('No')
        p1 += 1
        p2 += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 31600
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <list>
#include <map>

#define min_3(a, b, c) min(a, min(b, c))

typedef long long ll;
using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    if(n <= k) cout << x * n << endl;
    else cout << x * k + (n - k) * y << endl;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

const int INF = 3e8;

int h, w, k;
pair<int, int> s, e;
vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, -1, 1};
vector<vector<char>> b;
vector<vector<int>> d;
bool chk(pair<int, int> pos){
    return pos.f >= 0 && pos.f < h && pos.s >= 0 && pos.s < w;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w >> k >> s.f >> s.s >> e.f >> e.s;
    s.f--; e.f--; s.s--; e.s--;
    b.assign(h, vector<char>(w, ' '));
    d.assign(h, vector<int>(w, INF));
    for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) cin >> b[i][j];
    queue<pair<int, int>> q; q.push(s);
    d[s.f][s.s] = 0;
    while(!q.empty()){
        pair<int, int> c = q.front(); q.pop();
        for(int dir = 0; dir < 4; ++dir){
            for(int i = 1; i <= k; ++i){
                pair<int, int> cc = {c.f + dx[dir] * i, c.s + dy[dir] * i};
                if(!chk(cc)) break;
                if(b[cc.f][cc.s] == '@') break;
                if(d[cc.f][cc.s] != INF){
                    if(d[cc.f][cc.s] == d[c.f][c.s] + 1) continue;
                    else break;
                }
                d[cc.f][cc.s] = d[c.f][c.s] + 1;
                q.push(cc);
            }
        }
    }
    cout << (d[e.f][e.s] == INF ? -1 : d[e.f][e.s]);
    return 0;
}

Measured memory_bytes: 11876
s = input()


def check_kaibun(s):
    return s == s[::-1]


if (
    check_kaibun(s)
    and check_kaibun(s[: (len(s) - 1) // 2])
    and check_kaibun(s[(len(s) + 2) // 2 :])
):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define SZ (2001)
#define N (200010)
#define rhl (1000000007)

using namespace std;

int f[5010][5010],fac[SZ<<2],ifac[SZ<<2],inv[SZ<<2],a[N],b[N],n,ans;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

il int C(RG int n,RG int m){
  return 1LL*fac[n]*ifac[m]%rhl*ifac[n-m]%rhl;
}

int main(){
  n=gi(),fac[0]=ifac[0]=1;
  for (RG int i=1;i<(SZ<<2);++i){
    inv[i]=i==1 ? 1 : 1LL*(rhl-rhl/i)*inv[rhl%i]%rhl;
    fac[i]=1LL*fac[i-1]*i%rhl,ifac[i]=1LL*ifac[i-1]*inv[i]%rhl;
  }
  for (RG int i=1;i<=n;++i){
    a[i]=gi(),b[i]=gi(),++f[SZ-a[i]][SZ-b[i]];
    ans-=C((a[i]+b[i])<<1,a[i]<<1); if (ans<0) ans+=rhl;
  }
  for (RG int i=1;i<(SZ<<1);++i)
    for (RG int j=1;j<(SZ<<1);++j){
      f[i][j]+=f[i-1][j]+f[i][j-1];
      if (f[i][j]>=rhl) f[i][j]-=rhl;
    }
  for (RG int i=1;i<=n;++i){
    ans+=f[SZ+a[i]][SZ+b[i]]; if (ans>=rhl) ans-=rhl;
  }
  cout<<500000004LL*ans%rhl; return 0;
}


Measured memory_bytes: 82176
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(N):
  for j in range(i+1,N):
      add_len = L[i]+L[j]
      idx = bisect.bisect_left(L, add_len)
      ans += max(0, idx-(j+1))
print(ans)
      

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int l, r;
    cin >> l >> r;

    // 2019の倍数を必ず選べる
    if ((r - l) >= 2018) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 2019;
    for (int i = l; i < r; i++) {
        for (int j = i + 1; j <= r; j++) {
            int m = (i % 2019) * (j % 2019);
            m %= 2019;
            ans = min(ans, m);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a, b;
	cin >> a >> b;
	if (b % a == 0) cout << a + b << endl;
	else cout << b - a << endl;
}


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

typedef long long int lli;
using namespace std;

int main()
{
    
    lli n, k, q;
    cin >> n >> k >> q;
    lli arr[n];
    for(lli i = 0; i < n; i++)
    {
        arr[i] = k;
    }
    
    lli pnum;
    for(lli i = 0; i < q; i++)
    {
        cin >> pnum;
        arr[pnum-1]+=1;
    }
    for(lli i = 0; i < n; i++)
    {
        if((arr[i] - q) > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
class Array
  def warshall_floyd
    v = size

    dist = map(&:dup)

    v.times do |k|
      v.times do |i|
        v.times do |j|
          dist[i][j] = [dist[i][j], dist[i][k] + dist[k][j]].min
        end
      end
    end

    dist
  end
end

H, W = gets.split.map(&:to_i)

cost = 10.times.map { gets.split.map(&:to_i) }.warshall_floyd
wall = H.times.map { gets.split.map(&:to_i) }

ans = 0

wall.each do |row|
  row.each do |num|
    next if num == -1

    ans += cost[num][1]
  end
end

puts ans


Measured memory_bytes: 4604
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int[] a = new int[n];
      	for(int i = 0; i < n; i++){
        	a[i] = sc.nextInt();
        }
      
      	int ans = 0;
      	while(true){
        	boolean exist = false;//a[i]がすべて奇数かどうか
          	for(int i = 0; i < n; i++){
            	if(a[i]%2 != 0) exist = true;
            }
          	if(exist) break;
          	for(int i = 0; i < n; i++){
            	a[i] /= 2;
            }
          	ans++;
        }
      	System.out.println(ans);
    }
}


Measured memory_bytes: 36240
main=do
    line<-getLine
    let ipn=[read x::Int|x<-words line]
    let vr=ipn!!0
    let vg=ipn!!1
    let vb=ipn!!2
    let n=ipn!!3
    print $ length [nr|nr<-[0..(div n vr)],ng<-[0..(div n vg)],n-nr*vr-ng*vg>=0,mod (n-nr*vr-ng*vg) vb ==0]
    



Measured memory_bytes: 764
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt=0,cnt2=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){cnt++;}
        else if(s[i]=='B'){cnt2++;}
    }
    cout<<(cnt>cnt2?"Yes":"No")<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define pwll(x) (1LL<<(x))
#define SZ(x) ((int)(x).size())
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define NEWL EVAL({cout << '\n';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

const int MAX_NODES = 1e5 + 100;

LL n, L;
int trie_nodes = 1;
int edge[MAX_NODES][2];
LL ans = 0;

void add_to_trie(const string& s) {
    int u = 0;
    for(char c : s) {
        int nex = int(c - '0');
        if (edge[u][nex] == -1) {
            edge[u][nex] = trie_nodes++;
        }
        u = edge[u][nex];
    }
}

LL grundy(LL x) {
    LL ret = 1;
    while(x % 2 == 0) {
        x >>= 1;
        ret <<= 1;
    }
    return ret;
}

void dfs(int u, int d) {
    int children = 0;
    REP(nex, 2) {
        int v = edge[u][nex];
        if (v != -1) {
            dfs(v, d+1);
            children++;
        }
    }
    if (children == 1) {
        ans ^= grundy(L + 1 - d);
    }
}

int main() {
    memset(edge, -1, sizeof edge);
    cin >> n >> L;
    REP(i, n) {
        string s;
        cin >> s;
        add_to_trie(s);
    }
    dfs(0, 1);
    cout << (ans ? "Alice\n" : "Bob\n");
}






























Measured memory_bytes: 4332
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()

	var lst []int
	var rec func(n int, zerook bool, count [8]int, acc []byte)
	rec = func(n int, zerook bool, count [8]int, acc []byte) {
		if n == 0 {
			if count['3'-'0'] < 1 || count['5'-'0'] < 1 || count['7'-'0'] < 1 {
				return
			}
			v, err := strconv.ParseInt(string(acc), 10, 64)
			if err != nil {
				panic(err)
			}
			lst = append(lst, int(v))
			return
		}
		if 3 < n && zerook {
			rec(n-1, true, count, append(acc, '0'))
		}
		for _, c := range []byte{'3', '5', '7'} {
			count[c-'0']++
			rec(n-1, false, count, append(acc, c))
			count[c-'0']--
		}
	}
	rec(9, true, [8]int{}, []byte{})
	var ans int
	for _, v := range lst {
		if v <= N {
			ans++
		}
	}
	println(ans)

}

// -----------------------------------------------------------------------------


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = Integer.parseInt(sc.next());
        sum += Integer.parseInt(sc.next());
        sum += Integer.parseInt(sc.next());
        if (sum > 21) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
        sc.close();
    }
}

Measured memory_bytes: 21332
# ABC135b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
p = list(map(int, input().split()))
# print(p)
# print(p2)
#print(p == p2)

for i in range(len(p)):
    for j in range(i, len(p)):
        p2 = sorted(p)
        tmp = p2[i]
        p2[i] = p2[j]
        p2[j] = tmp
        if (p == p2):
            print("YES")
            exit()
print("NO")

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int f(int n)
{
    return ((n & 1) ? 3 * n + 1 : n / 2);
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n + 1), y(m + 1);
    cin >> x[0] >> y[0];
    rep2(i, 1, n + 1) cin >> x[i];
    rep2(i, 1, m + 1) cin >> y[i];

    sort(all(x));
    sort(all(y));

    cout << ((x[n] < y[0]) ? "No War" : "War") << '\n';
    return 0;
}


Measured memory_bytes: 3628