akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	string s;
	cin>>s;
	s[3]='8';
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
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()
    prev = (0, 0, 0)
    for _ in range(N):
        T, X, Y = prev
        t, x, y = MI()
        if abs(x - X) + abs(y - Y) <= abs(T - t):
            if (abs(x - X) + abs(y - Y) - (T - t)) % 2 != 0:
                print("No")
                exit()
        else:
            print("No")
            exit()
        prev = (t, x, y)
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]

A,B = zip(*AB)
A = sorted(list(A))
B = sorted(list(B))


if N % 2 == 1:
    mn = A[N//2]
    mx = B[N//2]
    print(mx-mn+1)
else:
    mn1 = 2*A[N//2-1]
    mn2 = 2*A[N//2]
    mn = (mn2+mn1)//2
    mx1 = 2*B[N//2-1]
    mx2 = 2*B[N//2]
    mx = (mx2+mx1)//2
    print(mx-mn+1)





Measured memory_bytes: 129420
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<17)
set<int> g[MX];
ll S[MX],X[MX];
int N,a,b,A[MX],q[MX],e;
bool go(){
    b=-1;
    F(N)if(g[i].size()==1u)q[e++]=i,S[i]=A[i];
    while(++b<e){
        a=q[b];
        if(S[a]>2ll*A[a]||S[a]<A[a]||X[a]>A[a])return 0;
        if(g[a].empty()&&S[a]^2*A[a])return 0;
        for(auto&h:g[a]){
            S[h]+=2ll*A[a]-S[a],X[h]=max(X[h],2ll*A[a]-S[a]);
            g[h].erase(a);
            if(g[h].size()<2u)q[e++]=h;
        }
    }
    return 1;
}
int main(void){
    scanf("%d",&N),ga(N,A);
    F(N-1)scanf("%d%d",&a,&b),g[--a].insert(--b),g[b].insert(a);
    puts(go()?"YES":"NO");
    return 0;
}


Measured memory_bytes: 18176
using System;
using System.Linq;

namespace ABC115
{
    class B
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var p = Enumerable.Repeat(0, N).Select(_ => int.Parse(Console.ReadLine())).ToArray();
            Console.WriteLine(p.Sum() - p.Max() + p.Max() / 2);
        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
using namespace std;
int main(){
	int n,t=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++){//1 2
		for(int j=i+1;j<=n;j++){//2 3 3
			t+=a[i]*a[j];
		}
	}

	cout<<t;
	return 0;
}

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

#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int n,W; cin >> n >> W;
    vector<int> w(n+1),v(n+1);
    rep(i,n) cin >> w[i+1]>>v[i+1]; 
    //1-index
    //dp[i][j]:i番目までの品物で重さj以下の時の最大価値
    vector<vector<int>> dp(110,vector<int>(100010,0));
    for(int i=0; i<n; i++){
        rep(j,W+1){
            if(j-w[i+1]>=0) chmax(dp[i+1][j],dp[i][j-w[i+1]]+v[i+1]);
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout<<dp[n][W]<<endl;
}

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

using namespace std;

#define ll long long

signed main() {
	int n, k;
	cin >> n >> k;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];

	ll ans = 0;

	/* 左からi個、右からj個取りだす. */
	for (int i = 0; i <= min(n, k); ++i) {
		for (int j = 0; j <= min(n, k) - i; ++j) {
			vector<ll> js; // 取り出した宝石
			for (int l = 0; l < i; ++l)
				js.push_back(v[l]);
			for (int l = n - 1; l >= n - j; --l)
				js.push_back(v[l]);
			sort(js.begin(), js.end());
			// 価値が負の宝石を最大k-i-j個取らない
			for (int l = 0; l < min(k - i - j, (int)js.size()); ++l) {
				if (js[l] < 0) js[l] = 0;
				else break;
			}
			// ansの更新
			ans = max(ans, accumulate(js.begin(), js.end(), (ll)0));
		}
	}

	cout << ans << endl;

	return 0;
}

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

int N, mx = -1, mxi, A[222][222], D[222];
bool vs[222];

void fail() {
    puts("-1");
    exit(0);
}

void bfs(int st) {
    D[st] = 1;
    queue<int> que;
    vs[st] = 1; que.push(st);
    while(que.size()) {
        int x = que.front(); que.pop();
        for(int i=1; i<=N; i++) {
            if(A[x][i] && !vs[i]) {
                vs[i] = 1;
                que.push(i);
                D[i] = D[x] + 1;
            }
        }
    }
}

int main() {
    scanf("%d",&N);
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=N; j++) {
            scanf("%1d", &A[i][j]);
        }
    }
    int ans = 1;
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=N; j++) vs[j] = D[j] = 0;
        bfs(i);
        for(int j=1; j<=N; j++) ans = max(ans, D[j]);
    }
    for(int i=1; i<=N; i++) {
        for(int j=1; j<=N; j++) {
            if(A[i][j]) {
                if(D[i] + 1 != D[j] && D[i] != D[j] + 1) fail();
            }
        }
    }
    printf("%d", ans);
    return 0;
}


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

int main()
{
  int a,b,c;
  cin >> a >> b >> c ;
  
  int count = 0;
  for( int i = a; i <= b; i++)
    {
      if(c % i == 0)
	{count = count + 1;}
    }

  cout << count << endl;
}
      



Measured memory_bytes: 3136
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	x%=m;
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N;cin>>N;
	int ans=mod_pow(10,N);
	ans-=mod_pow(9,N)*2;
	ans+=mod_pow(8,N);
	cout<<(ans+mod*10)%mod<<"\n";
}

Measured memory_bytes: 3648
"Template made by : https://codeforces.com/profile/c1729 , github repo : https://github.com/cheran-senthil/PyRival"
from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register

if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream


if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip


def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def main():
    s=input()
    t=input()
    L=[ [0]*(len(t)+1) for _ in range(len(s)+1) ]
    
    def lcs(s,t):
        n=len(s)
        m=len(t)
        for i in range(0,n+1):
            for j in range(0,m+1):
                if i==0 or j==0:
                    L[i][j]=0
                elif s[i-1]==t[j-1]:
                    L[i][j]=L[i-1][j-1]+1
                else :
                    L[i][j]=max(L[i-1][j],L[i][j-1])
    lcs(s,t)
    ans=[]
    i=len(s)
    j=len(t)
    while L[i][j]!=0:
        if L[i][j]!=L[i-1][j] and L[i][j]!=L[i][j-1]:
            ans.append(s[i-1])
            i-=1
            j-=1
        else :
            if L[i][j]==L[i-1][j]:
                i-=1
                continue
            else :
                j-=1
                continue
    print(''.join(ans[::-1]))
if __name__ == '__main__':
    sync_with_stdio(False)
    main()

Measured memory_bytes: 103324
#include <iostream>
#include <algorithm>
#include <set>

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

	std::set<int> seti;
	int a[200010];
	for (int i = 0; i < n; ++i)
	{
		std::cin >> a[i];
		seti.insert(a[i]);
	}

	if (seti.size() == n)
		std::cout << "YES";
	else
		std::cout << "NO";

}

Measured memory_bytes: 13740
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,cnt;
	char s[4],t[4];
	cnt=0;
	cin>>s>>t;
	for(i=0;i<3;i++){
		if(s[i]==t[i]) cnt=cnt+1;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
def main():
    n = int(input())
    cards = list(map(int, input().split()))
    alice_point = 0
    bob_point = 0

    cards.sort()
    for i in range(0, n):
        if i%2 == 0:
            alice_point += cards[i]
        else:
            bob_point += cards[i]

    print(abs(alice_point - bob_point))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> X, std::vector<long long> L){
  vector<pll> XL(N);
  REP(N){
    XL[i]=pll(X[i]+L[i],L[i]);
  }
  sort(XL.begin(),XL.end());
  ll last=-10000000000LL;
  ll ans=0;
  REP(N){
    ll x=XL[i].first-XL[i].second,l=XL[i].second;
    if(x-l>=last){
      ++ans;
      last=x+l;
    }
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(X), std::move(L));
    return 0;
}


Measured memory_bytes: 3456
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)1e5+10;
const ll DIV = (ll)1e9+7;
// ll dp[MAXN][MAXN];


int main(void) {
   ll N,M;
   cin>>N>>M;
   ll onestep = (N-M)*100 + M*1900;
   ll ans = onestep * pow(2,M);
   cout<<ans<<endl;




   return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
 
int main()
{
    int N; cin >> N;
    cout << 111 * ((N - 1) / 111 + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

from collections import deque
tuples=[]
def f(que):
    if len(que)==n:
        tuples.append(tuple(que))
        return
    
    for v in range(1,n+1):
        if v not in que:
            que.append(v)
            f(que)
            que.pop()
f(deque([]))
#print(tuples)
#print(tuples.index(p))
#print(tuples.index(q))
print(abs(tuples.index(p)-tuples.index(q)))

Measured memory_bytes: 8180
n,y = map(int,input().split())
p = 0
for i in range(n+1):
    for j in range(n+1):
        k = (n-i-j)
        if k < 0:
            k = 0
        if 1000*i+5000*j+10000*k == y:
            if i+j+k == n:
                print(k,j,i)
                p += 1
                break       
    if p == 1:
        break
            
    
if p == 0:
    print("-1 -1 -1")
    

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  public static class edge {
    int from;
    int to;
    int cost;
    edge (int _from, int _to, int _cost) {
      from = _from;
      to   = _to;
      cost = _cost;
    }
  }

  static final int INF = Integer.MAX_VALUE;
  static int n;
  static int d[];
  static edge es[][];

  public static void shortest_path_BF(int s) {
    int i, j;
    Arrays.fill(d, INF);

    d[s] = 0;
    while (true) {
      boolean update = false;
      for (i=0; i<n; i++)
        for (j=0; j<es[i].length; j++) {
          edge e = es[i][j]; 
          if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
            d[e.to] = d[e.from] + e.cost;
            update = true;
          }
        }
      if (!update) break;
    }
  }

  public static void main(String[] args) {
    int i, j;

    Scanner sc = new Scanner(System.in);
    n = Integer.parseInt(sc.next());
    es = new edge[n][];
    d = new int[n];

    for (i=0; i<n; i++) {
      int u = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
      es[i] = new edge[k];
      for (j=0; j<k; j++) {
        int v = Integer.parseInt(sc.next());
        es[i][j] = new edge(u-1, v-1, 1);
      }
    }

    shortest_path_BF(0);

    for (i=0; i<n; i++) {
      int v = (d[i] != INF) ? d[i] : -1;
      System.out.print(String.valueOf(i+1) + ' ');
      System.out.print(String.valueOf(v) + '\n');
    }
  }
}

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

public class Main
{
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer ST = new StringTokenizer(BR.readLine());
		int A = Integer.parseInt(ST.nextToken()), B = Integer.parseInt(ST.nextToken()), C = Integer.parseInt(ST.nextToken()), D = Integer.parseInt(ST.nextToken());
		boolean takaTurn = true;
		while (A > 0 && C > 0)
		{
			if (takaTurn) C -= B;
			else A -= D;
			takaTurn = !takaTurn;
		}
		System.out.println((A > 0) ? "Yes" : "No");
	}
}


Measured memory_bytes: 25360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int n, W;
const int maxn = 1e5 + 5;
ll w[111], v[111];
ll f[111][maxn];
//ll f[maxn];
ll ans, sum;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),	cout.tie(0);
	cin >> n >> W;
	for(int i = 1; i <= n; ++i){
		cin >> w[i] >> v[i];
		sum += v[i];
	}
//	for(int i = 1; i <= sum; ++i) f[i] = 1e18;
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= maxn; ++j) f[i][j] = 1e18;
	}f[0][0] = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = sum; j >= 0; --j){
			if(j >= v[i]) f[i][j] = min(f[i-1][j], f[i-1][j-v[i]] + w[i]);
			else f[i][j] = f[i-1][j];
		}
	}
	for(int j = 1; j <= sum; ++j){
		if(f[n][j] <= W) ans = j;
	}
	printf("%d", ans);
}

Measured memory_bytes: 82588
#include<bits/stdc++.h>
using namespace std;
int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,c,p[200],a=0,b=0;
  cin>>n>>c;
  for(int i=0;i<c;i++){
    cin>>p[i];
    a+=p[i];
    if(a%(n+1)!=0){
      b=a/(n+1)+1;
    }
    else{
      b=a/(n+1);
    }
  }
  cout<<b<<"\n";
}



Measured memory_bytes: 3212
import java.util.Scanner;

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

    int n = sc.nextInt();
    int min =  Integer.MAX_VALUE;
    int max = -Integer.MAX_VALUE;
    long sum = 0;

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

        int a = sc.nextInt();
        min = Math.min(min,a);
        max = Math.max(max,a);
        sum += a;

      }

    System.out.println( min + " " + max + " " + sum );

    } 
}


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

const int MAXN = 200005;

char s[MAXN];
int N, dp[MAXN][3];

int main(){
	scanf("%s", s);
	N = strlen(s);
	
	for(int i = N; i >= 0; i--)
	for(int j = 0; j <= 2; j++){
		if(i == N)dp[i][j] = 0;
		else{
			dp[i][j] = -1 << 20;
			if(j == 0 || j == 2 || (i > 0 && s[i - 1] != s[i])){
				dp[i][j] = max(dp[i][j], 1 + dp[i + 1][1]);
			}
			if(i + 2 <= N && (j == 0 || j == 1 || (i > 2 && (s[i - 2] != s[i] || s[i - 1] != s[i + 1])))){
				dp[i][j] = max(dp[i][j], 1 + dp[i + 2][2]);
			}
		}
	}
	printf("%d\n", dp[0][0]);
	
	return 0;
}


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

using namespace std;

#define arr array
#define ll long long
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#define dump(x) cerr << #x " = " << x << endl

bool is_lowercase(char c) {
  return c>='a'&&c<='z';
}
bool is_uppercase(char c) {
  return c>='A'&&c<='Z';
}

char to_lowercase(char c) {
//  assert(is_uppercase(c));
  if (is_lowercase(c))
    return c;
  return c-'A'+'a';
}

char to_uppercase(char c) {
//  assert(is_lowercase(c));
  if (is_uppercase(c))
    return c;
  return c-'a'+'A';
}

char switch_case(char c) {
  if (is_uppercase(c)) {
    return to_lowercase(c);
  } else {
    return to_uppercase(c);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  constexpr char endl = '\n';

  int k, n;
  cin >> k >> n;
  vector<int> v;
  REP(i, n) {
    int a;
    cin >> a;
    v.push_back(a);
    v.push_back(a-k);
  }
  sort(v.begin(), v.end());

  int mn=k;
  int sz=v.size();
  REP(i,sz-n+1) {
    int d=v[i+n-1]-v[i];
    if (d<mn) {
      mn=d;
    }
  }

  cout << mn << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
int Q;
cin>>Q;
deque<string> que{s};
ll t1=0;
rep(i,Q){
    int q;
    cin>>q;
    if(q==1){
        t1++;
    }
    else if(q==2){
        int f;
        string c;
        cin>>f>>c;
        if(t1%2==0){
            if(f==1)que.push_front(c);
            else que.push_back(c);
        }
        else{
            if(f==1)que.push_back(c);
            else que.push_front(c);
        }
    }
}

string ans = "";
while(!que.empty()){
    ans+=que.front();
    que.pop_front();
}
if(t1%2!=0){
    reverse(ans.begin(),ans.end());
}

cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 12084
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, ans;
void rec(int cur){
	int f = 0;
	for(int m = cur; m; m /= 10){
		if(m % 10 == 7) f |= 4;
		if(m % 10 == 5) f |= 2;
		if(m % 10 == 3) f |= 1;
	}
	if(f == 1 + 2 + 4) ans++;
	if((ll)cur * 10 + 7 <= n) rec(cur * 10 + 7);
	if((ll)cur * 10 + 5 <= n) rec(cur * 10 + 5);
	if((ll)cur * 10 + 3 <= n) rec(cur * 10 + 3);
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	rec(0);
	cout << ans << endl;
	return 0;
}

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

bool d[52][52][52][52];
int X, Y, tx, ty, kx, ky;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, mem[52][52];

int main()
{
loop:
  cin >> X >> Y;
  if(!X)
    return 0;
  cin >> tx >> ty >> kx >> ky;
  for(int y = 1; y <= Y; y++)
  {
    for(int x = 1; x <= X; x++)
    {
      int a;
      cin >> a;
      mem[y][x] = a;
    }
    mem[y][0] = 1;
    mem[y][X + 1] = 1;
  }
  for(int x = 0; x <= X + 1; x++)
  {
    mem[0][x] = 1;
    mem[Y + 1][x] = 1;
  }

  fill_n((bool*)d, 52 * 52 * 52 * 52, false);
  
  queue<int> q;
  q.push(tx);
  q.push(ty);
  q.push(kx);
  q.push(ky);
  q.push(0);
  while(!q.empty())
  {
    int x1 = q.front(); q.pop();
    int y1 = q.front(); q.pop();
    int x2 = q.front(); q.pop();
    int y2 = q.front(); q.pop();
    int n = q.front(); q.pop();
    
    if(n >= 100)
    {
      break;
    }
    
    if(y1 == y2 && x1 == x2)
    {
      cout << n << endl;
      goto loop;
    }

    for(int i = 0; i < 4; i++)
    {
      int tx1 = x1 + dx[i];
      int ty1 = y1 + dy[i];
      int tx2 = x2 - dx[i];
      int ty2 = y2 - dy[i];

      if(mem[ty1][tx1])
      {
        tx1 = x1;
        ty1 = y1;
      }
      if(mem[ty2][tx2])
      {
        tx2 = x2;
        ty2 = y2;
      }
      if(d[tx1][ty1][tx2][ty2])
        continue; 

      d[tx1][ty1][tx2][ty2] = true;
      q.push(tx1);
      q.push(ty1);
      q.push(tx2);
      q.push(ty2);
      q.push(n + 1);
    }
  }
  cout << "NA" << endl;
  goto loop;
}

Measured memory_bytes: 8716
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

int main (){
	int NNN;
	cin >> NNN ;
	vector <pair<int,int>> aka;
	vector <pair<int,int>> aoi;
	int tempx,tempy;
	
	rep(i,NNN){
		cin >> tempx >> tempy;
		aka.push_back(make_pair(tempx,tempy));
	}
	
	rep(i,NNN){
		cin >> tempx >> tempy;
		aoi.push_back(make_pair(tempx,tempy));
	}
	sort(aka.begin(),aka.end());
	sort(aoi.begin(),aoi.end());
	int counter=0;
	int akax,akay;
	int aoix,aoiy;
	int maxakay=-1;
	int pointeraka=0;
	int pointeraoi=0;
	int memoakamax;
	bool check = false;
	bool akaused[aka.size()];
	rep(i,aoi.size()){
		akaused[i]=true;
	}
	while(pointeraoi!=aoi.size()){
		aoix = aoi[pointeraoi].first;
		aoiy = aoi[pointeraoi].second;
		check = false;
		pointeraka=0;
		maxakay=-1;
		while(pointeraka<=aka.size()){
			
			if(akaused[pointeraka]==false) {
				pointeraka++;
				continue;
			}
			//aoiused == trueでしか行かない

			akax = aka[pointeraka].first;
			akay = aka[pointeraka].second;
			if(akax>=aoix){
				break;
			}
			if(akay<aoiy && akax<aoix){
				if(akay > maxakay){
					maxakay = akay;
					memoakamax = pointeraka;
					check=true;
				}
			}
			pointeraka++;
			if(pointeraka>=aka.size()){
				break;
			}
		}

		if(check){
			akaused[memoakamax]= false;
			counter ++;
			//cout << aka[memoakamax].first <<" " << aka[memoakamax].second << " " <<aoi[pointeraoi].first << " "<< aoi[pointeraoi].second << endl;
		}

		pointeraoi++;
		if(pointeraoi>=aoi.size()){
			break;
		}
	}

	cout << counter << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll n, k;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {cin >> a[i]; a[i] -= i + 1;}
    sort(a.begin(), a.end());
    int mid;
    mid = a[n / 2];
    //for(int i = 0; i < n; i++) cout << a[i] << " ";
    ll ans = 0;
    for(int i = 0; i < n; i++) ans += abs(mid - a[i]);
    cout << ans << "\n";
}

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

kmax = 40

def main():
    n = int(input())
    di = []
    for i in range(kmax):
        assert abs(n) % (1 << i) == 0
        d = (abs(n) & (1 << i)) >> i
        assert d in [0, 1]
        n -= (-2) ** i * d
        di.append(d)
    di = reversed(di)
    di = [str(x) for x in di]
    di = "".join(di)
    print(int(di))

main()



Measured memory_bytes: 3064
n,a,b = map(int,input().split())
H = [int(input()) for i in range(n)]

lo = -1
hi = 10**9+1

while hi-lo > 1:
    mi = (hi+lo)//2
    rest = 0
    for i in range(n):
        rest += max(0,-(-(H[i]-b*mi)//(a-b)))
    if rest <= mi:
        hi = mi
    else:
        lo = mi
        
print(hi)

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

int main(){
    string s;
    cin >> s;
    bool flag=true;
    int n=s.size();
    string d="dream",der="dreamer",e="erase",eer="eraser";
    reverse(s.begin(),s.end());
    for(int i=0; i<n; i++){
        if(s.substr(i,7)=="remaerd")i+=6;
        else if(s.substr(i,6)=="resare")i+=5;
        else if(s.substr(i,5)=="esare")i+=4;
        else if(s.substr(i,5)=="maerd")i+=4;
        else{
            flag=false;
            break;
        }
    }
    if(flag)cout << "YES";
    else cout << "NO";
    cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 998244353
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    while(true){
        ll n,m;
        cin >> n >> m;
        if (n+m==0)break;
        ll c[m],x[n];
        for (ll i=0;i<m;i++){
            cin >> c[i];
        }
        for (ll i=0;i<n;i++){
            cin >> x[i];
        }
        ll dp[n+1][260];
        for (ll i=0;i<=n;i++){
            fill(dp[i],dp[i]+260,INF);
        }
        dp[0][128]=0;
        for (ll i=1;i<=n;i++){
            for (ll j=0;j<=255;j++){
                for (ll k=0;k<m;k++){
                    ll num=max(0LL,min(255LL,j+c[k]));
                    dp[i][num]=min(dp[i][num],dp[i-1][j]+(x[i-1]-num)*(x[i-1]-num));
                }
            }
        }
        ll ans=INF;
        for (ll i=0;i<=255;i++){
            ans=min(dp[n][i],ans);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 43772
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  int a,b,c;cin>>a>>b>>c;
  int res=0;
  vector<int> memo(101,0);
  memo[a]++;
  memo[b]++;
  memo[c]++;
  rep(i,101){
    if(memo[i]!=0)res++;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    int flag = 1;
    char t[n];
    string s[n];
    rep(i,n)cin >> s[i];

    rep(i,n){
        if(s[i] == "AB"){
            if(a == 0 && b == 0){
                flag = 0;
                break;
            }else if(a == 1 && b == 1 && i < n - 1 && s[i+1] != "AB"){
                if(s[i+1] == "AC"){
                    t[i] = 'A';
                    a++;
                    b--;
                }else{
                    t[i] = 'B';
                    a--;
                    b++;
                }
            }else if(a >= b){
                t[i] = 'B';
                a--;
                b++;
            }else{
                t[i] = 'A';
                a++;
                b--;
            }
        }
        if(s[i] == "AC"){
            if(a == 0 && c == 0){
                flag = 0;
                break;
            }else if(a == 1 && c == 1 && i < n - 1 && s[i+1] != "AC"){
                if(s[i+1] == "AB"){
                    t[i] = 'A';
                    a++;
                    c--;
                }else{
                    t[i] = 'C';
                    a--;
                    c++;
                }
            }else if(a >= c){
                t[i] = 'C';
                a--;
                c++;
            }else{
                t[i] = 'A';
                a++;
                c--;
            }
        }
        if(s[i] == "BC"){
            if(b == 0 && c == 0){
                flag = 0;
                break;
            }else if(b == 1 && c == 1 && i < n - 1 && s[i+1] != "BC"){
                if(s[i+1] == "AC"){
                    t[i] = 'C';
                    c++;
                    b--;
                }else{
                    t[i] = 'B';
                    c--;
                    b++;
                }
            }else if(b >= c){
                t[i] = 'C';
                b--;
                c++;
            }else{
                t[i] = 'B';
                b++;
                c--;
            }
        }
    }

    if(flag)yn;

    if(flag){
        rep(i,n)cout << t[i] << endl;
    }
    
    return 0;
}




Measured memory_bytes: 6852
#include<stdio.h>
int main()
{
	int n, m, l, i, j, k=0, a[100][100], b[100][100];
	long long c[100][100] = {};
	scanf("%d %d %d", &n, &m, &l);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for(i=0;i<m;i++)
	{
		for(j=0;j<l;j++)
		{
			scanf("%d", &b[i][j]);
		}
	}
	while(k!=m)
	{
		for(i=0;i<n;i++)
		{
			for(j=0;j<l;j++)
			{
				c[i][j] += a[i][k] * b[k][j];
			}
		}
		k++;
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<l;j++)
		{
			printf("%ld", c[i][j]);
			if(j != l-1) printf(" ");
			else printf("\n");
		}
	}
}



Measured memory_bytes: 2064
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=(len(sb)+len(tb))
print(ans)


Measured memory_bytes: 41636
a, b = map(int, input().split())
c=[0]*a
cnt=0
c=list(map(int, input().split()))
c.sort(reverse=True)
for i in range(a):
    if c[i]>=sum(c)/(b*4):
        cnt=cnt+1
if cnt>=b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

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

using namespace std;

int main(){
    int n; cin >> n;
    int max_number = 0, second_max_number = 0;
    int index;

    REP(i, n){
        int x; cin >> x;
        if(!(max_number <= x))
          second_max_number = max(second_max_number, x);
        else{
            index = i;
            second_max_number = max_number;
            max_number = x;
        }
    }

    REP(i, n){
        if(index != i) cout << max_number << '\n';
        else cout << second_max_number << '\n';
    }
}


Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

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

    vi B(0);
    for (int i = 0; i < N; i++) {
        auto it = upper_bound(B.begin(), B.end(), -A[i]);
        if (it != B.end()) {
            // B[it] > -A[i]
            *it = -A[i];
        } else {
            // B[it] <= -A[i]
            B.push_back(-A[i]);
        }
    }

    cout << B.size() << endl;
    return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

//?´?????????????????§????
//Union-Find??¨
struct UnionFind {
	vector<int> par;
	vector<int> rank;
	int sz; //size
	UnionFind(int n) :par(n, -1), rank(n, 0) {}
	void unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return;
		if (rank[x] < rank[y]) swap(x, y);
		else if (rank[x] == rank[y])rank[x]++;
		par[x] += par[y]; par[y] = x;
		sz--;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
	int size(int x) { return -par[root(x)]; }
	int size() { return sz; }
	void dump() {
		for (int i = 0; i < par.size(); i++) cout << par[i] << " ";
		cout << "par" << endl;
		for (int i = 0; i < rank.size(); i++) cout << rank[i] << " ";
		cout << "rank" << endl;
	}
};

int main() {
	int n, q; cin >> n >> q;
	UnionFind UF(n);

	//UF.dump();
	for (int i = 0; i < q; i++) {
		int com, x, y; cin >> com >> x >> y;
		if (com == 0)UF.unite(x, y);
		else cout << UF.same(x, y) << endl;
		//UF.dump();
	}
	return 0;
}

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

int main (){
  string s;cin>>s;
  ll k;cin>>k;
  ll n = s.size();
  bool ok = true;
  int a;
  rep(i,k){
    if (s.at(i) != '1'){
      ok = false;
      a = s.at(i) - '0';
      break;
    }
  }
  if (ok){
    cout << 1 << endl;
  }
  else {
    cout << a << endl;
  }
}

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

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

const long long INF = 1LL << 60;
int N;
long long h[100010];
long long dp[100010];

int main(int argc, char const *argv[]){
	int N; cin >> N;
	for(int i = 0; i < N; i++) cin >> h[i];

	for(int i = 0; i < 100010; i++) dp[i] = INF;

	dp[0] = 0;

	for (int i = 1; i < N; ++i) {
		chmin(dp[i], dp[i-1] + abs(h[i-1]-h[i]));
		if(i>1) chmin(dp[i], dp[i-2] + abs(h[i-2]-h[i]) );
	}

	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int a[10],temp,i,j;
    for(i=0;i<10;i++) scanf("%d",a+i);
    for(i=0;i<3;i++)
    {  for(j=i;j<10;j++)
        {
            if(*(a+j)>*(a+i))
            {
                temp=a[j];
                a[j]=a[i];
                a[i]=temp;
            }
        }
    printf("%d\n",a[i]);
    }
    return 0;
}

Measured memory_bytes: 600
N = int(input())

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

A.sort(reverse=True)
ans = A.pop(0)
N -= 2
n = N//2
if N % 2 == 0:
    ans += 2 * sum(A[:n])
else:
    ans += 2 * sum(A[:n])
    ans += A[n]

print(ans)

Measured memory_bytes: 94208
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll MAX_N = 1000000;


// m>=nを想定している
ll gcd(ll m, ll n){
    if(n==0) return m;
    return gcd(n,m%n);
}


/*map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(int i=2; i*i<=n; i++){
        while(n%i==0){
            res[i]++;
            n /= i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}*/

// [[vectorを使うかmapを使うか.]]
// 要素の個数に興味があるので
// insertがO(1)のvectorの方が
// insertにO(log n)かかるmapよりも
// 使えるってことね!

// 素因数分解
// nを次々と割っていく
// i=2からスタート
vector<pair<ll,int>> prime_factor(ll n){
    vector<pair<ll,int>> res;
    for(ll i=2; i*i<=n; i++){
        int k=0;
        while(n%i==0){
            n/=i;
            k++;
        }
        // iで一回以上割り切れるなら追加
        if(k!=0) res.push_back({i,k});
    }
    // 残ったnが1ではない時、i*i<=nに引っかかったn=iである.
    if(n!=1) res.push_back({n,1});
    return res;
}


int main(void){
    // 入力
    ll a,b;
    cin >> a >> b;

    // a,bのGCDを求める
    ll gcd_of_ab;
    if(a>=b) gcd_of_ab = gcd(a,b);
    else gcd_of_ab = gcd(b,a);

    // 求めたいのはGCD以下のGCDを割り切る素数の個数
    ll ans=1;
    auto m = prime_factor(gcd_of_ab);
    ans += m.size();

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
ll dp[5001][5001];
int main() {
	int N;
	string s;
	cin >> N;
	cin >> s;
	dp[1][0] = 1;
	dp[1][1] = 2;
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (j > 0) (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
			else (dp[i + 1][0] += dp[i][0]) %= MOD;
			(dp[i + 1][j + 1] += dp[i][j] * 2) %= MOD;
		}
	}
	ll inv = mod_pow(2, MOD - 2);
	cout << (dp[N][s.size()] * mod_pow(inv, s.size())) % MOD << endl;
}

Measured memory_bytes: 193792
import Data.List

main :: IO ()
main = do
  l1 <- getLine
  let [n] = map read $ words l1 :: [Int]
      f l1 l2 = do
        a <- l1
        b <- l2
        return $ a*b
      l = f [1..9] [1..9]
  putStrLn $ if n `elem` l then "Yes" else "No"


Measured memory_bytes: 508
from collections import defaultdict
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    color = defaultdict(int)
    g = 0
    for a in A:
        if a >= 3200:
            g += 1
            continue
        for j in range(8):
            if 400 * j <= a < 400 * (j + 1):
                color[j] = 1
    print(max(1, len(color)), len(color) + g)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define gloop(n) for(ll g=0; g<(n); g++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll LINF = 2e17+423;
const int INF = 2e9 + 69;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);



































int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(u==t) b--;
    else if(u==s) a--;
    cout << a << " "<< b;
    R 0;
}
/*

*/



























































ll po(ll x, ll n){
  if(n==0) R 1%mod;
  ll y = po(x, n/2)%mod;
  y = ((y%mod)*(y%mod));
  if(n%2) y = (y*(x%mod))%mod;
  R y%mod;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, a[100000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	int b = 0, c = 0;
	for (int i = 0; i < n-1; i++) {
		if (b != 0) {
			if (a[i] == a[i + 1]) {
				c = a[i];
				break;
			}
		}
		else {
			if (a[i] == a[i + 1]) {
				b = a[i];
				i++;
				continue;
			}
		}
	}
	cout << b*c << endl;
	getchar(); getchar();
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n,k=0;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
        cin >> d[i];

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

    cout << d[n/2]-d[n/2-1] << "\n";
	return 0;
}



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

int main(){
	long long x,temp,pen;
	cin>>x;
	pen=100;
	for(int i=1;;i++){
		temp=pen/100;
		pen+=temp;
		if(pen>=x){
			cout<<i<<endl;
			break;
		}
	}
}

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

int main() {
  string s;
  cin >> s;
  bool fla = false;

  for(int i = 0; i < s.size()-1; i++) {
    if(s.at(i) == s.at(i+1)) {
      fla = true;
    }
  }
  fla == true ? cout << "Bad" : cout << "Good";

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int H,W;
	cin>>H>>W;
	string S[26][26];
	rep(i,H)rep(j,W)cin>>S[i][j];
  
	int ansH,ansW;
	rep(i,H)rep(j,W){
		bool snuke=true;
		if(S[i][j][0]!='s')snuke=false;
		if(S[i][j][1]!='n')snuke=false;
		if(S[i][j][2]!='u')snuke=false;
		if(S[i][j][3]!='k')snuke=false;
		if(S[i][j][4]!='e')snuke=false;
		if(snuke){
			ansH=i;
			ansW=j;
			break;
		} 
	}
	char x='A'+ansW;
	cout<<x;
	cout<<ansH+1;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x =0;
    int y =0;

    for (x=1;x<=9;x++)
    {
        for (y=1;y<=9;y++)
        cout << x << "x" << y << "=" << x*y << endl;
    }

    return 0;
}

Measured memory_bytes: 2988