akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(0, i, N)
    {
        cin >> A.at(i);
    }

    sort(all(A));
    reverse(all(A));

    ll ans = A.at(0);

    rep(1, i, N - 1)
    {
        ans += A.at((i - 1) / 2 + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,t = LI()
    aa = sorted([LI() for _ in range(n)])
    m = max(map(lambda x: x[0], aa))
    r = [0] * (t+m+1)
    for a,b in aa:
        for i in range(t-1,-1,-1):
            if r[i+a] < r[i] + b:
                r[i+a] = r[i] + b

    return max(r)


print(main())




Measured memory_bytes: 69868
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(1..2*N).to_a
f=a I[0,N]
l,r=0,N
9.times{
m=(l+r)/2
f==a(I[m,N])?l=m:r=m
}
x=I[r,N-1]
y=I-I[l,N+1]
I.map{|i|
s+=a([i]+(x.index(i)?y:x))[0]
}
puts s

Measured memory_bytes: 4300
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define l long long
int main()
{
  string s;
  cin>>s;
  l n=s.size();
  l a[n]={0};
  l k,m;
  for(l i=0;i<n-1;i++)
  {
    if(s[i]=='R'&&s[i+1]=='L')
    {
      k=i-1;
      m=i+2;
      a[i]++;
      a[i+1]++;
      while(s[k]=='R')
      {
        if((i-k)%2==0)
        {
          a[i]++;
        }
        else
        {
          a[i+1]++;
        }
        k--;
      }
      while(s[m]=='L')
      {
        if((m-i-1)%2==0)
        {
          a[i+1]++;
        }
        else
        {
          a[i]++;
        }
        m++;
      }
    }
  }
  for(l i=0;i<n;i++)
  {
    cout<<a[i]<<" ";
  }
  return 0;
}    

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int b[200010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if((a[i]+i+1)<=200005&&a[i]<=200000){
			b[a[i]+i+1]++;
		}
		if((i-a[i]+1)>=0) ans+=b[i-a[i]+1];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5172
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	int a[11]={0};
    int n,mx=0,sum=0;
    cin>>n;
    REP(i,n){
        cin>>a[i];
        mx=max(a[i],mx);
        sum+=a[i];
    }
    if(sum-mx>mx){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <cstdlib>
#include <algorithm>

using namespace std;

main(){
    int size; cin >> size;
    int num;
    int sum = 0;
    vector<int> arr(size,0);
    for(int i=0;i<size;++i){
        cin >> num;
        sum += num;
        arr[i] = num;
    }
    sort(arr.begin(),arr.end());
    if(sum%10!=0) cout << sum << endl;
    else{ 
        int i;
        for(i;i<size;++i){
            sum -= arr[i];
            if(sum%10!=0) break;
            sum += arr[i];   
        }
        if(i>=size-1) cout << 0 << endl;
        else cout << sum << endl;
    }
}

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


int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  for(int i=1;i<=n;++i){
    int p;
    cin >> p;
    a[p]=i;
  }
  int ans=0;
  int cnt=1;
  for(int i=1;i<=n;++i){
    if(a[i]<a[i+1])cnt++;
    else{
      ans=max(ans,cnt);
      cnt=1;
    }
  }
  ans=max(ans,cnt);
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
vector<ull>hashh,power;
void Roliha(string &s){
  ull B=1000000007;
  int sz=s.size();
  hashh.assign(sz+1,0);
  power.assign(sz+1,0);
  power[0]=1;
  for(int i=1;i<=sz;i++)power[i]=power[i-1]*B;
  for(int i=1;i<=sz;i++)hashh[i]=(hashh[i-1]+s[i-1])*B;
}
ull get_hash(int l,int r){return hashh[r]-hashh[l]*power[r-l];}
int main(){
  int n,m,l=0,r=1;
  string s,t;
  cin>>n>>m>>s;
  unordered_set<ull>p;
  Roliha(s);
  while(m--&&cin>>t){
    if(t[0]=='R')t[1]=='+'?r++:r--;
    else t[1]=='+'?l++:l--;
    p.insert(get_hash(l,r));
  }
  cout<<p.size()<<endl;
}

Measured memory_bytes: 21912
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > 0) {
            so.println("Positive");
            return;
        }
        
        if (b < 0) {
            so.println((b - a) % 2 == 0 ? "Negative" : "Positive");
            return;
        }
        
        so.println("Zero");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pb push_back
#define tam 900000
#define se second
#define fi first
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<int,int> ii;
string f(int num)
{
    stringstream ss;
    ss<<num;
    string txt;
    ss>>txt;
    return txt;
}
int valid[100];
int main()
{
    int N,K;
    cin>>N>>K;
    memset(valid,0,sizeof valid);
    int num;
    forr(i,0,K){
        cin>>num;
        valid[num]=1;
    }
    string totxt;
    forr(i,N,tam)
    {
        totxt=f(i);
        bool cond=true;
        forr(j,0,totxt.size())
        {
            if (valid[totxt[j]-'0']==1)
                cond=false;
        }
        if (cond)
        {
            cout<<i<<endl;
            break;
        }
    }
}   

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //CASH MONEY
 
	public static void main(String[] args) { //Ball out dawg
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		long H = I.nextLong();
		long[][] dmg = new long[N][2];
		long maxWield = 0;
		long ans = 0;
		PriorityQueue<Long> thr = new PriorityQueue<Long>(Collections.reverseOrder());
		for (int i = 0; i < N; i++) {
			dmg[i][0] = I.nextLong();
			dmg[i][1] = I.nextLong();
			maxWield=Math.max(maxWield, dmg[i][0]);
		}
		for (int i = 0; i < N; i++) {
			thr.add(dmg[i][1]);
		}
		while (!thr.isEmpty()) {
			long cur = thr.poll(); //Can use max wield sword to throw once at end as well
			if (cur>=maxWield) {
				H-=cur;
				ans++;
			}
			else break;
			if (H<=0) break;
		}
		if (H>0) {
			ans+=ceil(H,maxWield);
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

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

using namespace std;
using ll = long long;

ll N, K;
vector<ll> A, F;

bool check(ll x) {
  ll cost = 0;
  for (int i = 0; i < N; i++) {
    ll need = x / F[i];
    cost += max(0LL, A[i] - need);
  }
  return cost <= K;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  A.assign(N, 0), F.assign(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> F[i];
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  ll lo = 0, hi = 1e12;
  while (lo < hi) {
    ll mi = (lo + hi) / 2;
    if (check(mi)) {
      hi = mi;
    } else {
      lo = mi + 1;
    }
  }
  cout << lo << '\n';
  return 0;
}


Measured memory_bytes: 3328
n=int(input())
s=list(map(int ,input().split()))

sum=[0]*n

sum[-1]=s[-1]

for i in range(n-2,-1,-1):
    sum[i]=sum[i+1]+s[i]

ans=0
for i in range(n-1):
    ans=ans+sum[i+1]*s[i]

print(ans%(1000000007))


Measured memory_bytes: 31532
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;



int main()
{
	int n;
	cin >> n;
	vector<int> a(n+2);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	a[0] = 0;
	a[n + 1] = 0;
	int s = 0;
	for (int i = 0; i < a.size()-1; i++) {
		s += abs(a[i] - a[i + 1]);
	}
	for (int i = 1; i <= n; i++) {
		cout << s - (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]) << endl;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include<vector>
#include<algorithm>
#include<list>
#include<string>
using namespace std;
using ll=long long ;
int main(){
	int n,cnt=0,ue=0,sita=0;
	string name;
	cin >> n;
	vector<string> str(n);
	for(int i=0;i<n;i++)	cin >> str[i];
	cin >> name;
	for(int i=0;i<n;i++){
		string keep1="",keep2="";
		for(int j=0;j<str[i].size();j++){
			if(str[i][j]=='?'){
				keep1+='a';
				keep2+='z';
			}
			else{
				keep1+=str[i][j];
				keep2+=str[i][j];
			}
		}
		if(keep1<name&&keep2<name)	ue++;
		else if(keep1>name&&keep2>name)	sita++;
		else cnt++;
	}
	//cout << ue << ' ' << sita << ' ' << cnt << endl;
	for(int i=ue+1;i<=ue+1+cnt;i++){
		if(i!=ue+1)	cout << ' ';
		cout << i;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 896
s = input()
if len(s) == 1:
    ans = 0
else:
    ans_w = sum([ 1 for i in s[::2] if i != '1']) + sum([ 1 for i in s[1::2] if i != '0'])
    ans_b = sum([ 1 for i in s[::2] if i != '0']) + sum([ 1 for i in s[1::2] if i != '1'])
    ans = min([ans_w, ans_b])
print(ans) 

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

#define ll long long
#define mod 1000000007
#define f(i, a, b) for (long long i = a; i < b; i++)
#define fm(i, a, b, c) for (long long i = a; i > b; i--)
#define vi vector<i>
#define vl vector<long long>
#define vs vector<string>
#define t     \
    ll t;     \
    cin >> t; \
    while (t--)
#define pb(i) push_back(i)
#define mp(i, j) make_pair(i, j)
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL)
int main()
{
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vl p;
    vl q;
    vl r;
    f(i, 0, a)
    {
        ll m;
        cin >> m;
        p.pb(m);
    }
    f(i, 0, b)
    {
        ll m;
        cin >> m;
        q.pb(m);
    }
    f(i, 0, c)
    {
        ll m;
        cin >> m;
        r.pb(m);
    }
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    f(i, 0, x)
    {
        r.pb(p[i]);
    }
    f(i, 0, y)
    {
        r.pb(q[i]);
    }
    sort(r.begin(), r.end(), greater<ll>());
    ll sum = 0;
    f(i, 0, x + y)
    {
        sum += r[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 7792
import sys
import math
from collections import deque
import itertools
import copy
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()
ans = 0
N, M = map(int, input().split())
ks = [tuple(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
t = []
for i in range(N):
    tt = list(itertools.combinations(range(1, N+1), i+1))
    for l in tt:
        t.append(l)
t.append(tuple())
for i in range(len(t)):
    pp = 0
    for l in range(M):
        if len(set(ks[l][1:]) & set(t[i])) % 2 == p[l]:
            pp += 1
    if pp == M:
        ans += 1
print(ans)


Measured memory_bytes: 3564
n, k = map(int,input().split())
dList = list(map(int,input().split()))

minN = -1
for i in range(n,10*n+1):
  for j in range(len(str(i))):
    if dList.count(int(str(i)[j])) == 0:
      minN = i
    else:
      minN = -1
      break
  if minN != -1:
    break

print(minN)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read cin >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :
#define var auto&&
#define let const auto

signed main ( ) {

    int n;
    read n;
    if ( n & 1 ) echo 0 fin;
    else {
        int ans = 0;
        for ( int i = 5; i <= n; i *= 5 ) {
            ans += n / (i*2);
        }
        echo ans fin;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

const int MOD = 1000000007;
const int INF = 1000000000;

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


int main(){
    int x; cin >> x;
    FORS(i, 1, 953){
        if(100*i <= x && x <= 105*i){
            cout << 1 << "\n"; return 0;
        }
        if(x < 100*i) break;
    }
    cout << 0 << "\n";
    return 0;
}


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

const int maxN = 111;

int n, sum;
int a[maxN];

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    if (sum % 10) printf("%d\n", sum); else {
        sort(a + 1, a + n + 1);
        for (int i = 1; i <= n; ++i) if (a[i] % 10) {
            printf("%d\n", sum - a[i]);
            return 0;
        }
        puts("0");
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String c = sc.next();
    String a = "a";
    String i = "i";
    String u = "u";
    String e = "e";
    String o = "o";
    if(c.equals(a) || c.equals(i) || c.equals(u) || c.equals(e) || c.equals(o)){
      System.out.println("vowel");
    }
    else{
      System.out.println("consonant");
    }
  }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define sc second
#define int long long
using namespace std;

void solve()
{

}

int32_t main()
{
    int n;
    cin >> n;
    double d, x[n], y[n];
    cin >> d;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
        if (sqrt(x[i] * x[i] + y[i] * y[i]) <= d)
            ans++;
    }
    cout << ans;
}


Measured memory_bytes: 6868
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define repb(i, n) for (int i = (int) n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int) m; i < (int) n; i++)
#define repsb(i, m, n) for (int i = (int) m; i >= (int) n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define pb(a) push_back(a)
#define ll long long int
const ll LLINF = 1e18 + 10;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
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; }
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const * argv[]){
    int n;
    cin>>n;
    vector<int> v(n,-1);
    vector<int> vc(n,-1);
    rep(i,n) cin>>v[i];
    
    rep(i,n)    vc[v[i]-1] = i + 1;
    rep(i,n)    cout<<vc[i]<<endl;
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
using namespace std;
int main(void){
    int S;
    int h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3100
n = int(input())
arr = [input() for _ in range(n)]
ans_dict = {}

for s in arr:
    samp = sorted(s)
    tmp = ""
    for i in samp:
        tmp = tmp + i
    if tmp in ans_dict:
        ans_dict[tmp] += 1
    else:
        ans_dict[tmp] = 1

ans = 0
for i in ans_dict.values():
    ans += i * ( i - 1) / 2
print( int(ans) )
    

Measured memory_bytes: 73176
#include<cstdio>

int main(){
    int N,K,i,j;
    scanf("%d%d",&N,&K);
    
    int A[N];
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    int cnt[N+1];
    for(i=0;i<=N;i++){
        cnt[i] = 0;
    }
    int a = 0;
    for(i=0;i<N;i++){
        a = A[i];
        cnt[a]++;
    }

    int v;
    for(i=1;i<=N;i++){
        v = cnt[i];
        j = i-1;
        while(j >= 0 && cnt[j] < v){
            cnt[j+1] = cnt[j];
            j--;
        }
        cnt[j+1] = v;
    }
    
    int ans = 0;
    for(i=K;i<=N;i++){
        ans+=cnt[i];
    }
    
    printf("%d",ans);
    
}

Measured memory_bytes: 1664
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;

int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003

int dp[353][353]={0};
int bow[353][353]={0};

set<string> a;

int main(){
	
	int n;
	
	while(cin>>n,n!=0){
		
		vector< P > s(n);
		
		rep(i,n)
			cin>>s[i].second>>s[i].first;
		
		sort(s.begin(),s.end());
		
		int b=0;
		
		bool f=false;
		rep(i,n){
			b+=s[i].second;
			if(b>s[i].first)
				f=true;
		}
		if(!f)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}

	
}

Measured memory_bytes: 1196
def solve():

    N, T = map(int, input().split())

    ct = []

    for i in range(N):
        ct.append(list(map(int, input().split())))

    ans = 1001

    for c, t in ct:
        if t <= T:
            ans = min(ans, c)

    if ans <= 1000:
        print(ans)
    else:
        print("TLE")


if __name__ == "__main__":
    solve()


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

int main(){
    int a, b;
    cin >> a >> b;
    int c[3];
    c[0] = a + b;
    c[1] = a - b;
    c[2] = a * b;

    if(c[0] >= c[1]){
        if(c[1] >= c[2]){
            cout << c[0] << endl;
        }else{
            if(c[0] >= c[2]){
                cout << c[0] << endl;
            }else{
                cout << c[2] << endl;
            }
        }    
    }else{
        if(c[0] >= c[2]){
            cout << c[1] << endl;
        }else{
            if(c[1] >= c[2]){
                cout << c[1] << endl;
            }else{
                cout << c[2] << endl;
            }
        }
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
const int SIZEN = 100010;
int N;
int A[SIZEN] = {0};
int a[SIZEN] = {0};
bool flag[SIZEN] = {0};
void work(){
	scanf("%d",&N);
	for(int i = 1;i <= N;i++)flag[i] = false;
	for(int i = 1;i <= N;i++)a[i] = 0;
	for(int i = 1;i <= N;i++){
		scanf("%d",&A[i]);
		if(A[i] != A[i-1]){
			a[i] = A[i];
			flag[a[i]] = true;
		}
	}
	int now = 1;
	for(int i = 1;i <= N;i++){
		if(flag[i])continue;
		while(a[now])now++;
		a[now] = i;
	}
	int mx = 0;
	for(int i = 1;i <= N;i++){
		mx = max(mx,a[i]);
		if(mx != A[i]){
			puts("-1");
			return;
		}
	}
	for(int i = 1;i <= N;i++)printf("%d ",a[i]);printf("\n");
}
int ans[100010] = {0},cnt = 0;
int main(){
	long long N;
	scanf("%lld",&N);
	while(N){
		ans[++cnt] = N % 26;
		N /= 26;
	}
	for(int i = 1;i < cnt;i++){
		if(ans[i] <= 0)ans[i] += 26,ans[i+1]--;
	}
	while(ans[cnt] == 0)cnt--;
	for(int i = cnt;i >= 1;i--){
		printf("%c",ans[i] + 'a'-1);
	}
	
}
/*
26
*/

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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  int Sum=0;
  int Max=0;
  for(int i=0; i<N; i++){
    cin >> L.at(i);
    Max=max(Max, L.at(i));
    Sum+=L.at(i);
  }
  if(2*Max<Sum){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n;
    cin >> n;
    cout << n * n * n;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = [0]*10010

for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x*x + y*y + z*z + x*y + y*z + z*x
            if v <= 10005:
                ans[v] += 1
for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 9304
import sys
readline = sys.stdin.readline
from bisect import bisect_right

def main():
    N, M, K = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    B = list(map(int, readline().rstrip().split()))

    a_acc, b_acc = A[:], B[:]
    for i in range(1, N):
        a_acc[i] += a_acc[i-1]
    
    for i in range(1, M):
        b_acc[i] += b_acc[i-1]
    
    res = 0
    for i, a in enumerate(a_acc):
        if a > K:
            break
        left = K - a
        j = bisect_right(b_acc, left)
        res = max(res, i + 1 + j)
    
    #res = max(res, bisect_right(a_acc, K))
    res = max(res, bisect_right(b_acc, K))

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 47328
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	count := 0
	for i := 0; i < N; i++ {
		if A[i] % 2 == 1 {
			count++
		}
	}
	if count % 2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7424
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	double prob_win = 0.0;
	for (int i = 1; i <= n; ++i) {
		double curr = 1.0 / n;
		int p = i;
		while (p < k) {
			curr *= 0.5;
			p <<= 1;
		}

		prob_win += curr;
	}

	cout << setprecision(12) << prob_win << "\n";

	return 0;

}

Measured memory_bytes: 256
/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define mod ((long long)(1e9+7))

struct room{
	int num;
	int dis;
};

struct comp{
	bool operator()(room a, room b){
		return a.dis > b.dis;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	ll n, m;
	cin>>n>>m;
	vector<vector<int>> g(n+1);
	for(int i = 0; i < m; ++i){
		ll u, v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}


	vector<vector<int>> dis(n+1, vector<int> (2, INT_MAX));
	int cnt = 0;
	priority_queue<room, vector<room>, comp> pq;
	dis[1][0] = 0; pq.push({1, dis[1][0]});
	while(!pq.empty()){
		room cur = pq.top();
		pq.pop();
		cnt++;
		for(int v : g[cur.num]){
			if(dis[v][0] > dis[cur.num][0] + 1){
				dis[v][0] = dis[cur.num][0] + 1;
				dis[v][1] = cur.num;
				pq.push({v, dis[v][0]});
			}
		}
	}

	if(cnt < n){
		cout<<"No";
	}
	else{
		cout<<"Yes";
		for(int i = 2; i <= n; ++i)
			cout<<endl<<dis[i][1];
	}
	return 0;
}

Measured memory_bytes: 15664
#include "bits/stdc++.h"
using namespace std;
const int N = 805;
const int dx[4] = {0 , 1 , 0 , -1};
const int dy[4] = {1 , 0 , -1 , 0};
int n , m , k;
char str[N][N];
int dist[N][N];
pair < int , int > que[N * N];
int ql , qr;
int main(){
	scanf("%d %d %d" , &n , &m , &k);
	for(int i = 1 ; i <= n ; ++i){
		for(int j = 1 ; j <= m ; ++j){
			dist[i][j] = 1e9;
		}
	}
	for(int i = 1 ; i <= n ; ++i){
		scanf("%s" , str[i] + 1);
		for(int j = 1 ; j <= m ; ++j){
			if(str[i][j] == 'S'){
				que[qr++] = make_pair(i , j);
				dist[i][j] = 0;
			}
		}
	}
	while(ql < qr){
		int x = que[ql].first;
		int y = que[ql].second;
		++ql;
		for(int i = 0 ; i < 4 ; ++i){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx < 1 || ny < 1 || nx > n || ny > m){
				continue;
			}
			if(str[nx][ny] == '#'){
				continue;
			}
			if(dist[nx][ny] > dist[x][y] + 1){
				dist[nx][ny] = dist[x][y] + 1;
				que[qr++] = {nx , ny};
			}
		}
	}
	int ans = 1e9;
	for(int i = 1 ; i <= n ; ++i){
		for(int j = 1 ; j <= m ; ++j){
			if(dist[i][j] <= k){
				ans = min(ans , 1 + ((min(min(i - 1 , n - i) , min(j - 1 , m - j)) + k - 1) / k));
			}
		}
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main(){
  int n,m,k;
  cin >> n >> m >> k;
  UnionFind kk(n);
  vector<vector<int>> fr(n,vector<int>(1,-1));
  vector<vector<int>> bl(n,vector<int>(1,-1));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    fr[a].push_back(b);
    fr[b].push_back(a);
    kk.unionSet(a,b);
  }
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    bl[a].push_back(b);
    bl[b].push_back(a);
  }
  int ans[n];
  rep(i,n){
    int aa=kk.size(i);
    int ll=fr[i].size()-1;
    aa-=ll;
    for(int u: bl[i]){
      if(u==-1)continue;
      if(kk.findSet(i,u))aa--;
    }
    ans[i]=aa-1;
  }
  rep(i,n-1)cout << ans[i] << " ";
  cout << ans[n-1] << endl;
}


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

int n, m;
int k[30001], s[30001];

int main()
{
	while (scanf("%d %d", &n, &m), n){
		set<int> T;
		
		for (int i = 1; i <= n; i++){
			scanf("%d", &k[i]);
			k[i] %= m;
			s[i] = (k[i] + s[i - 1]) % m;
		}
		
		int res = 0;
		for (int i = 1; i <= n; i++){
			res = max(res, s[i]);
			set<int>::iterator il = T.lower_bound(0);
			set<int>::iterator ir = T.upper_bound(s[i]);
			int vl = 0, vr = 0;
			if (il != T.end()){
				vl = s[i] - *il;
			}
			if (ir != T.end()){
				vr = (s[i] - *ir + m) % m;
			}
			res = max(res, max(vl, vr));
			T.insert(s[i]);
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 2576
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <string>

using namespace std;


int n;
int h,w,k;

char b[7][7];



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>k;

    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            cin>>b[i][j];
        }
    }
    
    int res = 0;
    for(int i=0;i<=(1<<h);i++) {
        for(int j=0;j<=(1<<w);j++) {

            int cnt = 0;
            for(int ii=0;ii<h;ii++) {

                for(int jj=0;jj<w;jj++) {

                    if(i&(1<<ii) && (j&(1<<jj)) && b[ii][jj]=='#') {
                        cnt++;
                    }
                }
            }
            if(cnt==k) {
                res++;
            }
        }
    }

    cout<<res<<endl;

    

    
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)



bool same(string t){
    bool ok = true;
    char l = t[0];
    for(auto r : t){
        if(r != l)ok = false;
    }
    return ok;
}

void cal(int i,string s,int& ct){
    if(same(s))return;

    char c = 'a' + i;
    string t;
    rep(r,s.size()-1){
        if(s[r] == c || s[r+1] == c)t.push_back(c);
        else t.push_back(s[r]);
    }
    ct++;
    cal(i,t,ct);
}

int main() {
    string s;cin >> s;
    int ans = 1e9;

    rep(i,26){
        int ct = 0;
        cal(i,s,ct);
        ans = min(ans,ct);
    }

    cout << ans << endl;

}

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

int main(){
    int N;
    cin >> N;
    int sum=0;
    int n = N;
    while(N>0){
        sum += N % 10;
        N /= 10;
    }
    if(n%sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main(){
        int n,m;
        cin >> n >> m;
        long long a,b,c;
        long long p[1000][8];
        for(int i=0; i<n; i++){
                cin >> a >> b >> c;
                p[i][0] = a+b+c;
                p[i][1] = p[i][0]*-1;
                p[i][2] = a*-1+b+c;
                p[i][3] = p[i][2]*-1;
                p[i][4] = a+b*-1+c;
                p[i][5] = p[i][4]*-1;
                p[i][6] = a+b+c*-1;
                p[i][7] = p[i][6]*-1;
        }

        long long ans=0;
        for(int i=0; i<8; i++){
                for(int j=0; j<n-1; j++){
                        for(int k=j+1; k<n; k++){
                                if(p[j][i]<p[k][i]){
                                        long long tmp=p[j][i];
                                        p[j][i]=p[k][i];
                                        p[k][i]=tmp;
                                }
                        }
                }
                long long sum=0;
                for(int j=0; j<m; j++) sum+=p[j][i];
                if(ans<sum) ans=sum;
        }

        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
H, W, K = map(int,input().split())
dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1

ck = [0]*9
ck[0] = 1
for i in range(1,9):
  for j in range(2**(i-1)):
    for k in range(i-1):
      if (j>>k)&(j>>(k+1))==True:
        break
    else:
      ck[i] += 1

mod = 10**9+7
for i in range(1,H+1):
  for j in range(W):
    if (j == 0)&(j == W-1):
      dp[i][j] = dp[i-1][j]*(ck[j]*ck[W-1-j])
    elif j == 0:
      dp[i][j] = dp[i-1][j+1]*(ck[j]*ck[W-j-2])+dp[i-1][j]*(ck[j]*ck[W-1-j])
    elif j == W-1:
      dp[i][j] = dp[i-1][j]*(ck[j]*ck[W-1-j])+dp[i-1][j-1]*(ck[j-1]*ck[W-j-1])
    else:
      dp[i][j] = dp[i-1][j+1]*(ck[j]*ck[W-j-2])+dp[i-1][j]*(ck[j]*ck[W-1-j])+dp[i-1][j-1]*(ck[j-1]*ck[W-j-1])

print(dp[H][K-1]%mod)

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

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

    int minimum = (X < Y) ? X : Y;
    int pizza_pair = ((A + B) < (2 * C)) ? (A + B) : (2 * C);
    long long res = 0;
    res = minimum * pizza_pair;

    if (X > Y)
    {
        res += (A > (2 * C)) ? ((X - Y) * 2 * C) : ((X - Y) * A);
    }
    else
    {
        res += (B > (2 * C)) ? ((Y - X) * 2 * C) : ((Y - X) * B);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <queue>
#include <utility>
#define S 60

using namespace std;

int main(void){
	int i, j, x, y, sx, sy, t, n, f[S * 2 + 1][S * 2 + 1], ans, dx[6] = {1,1,0,-1,-1,0}, dy[6] = {1,0,-1,-1,0,1};
	queue<pair<int,int> > que;
	while(1){
		scanf("%d%d",&t,&n);
		if(!t && !n) break;
		memset(f,0,sizeof(f));
		for(i = 0;i < n;i++){
			scanf("%d%d",&x,&y);
			f[x + S][y + S] = -1;
		}
		scanf("%d%d",&sx,&sy);
		que.push(pair<int,int>(sx + S,sy + S));
		while(que.size()){
			x = que.front().first, y = que.front().second;
			que.pop();
			if(f[x][y] >= t) continue;
			for(i = 0;i < 6;i++){
				if(0 <= x + dx[i] && x + dx[i] <= S * 2 && 0 <= y + dy[i] && y + dy[i] <= S * 2 && f[x + dx[i]][y + dy[i]] == 0){
					f[x + dx[i]][y + dy[i]] = f[x][y] + 1;
					que.push(pair<int,int>(x + dx[i],y + dy[i]));
				}
			}
		}
		f[sx + S][sy + S] = 0;
		ans = 1;
		for(i = 0;i <= S * 2;i++)
			for(j = 0;j <= S * 2;j++) if(f[i][j] > 0) ans++;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000

int get(long long A,long long K){

	if(A<K)return 0;
	if(A%K==0)return A/K;
	long long ok = 0LL,ng = 1000000001;
	long long x = A/K;
	while(ng-ok>1){
		long long mid = (ok+ng)/2;
		if(A - (x+1)*mid<0)ng = mid;
		else if((A-(x+1)*mid)/K!=A/K)ng = mid;
		else ok = mid;
	}
	A-=(x+1)*ok;
	if(A%K==0)return A/K;
	return get(A-(x+1),K);
	
}

int main(){
	
	int N;
	cin>>N;
	
	int X = 0;
	
	for(int i=0;i<N;i++){
		int a,k;
		cin>>a>>k;

		X ^= get(a,k);
		
	}
	
	if(X==0)cout<<"Aoki"<<endl;
	else cout<<"Takahashi"<<endl;
	
	return 0;
}

Measured memory_bytes: 3596
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        var nl = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nl[0];
        var l = nl[1];
        Console.WriteLine(Enumerable.Range(l, n).Sum() - Enumerable.Range(l, n).OrderBy(Abs).First());
    }
}



Measured memory_bytes: 11348
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

X = []
N, M = get_ints
M.times do |i|
  a, b = get_ints
  X << [a, 'a', i]
  X << [b, 'b', i]
end
X.sort! do |x, y|
  if (x[0] <=> y[0]) == 0
    if x[1] == 'a'
      1
    elsif y[1] == 'a'
      -1
    else
      0
    end
  else
    x[0] <=> y[0]
  end
end

hash = Hash.new
phase = 0
count = 0
X.each do |v, type, index|
  if type == 'a'
    hash[index] = phase
  else
    if hash[index] == phase
      count += 1
      phase += 1
    end
  end
end

puts count


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

using namespace std;

int main()
{
	string a, b, c, A = "a", B = "b", C = "c", temp = "a";
	cin >> a >> b >> c;
	
	stack<char> sa;
	stack<char> sb;
	stack<char> sc;
	bool condA = false, condB = false, condC = false;
	
	for(int i = a.size()-1; i >= 0; sa.push(a[i]), i--);
	for(int i = b.size()-1; i >= 0; sb.push(b[i]), i--);
	for(int i = c.size()-1; i >= 0; sc.push(c[i]), i--);
	
	while(true)
	{
		if(sa.empty() && temp == A)
		{
			condA = true;
			break;
		}
		else if(sb.empty() && temp == B)
		{
			condB = true;
			break;
		}
		else if(sc.empty() && temp == C)
		{
			condC = true;
			break;
		}
		else if(A == temp)
		{
			temp = sa.top();
			sa.pop();
		}
		else if(B == temp)
		{
			temp = sb.top();
			sb.pop();
		}
		else if(C == temp)
		{
			temp = sc.top();
			sc.pop();
		}
	}
	
	printf("%c\n", (condA)? 'A' : (condB) ? 'B' : 'C');
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll n;
  cin >> n;
  ll l[2000];
  FOR(i,0,n-1) {
    scanf("%lld", &l[i]);
  }

  ll ans = 0;

  sort(l,l+n);

  FOR(i,0,n-3){
    FOR(j,i+1,n-2){
      FOR(k,j+1,n-1){
        if(l[i]+l[j]>l[k]) ++ans;
        else break;
      }
    }
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = A + B;
      int D = A + (A-1);
      int E = B + (B-1);
      if(C>=D && C>=E){
        System.out.println(C);
      }else if(D>=C && D>=E){
        System.out.println(D);
      }else if(E>=C && E>=D){
        System.out.println(E);
      }
    }
}

Measured memory_bytes: 35780
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<=(int)(b);++i)
#define per(i, a, b) for(int i=(a);i>=(int)(b);--i)
#define debug(x)   cout << #x << ' ' << x << endl;
#define one(x) __builtin_popcount(x)
using namespace std;

int main(){
    int n;
    cin >> n;
    int tot = 0;
    rep(i, 1, n){
        if(i < 10)  tot++;
        if(i >= 100 && i < 1000)    tot++;
        if(i >= 10000 && i < 100000)    tot++;
    }
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<int> v(n);

  REP(i, n) cin >> v[i];

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

  ll sum = 0;
  REP(i, k) sum += v[i];

  cout << sum << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>

int a,b,c,d,e,i;

int main(){
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
    if(a == 0)printf("1");
	if(b == 0)printf("2");
    if(c == 0)printf("3");
    if(d == 0)printf("4");
    if(e == 0)printf("5");
	return 0;
}

Measured memory_bytes: 1656
A, B, C, X = [int(input()) for i in range(4)]
count = 0
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if 500 * a + 100 * b + 50 * c == X:
        count += 1
print(count)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int N=1e5+5;
int n,col[N];
vector<int> E[N];
inline void add(int u,int v){E[u].push_back(v),E[v].push_back(u);}

struct Tree{
    int rt,son[N];
    vector<int> E[N];
    int dfs(int u){
	son[u]=1;int res=0;
	for(int v:E[u]){
	    son[u]^=1;int t=dfs(v);
	    if(!t)continue;
	    if(res)add(res,t),res=0;
	    else res=t;
	}
	if(son[u]){
	    if(res)add(res,u),res=0;
	    else res=u;
	}
	return res;
    }
    void Main(){
	REP(i,1,n){
	    int p=read();
	    if(~p)E[p].push_back(i);
	    else rt=i;
	}
	dfs(rt);
    }
} A,B;

void colored(int u){
    for(int v:E[u])
	if(A.son[v]&&!col[v])col[v]=-col[u],colored(v);
}

int main(){
    //freopen("in.in","r",stdin);
    n=read();A.Main(),B.Main();
    REP(i,1,n)if(A.son[i]^B.son[i])return puts("IMPOSSIBLE"),0;
    puts("POSSIBLE");
    REP(i,1,n)if(A.son[i]&&!col[i])col[i]=1,colored(i);
    REP(i,1,n)printf("%d%c",col[i],i==n?'\n':' ');
    return 0;
}


Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define MN 201
#define pb push_back
#define mp make_pair
using namespace std;
int a[3],k;
int main(){
    cin>>a[0]>>a[1]>>a[2]>>k;
    int mx = 0;
    for(int i=0;i<3;i++) mx = max(mx,a[i]);
    int tmp = mx;
    for(int i=1;i<=k;i++) mx = mx*2;
    cout<<(a[0]+a[1]+a[2]-tmp+mx)<<'\n';
    return 0;
}


Measured memory_bytes: 256