akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int ans = (n - 1) / 2;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 20948
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ');

        var list = new Dictionary<int, long>();
        var cnt = 0;
        foreach(var num in line)
        {
            list.Add(cnt, long.Parse(num));
            cnt++;
        }
        var ans = 0;

        for (var i = 0; i < n - 2; i++)
        {
            for(var j = i + 1; j < n - 1; j++)
            {
                for(var k = j + 1; k < n; k++)
                {
                    if (list[i] == list[j] || list[j] == list[k] || list[k] == list[i])
                    {

                    }
                    else if (list[i] + list[j] > list[k] && list[i] + list[k] > list[j] && list[j] + list[k] > list[i]) 
                    {
                        ans++;
                    }
                }
            }
        }

        Console.WriteLine(ans);
        Console.ReadLine();
    }


}


Measured memory_bytes: 18168
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
	a = list(map(int,input().split()))
	tokuten = 0
	for j in range(m):
		tokuten += b[j]*a[j]
	if tokuten > -c:
		count += 1

print(count)

Measured memory_bytes: 3060
#AGC011-A Airport Bus
"""
時刻順にソート
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,c,k = map(int,readline().split())
t = []
for i in range(n):
    t.append(int(readline()))

t.sort()
res_k = t[0]
res_c = 0
ans = 0
for i in range(n):
    res_c += 1
    if i+1 < n:
        if t[i+1] - res_k > k:
            ans += 1
            res_c = 0
            res_k = t[i+1]
    if res_c == c:
        ans += 1
        if i+1 < n:
            res_k = t[i+1]
        res_c = 0

print(ans if res_c == 0 else ans + 1)

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

int main(){
   IOS;

   long int n;
   cin>>n;

   vector<long int> v(n);
   for(long int i = 0 ; i < n; i++)
   		cin>>v[i];

   sort(v.begin(),v.end());

   long int ans = 0;
   for(long int i = 0; i < n; i++){
   	for(long int j = i+1; j < n; j++){
   		long int sum = v[i] + v[j];
   		long int pos = lower_bound(v.begin(),v.end(),sum) - v.begin();
   		if(pos >= n)
   			pos = n-1;

   		if(v[pos] >= v[i] + v[j])
   			pos--;
   		pos -= j;
   		ans += pos;
   	}
   }
   	
   	cout<<ans;

   return 0;
}

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

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

using namespace std;
using graph=vector<vector<int>>;

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

vector<int> distance(const graph& G,int s){
	const int INF=INT_MAX;
	int n=G.size();
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> Q; Q.emplace(s);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int v:G[u]) if(d[v]==INF) {
			d[v]=d[u]+1;
			Q.emplace(v);
		}
	}
	return d;
}

const int INF=1<<29;

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char B[20][21];
	rep(i,h) scanf("%s",B[i]);

	graph G(h*w);
	rep(i,h) rep(j,w) if(B[i][j]=='.') rep(k,4) {
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<=h && 0<=x && x<w && B[y][x]=='.') G[i*w+j].emplace_back(y*w+x);
	}

	int ans=0;
	rep(i0,h) rep(j0,w) {
		auto d=distance(G,i0*w+j0);
		rep(i,h) rep(j,w) if(d[i*w+j]<INF) ans=max(ans,d[i*w+j]);
	}
	printf("%d\n",ans);

	return 0;
}


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

int main(void) {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}

    int ans=0;
    rep(i, n){
        while(a[i]%2==0){
            a[i]/=2;
            ans++;
        }
    }
    cout << ans << endl;
}



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

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

  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        if (a == b) System.out.printf("Yes\n");
        else System.out.printf("No\n");
        in.close();
    }
}


Measured memory_bytes: 21844
#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <deque>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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 INF = 1e9;
const long long LINF = 1e18;

int main() {
    int R;
    cin >> R;

    printf("%f\n", 2.0 * 3.14159265359 * R);

    return 0;
}


Measured memory_bytes: 3264
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define PB push_back
#define MP make_pair
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define INF (1 << 28)
#define LLINF (1LL << 60)
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n, count=0;
    bool ans = false;
    cin >> n;
    REP(i,n){
        int d1,d2;
        cin>>d1>>d2;
        if(d1==d2){
            count++;
        }
        else{
            count = 0;
        }
        if(count==3){
            ans = true;
        }
    }
    if(ans)Yes;
    else No;
    return 0;
}


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

int c[33], s[444][33];
int sco(int t, const vector<int> &v) {
    int r = 0, l = 0, d = v.size();
    for(int i = 0; i < d; i++)
        if(v[i] == t)
            r += s[i][t] - c[t] * (i + 1 - l) * (i - l) / 2, l = i + 1;
    r -= c[t] * (d + 1 - l) * (d - l) / 2;
    return r;
}
int main() {
    auto ti = clock();
    int d;
    cin >> d;
    for(int i = 0; i < 26; i++)
        cin >> c[i];
    for(int i = 0; i < d; i++)
        for(int j = 0; j < 26; j++)
            cin >> s[i][j];
    vector<int> ss, tt;
    int M = -1e9;
    for(int a = 10; a < 16; a++) {
        for(int b = 0; b < 4; b++) {
            for(int z = 5; z < 16; z++) {
                int r = 0, l[33] = {};
                ss.clear();
                for(int i = 0; i < d; i++) {
                    auto m = 0.;
                    int t = 0;
                    for(int j = 0; j < 26; j++) {
                        double p = s[i][j];
                        p += c[j] * (i + 1 - l[j]) * .4 * a;
                        for(int k = 1; k < z; k++)
                            if(i + k < d)
                                p -= s[i + k][j] * (z - k) * .05 / z * b;
                        if(p > m)
                            m = p, t = j;
                    }
                    ss.push_back(t);
                    r -= c[t] * (i + 1 - l[t]) * (i - l[t]) / 2;
                    l[t] = i + 1;
                    r += s[i][t];
                }
                for(int j = 0; j < 26; j++)
                    r -= c[j] * (d + 1 - l[j]) * (d - l[j]) / 2;
                if(r > M)
                    M = r, tt.swap(ss);
            }
        }
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rc(0, 25), r0(0, d - 1), r2(1, 6);
    uniform_real_distribution<> ru(0, 1);
    int cnt = 0;
    for(;;) {
        auto T = (clock() - ti + 0.) / CLOCKS_PER_SEC;
        if(T > 1.9)
            break;
        auto U = 1e3;
        for(int cn = 0; cn < 100; cn++, cnt++) {
            auto uu = tt;
            int di;
            if(rc(mt) < 12) {
                int x0 = r0(mt), xc = rc(mt);
                uu[x0] = xc;
                di = sco(tt[x0], uu) + sco(xc, uu) - sco(tt[x0], tt) -
                     sco(xc, tt);
            } else {
                int x2 = r2(mt);
                uniform_int_distribution<> r1(0, d - 1 - x2);
                int x1 = r1(mt);
                x2 += x1;
                swap(uu[x1], uu[x2]);
                di = sco(tt[x1], uu) + sco(tt[x2], uu) - sco(tt[x1], tt) -
                     sco(tt[x2], tt);
            }
            if(ru(mt) <= exp(di / U))
                tt.swap(uu), M += di;
        }
    }
    int S = 0;
    for(int j = 0; j < 26; j++)
        S += sco(j, tt);
    assert(S == M);
    for(int i : tt)
        cout << i + 1 << '\n';
    cerr << M << endl;
    cerr << cnt << endl;
    return 0;
}


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

int main() {
  int N,chukan=0;
  long long sum=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
  }
  for(int i=0;i<N;i++){
    chukan=max(chukan,vec[i]);
    sum += chukan - vec[i];
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;

    vector<int> vans{1,2,4,8,16,32,64};
    auto it = upper_bound(ALL(vans),n);

    cout << *(--it) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define fst first
#define snd second

int main() {
  int t, n;
  while(cin >> t >> n && (t|n)) {
    int M[121][121] = {};
    int const BX = 60, BY = 60;
    for(int i=0; i<n; i++) {
      int x, y;
      cin >> x >> y;
      M[y+BY][x+BX] = 1;
    }
    
    int const dx[] = {-1,1,0,0,1,-1};
    int const dy[] = {0,0,-1,1,1,-1};
    
    typedef pair<int, int> Pii;
    typedef pair<Pii, int> P;
    
    bool used[121][121] = {};
    int ans = 0;
    
    int sx, sy;
    cin >> sx >> sy; sx += BX, sy += BY;
    
    queue<P> Q;
    Q.push(P(Pii(sx, sy), t));
    used[sy][sx] = true;
    
    while(!Q.empty()) {
      P const p = Q.front(); Q.pop();
      ans ++;
      
      if(p.snd <= 0) continue;
      
      for(int i=0; i<6; i++) {
	int nx = p.fst.fst + dx[i], ny = p.fst.snd + dy[i];
	if(!used[ny][nx] && M[ny][nx] == 0) {
	  Q.push( P(Pii(nx, ny), p.snd-1) );
	  used[ny][nx] = true;
	}
      }
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1292
# Caesar Cipher
s = input()
while 1:
    for diff in range(0,26):
        dec = []
        for c in s:
            chn = ord(c)
            if 97 <= chn < 97+26:
                chn -= 97 + diff
                chn = (chn % 26) + 97
                dec.append(chr(chn))
            else: dec.append(c)
        ss = ''.join(dec)
        if 'the' in ss or 'that' in ss or 'this' in ss:
            print(ss)
            break
    try: s = input()
    except EOFError: break


Measured memory_bytes: 7452
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define ll long long
int h,w,a,b,ans[1002][1002];
int x[1002],y[1002];
int main()
{
	//freopen("stone.out","w",stdout);
    //freopen("stone.in","r",stdin);
    scanf("%d%d%d%d",&h,&w,&a,&b);
    for(int i=1;i<=h;i++)
    {
		if(i<=b)
		{
			for(int j=1;j<=a;j++)printf("1");
			for(int j=a+1;j<=w;j++)printf("0");
		}
		else
		{
			for(int j=1;j<=a;j++)printf("0");
			for(int j=a+1;j<=w;j++)printf("1");
		}
		printf("\n");
    }
    //printf("-1");
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const ll MOD=998244353;

int main(){
  int N; cin >> N; int p[N];
  rep(i, N){
    cin >> p[i]; p[i]--;
  }
  vector<ll> a(N), b(N);
  rep(i, N-1){
    if(p[i+1]>p[i]){
      a[p[i+1]] = a[p[i]]+2*(p[i+1]-p[i])*10000;
      b[p[i+1]] = b[p[i]]-2*(p[i+1]-p[i])*10000+1;
    }
    else{
      a[p[i+1]] = a[p[i]]-2*(p[i]-p[i+1])*10000+1;
      b[p[i+1]] = b[p[i]]+2*(p[i]-p[i+1])*10000;
    }
  }
  int t = a[0];
  rep(i,N){
    a[i]+=(1-t);
  }
  t = b[N-1];
  rep(i, N){
    b[i]+=(1-t);
  }
  rep(i, N){
    cout << a[i]; cout << " ";
  }
  cout << endl;
  rep(i, N){
    cout << b[i]; cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1024
n=int(input())
dic={}

for i in range(n):
    s=input()
    count=dic.get(s,0)
    count+=1
    dic[s]=count
mx=1
for v in dic.values():
    mx=max(v,mx)
ans=[]
for k,v in dic.items():
    if v==mx:
        ans.append(k)
ans.sort()
#print("---")
for st in ans:
    print(st)




Measured memory_bytes: 32096
n, k = list(map(int, input().split(' ')))
aaa = sorted(list(map(int, input().split(' '))))
mmm = 1000000000 + 7
# 二項係数 mod [検索]
fac = []
inv = []
inv_fac = []
def init(n):
    fac.append(1)
    fac.append(1)
    inv.append(0)
    inv.append(1)
    inv_fac.append(1)
    inv_fac.append(1)
    for i in range(2, n):
        fac.append(fac[-1] * i % mmm)
        inv.append(mmm - inv[mmm%i] * (mmm // i) % mmm)
        inv_fac.append(inv_fac[-1] * inv[-1] % mmm)

def choice(a, b):
    if a < b:
        return 0
    return fac[a] * (inv_fac[b] * inv_fac[a-b] % mmm) % mmm
ans = 0
init(1000000)
for target in range(n):
    p_pattern = choice(target, k-1)
    #print(target, k-1, 'p_choice', choice(target, k-1))
    n_pattern = choice(n-target-1, k-1)
    #print(n-target-1, k-1, 'n_choice', choice(n-target-1, k-1))
    ans = (ans + aaa[target] * p_pattern - aaa[target] * n_pattern) % mmm
    #print(aaa[target], target-1, n-target, k-1, p_pattern, n_pattern)
print(ans % mmm)

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


int main()
{
	int n;
	int steps = 0;
	int j = 1;
	cin >> n;

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

	int maximum = 0;
	for (int i = 0; i < n; i++)
	{
		steps = 0;
		while (arr[i+1] <= arr[i] && i < n - 1)
		{
			i++;
			steps++;
		}
		if (steps > maximum) maximum = steps;
	}


	cout << maximum << endl;

	return 0;
}


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

char s[110];
int n;

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if(n & 1) return puts("No"), 0;
	for(int i = 2; i <= n; i += 2)
		if(s[i] != 'i' || s[i - 1] != 'h') return puts("No"), 0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long k,a,b,count=0;
cin>>k>>a>>b;
for(long long i=a;i<=b;i++)
{
if((i%k)==0)
{
count++;
break;
}}
if(count>0)
cout<<"OK"<<endl;
else
cout<<"NG"<<endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int k;
    cin >> k;
    string ans = "";
    Srep(k) ans += "ACL";
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n;
    scanf("%d",&n);
    vector<int> d(n,0);
    for (int i = 0; i < n; i++) scanf("%d",&d[i]);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

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

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

bool check(vector<vector<vector<ll>>>& b, int t, int M) {
	int n = b.size();
	for (int x = 0; x < n; x++) {
		for (int y = 0; y < n; y++) {
			for (int z = 0; z < n; z++) {
				if (b[x][y][z] != t) continue;
				for (int i = 0; i < 13; i++) {
					int cnt = 1;
					int nx = x;
					int ny = y;
					int nz = z;
					while (1) {
						nx = nx + dx[i];
						ny = ny + dy[i];
						nz = nz + dz[i];
						if (nx < 0 or nx >= n or ny < 0 or ny >= n or nz < 0 or nz >= n) break;
						if (b[nx][ny][nz] == t) cnt++;
						else break;
						if (cnt >= M) return true;
					}
				}
			}
		}
	}
	return false;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		ll n, m, p; scanf("%lld %lld %lld", &n, &m, &p); if (n == 0 and m == 0 and p == 0) break;
		vector<vector<vector<ll>>> board(n, vector<vector<ll>>(n, vector<ll>(n)));
		vector<vector<ll>> next(n, vector<ll>(n));
		vector<pair<ll, ll>> vp(p);;
		for (int i = 0; i < p; i++) {
			scanf("%lld %lld", &vp[i].first, &vp[i].second);
			vp[i].first--;
			vp[i].second--;
		}
		int win = 0;
		int res = 0;
		for (int i = 0; i < p; i++) {
			int x = vp[i].first;
			int y = vp[i].second;
			int t = (i % 2 == 0) ? 1 : 2;
			if (next[x][y] == n) {
				break;
			}
			board[x][y][next[x][y]] = t;
			next[x][y]++;
			if (check(board, t, m)) {
				win = t;
				res = i + 1;
				break;
			}
		}
		if (win == 0) puts("Draw");
		else if (win == 1) printf("Black %d\n",res);
		else printf("White %d\n",res);
	}
	return 0;

}



Measured memory_bytes: 3296
#include<iostream>
#include<random>
using namespace std;
std::random_device rnd;
std::mt19937 mt(rnd());
std::uniform_int_distribution<> r(1, 26);
int D=365,c[26+1],last[26+1],M;
int main(){
    cin>>D;
    //input
    int s[D+1][26+1];
    for(int i=1;i<=26;i++)cin>>c[i];
    for(int i=1;i<=D;i++)for(int j=1;j<=26;j++)cin>>s[i][j];
    //output:random
    int t[D+1];
    for(int i=1;i<=D;i++){
        //greedy:s[i][type]
        int max_type=0,max=0;
        for(int type=1;type<=26;type++){
            if(s[i][type]>max)max=s[i][type],max_type=type;
        }
        t[i]=max_type;
    }
    for(int i=1;i<=D;i++)cout<<t[i]<<endl;
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(256);
    for(int i=0;i<n;i++) cin >>a[i];
    
    int max_v=a[0], min_v=a[0];
    for(int i=1;i<n;i++){
        if(a[i]>max_v){
            max_v=a[i];
        } else if(a[i]<min_v){
            min_v=a[i];
            
        }
    }

    cout << max_v-min_v << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
const int MAXN = (1 << 20);

int n, k;
int a[MAXN];

void read()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
}

int ans = 0;
int depth[MAXN], dist[MAXN], par[MAXN];
vector<int> G[MAXN];

void dfs(int u, int pr, int d = 0)
{
	dist[u] = d;
	depth[u] = 0;

	for(int v: G[u])
		if(v != pr)
		{
			dfs(v, u, d + 1);			
					depth[u] = max(depth[u], depth[v] + 1);
		}
}

void solve_dfs(int u)
{
	int nw_depth = 0;
	for(int v: G[u])
	{
		solve_dfs(v);
		if(u != 1 && depth[v] + 1 == k)
		{
			ans++;
			continue;
		}
		
		nw_depth = max(nw_depth, depth[v] + 1);
	}

	depth[u] = nw_depth;
}

void solve()
{
	if(a[1] != 1) ans++, a[1] = 1;
	for(int i = 2; i <= n; i++)
		G[a[i]].push_back(i);

	dfs(1, 1);
	solve_dfs(1);

	cout << ans << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 36992
#include <bits/stdc++.h>
#define INF 1<<19
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	int cnt[1<<20];
	segtree(){
		for(int i=0;i<N*2;i++){
			dp[i]=INF;
			cnt[i]=0;
		}
	}
	void update(int k,int v){
		k+=N-1;
		dp[k]=v;
		if(v==INF){
			cnt[k]=0;
		}else{
			cnt[k]=1;
		}
		while(k>0){
			k=(k-1)/2;
			dp[k]=min(dp[k*2+1],dp[k*2+2]);
			cnt[k]=cnt[k*2+1]+cnt[k*2+2];
		}
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return INF;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		return min(vl,vr);
	}

	int query2(int a,int b,int k=0,int l=0,int r=N){
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return cnt[k];
		int mid=(l+r)/2;
		int vl=query2(a,b,k*2+1,l,mid);
		int vr=query2(a,b,k*2+2,mid,r);
		return vl+vr;
	}
};

segtree seg[4];
int bit[300005];

int main(void){
	int q;
	string a,b;
	cin >> q >> a >> b;
	int n2=a.size();
	int m2=b.size();
	for(int i=0;i<n2;i++){
		if(a[i]=='1'){
			bit[i+max(0,m2-n2)]^=1;
		}
	}
	for(int i=0;i<m2;i++){
		if(b[i]=='1'){
			bit[i+max(0,n2-m2)]^=2;
		}
	}
	int n=max(n2,m2);
	for(int i=0;i<n;i++){
		seg[bit[i]].update(i,i);
	}
	for(int i=0;i<q;i++){
		char c;
		scanf(" %c",&c);
		if(c=='Q'){
			int pos[4];
			for(int j=0;j<4;j++){
				pos[j]=seg[j].dp[0];
			}
			if(min(pos[1],pos[2])>pos[3]){
				printf("%d\n",n-pos[3]);
			}else if(pos[1]<pos[2]){
				if(seg[0].query(pos[1],n)>seg[3].query(pos[1],n)){
					printf("%d\n",n-pos[1]);
				}else if(seg[2].query(pos[1],n)>seg[3].query(pos[1],n)){
					int v=seg[3].query(pos[1],n);
					printf("%d\n",n-v+seg[1].query2(0,v));
				}else{
					int v=seg[2].query(pos[1],n);
					if(seg[0].query(v,n)>seg[3].query(v,n)){
						printf("%d\n",n-min(v,n)+seg[1].query2(0,v));
					}else{
						printf("%d\n",max(n-min(v,n)+seg[1].query2(0,v)-1,0));
					}
				}
			}else{
				if(seg[0].query(pos[2],n)>seg[3].query(pos[2],n)){
					printf("%d\n",n-pos[2]);
				}else{
					printf("%d\n",n-pos[2]-1);
				}
			}
		}else{
			int a;
			scanf("%d",&a);
			a=n-a-1;
			seg[bit[a]].update(a,INF);
			if(c=='A'){
				bit[a]^=1;
			}else{
				bit[a]^=2;
			}
			seg[bit[a]].update(a,a);
		}
	}
	return 0;
}


Measured memory_bytes: 37476
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <memory.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    vector<int> S(N), L(N), P(N);
    for (int n = 0; n < N; ++n) {
        cin >> S[n] >> L[n] >> P[n];
    }
    int M;
    cin >> M;
    vector<int> W(M);
    for (int m = 0; m < M; ++m) {
        cin >> W[m];
    }
    
    int DP[395][395];
    memset(DP, 0, sizeof(DP));
    for (int n = 1; n <= N; ++n) {
        for (int w = 0; w <= 395; ++w) {
            DP[n][w] = DP[n-1][w];
            if (w >= S[n-1]) {
                for (int k = max(0, w-L[n-1]); k <= w-S[n-1]; ++k) {
                    DP[n][w] = max(DP[n][w], DP[n-1][k] + P[n-1]);
                    DP[n][w] = max(DP[n][w], DP[n][k] + P[n-1]);
                }
            }
        }
    }
    
    for (int m = 0; m < M; ++m) {
        if (DP[N][W[m]] == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    for (int m = 0; m < M; ++m) {
        cout << DP[N][W[m]] << endl;
    }
    

    return 0;
}



Measured memory_bytes: 3720
import numpy as np
N, M, X = map(int, input().split())
C = []
A = np.zeros((N, M), dtype=int)
for i in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A[i] = a

S = np.sum(A, axis=0)
if True in (S < X):
    print(-1)
    exit(0)

C_ = []
for i in range(2**N):
    total = 0
    arr = np.zeros((M,),dtype=int)
    for j in range(N):
        if ((i>>j) & 1) == 1:
            total += C[j]
            arr += A[j]
    if True in (arr < X):
        continue
    C_.append(total)
print(min(C_))

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

int color[210];
//0は未確定、1は黒、２は白で塗るものとして、BFSで二部グラフ判定
int dist[210][210];
const int inf = 1e8;

void chmin(int &a, int b){ if( a > b ){ swap(a,b);} return ;}

int main(){
 int n; cin >> n;
  vector<vector<int>> to(n);
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){ 
      dist[i][j] = inf;
    }
  }

  for(int i = 0; i < n; i++){ dist[i][i] = 0;}
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){ 
     char c; cin >> c; ;
      if( c == '1'){ to[i].push_back(j); to[j].push_back(i);//隣接リスト作成
                     dist[i][j] = c-'0';}
    }
  }
  
  memset(color, 0, sizeof(color));
  
  color[0] = 1; //グラフは連結だから０からBFSすれば全ての点を調べられる
  
  queue<int> Q; Q.push(0);
  
  while(!Q.empty()){ 
   int p = Q.front(); Q.pop();
    for(int k = 0; k < to[p].size(); k++){ 
      int q = to[p][k];
      if( color[q] != 0){
        if( color[p] == color[q]){ cout << -1 << endl; return 0;}
        //二部グラフではなかった
      }
      else{
        if(color[p] == 1){color[q] = 2;}
        else{color[q] = 1;}
        
        Q.push(q);
      }
    }
  }
  
  int res = 0;
  
  for(int k = 0; k < n; k++){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){ 
        chmin(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      res = max(res, dist[i][j]);
    }
  }
  
  cout << res+1 << endl; return 0;}
  

    
  
  
    
  

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

class Dice
{
public:
	int n[6];
	
	void Input()
	{
		cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4] >> n[5];
	}
	
	void Set(int a, int b, int c, int d, int e, int f)
	{
		n[0] = a;
		n[1] = b;
		n[2] = c;
		n[3] = d;
		n[4] = e;
		n[5] = f;
	}
	
	void Roll(char c)
	{
		switch(c)
		{
			case 'N':
				Set(n[1], n[5], n[2], n[3], n[0], n[4]);
				break;
			case 'W':
				Set(n[2], n[1], n[5], n[0], n[4], n[3]);
				break;
			case 'S':
				Set(n[4], n[0], n[2], n[3], n[5], n[1]);
				break;
			case 'E': 
				Set(n[3], n[1], n[0], n[5], n[4], n[2]);
				break;
		};
	}
	
	bool operator==(Dice d)
	{
		for(int i = 0; i < 6; ++i)
		{
			if(n[i] != d.n[i])
			{
				return false;
			}
		}
		
		return true;
	}
	
	bool Equal(Dice d)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			d.Roll(cmd[i]);
			if(*this == d)
			{
				return true;
			}
		}
		
		return false;
	}
	
	int Find(int t, int f)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			Roll(cmd[i]);
			if(n[0] == t && n[1] == f)
			{
				return n[2];
			}
		}
		
		return 0;
	}
};

int main()
{
	Dice d;
	d.Input();
	
	int N;
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		int f, t;
		cin >> t >> f;
		
		Dice dice = d;
		cout << dice.Find(t, f) << endl;
	}
	
	return 0;
} 


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  map<ll,int> mp;
  int n;
  cin >> n;
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
  }
  for(auto it : mp){
    if(it.se>1){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

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


int main(){
   int a,b,c;
   int k;
   scanf("%d%d%d%d",&a,&b,&c,&k);
   c*=(int)pow(2,k);
   bool flag=false;
   if(a<b&&b<c){
        flag=true;
    }
   for(int i=0;i<k;i++){
    b*=2;
    c/=2;
    if(a<b&&b<c){
        flag=true;
        break;
    }
   }
   printf("%s",flag?"Yes":"No");
   return 0;
}


Measured memory_bytes: 4200
#include <cstdio>
#include <stack>
#include <vector>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (register int i = 1; i <= stop; ++i)

const int is = 1 << 17;
char ib[is], *ip = ib + is, it;
inline char getc() {
	if (ip == ib + is) { fread_unlocked(ib, 1, is, stdin); ip = ib; }
	return *ip++;
}
inline int read() {
	int r = 0;
	if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
	else while ((it = *ip++) & 16) r = r * 10 + it - '0';
	return r;
}

const int os = 1 << 17;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
	*op++ = c;
	if (op == ob + os) { fwrite_unlocked(ob, 1, os, stdout); op = ob; }
}
// x shoud be greater than or equal to zero
inline void write(int x) {
	char d[6];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putc(d[i]);
	}
	putc(' ');
}

i64 cnt[200001];
bool used[200001];
signed main() {
  i64 N = read(), Q = read();
  vector<vector<i64>> G(N + 1);
  REP(_, N - 1) {
    i64 a = read(), b = read();
    G[a].push_back(b);
    G[b].push_back(a);
  }
  REP(_, Q) {
    i64 p = read(), x = read();
    cnt[p] += x;
  }
  stack<i64> st;
  st.push(1);
  while (st.size()) {
    i64 a = st.top();
    st.pop();
    used[a] = true;
    for (i64 b : G[a]) {
      if (!used[b]) {
        cnt[b] += cnt[a];
        st.push(b);
      }
    }
  }
  REP(i, N) {
    printf("%d ", cnt[i]);
//    write(cnt[i]);
  }
//  fwrite_unlocked(ob, 1, op - ob, stdout);
}


Measured memory_bytes: 18160
#include<stdio.h>
#include<math.h>

typedef struct box{//頂点のx,y座標をメンバとした構造体
	double x;
	double y;
} point;

void kock(int n,point p1,point p2)//p1-p2間で正三角形を形成し、各頂点座標を出力しながら各辺に置いて再帰
{
	point s,t,u;
	if(n==0) return;
	s.x=(2*p1.x+p2.x)/3;//内分の性質を利用
	s.y=(2*p1.y+p2.y)/3;
	t.x=(p1.x+2*p2.x)/3;
	t.y=(p1.y+2*p2.y)/3;
	u.x=(t.x-s.x)*cos(M_PI*1/3)-(t.y-s.y)*sin(M_PI*1/3)+s.x;//回転行列を利用
	u.y=(t.x-s.x)*sin(M_PI*1/3)+(t.y-s.y)*cos(M_PI*1/3)+s.y;
	//ここまでで正三角形の頂点座標を計算
	kock(n-1,p1,s);//左端に近い辺から再帰
	printf("%.8f %.8f\n",s.x,s.y);//頂点座標を出力
	kock(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	kock(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	kock(n-1,t,p2);
}


int main(void)
{
	int n;
	point p1,p2;
	scanf("%d",&n);
	p1.x=0;//初期値
	p1.y=0;
	p2.x=100;
	p2.y=0;
	printf("%.8f %.8f\n",p1.x,p1.y);
	kock(n,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);
	
	return 0;
}


Measured memory_bytes: 2088
#include<cstdio>
#include<algorithm>
int a[100000];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    std::sort(a,a+n);
    int s=n-1;
    while(s>0&&a[s]!=a[s-1])s--;
    int t=s-2;
    while(t>0&&a[t]!=a[t-1])t--;
    if(t<=0)printf("0");
    else printf("%lld",(long long)a[s]*a[t]);
    return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
    else if (A + B < C + D) {
    cout << "Right" << endl;
  }
    else if(A + B == C + D){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	for(int i=1;i<10;i++) for(int j=1;j<10;j++) {
		if(i*j==n) {
			print("Yes");
			return 0;
		}
	}
	print("No");
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left

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

dics = []
q = []
Ind = []
ans = [0]*N

for i, a in enumerate(A):
    ia = bisect_left(q, a)
    if ia == len(q):
        Ind.append(i)
        q.append(a)
        dics.append({a:1})
    else:
        dic = dics[ia]
        if not a in dic.keys():
            dic[a] = 1
        else:
            dic[a] += 1

L = len(q)
for l in reversed(range(L)):
    if l == 0:
        for k, v in dics[0].items():
            ans[Ind[0]] += k*v
    else:
        bef = q[l-1]
        for k, v in dics[l].items():
            ans[Ind[l]] += (k-bef)*v
            dics[l-1][bef] += v

for a in ans:
    print(a)

Measured memory_bytes: 50344
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n; scan(n);
  print(n / 3);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

template<typename T>
using v = vector<T>;



int main() {
	int N, M;
	cin >> N >> M;
	if (M > N) {
		int tmp = N;
		N = M;
		M = tmp;
	}
	// N>M
	if (N - M > 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	rep(i, N) {
		ans *= i + 1;
		ans %= MOD;
	}
	rep(i, M) {
		ans *= i + 1;
		ans %= MOD;
	}
	if (N == M) {
		ans *= 2;
		ans %= MOD;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    k, x = map(int, input().split())

    left = max(-1000000, x - (k-1))
    right = min(1000000, x + (k-1))

    ans = [i for i in range(left, right+1)]

    print(*ans)


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	long n = sc.nextLong();
      	long m = sc.nextLong();
      	long res = (n-2)*(m-2);
      	System.out.println(res >= 0 ? res : res*-1);
    }
}

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

const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};
bool seen[50][50];
void dfs(vector<vector<int>> C, int h, int w, int a, int b){
    seen[a][b]=true;
    for (int i=0; i<8; i++) {
        int aa=a+dx[i];
        int bb=b+dy[i];
        if (aa<0 || bb<0 || aa>=h || bb>=w) continue;
        if (C[aa][bb]==0) {
            continue;
        }
        if (seen[aa][bb]==true) continue;
        dfs(C,h,w,aa,bb);
    }
}

int main() {
    int w,h;
   cin >> w >> h;
   int total=0;
   vector<int> x;
   while(w!=0 || h!=0) {
       total++;
   vector<vector<int>> C(h,vector<int>(w));
   for (int i=0; i<h; i++) {
       for (int j=0; j<w; j++) {
           int p;
           cin >> p;
           C[i][j]=p;
       }
   }
   int count=0;

   for (int i=0; i<h; i++) {
       for (int j=0; j<w; j++) {
           seen[i][j]=false;
       }
   }

   for (int i=0; i<h; i++) {
       for (int j=0; j<w; j++) {
           if (seen[i][j]==true) continue;
           if (C[i][j]==0) continue;
           count++;
           dfs(C,h,w,i,j);
           
       }
   }


   x.push_back(count);
   int a,b;
   cin >> a >> b;
   w=a,h=b;
   }
   for (int i=0; i<total; i++) {
       cout << x[i] << endl;
   }
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int h, n;
    cin >> h >> n;
    int a[n];
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
import itertools
while True:
    n,x = list(map(int, input().split()))
    if n == x == 0:
        break
    a = []
    for i in range(1, n+1):
        a.append(i)
    b = list(itertools.combinations(a,3))
    c = []
    for i in range(len(b)):
        if sum(b[i]) == x:
            c.append(b[i])
    print(len(c))

Measured memory_bytes: 31420
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
	int u, minv;
	int d[MAX], p[MAX], color[MAX];
	
	for(int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}
	
	d[0] = 0;
	
	while(1) {
		minv = INFTY;
		u = -1;
		for(int i = 0; i < n; i++) {
			if(minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
	   if(u == -1) break;
	   color[u] = BLACK;
	   for(int v = 0; v < n; v++) {
           if(color[v] != BLACK && M[u][v] != INFTY){
		   	  if(d[v] > M[u][v]) {
	   		      d[v] = M[u][v];
   		          p[v] = u;
           	   	  color[v] = GRAY;
   	           }
           }
   	   }	
	}
	int sum = 0; 
	for(int i = 0; i < n; i++) {
		if(p[i] != -1) sum += M[i][p[i]];
	}
	return sum;
} 

int main() {
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++){
			int e;
			cin >> e;
			M[i][j] = (e == -1) ? INFTY :e;
		}
	}
	
	cout << prim() << endl;
	
	return 0;
}

Measured memory_bytes: 3100
s=input()
n=len(s)
m=2019

ak10k = [(pow(10,n-k-1,m)*int(s[k]))%m for k in range(0,n)]+[0]

ruiseki=[0]*n
ruiseki[0]=ak10k[0]
for i in range(1,n):
    ruiseki[i]=(ruiseki[i-1]+ak10k[i])%2019

from collections import Counter
c = Counter(ruiseki)

ans=sum(cc*(cc-1)//2 for cc in c.values()) + c[0]

print(ans)

Measured memory_bytes: 89716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long f(long long a,long long b){
    if(a==0||b==0) return -max(a,b);
    if(b<a) swap(a,b);
    return 2*a*(b/a)+f(a,b%a);
}
int main(){
    long long n,x; cin>>n>>x;
    cout<<n+f(x,n-x)<<endl;
    return 0;
}


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

int main()
{
    unordered_map<int,int> s;
    int res = 0;
    int n,a;
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&a);
        s[a]++;
    }
    for(auto p : s) {
        int x = p.first;
        if(s[x]>1) continue;
        if(x!=1 && s.count(1)) continue;
        bool valid = true;
        for(int i=2;i<=sqrt(x) && valid;i++) {
            if(x%i==0) {
                    int com = x/i;
            if(s.count(com) || s.count(i))
                    valid = false;
            }
        }
        if(valid) {
                res++;
//                printf("test %d\n",x);
        }
    }
    printf("%d\n", res);
}


Measured memory_bytes: 11524