akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int N, L;

int sum(int s, int e){
	int t = 0;
	for(int i = s; i <= e; i++) t += i;
	return t;
}

int main(){		
	scanf("%d%d", &N, &L);
	if(L > 0) printf("%d\n", sum(L + 1, L + N - 1));
	else if(L <= 0 && L + N - 1 >= 0) printf("%d\n", sum(L, L + N - 1));
	else printf("%d\n", sum(L, L + N - 2));
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int[] res = new int[S.length()];

        char target = 'L';
        int pos = 0;
        int counter = 0;
        for (int i = 0; i < S.length(); i++) {
            if (target != S.charAt(i)) {
                counter++;
                continue;
            }
            if (target == 'L') {
                counter++;
                target = 'R';
                pos = i;
                int tmp = counter / 2;
                res[pos - 1] += tmp;
                res[pos] += counter - tmp;
                counter = 0;
            } else {
                target = 'L';
                int tmp = counter / 2;
                res[pos] += tmp;
                res[pos - 1] += counter - tmp;
                counter = 1;
            }
        }
        int tmp = counter / 2;
        res[pos] += tmp;
        res[pos - 1] += counter - tmp;

        System.out.println(Arrays.stream(res).mapToObj(String::valueOf).collect(Collectors.joining(" ")));

    }
}


Measured memory_bytes: 35620
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int K, N;
  int i, j;
 
  cin >> K >> N;
  vector<int> vec(N);

  
  for(i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int max = 0;
  for(j=1; j<N; j++){
    if(max < vec.at(j) - vec.at(j-1)){
      max = vec.at(j) - vec.at(j-1);
    }
  }

  
  if (max < K - vec.at(N-1) + vec.at(0)){
    max = K - vec.at(N-1) + vec.at(0);
  }
  
  cout << K - max << endl;

}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = ReadLine();

        var first = int.Parse(N[0].ToString());
        first -= (N.Skip(1).Any(c => c != '9')) ? 1 : 0;

        WriteLine(first + ((N.Length - 1) * 9));
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();
        string t = sc.Next();
        string s2 = string.Join("", s.OrderBy(c => c));
        string t2 = string.Join("", t.OrderByDescending(c => c));

        Console.WriteLine(s2.CompareTo(t2) < 0 ? "Yes" : "No");
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  vector<int> x = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << x[k - 1] << endl;
  return 0;
}

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int>sume(n+1);
    vector<int>sumw(n+1);
    rep(i,n){
       if(s[i]=='W')sumw[i+1]=sumw[i]+1;
       else sumw[i+1]=sumw[i];
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='E')sume[i]=sume[i+1]+1;
        else sume[i]=sume[i+1];
    }
    int ans=1000000;
    for(int i=0;i<n;i++){
        int cnt;
        cnt=sumw[i]+sume[i+1];
        ans=min(cnt,ans);
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3076
N, K = map(int, input().split())
H = list(map(int, input().split()))

cnt = 0
if K >= N:
    cnt = 0
elif 1 <= K < N:
    H_down = sorted(H, reverse = True)
    cnt = sum(H_down[K:])

elif K == 0:
    cnt = sum(H)

print(cnt)

Measured memory_bytes: 26764
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    atcg=set(['A','T','C','G'])
    s=STR()
    ct=0
    for i in range(len(s)):
        if s[i] in atcg:
            temp=1
            for k in range(1,len(s)-i):
                if s[i+k] in atcg:
                    temp+=1
                    #print('aa')
                else:
                    break
            ct=max(temp,ct)
    print(ct)
if __name__ == '__main__':
    do()

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

using namespace std;

bool dfs(int x, int t, int fa, vector<pair<int, int>> *G, long long &a) {
    if (x == t) return true;
    for (int i = 0; i < (int)G[x].size(); ++i) {
        int y = G[x][i].first;
        if (y == fa) continue;
        if (dfs(y, t, x, G, a)) {
            a |= (1LL << G[x][i].second);
            return true;
        }
    }
    return false;
}

long long pow(long long a, long long b) {
    long long res = 1;
    while (b) {
        if (b & 1) res *= a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> G[n];
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].push_back(make_pair(v, i));
        G[v].push_back(make_pair(u, i));
    }
    int m;
    cin >> m;
    vector<long long> a(m);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        dfs(u, v, -1, G, a[i]);
    }
    long long ans = 0;
    for (int i = 0; i < (1 << m); ++i) {
        long long res = 0;
        for (int j = 0; j < m; ++j) {
            if (i >> j & 1) {
                res |= a[j];
            }
        }
        int cnt = __builtin_popcountll(res);
        if (__builtin_popcount(i) & 1) ans -= pow(2, n - 1 - cnt);
        else ans += pow(2, n - 1 - cnt);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <chrono>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;

// Computes the inverse of `a` modulo 2^64.
uint64_t mod_inv_2_64(uint64_t a) {
    // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
    // https://www.di-mgt.com.au/euclidean.html#code-modinv
    uint64_t g = 0, r = a, x = 0, y = 1;
    int sign = -1;

    // Do the first iteration manually to avoid overflow issues.
    uint64_t u64_max = ((uint64_t) -1);
    uint64_t q = u64_max / r + (u64_max % r == r - 1 ? 1 : 0);
    g = u64_max % r == r - 1 ? 0 : u64_max % r + 1; swap(g, r);
    x += q * y; swap(x, y);
    sign = -sign;

    while (r != 0) {
        q = g / r;
        g %= r; swap(g, r);
        x += q * y; swap(x, y);
        sign = -sign;
    }

    assert(g == 1);
    assert(y == 0);
    return sign > 0 ? x : -x;
}

auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));

using hash_t = uint64_t;

// HASH_MULT is a random number 3 or 5 mod 8. This ensures the hash is reliable until comparing strings of length 1024.
const hash_t HASH_MULT = (rng() & ~7) + (rng() % 2 ? 3 : 5);
const hash_t HASH_MULT_INV = mod_inv_2_64(HASH_MULT);

vector<hash_t> hash_pow = {1};
vector<hash_t> inv_pow = {1};


int N;
string S;

struct state {
    vector<int> A;
    int position;
    hash_t hash;

    state() {
        A.assign(2 * N + 1, 0);
        position = N;
        hash = 0;
    }

    void modify(int change) {
        assert(change == +1 || change == -1);
        A[position] += change;
        hash += change * hash_pow[position];
    }

    void move(int dir) {
        assert(dir == +1 || dir == -1);
        position += dir;
    }
};

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

    assert(HASH_MULT * HASH_MULT_INV == 1);
    cin >> N >> S;

    for (int i = 0; i < 2 * N; i++)
        hash_pow.push_back(HASH_MULT * hash_pow.back());

    for (int i = 0; i < 2 * N; i++)
        inv_pow.push_back(HASH_MULT_INV * inv_pow.back());

    state current;
    vector<hash_t> prefix_hashes = {current.hash};

    for (int i = 0; i < N; i++) {
        if (S[i] == '+' || S[i] == '-')
            current.modify(S[i] == '+' ? +1 : -1);
        else
            current.move(S[i] == '>' ? +1 : -1);

        prefix_hashes.push_back(current.hash);
    }

    map<hash_t, int> freq;

    for (hash_t h : prefix_hashes)
        freq[h]++;

    hash_t goal = prefix_hashes.back();
    current = state();
    long long total = 0;

    for (int i = 0; i < N; i++) {
        freq[prefix_hashes[i]]--;

        hash_t mult = current.position >= N ? hash_pow[current.position - N] : inv_pow[N - current.position];
        hash_t target = prefix_hashes[i] + goal * mult;
        total += freq[target];

        if (S[i] == '+' || S[i] == '-')
            current.modify(S[i] == '+' ? +1 : -1);
        else
            current.move(S[i] == '>' ? +1 : -1);
    }

    cout << total << '\n';
}


Measured memory_bytes: 43652
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

cin>>n;
ll a[n][2];
memset(a,0,sizeof a);
for(int i=0;i<n;i++){cin>>a[i][0];}
a[0][1]=0;
a[1][1]=abs(a[0][0]-a[1][0]);
for(int i=2;i<n;i++){
a[i][1]=min(abs(a[i][0]-a[i-1][0])+a[i-1][1],abs(a[i][0]-a[i-2][0])+a[i-2][1]);
}
cout<<a[n-1][1]<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n >> m;
    vec a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    vector<P> p(n);
    rep(i, n) p[i] = make_pair(a[i], b[i]);

    lint res = 0;

    sort(all(p));

    rep(i, n) {
        if (m > p[i].second) {
            lint t = p[i].first;
            t *= p[i].second;
            m -= p[i].second;
            res += t;
        }
        else {
            lint t = p[i].first;
            t *= m;
            res += t;
            break;
        }
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
#include <numeric>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int c = 0;
    for(c = 1; c < 4; c++){
        if(a*b*c % 2 == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N,M = map(int,input().split())
    K = []
    s = []
    answer = 0
    for _ in range(M):
        ks = list(map(int,input().split()))
        K.append(ks[0])
        s.append(ks[1:])
    p = list(map(int,input().split()))

    for switch in range(0,2**N):

        for j in range(M):
            count = 0
            for k in s[j]:
                if 1 << k-1 & switch:
                    count += 1
            if count%2 == p[j]:
                continue
            else:
                break
        else:
            answer +=1

        
    print(answer)


if __name__ == '__main__':
    main()


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

int main() {
	long long a,b,c,i,j,k,n,m,x,y,ans = 0;
	long long aa,bb;
	
	cin >> a >> b >> c;

	
	aa = 4*a*b;
	bb = (c - a - b)*(c - a - b);
	
	if (( aa < bb ) && ( c - a - b > 0 )) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  bool ans=false;
  if(s[2]==s[3])
    if(s[4]==s[5])
    	ans=true;

  if(ans)
      cout<<"Yes";
  else
 	 cout<<"No";
}

Measured memory_bytes: 256
#!/usr/bin/env python

N = int(input())

v = 0

def dsum(num):
  d = len(str(num))
  s = 0

  for i in range(d-1, -1, -1):
    n = num // 10**i
    s += n
    num = num % 10**i

  return s


min_s = 54
for A in range(1, N):
  B = N - A
  s = 0
  s += dsum(A)
  s += dsum(B)
  if s < min_s: min_s = s

print(min_s)


Measured memory_bytes: 3060
import sys
n = int(input())
a = list(map(int, input().split(' ')))

a.sort()
if n%2 == 0:
    for i in range(n-1):
        if i%2 == 0:
            if a[i] == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
        else:
            if a[i]+2 == a[i+1]:
                continue
            else:
                print(0)
                sys.exit()
    result = 2 ** (n//2)
    print(result % (10**9+7))
else:
    if a[0] == 0:
        for i in range(1, n-1):
            if i%2 == 1:
                if a[i] == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
            else:
                if a[i]+2 == a[i+1]:
                    continue
                else:
                    print(0)
                    sys.exit()
        result = 2**((n-1)//2)
        print(result %(10**9+7))
    else:
        print(0)
        sys.exit()

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

using namespace std;
using ll = long long;

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

int main() {
  string s, t;
  cin >> s >> t;

  map<char, vector<int>> idx;
  rep(i, s.size()) { idx[s[i]].push_back(i); }
  rep(i, s.size()) { idx[s[i]].push_back(i + s.size()); }

  int cur = -1;
  ll ans = 0;
  rep(i, t.size()) {
    if (idx.count(t[i]) == 0) {
      cout << "-1" << endl;
      return 0;
    }

    cur = *lower_bound(idx[t[i]].begin(), idx[t[i]].end(), cur + 1);
    if (cur >= (int)s.size() - 1) {
      ans += s.size();
      cur -= s.size();
    }

    // auto it = lower_bound(idx[t[i]].begin(), idx[t[i]].end(), cur + 1);
    // if (it != idx[t[i]].end()) {
    //   cur = *it;
    // } else {
    //   cur = -1;
    //   auto it = lower_bound(idx[t[i]].begin(), idx[t[i]].end(), cur + 1);
    //   if (it == idx[t[i]].end()) {
    //     cout << -1 << endl;
    //     return 0;
    //   }
    //   cur = *it;
    //   ++loop;
    // }
  }

  // ll ans = (ll)loop * s.size() + cur + 1;
  cout << ans + cur + 1 << endl;
  return 0;
}


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

int main()
{
    int q;
    set<int> s;
    cin >> q;
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        if (x == 0)
        {
            s.insert(y);
            cout << s.size() << endl;
        }
        if (x == 1)
        {
            cout << s.count(y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12460
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

typedef pair<int, int> P;

signed main() {
  int n, k;
  cin >> n >> k;
  P a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a, a + n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    count += a[i].second;
    if (count >= k) {
      cout << a[i].first << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
import sys
import collections


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    mod = 10**9+7
    ans = 0
    count = 0
    c = collections.Counter(A)
    k = list(c.keys())
    k.sort(reverse=True)

    # print(c)
    s = c[k[0]]
    for i in k[1:]:
        count += s*c[i]
        s += c[i]

    for i, v in enumerate(A):
        for j in range(0, i):
            if A[j] > v:
                ans += 1
    # print(ans, count)

    print((ans*K+K*(K-1)//2*count) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;
    int ans = 1e9;
    for(int i = 0; i <= max(x, y); i++){
        int tmp = max(x-i,0)*a + max(y-i,0)*b + i*c;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 1;
  for (int i=0; i<N; i++) {
    if (sum < K) {
      sum *= 2;
    }
    else {
      sum += K;
    }
  }
  cout << sum << endl;
}


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

int main(void){
  stack<int> data;
  int a;

  while(scanf("%d",&a) != EOF){
    if(a) data.push(a);
    else {
      if(data.empty()) break;
      printf("%d\n",data.top());
      data.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int main() {
	int m, t, p, r;
	vector<pair<PII, int> > _team;
	map<PII, int> ma;
	while ( ~scanf( "%d %d %d %d", &m, &t, &p, &r ) && m && t && p ) {
		_team.resize( t );
		for ( int i = 0; i < t; i++ ) {
			_team[ i ] = make_pair( PII( 0, 0 ), i + 1 );
		}
		for ( int i = 0; i < r; i++ ) {
			int tid, pid, time, j;
			scanf( "%d %d %d %d", &time, &tid, &pid, &j );
			if ( j ) {
				ma[ PII( tid, pid ) ]++;
			}
			else {
				_team[ tid - 1 ].first.first++;
				_team[ tid - 1 ].first.second -= time + ma[ PII( tid, pid ) ] * 20;
			}
		}
		sort( _team.rbegin(), _team.rend() );
		for ( int i = 0; i < t - 1; i++ ) {
			printf( "%d", _team[ i ].second );
			if ( _team[ i ].first == _team[ i + 1 ].first ) {
				printf( "=" );
			}
			else {
				printf( "," );
			}
		}
		printf( "%d\n", _team[ t - 1 ].second );
		ma.clear();
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
int a[200002];
int len;
ll l[200002];
ll r[200002];

int main(){
    scanf("%d %d", &len, &n);
    for(i=1;i<=n;++i){
        scanf("%d", a+i);
    }
    sort(a+1, a+n+1);
    l[0] = 0;
    for(i=1;i<=n;++i){
        l[i] = a[i] + l[i-1];
    }
    r[n+1] = 0;
    for(i=n;i>=1;--i){
        r[i] = len - a[i] + r[i+1];
    }
    ll ans = 0;
    for(i=1;i<=n;++i){
        int num = min(i-1, n-i);
        // ending i-1 - > i
        if(num < n-i){
            ans = max(ans, 2*(l[i-1] - l[i-1-num]) + 2*(r[i+1] - r[i+2+num]) + a[i]);
        }
        else{
            ans = max(ans, 2*(l[i-1] - l[i-1-num]) + 2*(r[i+1] - r[i+1+num]) + a[i]);
        }
        // ending i+1 - > i
        if(num < i-1){
            ans = max(ans, 2*(l[i-1] - l[i-2-num]) + 2*(r[i+1] - r[i+1+num]) + len - a[i]);
        }
        else{
            ans = max(ans, 2*(l[i-1] - l[i-1-num]) + 2*(r[i+1] - r[i+1+num]) + len - a[i]);
        }
    }
    printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4096
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll min(ll a, ll b) {
	if (a < b)
		return a;


	return b;
}

ll max(ll a, ll b) {
	if (a < b)
		return b;

	return a;
}


ll N, X;
vector<ll> x;

unsigned long long sum[2 * 100005];

unsigned long long E(int a) {

	if (a == 1) {
		return 5;
	}
	else
		return 2 * a + 1;

}


int main() {

	cin >> N >> X;
	
	x.resize(N+1);
	rep(i, N) {
		cin >> x[i+1];

		sum[i + 1] = sum[i] + x[i+1];
	}

	unsigned long long ans = inf;
	unsigned long long  val = 0;
	for (int k = 1; k <= N; k++) {

		for (int j = 1; j <= N / k; j++) {
			val += E(j) * (sum[N - k * (j - 1)] - sum[N - k * j]);
		}

		if (N % k != 0) {

			val += E(N / k + 1) * (sum[N - k * (N / k)] - sum[0]);
		}

		ans = min(val + k * X + N * X, ans);
		val = 0;
	}

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,w;
	cin>>n>>w;
	vvl dp(n+1,vl(w+1,0));
	rep(i,n){
		ll wg,vl;
		cin>>wg>>vl;
		rep(j,w){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+wg<=w)dp[i+1][j+wg]=max(dp[i+1][j+wg],dp[i][j]+vl);
		}
	}

	cout<<*max_element(all(dp[n]))<<endl;
	return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

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

  vector<string> g(h);
  int black = 0;
  for (int i = 0; i < h; i++) {
    cin >> g[i];
    for (int j = 0; j < w; j++) {
      black += g[i][j] == '#';
    }
  }

  queue<pair<int, int>> q;
  q.emplace(0, 0);

  vector<vector<int>> dist(h, vector<int>(w, -1));
  dist[0][0] = 0;
  
  const int dy[] = { 0, 1, 0, -1 };
  const int dx[] = { 1, 0, -1, 0 };

  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int yy = y + dy[k];
      int xx = x + dx[k];
      if (yy < 0 || xx < 0 || yy >= h || xx >= w) continue;
      if (g[yy][xx] == '#') continue;
      if (dist[yy][xx] != -1) continue;
      dist[yy][xx] = dist[y][x] + 1;
      q.emplace(yy, xx);
    }
  }

  if (dist[h - 1][w - 1] == -1) {
    cout << -1 << endl;
  } else {
    cout << (h * w) - dist[h - 1][w - 1] - black - 1 << endl;
  }
}

Measured memory_bytes: 256
import collections

def main():
    n = int(input())
    v = list(map(int, input().split()))

    even = [j for i, j in enumerate(v) if i % 2 == 0]
    odd = [j for i, j in enumerate(v) if i % 2 == 1]

    cnt_e = collections.Counter(even)
    cnt_o = collections.Counter(odd)

    if len(set(v)) == 1:
        print(n // 2)
        exit()

    if cnt_e.most_common()[0][0] == cnt_o.most_common()[0][0]:
        if cnt_e.most_common()[0][1] > cnt_o.most_common()[0][1]:
            print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[1][1])
        elif cnt_e.most_common()[0][1] < cnt_o.most_common()[0][1]:
            print(n - cnt_e.most_common()[1][1] - cnt_o.most_common()[0][1])
        else:
            if cnt_e.most_common()[1][1] > cnt_o.most_common()[1][1]:
                print(n - cnt_e.most_common()[1][1] - cnt_o.most_common()[0][1])
            else:
                print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[1][1])
    else:
        print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[0][1])


main()

Measured memory_bytes: 90756
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [0]*(n+1)
    blocks = [0]*(n+1)
    uf = UnionFind(n)
    ans = []
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a] += 1
        friends[b] += 1
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        if uf.same(c, d):
            blocks[c] += 1
            blocks[d] += 1
    for i in range(1, n+1):
        ans.append(uf.size(i)-1-friends[i]-blocks[i])
    print(" ".join(list(map(str, ans))))


if __name__ == "__main__":
    main()

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    string s;
    cin >> s;
    if(s=="#") return 0;
    int n = s.length();
    vector<int> pos={-1,0,1,-1,0,1,-1,0,1};
    vector<int> x(n);
    rep(i,n) x[i]=pos[s[i]-'1'];
    int l=-2,r=2;
    int ans=IINF;
    int tmp=0;
    l=x[0],r=2;
    int t=1;
    repp(i,1,n){
      if(t%2){
        if(l<=x[i]) r=x[i],t=1-t;
        else l=x[i],tmp++;
      }else{
        if(r>=x[i]) l=x[i],t=1-t;
        else r=x[i],tmp++;
      }
    }
    ans=min(ans,tmp);
    tmp=0;
    l=-2,r=x[0];
    t=1;
    repp(i,1,n){
      if(t%2){
        if(r>=x[i]) l=x[i],t=1-t;
        else r=x[i],tmp++;
      }else{
        if(l<=x[i]) r=x[i],t=1-t;
        else l=x[i],tmp++;
      }
    }
    ans=min(ans,tmp);
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
const int BASE = 2002;
const int mod = 1e9+7;

int n, a[N], b[N], ans = 0, f[BASE*2+5][BASE*2+5], inv[N], fac[N], pinv[N];

void init(){
	fac[0] = inv[0] = pinv[0] = fac[1] = inv[1] = pinv[1] = 1;
	for(int i = 2; i <= BASE*4; i++){
		fac[i] = 1ll*fac[i-1]*i%mod;
		inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod;
		pinv[i] = 1ll*pinv[i-1]*inv[i]%mod;
	}
}

int C(int n, int m){ return 1ll*fac[n]*pinv[m]%mod*pinv[n-m]%mod; }

int main(){
	ios::sync_with_stdio(false);
	cin >> n, init();
	for(int i = 1; i <= n; i++)
		cin >> a[i] >> b[i], f[BASE-a[i]][BASE-b[i]]++;
	for(int i = 1; i <= BASE*2; i++)
		for(int j = 1; j <= BASE*2; j++)
			(f[i][j] += (f[i-1][j]+f[i][j-1])%mod) %= mod;
	for(int i = 1; i <= n; i++) (ans += f[a[i]+BASE][b[i]+BASE]) %= mod;
	for(int i = 1; i <= n; i++) (ans += mod-C((a[i]+b[i])*2, b[i]*2)) %= mod;
	ans = 1ll*ans*inv[2]%mod;
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int max = 0;
  int min = 1000000001;
  
  for(int i = 0; i < N; i++) {
    if(max < A[i]) {
      max = A[i];
    }
    if(A[i] < min) {
      min = A[i];
    }
  }
  
  cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,m,X,Y; cin >> n >> m >> X >> Y;
    ll xmax = -INF;
    ll ymin = INF;
    vl x(n),y(m);
    rep(i,n){
        cin >> x[i];
        xmax = max(xmax,x[i]);
    }
    rep(i,m){
        cin >> y[i];
        ymin = min(ymin,y[i]);
    }
    if(xmax < ymin && xmax < Y && ymin > X) puts("No War");
    else puts("War");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0

ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}

int h,w,n,k;

int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}

int ans[50][50];

void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if((h == w && rand()%2) || h > w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}

int main(){
    srand(time(0));
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);

    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }

    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    string a,b;
    cin>>a>>b;
    sort(all(a));
    sort(all(b));
    reverse(all(b));
    cout<<(a<b?"Yes":"No")<<endl;
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  int n;
  cin>>n;
  if(n<1200)
    cout<<"ABC";
  else if(n>=2800)
    cout<<"AGC";
  else
    cout<<"ARC";
  cout<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


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

typedef pair<int, int> P;

int N;
int res;
vector<vector<int>> G;
vector<bool> visited;
vector<P> E;
map<P, int> m;

void dfs(int u, int c) {
    visited[u] = true;
    res = max(res, (int)G[u].size());

    int color = 1;
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (visited[v]) continue;
        if (color == c) color++;
        m[P(u, v)] = color;
        dfs(v, color);
        color++;
    }
}

int main() {
    cin >> N;
    G.resize(N);
    visited.resize(N, false);
    E.resize(N - 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);
        E[i] = P(a, b);
    }

    dfs(0, 0);

    cout << res << endl;
    for (int i = 0; i < E.size(); i++) {
        cout << m[E[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 13184
N, M = map(int, input().split(' '))
st = {i: list(map(int, input().split(' '))) for i in range(N)}
chk = {i: list(map(int, input().split(' '))) for i in range(M)}
num_chk = [0] * N
for s_k, s_v in st.items():
    prev = float('inf')
    for c_k, c_v in chk.items():
        dist = abs(c_v[0] - s_v[0]) + abs(c_v[1] - s_v[1])
        if dist < prev:
            prev = dist
            num_chk[s_k] = c_k + 1
for i in num_chk:
    print(i)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
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 mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600
typedef pair<int, int> P;

int mat[1500][1500];

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

  rep(i,h)rep(j,w) scanf("%d", &mat[i][j]);

  // convert matrix to vertiacl succeeding numbers
  rep(i,h)rep(j,w){
    if(i==0){
      mat[i][j] = !mat[i][j];
      continue;
    }
    if(mat[i][j]==0) mat[i][j] = mat[i-1][j]+1;
    else mat[i][j] = 0;
  }

  // see matrix row as a histogram to make the largert rectangle
  int res = 0;
  rep(i,h){
    mat[i][w] = 0;
    stack<P> st;
    rep(j,w+1){
      int d=mat[i][j];
      if(st.empty()) st.push(mp(j,d));
      else if(st.top().se < d) st.push(mp(j,d));
      else if (st.top().se > d){
        int last = j;
        while(!st.empty() && st.top().se > d){
          P p = st.top(); st.pop();
          res = max(res, (j-p.fi)*p.se);
          last = p.fi;
        }
        st.push(mp(last,d));
      }
    }
  }

  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 9448
#coding:utf-8
while 1:
    try:
        #初期化
        key=[0]*101
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        if(key[1]%2 == 1 and key[2]%2==1 and len(filter(lambda x:x%2==1,key[3:]))==0):
            print "OK"
        else:
            print "NG"
    except:
        break

Measured memory_bytes: 4220
def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans = [0 for i in range(n+1)]
    for i in range(n):
        s = 0
        k = n-i
        for j in range(1,n//k+1):
            s += ans[k*j]
        if s%2!=a[k-1]:
            ans[k] = 1
    print(sum(ans))
    if sum(ans)!=0:
        print(' '.join([str(i) for i , x in enumerate(ans) if x==1]))



if __name__ == "__main__":
    main()

Measured memory_bytes: 14776
# -*- coding: utf-8 -*-

n = int(input())
s = input()

words = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

lis = list(words)

ans = ""
for w in list(s):
    idx = lis.index(w)
    n_idx = idx + n
    ans += lis[n_idx]
print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	double n, m, d;
	cin >> n >> m >> d;
	printf("%.12e\n", ((d==0)?1:2)*max((n - d), 0.0)*(m - 1) / (n*n));
	return 0;
}

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

int main() {
    ll x;
    cin >> x;
    ll i = 0;
    while((i+1)*i < 2*x){
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 505
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;

char s[N][N];

int main()
{
	fast;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		fo(j,1,m)
			cin>>s[i][j];
	fo(i,1,n)
	{
		fo(j,1,m)
		{
			if((i%2==1 || s[i][j]=='#' || j==1) && j!=m)
				cout<<'#';
			else
				cout<<'.';


		}
		cout<<endl;
	}
	cout<<endl;
	fo(i,1,n)
	{
		fo(j,1,m)
		{
			if((i%2==0 || s[i][j]=='#' || j==m) && j!=1)

				cout<<'#';
			else
				cout<<'.';


		}
		cout<<endl;
	}


}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

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

#define ll long long
#define ar array

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

	int n, p;
	string s;
	cin >> n >> p >> s;
	ll ans=0;
	if(p==2) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%2==0)
				ans+=i+1;
	} else if(p==5) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%5==0)
				ans+=i+1;
	} else {
		map<int, int> mp;
		mp[0]++;
		int t=0, p2=1;
		for(int i=n-1; ~i; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
	}
	cout << ans;
}


Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,D,X;
    cin >> N >> D >>X;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    int count=0;
    for(int j=0;j<N;j++){
       if(vec.at(j)==1){
           if(N==1){
               count++;
               continue;
           }
           count += D;
           continue;
       }
      count += D/vec.at(j);
      count ++;
      if(D%vec.at(j)==0){
          count--;
      }
    }
     cout << count+X << endl;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int[] ni = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        Console.WriteLine(ni[0] - ni[1] + 1);


    }
}

Measured memory_bytes: 13268
package main

import (
	"fmt"
	"math"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func main() {
	// Code for C - Average Length
	var N int
	fmt.Scanf("%d", &N)

	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &x[i], &y[i])
	}

	a := make([]int, 0)
	for i := 0; i < N; i++ {
		a = append(a, i+1)
	}

	var ans float64
	for i := 0; i < N-1; i++ {
		ans += math.Sqrt(float64((x[a[i+1]-1]-x[a[i]-1])*(x[a[i+1]-1]-x[a[i]-1])) + float64((y[a[i+1]-1]-y[a[i]-1])*(y[a[i+1]-1]-y[a[i]-1])))
	}

	var n = len(a) - 1
	var i, j int
	for count := 2; count <= factorial(len(a)); count++ {
		i = n - 1
		j = n
		for a[i] > a[i+1] {
			i--
		}
		for a[j] < a[i] {
			j--
		}
		a[i], a[j] = a[j], a[i]
		j = n
		i++
		for i < j {
			a[i], a[j] = a[j], a[i]
			i++
			j--
		}

		for k := 0; k < N-1; k++ {
			ans += math.Sqrt(float64((x[a[k+1]-1]-x[a[k]-1])*(x[a[k+1]-1]-x[a[k]-1])) + float64((y[a[k+1]-1]-y[a[k]-1])*(y[a[k+1]-1]-y[a[k]-1])))
		}

	}

	fmt.Println(ans / float64(factorial(len(a))))
}


Measured memory_bytes: 1840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int start = 0;
		int end = 0;
		for(int i = 0; i < m; i++) {
			int tmp = sc.nextInt();
			if(tmp < x) {
				start++;
			} else {
				end++;
			}
		}
		System.out.println(Math.min(start, end));
	}

}


Measured memory_bytes: 23892