akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B = MAP()

def xor_cal(N):
	if N%2 == 1:
		return (N+1)//2%2
	else:
		return xor_cal(N-1)^N

print(xor_cal(B)^xor_cal(A-1))

Measured memory_bytes: 10576
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
  string S;
  cin >> S;
  
  if (S.length()%2 != 0){
    cout << "No" << endl;
    return 0;
  }
  
  for (int i=0; i<S.length(); i+=2){
    if (S[i]!='h' || S[i+1]!='i'){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}

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

int main() {
    int N; cin >> N;
    double sum_a = 0.;
    for (int i=0; i<N; i++){
        double a; cin >> a;
        sum_a += 1.0 / a;
    }
    cout << std::fixed << std::setprecision(10) << 1.0 / sum_a << endl;
}

Measured memory_bytes: 3780
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B, C;
    scan(A, B, C);
    bool b = B - A == C - B;
    writeln(b?"YES":"NO");
}


Measured memory_bytes: 256
n,m,k = map(int,input().split())
check = 0
for i in range(n+1):
    for j in range(m+1):
        x = i * m + j * n - 2 * i * j
        if x == k:
            check = 1
            break
if check == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;

namespace B
{
    class Visit
    {
        public void visit(ref int[,] point, ref int time, ref int[,] output, int now, ref string[] color)
        {
            int i;
            color[now] = "GRAY";
            output[now-1, 1] = ++time;
            for (i = 0; i < point[now, 1]; i++)
            {
                if (color[point[now, 2+i]]=="WHITE") {
                    visit(ref point, ref time, ref output, point[now, 2 + i], ref color);
                }
            }
            color[now] = "BLACK";
            output[now-1, 2] = ++time;
        }
    }

    class B
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input), i, j, time=0;
            int[,] point = new int[n + 1, n + 1];
            int[,] output = new int[n, 3];
            string[] color = new string[n + 1];
            for (i = 1; i <= n; i++)
            {
                output[i - 1, 0] = i;
                color[i] = "WHITE";
                string[] input2 = Console.ReadLine().Split(' ');
                point[i, 0] = int.Parse(input2[0]);
                point[i, 1] = int.Parse(input2[1]);
                for (j = 0; j < point[i,1]; j++)
                {
                    point[i, 2 + j] = int.Parse(input2[2 + j]);
                }
            }
            Visit visit = new Visit();
            visit.visit(ref point, ref time, ref output, 1, ref color);
            for (i = 1; i <= n; i++)
            {
                if (color[i]=="WHITE")
                {
                    visit.visit(ref point, ref time, ref output, i, ref color);
                }
            }
            for (i = 0; i < n; i++)
            {
                Console.WriteLine(output[i, 0] + " " + output[i, 1] + " " + output[i, 2]);
            }
        }
    }
}



Measured memory_bytes: 15936
n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans = -(1 << 30)
for bit in range(1, 1 << 10):
    cnt = 0
    for i in range(n):
        cnt2 = 0
        for j in range(10):
            if (bit >> j & 1) and f[i][j]:
                cnt2 += 1
        cnt += p[i][cnt2]
    if ans < cnt:
        ans = cnt
print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  string S, T;
  cin >> S >> T;

  string Ans = "";
  for (uint i = 0; i < S.size(); i++) {
    if (S.size() < i + T.size())
      break;

    string tmpS = S;
    int cnt = T.size();
    for (uint j = 0; j < T.size(); j++) {
      if (S[i + j] == '?' || S[i + j] == T[j]) {
        tmpS[i + j] = T[j];
        cnt--;
      }
    }
    if (cnt == 0) {
      for (uint j = 0; j < S.size(); j++) {
        if (tmpS[j] == '?')
          tmpS[j] = 'a';
      }
      if (Ans == "")
        Ans = tmpS;
      else
        Ans = min(Ans, tmpS);
    }
  }

  if (Ans == "")
    cout << "UNRESTORABLE" << endl;
  else
    cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 256
def verify(rel, n)
    max = 0
    1.upto(2 ** n) do |k|
        kk = Array.new(n, 0)
        i = 0
        while k > 0
            kk[i] = k % 2
            k /= 2
            i += 1
        end
        no = 0
        ret = 0
        rel.each_with_index do |r, i|
            next if kk[i] == 0
            r.each_with_index do |rr, j|
                next if rr == nil
                if kk[j] != rr
                    no += 1
                end
            end
            ret += 1
        end
        if no == 0
            max = ret if ret > max
        end
    end
    return max
end

n = gets.to_i
rel = Array.new(n).map { Array.new(n)  }
n.times do |i|
    a = gets.to_i
    a.times do |j|
        x, y = gets.split.map(&:to_i)
        rel[i][x-1] = y
    end
end

puts verify(rel, n)

Measured memory_bytes: 1788
IDX_TBL = \
{1:[2,3,5,4],
 2:[3,1,4,6],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[1,3,6,4],
 6:[2,4,5,3]}

l1=["-"] + raw_input().split(" ")
l2=["-"] + raw_input().split(" ")

if l1[1] not in l2:
    print "No"
else:
    idx_list = [i for i,x in enumerate(l2) if x==l1[1]]

    for idx in idx_list:
        nums1 = "".join([l1[i] for i in IDX_TBL[1]])
        nums2 = "".join([l2[i] for i in IDX_TBL[idx]])

        if nums2 in nums1*2:
            print "Yes"
            break
        else:
            continue
    else:
        print "No"

Measured memory_bytes: 4248
import collections
import numpy as np
from math import factorial

N = int(input())

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

cntr = collections.Counter(A)

uni_A = np.unique(A)

def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

comb_d = dict()

for a in uni_A:
    n = cntr[a]
    comb_d[a] = comb(n, 2) if n > 1 else 0

d = dict()
S = sum(comb_d.values())
for a in uni_A:
    s = S - (cntr[a] - 1)
    d.update({a:s})

for a in A:
    print(d[a])

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

namespace A {
static class Extensions {
   public static int ToInt(this string str) =>
      int.Parse(str);

   public static int[] readIntArr() =>
      ReadLine().Split(' ').Select(int.Parse).ToArray();

   public static long[] readLongArr() =>
      ReadLine().Split(' ').Select(long.Parse).ToArray();
   
   public static void Fill<T>(this List<T> a, T b) {
      for (var i = 0; i < a.Capacity; i++) {
         a.Add(b);
      }
   } 

   public static void Fill<T>(this T[] a, T b) {
      for (var i = 0; i < a.Length; i++) {
         a[i] = b;
      }
   }
}

class Program {
   public static void Main(string[] args) {
      var tmp = Extensions.readIntArr();

      var N = tmp[0];
      var W = tmp[1];
      var w = new long[N + 1];
      var v = new long[N + 1];
      
      for (var i = 1; i < N + 1; i++) {
         var tmp2 = Extensions.readIntArr();
         w[i] = tmp2[0];
         v[i] = tmp2[1];
      }

      var dp = new long[N + 1][];
      for (var i = 0; i < N + 1; i++)
         dp[i] = new long[W + 1];

      for (var i = 1; i <= N; i++) {
         for (var j = 0; j <= W; j++) {
            if (w[i] <= j) {
               dp[i][j] = Max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
            } else {
               dp[i][j] = dp[i - 1][j];
            }
         }
      }

      WriteLine(dp[N][W]);
   }
}

}


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

int main(){
    int K;
    cin >> K;
    int ans = 0;
    if (K % 2 == 0 || K % 5 == 0) ans = -1;
    else {
        int num = 7;
        int keta = 1;
        int r = num % K;
        while (r != 0) {
            // r = num % K;
            // num = num * 10 + 7;
            r = (r * 10 + 7) % K;
            // cout << r << endl;
            keta++;
        }
        ans = keta;
    }  
    cout << ans << endl;
}




Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B) << endl;
	return 0;
}

Measured memory_bytes: 3584
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 7, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int n;
ll dp[N][2], a[N];
bool vis[N][2] = { };
ll solve(int idx, bool is) {
	if (idx > n)
		return 0;
	ll &ret = dp[idx][is];
	if (vis[idx][is])
		return ret;
	vis[idx][is] = 1;
	ret = -1e15;
	if (idx + 1 <= n)
		ret = max(ret,
				solve(idx + 1, false) + ((is == true) ? -a[idx] : +a[idx]));
	ret = max(ret, solve(idx + 1, true) + ((is == true) ? +a[idx] : -a[idx]));
	return ret;
}
int main() {
	FAST
	cin >> n;
	lp(i,1,n)
		cin >> a[i];
	cout << solve(1, 1);
	return 0;
}

Measured memory_bytes: 7424
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=605,mod=1e9+7;
int n,m,a[N<<1],f[N<<1][N][N],cur,q[N<<1],tp; bool ext[N<<1],vis[N<<1];
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
int main()
{
	RI i,j,k; for (scanf("%d",&n),i=1;i<=2*n;++i)
	scanf("%d",&a[i]),ext[~a[i]?a[i]:0]=1;
	for (i=1;i<=n;++i) if (!~a[2*i-1]&&!~a[2*i]) ++cur;
	else if (~a[2*i-1]&&~a[2*i]) vis[a[2*i-1]]=vis[a[2*i]]=1;
	for (i=1;i<=2*n;++i) if (!vis[i]) q[++m]=ext[i];
	for (n=m,f[n][0][0]=1,i=n;i;--i) for (j=0;j<=n;++j)
	for (k=0;k<=n;++k) if (tp=f[i][j][k])
	{
		if (q[i]) inc(f[i-1][j+1][k],tp),k&&(inc(f[i-1][j][k-1],tp),0);
		else inc(f[i-1][j][k+1],tp),k&&(inc(f[i-1][j][k-1],tp),0),j&&(inc(f[i-1][j-1][k],1LL*tp*j%mod),0);
	}
	int ans=f[0][0][0]; for (i=1;i<=cur;++i) ans=1LL*ans*i%mod;
	return printf("%d",ans),0;
}

Measured memory_bytes: 212516
#include <iostream>

using namespace std;

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

	int t = n % 100;
	int i = 0;

	while ((t / 5) > 0) {
		t -= 5;
		i++;
	}
	while ((t / 4) > 0) {
		t -= 4;
		i++;
	}
	while ((t / 3) > 0) {
		t -= 3;
		i++;
	}
	while ((t / 2) > 0) {
		t -= 2; 
		i++;
	}

	i += t;

	if (i <= (int)(n / 100)) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math

max = [0, 0]
max2 = 0

n = int(input())

for i in range(n):
    sub = int(input())
    if(max2 < sub):
        if(max[0] < sub):
            max2 = max[0]
            max[0] = sub
            max[1] = i
        else: 
            max2 = sub

for i in range(n):
    if(max[1] == i):
        print(max2)
    else:
        print(max[0])

Measured memory_bytes: 4668
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())

import numpy as np

H = np.array(list(map(int,readline().split())),dtype = int)

dp = np.zeros(N, dtype = int)

for i in range(1, N):
  dp[i] = (dp[max(0,i - K):i] + abs(H[max(0,i - K):i] - H[i])).min()

print(dp[-1])

Measured memory_bytes: 38372
#include<stdio.h>
int main(void)
{
  int i,j,k;
  int ymd[100][3], n, y3=590, date;

  scanf("%d", &n);
  for(i=0; i<n; i++) {
    for(j=0; j<3; j++) {
      scanf("%d", &ymd[i][j]);
    }
  }

  for(i=0;i<n;i++) {
    date = 0;
    date += ((ymd[i][0]-1)/3)*y3;
    switch(ymd[i][0]%3){
    case 2:
      date += 195;
      for(j=0;j<ymd[i][1]-1;j++) {
	j%2 ? (date += 19):(date += 20);
      }
      date += ymd[i][2];
      break;
      
    case 1:
      for(j=0;j<ymd[i][1]-1;j++) {
	j%2 ? (date += 19):(date += 20);
      }
      date += ymd[i][2];
      break;
      
    case 0:
      date += 390;
      for(j=0;j<ymd[i][1]-1;j++) {
	date += 20;
      }
      date += ymd[i][2];
      break;
    }
    printf("%d\n", 196471 - date);
  }

  for(i=0;i<100000;i++) {
    for(j=0;j<100000;j++) k++;
}

  return 0;
}
      

Measured memory_bytes: 596
#include <vector>
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	int N, A, B;
	cin >> N >> A >> B;
	int diff = 0;
	for (int i = 0; i < N; ++i) {
		if (((A >> i) & 1) != ((B >> i) & 1)) {
			++diff;
		}
	}
	if (diff % 2 == 0) {
		cout << "NO" << '\n';
	}
	else {
		vector<int> way, cnt(N);
		cnt[0] = 1;
		for (int i = 0; i < 2 * N - 2; ++i) {
			if (i % 2 == 0) {
				way.push_back(i / 2 + 1);
				cnt[i / 2 + 1] ^= 1;
			}
			else {
				int pos = -1;
				for (int j = 0; j <= i / 2; ++j) {
					if ((j >= N - diff && cnt[j] == 0) || (j < N - diff && cnt[j] == 1)) {
						pos = j;
						break;
					}
				}
				if (pos != -1) {
					way.push_back(pos);
					cnt[pos] ^= 1;
				}
				else {
					way.push_back(0);
					cnt[0] ^= 1;
				}
			}
		}
		vector<int> seq = { 0 }, burger = { 0 };
		for (int i = 0; i < 2 * N - 2; ++i) {
			if (i % 2 == 0) {
				seq.push_back(i / 2 + 1);
				burger.push_back(i / 2 + 1);
				int sz = int(burger.size());
				for (int j = 0; j < sz - 1; ++j) {
					burger.push_back(burger[j]);
				}
			}
			else {
				int sz = int(seq.size());
				for (int j = 0; j < sz - 1; ++j) {
					seq.push_back((burger[j] + way[i] + 1) % (i / 2 + 1));
				}
			}
		}
		vector<int> perm;
		for (int i = 0; i < N; ++i) {
			if (((A ^ B) >> i) & 1) {
				perm.insert(perm.end(), i);
			}
			else {
				perm.insert(perm.begin(), i);
			}
		}
		vector<int> ans = { A };
		for (int i = 0; i < int(seq.size()); ++i) {
			ans.push_back(ans.back() ^ (1 << perm[seq[i]]));
		}
		cout << "YES" << '\n';
		for (int i : ans) {
			cout << i << ' ';
		}
	}
	return 0;
}

Measured memory_bytes: 2676
#include <iostream>

int main(){
    int x, y;
    while(1){
        std::cin >> x >> y;
        if( x==0 && y==0 )
            break;
        else if (x <= y)
            std::cout << x << ' ' << y << std::endl;
        else
            std::cout << y << ' ' << x << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    string a;
    cin >> a;
    cout << a.at(0) << a.size() - 2 << a.at(a.size() - 1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
#define vec2 vector<vector<int>>
#define set setprecision
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);}
int main() {
	int n;
	cin >> n;
	vec a(n);
	rip(i, n)cin >> a[i];
	int mini = 700009;
	int count = 0;
	rip(i, n) {
		mini = min(mini, a[i]);
		if (mini == a[i])count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

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

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

    int r;
    cin>>r;
    cout<<3*r*r;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  dynarr<dynarr<i64>> A(N, dynarr<i64>(N - 1)) ;
  queue<pair<i64, i64>> que;
  queue<pair<i64, i64>> nxt;
  dynarr<dynarr<i64>> cnt(N, dynarr<i64>(N));
  dynarr<i64> idx(N, 0);
  rep(i,0,N) rep(j,0,N - 1) {
    cin >> A[i][j];
    A[i][j]--;
  }
  rep(i,0,N) {
    cnt[min(i, A[i][0])][max(i, A[i][0])]++;
    if(cnt[min(i, A[i][0])][max(i, A[i][0])] == 2) {
      que.push({ min(i, A[i][0]), max(i, A[i][0]) });
    }
  }

  i64 OK = 0;

  i64 ans = 0;
  while(!que.empty()) {
    ans++;
    while(!que.empty()) {
      i64 i = que.front().first;
      i64 j = que.front().second;
      OK++;
      que.pop();
      {
        idx[i]++;
        if(idx[i] < N - 1) {
          cnt[min(i, A[i][idx[i]])][max(i, A[i][idx[i]])]++;
          if(cnt[min(i, A[i][idx[i]])][max(i, A[i][idx[i]])] == 2) {
            nxt.push({ min(i, A[i][idx[i]]), max(i, A[i][idx[i]]) });
          }
        }
      }
      {
        idx[j]++;
        if(idx[j] < N - 1) {
          cnt[min(j, A[j][idx[j]])][max(j, A[j][idx[j]])]++;
          if(cnt[min(j, A[j][idx[j]])][max(j, A[j][idx[j]])] == 2) {
            nxt.push({ min(j, A[j][idx[j]]), max(j, A[j][idx[j]]) });
          }
        }
      }
    }
    swap(que, nxt);
  }
  if(OK == N * (N - 1) / 2) {
    cout << ans << endl;
  }
  else {
    cout << -1 << endl;
  }

}


Measured memory_bytes: 18048
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    p = LF()
    # dp[i][j]:=i枚目までで、k枚が表の確率
    dp = [[0] * (N+1) for _ in range(N)]
    dp[0][1] = p[0]
    dp[0][0] = 1-p[0]
    for i in range(1, N):
        for k in range(i+2):
            if k != 0:
                dp[i][k] += dp[i - 1][k - 1] * p[i]
            if k <= i:
                dp[i][k] += dp[i-1][k]*(1-p[i])
    ans = 0
    for i in range((N + 1) // 2, N + 1):
        ans += dp[N - 1][i]
    #print(*dp, sep="\n")
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 264200
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	static ContestScanner in;
	static Writer out;
	public static void main(String[] args) {
		try {
			in = new ContestScanner();
			out = new Writer();
			new Main().solve();
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	void solve() throws IOException {
		int[] a = new int[3];
		for(int i = 0; i < 3; i++) a[i] = in.nextInt();
		int[] org = a.clone();
		int cnt = 0;
		while(swap(a) && !Arrays.equals(org, a)) cnt++;
		System.out.println(Arrays.equals(org, a) ? -1 : cnt);
	}
	
	int[] tmp = new int[3];
	boolean swap(int[] a) {
		for(int i = 0; i < 3; i++) {
			if(a[i] % 2 == 1) {
				Arrays.fill(a, 0);
				return false;
			}
			tmp[i] = a[i] / 2;
		}
		for(int i = 0; i < 3; i++) {
			a[i] = tmp[(i+1)%3] + tmp[(i+2)%3];
		}
		return true;
	}
}


class Writer extends PrintWriter{
	public Writer(String filename)throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
	private BufferedReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws IOException
	{in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException {
		StringBuilder sb=new StringBuilder();
		while((c=in.read())!=-1&&Character.isWhitespace(c));
		while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public String readLine()throws IOException{
		StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
		while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public long nextLong()throws IOException,NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException
	{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
	public void close() throws IOException {in.close();}
}

Measured memory_bytes: 21460
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {

    int h,w;
    cin >> h >> w;
    vs s(h);
    rep(i,h)cin >> s[i];
    vi t(4,INF);
    int v[4][2] = {{-1,-1},{-1,w},{h,-1},{h,w}};
    rep(i,h)rep(j,w)if(s[i][j] == 'B'){
        rep(x,4){
            t[x] = min(t[x], abs(v[x][0]-i)+abs(v[x][1]-j));
        }
    }
    vp p;
    rep(i,h)rep(j,w)if(s[i][j] == 'B'){
        rep(x,4){
            if(abs(v[x][0]-i)+abs(v[x][1]-j) == t[x]){
                p.push_back(pii(i,j));
            }
        }
    }
    int ans = 0;
    rep(i,p.size())rep(j,i){
        ans = max(ans, abs(p[i].first - p[j].first)+abs(p[i].second - p[j].second));
    }
    cout << ans << endl;
}



Measured memory_bytes: 3892
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
	string s;  cin >> s;
	set<int>m;
	m.insert(s[0]);
	m.insert(s[1]);
	m.insert(s[2]);
	if (m.size() == 3)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  bool debug=false;  
  int N;
  cin >> N;
  string* W=new string[N];
  for(int i=0;i<N;i++){
    cin >> W[i];
    
  }
    
  if(debug){
    for(int i=0; i<N; i++){
      cout << "W[" << i << "]=" << W[i] << endl;
      
    }  
  }
  for(int i=0;i<N-1;i++){
    char currentBackChar=W[i].back();
    char nextFrontChar=W[i+1].front();
    if(currentBackChar!=nextFrontChar){
      cout << "No" << endl;
      return 0;
      
    }
  }
  
  
  //check duplication
  sort(W, W+N);
  for(int i=0;i<N-1;i++){
    if(W[i]==W[i+1]){
      cout << "No" << endl;
      return 0;
      
    }
  }
  
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}
vector < ll > vec;
struct node
{
	ll a, b, c, d;
} arr[1000];

ll n, m, q;

ll score()
{
	ll ret = 0;

//	for(auto it: vec) cout << it << " ";

	for(ll i = 0; i < q; i++)
	{
		if(vec[arr[i].b] - vec[arr[i].a] == arr[i].c) ret += arr[i].d;
	}

//	cout << ret << endl;

	return ret;
}

ll ans;

void dfs(ll pos)
{
	if(pos == n) ans = max(ans, score());
	else
	{
//		cout << pos << " " << n << endl;
		ll st = pos == 0 ? 1 : vec.back();

//		cout << pos << " " << st << " " << (pos == 0 ? 1 : vec.back()) << endl;

		for(ll i = st; i <= m; i++)
		{
			vec.push_back(i);

			dfs(pos + 1);

			vec.pop_back();
		}
	}

	return;
}

int main()
{
    ll i, j;
    ll testcase;
    ll input, flag, tag;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m >> q)
    {
		vec.clear();

		for(ll i = 0; i < q; i++) cin >> arr[i].a >> arr[i].b >> arr[i].c >> arr[i].d, arr[i].a--, arr[i].b--;

		ans = 0;

		dfs(0);

		cout << ans << '\n';
    }


}





Measured memory_bytes: 3644
import java.io.*;

class Main{

	public static void main(String arg[]) throws IOException{
		String message;
		int n=0;
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		message = br.readLine();
		String num[] = message.split(" ");
		message = br.readLine();
		String nagasa[] = message.split(" ");
		n = Integer.parseInt(num[0]);
		int numnum[] = new int[n];
		long all = 0;
		int harf = 0;
		for(int i=0;i<n;i++){
			numnum[i] = Integer.parseInt(nagasa[i]);
			all += numnum[i];
		}
		long akun = 0;
		long maxlong=99999999999999L;
		for(int i=0;i<n-1;i++){
			akun += numnum[i];
			if(maxlong>Math.abs(all- 2*akun)){
				maxlong = Math.abs(all - 2*(akun));
			}
		}
		System.out.println(""+maxlong);

		
	}
}


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

int partition(vector<int> &A, int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j=p; j<=r-1; ++j){
        if(A[j] <= x ){
            i = i+1;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);

    return i+1;
}


int main()
{
    int n;
    cin >> n;
    vector<int> A(n,0);
    for(auto&& x : A){
        cin >> x;
    }

    int q = partition(A,0,n-1);
    for(int i=0; i<q; ++i){
        if(i>0){
            cout << ' ';
        }
        cout << A[i];
    }

    cout << " [" << A[q] << "]";

    for(int i=q+1; i<n; ++i){
        if(i>0){
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;

    return 0;
}


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

#define pb push_back
#define ll long long
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<n;i++)

using namespace std;

bool check_asc(int a[],int n){

	f(i,1,n){
		if(a[i]<=a[i-1]) return false;
	}

	return true;
}

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

	int n; cin>>n;

	int p[n+1];

	f(i,0,n) cin>>p[i];

	if(check_asc(p,n)==true){
		cout<<"YES";
		exit(0);
	}


	f(i,0,n){
		f(j,i+1,n){
			swap(p[i],p[j]);
			if(check_asc(p,n)==true){
				cout<<"YES";
				exit(0);
			}
			swap(p[i],p[j]);
		}
	}

	cout<<"NO";

	return 0;
}

Measured memory_bytes: 256
a,b,c,k = list(map(int, input().split(" ")))

d = k-a
if d == 0:
  print(a)
elif d < 0:
  print(k)
elif d > 0:
  if b >= d:
    print(a)
  else:
    i = d-b
    print(a-i)
  

Measured memory_bytes: 9172
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        c: chars
    }
    // println!("{}", std::char::from_u32((c as u32) + 1).unwrap());
    println!("{}", (c[0] as u8 + 1) as char);
}


Measured memory_bytes: 4352
#include<stdio.h>

int n, A[50];

int solve(int i, int m)
{
   if(m==0) return 1;
   if(i>=n) return 0;

   int x = solve(i+1, m) || solve(i+1, m-A[i]);

   return x;
}

int main()
{
   int q, M, i;

   scanf("%d", &n);
   for(i=0; i<n; i++)
      scanf("%d", &A[i]);
   scanf("%d", &q);
   for(i=0; i<q; i++) {
      scanf("%d", &M);
      if(solve(0, M)) {
         printf("yes\n");
      } else {
         printf("no\n");
      }
   }
   return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;
int main(){

    int n;cin>>n;
    vector<ll>ans(1000005,0),b(n);
    rep(i,n){
        cin>>b[i];
        ll l = 1;
        if(ans[b[i]]!=0) ans[b[i]]=2;
        else{
            while(b[i]*l<1000005){
                ans[b[i]*l]++;
                l++;
            }
        }
    }
    ll cnt=0;
    rep(i,n){
       if(ans[b[i]]==1)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 12736
package main

import (
	"fmt"
	"math"
)

func main()  {
	var n, a, min int64
	fmt.Scan(&n)
	min = 10000000000000000
	for i:=0; i<5; i++ {
		fmt.Scan(&a)
		min = int64(math.Min(float64(a), float64(min)))
	}
	//fmt.Println(n,min)
	if mod := n%min; mod == 0 {
		fmt.Println(n/min+4)
	} else {
		fmt.Println(n/min+5)
	}
}


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

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e3+5;
int k, n, a[N][N];
int main()
{
    n = read(); if((n&-n) == n) return puts("No"), 0;
    puts("Yes");
    printf("1 2\n2 3\n3 %d\n%d %d\n%d %d\n", n+1, n+1, n+2, n+2, n+3);
    for(int i = 2; i*2+1 <= n; ++i) 
        printf("1 %d\n1 %d\n%d %d\n%d %d\n", 2*i, 2*i+1, 2*i, n+2*i+1, 2*i+1, n+2*i);
    if(~n&1)
        for(int x = 2; x <= n; ++x)
        {
            int y = n^x^1; if(x == 3||y == 3||y > n) continue;
            printf("%d %d\n%d %d\n", n, x, n*2, y); break;
        }
    return 0;
}

Measured memory_bytes: 2176
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()


Measured memory_bytes: 9136
///
// File:  alds1_2_b.cpp
// Author: ymiyamoto
//
// Created on Wed Oct  4 01:21:55 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static vector<uint32_t> array;

uint32_t selection_sort()
{
  uint32_t count = 0;

  for (uint32_t i = 0; i < array.size(); i++) {
    uint32_t min = array[i];
    uint32_t min_index = i;
    for (uint32_t j = i; j < array.size(); j++) {
      if (array[j] < min) {
        min = array[j];
        min_index = j;
      }
    }
    if (min_index != i) {
      swap(array[i], array[min_index]);
      count++;
    }
  }

  return count;
}

int32_t main()
{
  uint32_t N;
  cin >> N;

  for (uint32_t i = 0; i < N; i++) {
    uint32_t val;
    cin >> val;
    array.push_back(val);
  }

  uint32_t count = selection_sort();

  for (uint32_t i = 0; i < array.size(); i++) {
    if (i != 0) cout << " ";
    cout << array[i];
  }

  cout << endl << count << endl;

  return 0;
}

Measured memory_bytes: 3136
"use strict";
function Main(input) {
    let b = input.split("\n")[0].split(/\s/)[0];
    let ans;
    switch (b) {
        case 'A': ans = 'T'; break;
        case 'C': ans = 'G'; break;
        case 'T': ans = 'A'; break;
        case 'G': ans = 'C'; break;
        default: ;
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
<?php
fscanf(STDIN, "%d", $n);
$x = fscanf(STDIN, str_repeat("%d ", $n));
  

$a = 1;
$b = array_shift($x);

foreach($x as $k => $v){
  $a = $a * $v + 1 * $b;
  $b = $b * $v;
}

echo $b / $a;


Measured memory_bytes: 4856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int r;
 cin >> r;
 cout<< r*r;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main(void)
{
    char s[1000];
    int i,j,c=1,a=1,b=1;
    int len;
    scanf("%s",s);
    len=strlen(s);

    for (i = 0; i < len;i++){
        if (toupper(s[i]) != toupper(s[len-i-1])){
            c= 0;
            break;
        }
    }
    for (i = 0; i <(len-1)/2;i++){
        if (toupper(s[i]) != toupper(s[(len-1)/2-i-1])){
            a= 0;
            break;
        }
    }
    char t[1000];
    strncpy(t,s+(len+3)/2-1,len-(len+3)/2+1+1);
    int lo=strlen(t);
    
    for (i =0; i <lo;i++){
        if (toupper(t[i]) != toupper(t[lo-i-1])){
            b= 0;
            break;
        }
    }
    if(a==1 && b==1 && c==1){                  
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.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 < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  vector<vector<int>> G(H, vector<int>(W));
  bool l = false;  // l==true　大きい方から入れる
  int x = 0, y = 0;
  REP(i, N) {
    int num = a[i];
    REP(j, num) {
      G[y][x] = (i + 1);
      if (!l && x == W - 1) {
        l = true;
        y++;
        continue;
      }
      if (l && x == 0) {
        l = false;
        y++;
        continue;
      }
      if (!l) {
        x++;
      } else {
        x--;
      }
    }
  }
  REP(i, H) {
    REP(j, W) { cout << G[i][j] << " "; }
    cout << endl;
  }
}


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

int main()
{
    int n = 0;
    int ac = 0,wa = 0,tle = 0,re = 0;
    string s;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s;

        if (s == "AC")
        {
            ac++;
        }
        if (s == "WA")
        {
            wa++;
        }
        if (s == "TLE")
        {
            tle++;
        }
        if (s == "RE")
        {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

int main() {
	long long int N, M, count = 1;
	cin >> N >> M;
	if (N == M) {
		for (int i = 1; i <= N; i++) {
			count *= i;
			count = count % 1000000007;
		}
		count *= count * 2;
	}
	else if (abs(N - M) == 1) {
		for (int i = 1; i <= min(N, M); i++) {
			count *= i;
			count = count % 1000000007;
		}
		count *= count;
		count = count % 1000000007;
		count *= max(N, M);
	}
	else count--;
	cout << count % 1000000007;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    while(1)
    {
        int n, x;
        
        cin >> n >> x;
        
        if(n==0 && x==0) break;
        
        int count = 0;

        for(int i=1;i<n+1;i++)
        {
            for(int j=i+1;j<n+1;j++)
            {
                for(int k=j+1;k<n+1;k++)
                {
                   if (i+j+k==x) count++;
                }
            }
        }
        
        cout << count << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
def yymm(s):
    if 1 <= int(s[2:4]) <= 12:
        return True
    else:
        return False
def mmyy(s):
    if 1<=int(s[:2]) <=12:
        return True
    else:
        return False
s = input()
if mmyy(s) and yymm(s):
    print("AMBIGUOUS")
elif mmyy(s):
    print("MMYY")
elif yymm(s):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
#include<stdio.h>
main(){
  int a,b,c,i;
  while(scanf("%d %d",&a,&b)!=EOF){
  c=a+b;
  for(i=0;c!=0;i++){
    c/=10;
  }
  printf("%d\n",i);
    }
  return 0;
}

Measured memory_bytes: 600
n, l = map(int, input().split())
apple = []
for i in range(n):
    apple.append(l+i)
apple_sum = sum(apple)
abs_list = []
ans_list = []
for i in range(n):
    abs_list.append(abs(sum(apple[:i])+sum(apple[i+1:])-apple_sum))
    ans_list.append(sum(apple[:i])+sum(apple[i+1:])-apple_sum)
if min(abs_list) in ans_list:
    print(min(abs_list)+apple_sum)
else:
    print(-min(abs_list)+apple_sum)

Measured memory_bytes: 38640
#include<stdio.h>
int sum(int a,int x,int n,int n2,int s);
int hako[10];
int type;

int main(void){
	int n,s;
	
	while(1){
		scanf("%d %d",&n,
			&s);
		if(n==0&&s==0){break;}
		type=0;
		type=sum(0,0,n,n,s);
		printf("%d\n",type);
	}
	return 0;
}

int sum(int a,int x,int n,int n2,int s)
{
	int i,sum_num=0;
	
	if(n==0){
		sum_num=0;
		for(i=0;i<n2;i++){
			sum_num+=hako[i];
		}
		if(s==sum_num){
			type++;
		}
		return type;
	}
	for(i=a;i<=9;i++){
		hako[x]=i;;
		if(x!=0){
			if(hako[x-1]==hako[x]){
				continue;
			}
		}
		sum(i+1,x+1,n-1,n2,s);
	}
	return type;
}

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

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

ws = []
vs = []

for i in range(N):
    w, v = map(int, input().split())
    ws.append(w)
    vs.append(v)

dp = [{} for i in range(N)]
dp[0][ws[0]] = vs[0]
dp[0][0] = 0

for i in range(1,N):
    tmp = dp[i-1].copy()
    for key, value in tmp.items():
        dp[i].setdefault(ws[i]+key, 0)
        dp[i].setdefault(key, 0)
        #print(i, key, value, value+vs[i], dp[i][ws[i]+key])
        dp[i][ws[i]+key] = max(value+vs[i], dp[i][ws[i]+key])
        dp[i][key] = max(value,dp[i][key])

max_value = 0
for i in range(N):
    tmp = []
    for key, value in dp[i].items():
        if key <= W:
            tmp.append(value)
    if len(tmp)!=0:
        max_value = max(max_value, max(tmp))

#print(dp)
print(max_value)

Measured memory_bytes: 25780
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define fi first
#define se second
int main()
{
	SPEED
	int k;
	cin >> k;

	string s;
	cin >> s;

	if (s.size() <= k)
	{
		cout << s;
	}
	else
	{
		string s2 = "";

		for (int i = 0; i < k; ++i)
		{
			s2 += s[i];
		}

		s2 += "...";

		cout << s2;
	}
	return 0;
}

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

bool kansu(int a){
  if(a==4||a==6||a==9||a==11) return(true);
  else return(false);
}
 
int main() {
  int x,y;
  cin >> x >> y;
  if(x==2||y==2) cout << "No" << endl;
  else{
    vector<int> a(4);
    a={4,6,9,11};
    if((kansu(x)+kansu(y))%2) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

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

	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());

	int count = 0;
	int k = 0;
	for (int i = 0; i < N; i++) {
		if (k < A.at(i)) count++;
		k = A.at(i);
	}
	cout << count << endl;

}

Measured memory_bytes: 3636
/*input
100000 3
7777 AC
7777 AC
7777 AC
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N, M;
	cin >> N >> M;

	vb gavo(N + 1, false);
	vi blog(N + 1, 0);
	for (int i = 0; i < M; ++i)
	{
		int a;
		str ch;
		cin >> a >> ch;
		if (gavo[a]) continue;
		else if (ch == "WA") blog[a]++;
		else gavo[a] = true;
	}
	int ger = 0, blogu = 0;
	for (int i = 0; i <= N; ++i)
	{
		if (gavo[i]) {
			ger++;
			blogu += blog[i];
		}
	}
	printf("%d %d\n", ger, blogu);
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/


Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll dp[5000];
int main(){
  int n,m;cin>>n>>m;
  vector<ll> a((1<<n),0);
  vector<bool> can(n,false);
for(int i=0;i<m;i++){
    ll c,b;
    ll res=0;
    cin>>c>>b;
    for(int j=0;j<b;j++){
          int d;cin>>d;
          d--;
          res+=(1<<d);
          can[d]=true;
    }
    if(a[res]!=0)a[res]=min(a[res],c);
    else a[res]=c;
}
for(int i=0;i<n;i++){
    if(!can[i]){
        cout<<-1<<endl;
        return 0;
    }
}
fill(dp,dp+5000,inf);
dp[0]=0;
for(int i=0;i<(1<<n);i++){
  if(a[i]==0)continue;
    for(int j=0;j<(1<<n);j++){
      dp[i|j]=min(a[i]+dp[j],dp[i|j]);
}
}
cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 256
n = int(input())

a = list(map(int, input().split()))


checked = []
ans = 0
cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1

for k in cnt_a.keys():
  if cnt_a[k] >= k:
    ans += cnt_a[k] - k
  else:
    ans += cnt_a[k]
    
print(ans)


Measured memory_bytes: 17780
import sys
input = sys.stdin.readline

n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append((a,i+1))

al.sort(reverse=True)

for i in range(1,n+1):
    if al[0][1] == i:
        print(al[1][0])
    else:
        print(al[0][0])

Measured memory_bytes: 86724
A, B = list(map(str, input().split()))

a = int(A)
b = int(B[0])
b2 = int(B[2:4])
#print(b)
#print(b2)
#print(b)


t = a*b
#print(t)
#b3 = b*100
bb = a*b2
tmp = bb//100
#print(tmp)
#print(a*b)
bef = tmp+t
ans = str(bef)

print(ans)


Measured memory_bytes: 9128