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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

constexpr auto M = 1000000007L;

const vector<int64_t>& factors(int64_t m) {
    static unordered_map<int64_t, vector<int64_t>> memo;

    if (memo.count(m) > 0) {
        return memo[m];
    }

    for (int64_t i = 2; i * i <= m; ++i) {
        if (m % i == 0) {
            memo[m].push_back(i);
            if (i != m / i) {
                memo[m].push_back(m / i);
            }
        }
    }

    memo[m].push_back(m);

    return memo[m];
}

template <typename Combi>
int64_t solve(const Combi& combi, int64_t n, int64_t m, int64_t d) {
    static unordered_map<pair<int64_t, int64_t>, int64_t,
                         boost::hash<std::pair<int64_t, int64_t>>>
            memo;

    if (d > n) {
        return 0L;
    }

    if (memo.count({m, d}) > 0) {
        return memo[{m, d}];
    }

    if (m == 1) {
        // C(n, d)
        return memo[{m, d}] = combi(n, d);
    }

    int64_t ret = 0;
    for (auto f : factors(m)) {
        ret += solve(combi, n, m / f, d + 1);
        ret %= M;
    }

    return memo[{m, d}] = ret;
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<int64_t> fact(100001L, 1L), inv_fact(100001L, 1L), inv(100001L, 1L);
    for (auto i : irange(2L, 100001L)) {
        fact[i] = fact[i - 1] * i % M;
        inv[i] = (M - inv[M % i] * (M / i) % M) % M;
        inv_fact[i] = inv_fact[i - 1] * inv[i] % M;
    }

    auto combi = [&](int64_t x, int64_t y) {
        if (y > x) {
            return 0L;
        }

        return fact[x] * inv_fact[y] % M * inv_fact[x - y] % M;
    };

    cout << solve(combi, n, m, 0L) << endl;
}

Measured memory_bytes: 3968
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
string s;
std::set<string> st;
// std::vector<> v;
ll k;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>s>>k;
  ll bo = MIN(s.size()+1,6);
  repl(j,1,bo){
    for(int i = 0 ; i + j <= s.size() ; i++){
      st.insert(s.substr(i,j));
    }
  }
  ll cnt= 1;
  for(auto itr = st.begin(); itr != st.end();++itr) {
    if(cnt==k) {
      cout<<*itr<<endl;
      return ;
    }
    cnt++;
  }

}
int main(){
  solve();
  return 0;
}



Measured memory_bytes: 1664
s=input()
x=[0,0,0,0]
for i in s:
    if i=="N":
        x[0]=1
    elif i=="S":
        x[1]=1
    elif i=="W":
        x[2]=1
    else:
        x[3]=1
#print(x)
if x==[1,1,1,1] or x==[0,0,1,1] or x==[1,1,0,0]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  int n = s.size();
  unordered_map<char, bool> c;
  rep(i, n) c[s[i]] = true;

  rep(i, 26) {
    if (!c['a' + i]) {
      char d = 'a' + i;
      cout << d << endl;
      return 0;
    }
  }
  cout << "None" << endl;


  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

int n;
ll sp[1 << 17];//bitmaskが示す全員が同じグループ
ll dp[1 << 17];//bitmaskが示す全員を使ってグループ 部分集合を全探索
ll match[17][17];
bool check[1 << 17];
bool dcheck[1 << 17];


ll dfs(const ll& a) {
   if (check[a])return sp[a];
   if (!a)return 0;
   check[a] = 1;
   ll atmp = a - ((a - 1)&a);//aの最下位bit
   int k = -1;
   while (atmp) {
	  atmp >>= 1;
	  k++;
   }
   if (a == (1 << k))return sp[a] = 0;
   ll tmp = a;
   while (tmp) {
	  tmp = (tmp - 1)&a;
	  dfs(tmp);
   }
   ll ret = dfs(a - (1 << k));
   int lp = k + 1;
   while (lp < n) {
	  if ((1 << lp)&a) {
		 ret += match[lp][k];
	  }
	  lp++;
   }
   return sp[a]=ret;
}
ll ddfs(const ll& a) {
   if (dcheck[a])return dp[a];
   if (!a)return 0;
   dcheck[a] = true;
   ll atmp = a - ((a - 1)&a);//aの最下位bit
   int k = -1;
   while (atmp) {
	  atmp >>= 1;
	  k++;
   }
   if (a == (1 << k))return dp[a] = 0;
   ll tmp = a;
   ll ret = sp[a];
   while (tmp) {
	  tmp = a & (tmp - 1);
	  ret = max(ret, ddfs(tmp) + ddfs(a - tmp));
   }
   return dp[a]=ret;
}



int main() {
   check[0] = sp[0] = 0;
   cin >> n;
   rep(i, n)rep(j, n) {
	  cin >> match[i][j];
   }
   dfs((1 << n) - 1);
   cout<<ddfs((1 << n) - 1);
}


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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int k=38,n=k*(k-1)+1;
int a[50][50];

int main()
{
    printf("%d %d\n",n,k);
    for(int i=1;i<=k;++i,putchar('\n'))
    {
        putchar('1');
        for(int j=(i-1)*(k-1)+2;j<=i*(k-1)+1;++j)printf(" %d",a[i][j-(i-1)*(k-1)-2]=j);
    }
    for(int i=0;i<k-1;++i)
        for(int j=0;j<k-1;++j,putchar('\n'))
        {
            printf("%d",i+2);
            for(int l=2,Cur=j;l<=k;++l,Cur=(Cur+i)%(k-1))printf(" %d",a[l][Cur]);
        }
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int count = 0;

    for (int i = 0; i < N; i++)
    {
        int d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2)
        {
            count++;
        }
        else
        {
            count = 0;
        }

        if (count == 3)
        {
            break;
        }
    }

    if (count == 3)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
def main():
    H, W = map(int, input().split())
    a = [input() for _ in range(H)]

    # ans = f(H, W, a)
    ans = T(H, W, a)
    for x in ans:
        print(*x, sep="")


def T(H, W, a):
    """
    転置
    本番ではバグらせるのを恐れて愚直に実装した
    """
    b = []
    c = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    for line in zip(*b):
        if len(line) != line.count("."):
            c.append(line)

    if not c:
        return [[]]

    return list(zip(*c))


def f(H, W, a):
    b = []
    for line in a:
        if len(line) != line.count("."):
            b.append(line)

    if not b:
        return [[]]

    idxes = []
    for x in range(len(a[0])):
        y = sum(1 for i in range(len(b)) if b[i][x] == ".")
        if y != len(b):
            idxes.append(x)

    if not idxes:
        return [[]]

    ans = []
    for i in range(len(b)):
        line = []
        for j in range(len(a[0])):
            if j in idxes:
                line.append(b[i][j])
        ans.append(line)

    return ans


if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
// Aizu Vol-1 0195: What is the Most Popular Shop in Tokaich
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int s[5];

int main()
{
	int i, k, max, am, pm;

	while (1) {
		for (i = 0; i < 5; i++) {
			gets(p = buf);	am = getInt(), pm = getInt();
			if (!i && !am && !pm) return 0;
			s[i] = am + pm;
		}
		max = -1;
		for (i = 0; i < 5; i++) {
			if (s[i] > max) max = s[i], k = i;
		}
		printf("%c %d\n", k+'A', max);
	}
	return 0;
}

Measured memory_bytes: 524
loop do
    n = gets.to_i
    break if n == 0
    n.times do
        a = gets.split.map(&:to_i)
        v1 = a[0..3]
        v2 = a[4..7]
        tab = [
            [1, 2, 3, 4],
            [2, -1, 4, -3],
            [3, -4, -1, 2],
            [4, 3, -2, -1]
        ]
        prod = [0, 0, 0, 0]
        (0..3).to_a.repeated_permutation(2).each do |i, j|
            if tab[i][j] > 0
                prod[tab[i][j]-1] += v1[i] * v2[j]
            else
                prod[-tab[i][j]-1] -= v1[i] * v2[j]
            end
        end
        puts prod * ' '
    end
end




Measured memory_bytes: 6940
# nikkei2019-qualC - Different Strokes
def main():
    # player gets ai <-> point spread increases by ai + bi -> sort A by ai + bi
    # player gets Ai whose index is even / rival gets Ai whose index is odd
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=sum, reverse=1)
    ans = sum(i for i, j in A[::2]) - sum(j for i, j in A[1::2])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22112
#include <iostream>
#include <vector>
#define ll long long
#define MOD_P 1000000007
using namespace std;

struct keta {
	int max;
	int min;
	void extra(int x);
};

int main()
{
	int n;
	keta tmp;
	int dp[10][10] = { 0 };
	int ans = 0;

	cin >> n;
	for (int i = 1; i <= n; i++) {
		tmp.extra(i);
		dp[tmp.max][tmp.min]++;
	}

	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			ans += dp[i][j] * dp[j][i];
		}
	}
	printf("%d", ans);
}

void keta::extra(int x)
{
	min = x % 10;
	while (x >= 10) {
		x /= 10;
	}
	max = x;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <fstream>
#include <map>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;

#define ll long long
#define mod 1000000007
#define infinity (ll)1e9+1
#define pdd pair<double,double>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define MP make_pair
#define vi vector<ll>

#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

int main()
{
	string e, o;
	cin >> o >> e;

	if (e.length() == o.length())
	{
		FOR(i, 0, o.length())
			cout << o[i] << e[i];
	}
	else
	{
		FOR(i, 0, o.length() - 1)
			cout << o[i] << e[i];
		cout << o[o.length() - 1];
	}




	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  int64_t max = a*c;
  if (max < a*d) {
    max = a*d;
  }
  if (max < b*c) {
    max = b*c;
  }
  if (max < b*d) {
    max = b*d;
  }
  
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=111;
int n,a[N],p[N],del[N],ans[N];

int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&a[i]),p[i]=i,del[i]=0;
	rep (i,1,n){
		int cnt=0,x;
		rep (j,1,n) if (!del[j]&&p[j]==a[j]) cnt++,x=j;
		if (!cnt) return puts("-1"),0;
		ans[n-i+1]=a[x],del[x]=1;
		rep (j,x+1,n) if (!del[j]) p[j]--;
	}
	rep (i,1,n) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 100;
int n, g[N+1];
V<pii> ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int s=n+1-(n&1);
  FOR(i, 1, n+1) g[i] = min(i, s-i);
  FOR(i, 1, n+1) FOR(j, i+1, n+1) if(g[i]!=g[j]) ans.pb(mp(i, j));
  cout << sz(ans) << endl;
  for(pii p:ans) cout << p.fi << " " << p.se << endl;
}

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

int main(){
    ll n; cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x.at(i);
    ll ans = INF;
    for(int i=1;i<=100;i++){
        ll kouho = 0;
        rep(j,n){
            kouho += (x.at(j)-i)*(x.at(j)-i);
        }
        ans = min(ans,kouho);
    }
    cout << ans << endl;
}


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

const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> key;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j, b) {
      int c;
      cin >> c;
      c--;
      s |= 1 << c;
    }
    key.push_back(P(s, a));
  }
  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  rep(s, 1 << n) {
    rep(i, m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

namespace ABC096B
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).ToList();
            var n = int.Parse(Console.ReadLine());

            var sum = list.Sum();
            var max = list.Max();
            var dis = max * (Math.Pow(2, n) - 1);

            Console.WriteLine(sum + dis);
        }
    }
}


Measured memory_bytes: 11220
import java.util.*;

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

    int[] x = new int[11];
    int r = sc.nextInt();
    int d = sc.nextInt();
    x[0] = sc.nextInt();

    for(int i=0; i<10; i++){
      x[i+1] = r * x[i] - d;
      System.out.println(x[i+1]);
    }
  }
}

Measured memory_bytes: 21204
#create date: 2020-06-14 10:29

import sys
stdin = sys.stdin
from itertools import accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    a = na()
    def step():
        b = [0] * n
        for i, ai in enumerate(a):
            start, stop = i - ai, i + ai + 1
            if start > 0:
                b[start] += 1
            else:
                b[0] += 1
            if stop < n:
                b[stop] -= 1
        return list(accumulate(b))

    for i in range(k):
        anext = step()
        if sum(a) == sum(anext):
            print(*a)
            quit()
        a = anext
    print(*a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 177676
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import itertools
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from typing import Dict, List, Optional, Set, Tuple


def solve(values: List[int], nb: int) -> int:
    for _v in values:
        pass
    return nb


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    # N = int(input())
    S, W = map(int, input().split())
    # values = []
    # for _ in range(N):
    #     values.append(input().split())
    # result = solve(values, N)
    print("safe" if S > W else "unsafe")


def print_output(testcase: int, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))
    # 6 digits float precision {:.6f} (6 is the default value)
    # print("Case #{}: {:f}".format(testcase + 1, result))


def configure_log() -> None:
    "Configure the log output"
    log_formatter = logging.Formatter("%(lineno)d - " "%(message)s")
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


class memoized:
    """Decorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.
    """

    def __init__(self, func):
        self.func = func
        self.cache = {}

    def __call__(self, *args):
        try:
            return self.cache[args]
        except KeyError:
            value = self.func(*args)
            self.cache[args] = value
            return value
        except TypeError:
            # uncachable -- for instance, passing a list as an argument.
            # Better to not cache than to blow up entirely.
            return self.func(*args)

    def __repr__(self):
        """Return the function's docstring."""
        return self.func.__doc__

    def __get__(self, obj, objtype):
        """Support instance methods."""
        return functools.partial(self.__call__, obj)


Measured memory_bytes: 18444
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32)::n,m,i,x,j,k,ans,cnt
    integer(int32), allocatable:: c(:), a(:,:),r(:)
    logical,allocatable:: buy(:)

    read*, n,m,x

    allocate(c(n), a(m,n), r(m))
    allocate(buy(n))

    do i=1,n
        read*, c(i), a(:,i)
    end do
    ans = 1000000000
    do i=0,2**n
        do j=1,n
            buy(j) = btest(i,j-1)
        end do
        r(:) = 0
        cnt=0
        do j=1,n
            if (buy(j))then
                r(:) = r(:) + a(:,j)
                cnt=cnt+c(j)
            end if
        end do
        if (minval(r) >= x) ans = min(ans,cnt)
    end do
    if (ans == 1000000000) ans=-1
    print'(i0)', ans
end program main

Measured memory_bytes: 2844
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[100005];

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

	ll sum = 0;
	for (ll i = 1; i <= n; i++)
	{
		ll inp;
		cin >> inp;

		arr[inp]++;

		sum += inp;
	}

	ll q;
	cin >> q;
	for (ll i = 0; i < q; i++)
	{
		ll x, y;
		cin >> x >> y;

		sum += arr[x] * (y - x);
		arr[y] += arr[x];
		arr[x] = 0;

		cout << sum << endl;
	}
}

Measured memory_bytes: 3940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL A(N);
    VL B(N);
    REP(i,N) cin >> A[i] >> B[i];

    LL ans = 0;
    REP(i,N) dump(B[i])

    for(int i = N-1; i >= 0; i--){
        A[i] += ans;
        dump(B[i])
        if(A[i] % B[i] != 0 && B[i] != 1){
            ans += B[i] - A[i] % B[i];
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n,x;
	cin>>x>>n;
	vector<ll> a(n);
	unordered_map<int,int> m;
	for(ll i=0;i<n;i++) {
		cin>>a[i];
		m[a[i]] = 1;
	}
	ll low = x;
	ll high = x;
	ll ans = -1;
	while(low>=0||high<=101) {
		if(!m[low]&&low>=0)
		{
			ans = low;
			break;
		}
		if(!m[high]&&high<=101)
		{
			ans = high;
			break;
		}
		low--;
		high++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <cstdio>

int main() {
  int h;
  int h1 = 0, h2 = 0, h3 = 0;

  while (scanf("%d", &h) != EOF) {
    if (h > h1) {
      h3 = h2;
      h2 = h1;
      h1 = h;
    } else if (h > h2) {
      h3 = h2;
      h2 = h;
    } else if (h > h3) {
      h3 = h;
    }
  }

  printf("%d\n%d\n%d\n", h1, h2, h3);

  return 0;
}
          
  

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
class UnionFind{
    public:
        ll size;
        ll *par;
        ll *rank;

        UnionFind(ll n){
            size = n;
            par = new ll[n];
            rank = new ll[n];
            for(int i = 0; i < n; ++i){
                par[i] = i;
                rank[i] = 0;
            }
        }

        ~UnionFind(){
            delete[] par;
            delete[] rank;
        }

        ll find(ll child){
            return (child == par[child] ? child : par[child] = find(par[child]));
        }

        void unit(ll x, ll y){
            x = find(x); y = find(y);
            if(x != y){
                if(rank[x] > rank[y]){
                    par[y] = x;
                }else{
                    par[x] = y;
                    if(rank[x] == rank[y]){
                        ++rank[y];
                    }
                }
            }
        }

        bool same(ll x, ll y){
            return (find(x) == find(y));
        }
};
int main(){
    ll N, M;
    cin >> N >> M;
    ll p[N];
    for(ll i = 0; i < N; i++) cin >> p[i];
    UnionFind U(N);
    for(ll i = 0; i < M; i++){
        ll x, y;
        cin >> x >> y;
        U.unit(x - 1, y - 1);
    }
    ll ans = 0;
    for(ll i = 0; i < N; i++) if(U.same(i, p[i] - 1)) ans++;
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int num = 0;
    if(s == "SUN"){
        num = 7;
    }
    if(s == "MON"){
        num = 6;
    }
    if(s == "TUE"){
        num = 5;
    }
    if(s == "WED"){
        num = 4;
    }
    if(s == "THU"){
        num = 3;
    }
    if(s == "FRI"){
        num = 2;
    }
    if(s == "SAT"){
        num = 1;
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
 
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
ll n,k;
const int mod=1000000007;
int main(){
    
    cin>>n>>k;
    
  ll pre[100008];
   ll pre2[100008];
   ll arr[100008];
    FOR(i,1,n){
        cin>>arr[i];
    }
   
    //cout<<"SDefes"<<endl;
    fo(i,100008) {pre[i]=0; pre2[i]=0;}
    ll counter=min(k,arr[1]);
    FOR(i,0,counter){
        pre[i]=1;
        //dbg(pre[i]);
    }
    //dbg(pre[10]);
    //cout<<"SDefes"<<endl;
    pre2[0]=pre[0];
  
    FOR(i,1,k){
        pre2[i]=(pre2[i-1]+pre[i])%mod;
    }
    ll big;
    FOR(i,2,n){
        
        counter=counter+arr[i];
        counter=min(counter,k);
        //dbg2(i,counter);

        FOR(j,0,counter){
            big=j-arr[i];
            //dbg(big);
            if(big>0){big--; pre[j]=(pre2[j]-pre2[big]+mod)%mod; }
            else pre[j]=pre2[j];
            //dbg2(j,pre[j]);
        }
        FOR(nn,counter+1,k) pre[nn]=0;
        pre2[0]=pre[0];
        FOR(ii,1,k){
 
         pre2[ii]=(pre2[ii-1]+pre[ii])%mod;
        }
 
 
    }
    cout<<pre[k]<<endl;
 
 
 
 
 
 
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> v[n];
  rep(i,m){
    int a,b; cin >> a >> b; a--; b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }

  rep(i,n){
    cout << v[i].size() << endl; 
  }
  return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, c;
    int[][] dss, css;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        c = sc.nextInt();
        dss = new int[c][c];
        css = new int[n][n];
        for (int i = 0; i < c; i++) {
            for (int j = 0; j < c; j++) {
                dss[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                css[i][j] = sc.nextInt() - 1;
            }
        }
        solve();
    }

    void solve() {
        int[][] costs = new int[3][c];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < c; k++) {
                    costs[(i + j) % 3][k] += dss[css[i][j]][k];
                }
            }
        }
        boolean[] used = new boolean[c];
        long ans = 1 << 60;
        for (int i = 0; i < c; i++) {
            for (int j = 0; j < c; j++) {
                for (int k = 0; k < c; k++) {
                    if (i == j || j == k || k == i) {
                        continue;
                    }
                    ans = Math.min(ans, costs[0][i] + costs[1][j] + costs[2][k]);
                }
            }
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    string s;
    int n;
    cin >> n;
    cin >> s;
    rep(i,s.size()){
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
		int i;
		int min;
		int a[100000];

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

		sort(a, a + n);

		min = a[m - 1] - a[0];
		for(i = 0; i < (n - m + 1); i++)
		{
			if(a[i + m - 1] - a[i] <= min)
				min = a[i + m - 1] - a[i];
		}
		printf("%d\n", min);
		
		return 0;
	
}

Measured memory_bytes: 512
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if(m==0)
    return 1;
  if(i>=n)
    return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

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: 2688
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005 , maxm = 400005;
const long long inf = 41351356514454ll;
typedef pair<int , long long> pii;
#define x first
#define y second
struct edge{
	int u , v , p;
	long long w;
	edge(){}
	void read(int i){scanf("%d%d%lld" , &u , &v , &w);p=i;}
	friend bool operator < (const edge &a , const edge &b){return a.w < b.w;}
}e[25][maxm] , t[maxm] , d[maxm];
pii q[maxm];
int n , m , qc;
long long sum[maxn] , f[maxn] , sz[maxn] , c[maxm] , a[maxm];
long long ans[maxm];
void reset(edge *s , int tot)
{
	for (int i = 1 ; i <= tot ; i++)
		f[s[i].u] = s[i].u , f[s[i].v] = s[i].v;
}
int set_find(int u){return f[u] == u ? u : f[u] = set_find(f[u]);}
void set_merge(int u , int v){f[set_find(u)] = set_find(v);}
void cont(int &tot , long long &cnt)
{
	int tmp = 0;
	reset(d , tot);
	sort(&d[1] , &d[tot + 1]);
	for (int i = 1 ; i <= tot ; i++)
		if (set_find(d[i].u) != set_find(d[i].v))
			set_merge(d[i].u , d[i].v) , t[++tmp] = d[i];
	reset(t , tmp);
	for (int i = 1 ; i <= tmp ; i++)
		if (t[i].w != -inf && set_find(t[i].u) != set_find(t[i].v))
			set_merge(t[i].u , t[i].v) , cnt+=t[i].w;
	tmp = 0;
	for (int i = 1 ; i <= tot ; i++)
		if (set_find(d[i].u) != set_find(d[i].v))
			t[c[d[i].p] = ++tmp] = d[i],
				t[tmp].u = f[d[i].u],
				t[tmp].v = f[d[i].v];
	for (int i = 1 ; i <= tmp ; i++)
		d[i] = t[i];
	tot = tmp;
}
void redu(int &tot)
{
	int tmp = 0;
	reset(d , tot);
	sort(&d[1] , &d[tot + 1]);
	for (int i = 1 ; i <= tot ; i++)
		if (set_find(d[i].u) != set_find(d[i].v))
			set_merge(d[i].u , d[i].v),
				t[c[d[i].p] = ++tmp] = d[i];
		else if (d[i].w == inf)
			t[c[d[i].p] = ++tmp] = d[i];
	for (int i = 1 ; i <= tmp ; i++) d[i] = t[i];
	tot = tmp;
}
void solv(int l , int r , int lay , long long cnt)
{
	int tot = sum[lay];
	if (l == r) a[q[l].x] = q[l].y;
	for (int i = 1 ; i <= tot ; i++) e[lay][i].w = a[e[lay][i].p];
	for (int i = 1 ; i <= tot ; i++) d[i] = e[lay][i] , c[d[i].p] = i;
	if (l == r)
	{
		ans[l] = cnt;
		reset(d , tot);
		sort(&d[1] , &d[tot + 1]);
		for (int i = 1 ; i <= tot ; i++)
			if (set_find(d[i].u) != set_find(d[i].v))
				set_merge(d[i].u , d[i].v) , ans[l] += d[i].w;
		return;
	}
	for (int i = l ; i <= r ; i++) d[c[q[i].x]].w = -inf;
	cont(tot , cnt);
	for (int i = l ; i <= r ; i++) d[c[q[i].x]].w = inf;
	redu(tot);
	for (int i = 1 ; i <= tot ; i++) e[lay + 1][i] = d[i];
	sum[lay + 1] = tot;
	int mid = (l + r) / 2;
	solv(l , mid , lay + 1 , cnt);
	solv(mid + 1 , r , lay + 1 , cnt);
}
int main()
{
	scanf("%d%d" , &n , &m);
	for (int i = 1 ; i <= m ; i++)
	{
		e[0][i].read(i);a[i] = e[0][i].w;
		q[++qc] = pii(i , (long long)1e13);
		q[++qc] = pii(i , e[0][i].w);
	}
	sum[0] = m;
	solv(1 , qc , 0 , 0);
	for (int i = 1 ; i <= qc ; i += 2)
		printf("%lld\n" , ans[i] < 1e13 ? ans[i] : -1ll);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int, ll> mp;
  int MAX = 100010;
  rep(i, MAX) mp[MAX] = 0;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  ll total = 0;
  rep(i, MAX) { total += mp[i] * i; }
  int q;
  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    int t = mp[b];
    mp[c] += t;
    total -= mp[b] * b;
    total += c * mp[b];
    mp[b] = 0;
    cout << total << endl;
  }
}


Measured memory_bytes: 9864
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    cout<<(abs(a-b)+abs(b-c)+abs(a-c)-max(abs(a-b),max(abs(a-c),abs(b-c))));
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7
INF = 1 << 60

# ---------------------------------------------------
# ---------------------------------------------------
# ---------------------------------------------------

def resolve():
    def rec(S, v):
        if dp[S][v] >= 0:
            return dp[S][v]
        if S == (1<<V)-1 and v==0:
            dp[S][v] = 0
            return 0
        res = INF
        for to in range(V):
            if not (S>>to & 1):
                res = min(res, rec((S | (1<<to)), to) + dist[v][to])

        dp[S][v] = res
        return res

    V, E = map(int, input().split())
    dist = [[INF] * V for _ in range(V)]
    for i in range(E):
        x, y, d = map(int, input().split())
        dist[x][y] = d

    dp = [[-1] * V for _ in range(1 << V)]

    res = rec(0, 0)
    if res == INF:
        print(-1)
    else:
        print(res)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 15460
n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[0 for _ in range(n-k+1)]
q=sum(p[:k])
s[0]=q
m=q
f=0
for i in range(1,n-k+1):
  q=q-p[i-1]+p[i-1+k]
  s[i]=q
  if q>m:
    f=i
    m=q
ans=0
for i in range(f,f+k):
  ans+=(p[i]+1)/2






print(ans)

Measured memory_bytes: 25060
n = int(input())
A = [int(num) for num in input().split()]
import collections as cl
dic = cl.Counter(A)

cont = False
if n % 2 == 1:
  if dic[0] != 1:
    cont = True
  else:
    dic[0] = 2
    for num in dic.values():
      if num != 2:
        cont = True
        break
else:
  for num in dic.values():
    if num != 2:
      cont = True
      break

if cont == True:
  print(0)
else:
  print(2**(n//2) % (10**9 + 7))

Measured memory_bytes: 55532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DMultipleOf2019 solver = new DMultipleOf2019();
        solver.solve(1, in, out);
        out.close();
    }

    static class DMultipleOf2019 {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            String s = in.next();
            long res = solveMe(s);
            out.println(res);
            //out.print("Case #"+ testNumber + ": ");
        }

        private long solveMe(String s) {
            int[] values = new int[2019];
            int cur = 0;
            int mult = 1;
            values[0]++;
            for (int i = 0; i < s.length(); i++) {
                cur = cur * 10 + (s.charAt(i) - '0');
                cur %= 2019;
                int ans = cur * mult;
                values[ans % 2019]++;
                //d("cur = " + cur);
                mult *= 202;
                mult %= 2019;

            }
            //d(stringMeDeb(toArray(values)));
            long res = 0;
            for (int i = 0; i < 2019; i++) {
                res += (values[i] - 1) * (values[i]) / 2;
            }
            return res;
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

    }
}



Measured memory_bytes: 36060
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;

  long long ans = 1800 * m + 100 * n;
  while (m--) {
    ans *= 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
cdl = list(map(int, input().split()))
res = 5 * 10 ** 8
for i in range(n-k+1):
    l = cdl[i]
    r = cdl[i+k-1]
    res = min(res, abs(l)+abs(r-l), abs(r)+abs(r-l))
print(res)
    

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  long long K;
  cin >> K;
  map<int, long long> M;
  for (int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    M[a] += b;
  }
  long long c = 0;
  for (auto x : M){
    c += x.second;
    if (c >= K){
      cout << x.first;
      break;
    }
  }
}

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

int n,x,gn[100006],gj[100006],maxgj,maxgn,maxgj2,maxgn2,ansgj,ansgj2,ansgn,ansgn2,ans;
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		if(i&1) gj[x]++;
		else gn[x]++;
	}
	for(int i=1;i<=1e5;i++){
		if(maxgj < gj[i]){
			maxgj2= maxgj;
			ansgj2= ansgj;
			maxgj= gj[i];
			ansgj= i;
		} else if(maxgj2 < gj[i]){
			ansgj2= i;
			maxgj2= gj[i];
		}
		if(maxgn < gn[i]){
			ansgn2= ansgn;
			maxgn2= maxgn;
			maxgn= gn[i];
			ansgn= i;
		} else if(maxgn2 < gn[i]){
			ansgn2= i;
			maxgn2= gn[i];
		}
	}
//	cout << maxgn2 << ' ' << maxgj2 << '\n';
	if(ansgj!=ansgn){
		ans= n/2-maxgj+n/2-maxgn;
	} else {
		if(maxgn == maxgn2 || maxgj == maxgj2){
			ans= n/2-maxgj+n/2-maxgn;
		} else {
			if(maxgj > maxgn){
				ans= n/2-maxgj+n/2-maxgn2;
			} else if(maxgn > maxgj){
				ans= n/2-maxgn+n/2-maxgj2;
			} else {
				if(maxgj2 > maxgn2){
					ans= n/2-maxgj2+n/2-maxgn;
				} else {
					ans= n/2-maxgn2+n/2-maxgj;
				}
			}
//			} else {
//				ans= n/2-maxgn+n/2-maxgj;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1024
n = int(input())
S = list(input())

a_z =[chr(ord('A') + i) for i in range(26)]
new_S=[]

for i in range(len(S)):
  old_index=a_z.index(S[i])
  new_index=(old_index+n)%26
  new_S.append(a_z[new_index])

print(*new_S, sep='')

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

void exchange(int *A, int n) {
  int harf = n / 2;
  for (int i = 0; i < harf; ++i) {
    swap(A[i],A[n - i - 1]);
  }
}

int main() {
  int A[1010];
  int i, n, q, begin, end, diff;

  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> A[i];
  }

  cin >> q;
  for (i = 0; i < q; ++i) {
    cin >> begin >> end;
    diff = end - begin;
    exchange(&A[begin],diff);
  }

  for (i = 0; i < n; ++i) {
    if (i != 0) cout << ' ';
    cout << A[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 3104