akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int memo[1010][1010][2];

int solve(int x, int y, int turn) {
    // printf("x = %lld, y = %lld, turn = %lld\n", x, y, turn);
    if(x > y) swap(x, y);
    if(memo[x][y][turn] != -1) return memo[x][y][turn];
    if(x == 0 && y == 0) return memo[x][y][turn] = (turn % 2 ? 0 : 1);
    if(x == 0 && y == 1) return memo[x][y][turn] = (turn % 2 ? 0 : 1);
    if(x == 1 && y == 1) return memo[x][y][turn] = (turn % 2 ? 0 : 1);

    bool ok = false;
    for(int t = 2; t <= x; t += 2) {
        if(turn % 2 && solve(x-t, y+t/2, turn^1)) ok = true;
        else if(turn % 2 == 0 && !solve(x-t, y+t/2, turn^1)) ok = true;
    }
    for(int t = 2; t <= y; t += 2) {
        if(turn % 2 && solve(x+t/2, y-t, turn^1)) ok = true;
        else if(turn % 2 == 0 && !solve(x+t/2, y-t, turn^1)) ok = true;
    }
    if(turn % 2) {
        return memo[x][y][turn] = (ok ? 1 : 0);
    }
    else return memo[x][y][turn] = (ok ? 0 : 1);
}

signed main() {
    int x, y; cin >> x >> y;
    if(x > y) swap(x, y);
    if(y == x || y == x+1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    

    /*
    memset(memo, -1, sizeof(memo));
    rep(i,0,100) rep(j,i,100) {
        int ans = solve(i, j, 0);
        // if(ans == 0) continue;
        printf("%lld, %lld, ", i, j);
        cout << (ans ? "Brown" : "Alice") << endl;
    }
    */
    return 0;
}

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

//UnionFind
int n = 100000;
vector<int> par(n);
vector<int> size(n);

void init(int n){
  for(int i=0; i<n; i++){
    par.at(i) = i;
    size.at(i) = 1;
  }
}

int root(int x){
  if(par.at(x) == x){
    return x;
  }
  else{
    return par.at(x) = root(par.at(x));
  }
}

bool same(int x, int y){
  return root(x) == root(y);
}

void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if (size.at(x) < size.at(y)){
    swap(x, y);
  }
  size.at(x) += size.at(y);
  par.at(y) = x;
}

int size_x(int x){
  return size.at(root(x));
}


int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int64_t>> vec(M,vector<int64_t>(2));
  for(int i=0; i<M; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
      vec.at(i).at(j)--;
    }
  }
  
  vector<int64_t> ans(M);
  init(N);
  int64_t MAX = N*(N-1)/2;
  ans.at(M-1) = MAX;
  
  for(int i=M-1; i>0; i--){
    int a = vec.at(i).at(0);
    int b = vec.at(i).at(1);
    //cout << a << " " << b << endl;
    int64_t ax = size_x(a);
    unite(a,b);
    int64_t bx = size_x(b);
    /*for(int j=0; j<N; j++){
      cout << size.at(j) << " ";
    }
    cout << endl;*/
    ans.at(i-1) = ans.at(i) - (ax*(bx-ax));
  }
  for(int i=0; i<M; i++){
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 8320
# https://atcoder.jp/contests/abc136/tasks/abc136_c

N = int(input())
H_list = list(map(int, input().split()))

past_H = 0
can_substract = False

for i in range(1, N - 1):

    if H_list[i] - H_list[i + 1] > 1:
        print('No')
        exit()

    if (H_list[i] - H_list[i + 1] == 1) and (H_list[i] - H_list[i - 1] < 1):
        print('No')
        exit()

    if H_list[i] - H_list[i - 1] >= 1:
        H_list[i] -= 1
        continue

print('Yes')

    


Measured memory_bytes: 14704
#include<cstdio>
#include<cmath>
#include<algorithm> 
using namespace std;
int n,q;
int Head[200001],To[400001],Next[400001],t1=0;
void add(int a,int b)
{
	t1++;
	Next[t1]=Head[a];
	Head[a]=t1;
	To[t1]=b;
}
int cnt[200001];
bool vis[200001];
void dfs(int curr)
{
	vis[curr]=true;
	for (int i=Head[curr];i;i=Next[i])
	{
		if (!vis[To[i]])
		{
			cnt[To[i]]+=cnt[curr];
			dfs(To[i]);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&q);
	for (int i=1,a,b;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		add(a,b); add(b,a);
	}
	for (int i=1,p,x;i<=q;i++)
	{
		scanf("%d%d",&p,&x);
		cnt[p]+=x;
	}
	dfs(1);
	for (int i=1;i<n;i++) printf("%d ",cnt[i]);
	printf("%d",cnt[n]);
	return 0;
}

Measured memory_bytes: 13440
def check(A):
  s = 0
  print(A)
  for i in A:
    s += (1+i)/2
    print(s)
  return s



N, K = map(int,input().split())
p = list(map(int,input().split()))

now = 0
s = 0
for i,j in enumerate(p):
  if i <= K-1:
    s += (j+1)/2
  else:
    s -= (p[i-K]+1)/2
    s += (j+1)/2
  if now < s:
    now = s
  

print(now)


Measured memory_bytes: 24804
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
const int maxm=2e6+5;
ll n,x;
ll cal(ll a,ll b){
    if(b%a==0){//
        return (b/a*2-1)*a;
    }
    ll ans=b/a*2*a;
    ans+=cal(b%a,a);
    return ans;
}
signed main(){
    cin>>n>>x;
    ll a=x,b=n-x;
    if(a>b)swap(a,b);
    ll ans=cal(a,b)+n;//外面两条边的长度=x+(n-x)=n
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
max = int(input())
orgList = list(map(int, input().split()))
min = 999999999999

result = 0;
for i in range(max):
    assertNo = orgList[i]
    if min > orgList[i]-1:
        min = orgList[i]

    if min >= assertNo:
        result+= 1

print(result)


Measured memory_bytes: 75472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> vec(H);
  for(int i = 0;i<W+2;i++)
    cout << "#";
  cout << endl;
  for(int i = 0;i < H;i++){
    cin >> vec.at(i);
    cout << "#" << vec.at(i) << "#" <<endl;
  }
  for(int i = 0;i<W+2;i++)
  cout << "#";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull A=9999973,B=950527;
 
int H,W;
char T[1005][1005];
ull t[1005][1005];
ull t2[1005][1005];
int h,w;
char U[1005][1005];
 
 
int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++)scanf("%s",T[i]);
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)scanf("%s",U[i]);
 
  ull target=0;
  for(int i=0;i<h;i++){
    ull key=0;
    for(int j=0;j<w;j++){
      key=key*B+U[i][j];
    }
    target=target*A+key;
  }
 
  ull C=1;
  for(int i=0;i<w;i++)C*=B;
 
  for(int i=0;i<H;i++){
    ull key=0;
    for(int j=0;j<W;j++){
      key=key*B+T[i][j];
      if(j-w>=0)key-=T[i][j-w]*C;
      t[i][j]=key;
      t2[i][j]=t[i][j];
    }
  }
 
  C=1;
  for(int i=0;i<h;i++)C*=A;
 
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i)t[i][j]+=t[i-1][j]*A;
      if(i-h>=0)t[i][j]-=t2[i-h][j]*C;
      if(t[i][j]==target){
        if(i-h+1>=0&&j-w+1>=0)
          printf("%d %d\n",i-h+1,j-w+1);
      }
    }
  }
 
 
  return 0;
}


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

int fact(int n){
    int m;
    if(n==0){
        return 1;
    }else{
        m = fact(n - 1);
        return n * m;
    }
}

int main() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  vector<int> num(N);
  int P_number = 0, Q_number = 0;

  for (int i = 0; i < N; i++){
      cin >> P.at(i);
      num.at(i) = 0;
  }
  for (int i = 0; i < N; i++){
      cin >> Q.at(i);
  }

  for (int i = 0; i < N;i++){
      int tmp = 0;
      num.at(P.at(i)-1) = 1;
      for (int j = 0; j < P.at(i)-1; j++)
      {
          
          if (num.at(j) == 0){
              tmp++;
          }
      }
      P_number += tmp * fact(N - i - 1);
  }

  for (int i = 0; i < N;i++){
      num.at(i) = 0;
  }

  for (int i = 0; i < N; i++)
  {
      int tmp = 0;
      num.at(Q.at(i) - 1) = 1;
      for (int j = 0; j < Q.at(i) - 1; j++)
      {

          if (num.at(j) == 0)
          {
              tmp++;
          }
      }
      Q_number += tmp * fact(N - i - 1);
  }

  cout << abs(P_number-Q_number);

}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, y, ans = 1;
  std::cin >> x >> y;
  for (int i = 1;; i++) {
    x *= 2;
    if (x > y)
      break;
    ans++;
  }
  print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

void bug();

/* BIEN CUC BO BEGIN*/
	ll a, b; 
/* BIEN CUC BO END*/

ll f(ll a){
	if (a%4 == 0){
		return a;
	}
	if (a%4 == 2){
		return (a+1);
	}
	if (a%4 == 1){
		return 1;
	}
	return 0;
}

void solve(){	
	cin >> a >> b;
	cout << (f(b) xor f(a-1));
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <int> vec;
set <int > st;
vector <int> v;
int const N=3e5;

map<int,int>mp;
int main()
{
int n;
cin>>n;
int j=1;
long long ans=0;
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
   if(x==j)
    {ans++;
    j++;}
}
if(ans==0)
    cout<<-1;
else
cout<<n-ans;
}


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

using namespace std;

const int N = 2e5 + 10;

char s[N], t[N];

int main()
{
	scanf("%s%s", s, t);
	
	int n = strlen(s), ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] != t[i]) ans ++;
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  vector<int> A0 = A;
  SORT(A); REV(A);
  int mx = A[0], mn = A.back();
  vector<int> X,Y;
  for (int i = 1; i < N-1; i++) {
    if (A[i] >= 0) X.push_back(A[i]);
    else Y.push_back(A[i]);
  }
  int ans = mn;
  for (int i = 0; i < X.size(); i++) {
    ans = ans - X[i];
  }
  ans = mx - ans;
  for (int i = 0; i < Y.size(); i++) {
    ans = ans - Y[i];
  }
  cout << ans << endl;
  ans = mn;
  for (int i = 0; i < X.size(); i++) {
    cout << ans << " " << X[i] << endl;
    ans = ans - X[i];
  }
  cout << mx << " " << ans << endl;
  ans = mx - ans;
  for (int i = 0; i < Y.size(); i++) {
    cout << ans << " " << Y[i] << endl;
    ans = ans - Y[i];
  }

  return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a,b;
    cin >> a;

    cout << a*a<< endl;

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin >> a>>b>>c>>d>>e;
  if(a == 0) cout << 1 << endl;
  else if(b==0) cout << 2 << endl;
  else if(c==0) cout << 3 << endl;
  else if(d==0) cout << 4 << endl;
  else if(e==0) cout << 5 << endl;
}


Measured memory_bytes: 3564
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], M = I[1];
		var l = new Pair[N];
		for (var i = 0; i < N; i++) l[i] = new Pair(G);
		Array.Sort(l);
		var money = 0L;
		for (var i = 0; i < N; i++)
		{
			if (M <= 0) break;
			var k = Min(M, l[i].B);
			M -= k;
			money += k * (long)l[i].A;
		}
		WriteLine(money);
	}
}
struct Pair : IComparable<Pair>
{
	public readonly int A, B;
	public Pair(params int[] I) { A = I[0]; B = I[1]; }
	public int CompareTo(Pair other) => A.CompareTo(other.A);
}


Measured memory_bytes: 17812
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int N_DIGIT = 5;
 
int main(){
  int N, A, B;
  cin >> N >> A >> B;
  
  vector<int> N_num(N_DIGIT), ans;
  
  for (int i = A; i <= B; i++){
    for (int j = 1; j <= N; j++){
      int n_sum = 0;
      int temp = j;
      for (int k = 0; k < N_DIGIT; k++){
        N_num.at(k) = temp / pow(10, (N_DIGIT-k-1));
        temp -= N_num.at(k) * pow(10, (N_DIGIT-k-1));
      }
      for (int n : N_num)	n_sum += n;
      if (n_sum == i)		ans.push_back(j);
    }
  } 
  int result = 0;
  for (int t = 0; t < ans.size(); t++) result += ans.at(t);
  cout << result << endl;
 
 
}

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

int main(){
  int N,Y;
  cin >> N >> Y;
  int x_max = Y/10000;
  int y_max = Y/5000;
  int z_max = Y/1000;
  int y,z;

  for(int x=0;x<=x_max;x++){
    y = (Y-(1000*N)-(9000*x))/4000;
    z = N-(x+y);
    if(y>=0 && z>=0 && y<=y_max && z<=z_max && (10000*x) + (5000*y) + (1000*z) == Y){
      printf("%d %d %d\n",x,y,z);
      exit(0);
    }
  }
  printf("-1 -1 -1\n");
}

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

typedef long long ll;
typedef long double ld;

int main(){
    int n;
    cin >> n;
    pair<int,int> usagi[n];

    for(int i=0; i<n;i++){
        int a;
        cin >> a;
        a--;
        usagi[i] = make_pair(i,a);
    }

    int k(0);
    for(int i=0; i<n; i++){
        int t = usagi[i].second;
        if(usagi[t].second == i){
            k++;
            usagi[i].second = -1;
        }
    }
    cout << k << endl;
}


Measured memory_bytes: 4432
n = int(input())
mod = 1000000007
a = [int(i)%mod for i in input().split()]
s = [0]*(n+1)
for i in range(n)[::-1]:
    s[i] = (s[i+1] + a[i])%mod
ans = 0
for i in range(n-1):
    ans += s[i+1]*a[i]%mod
    ans %= mod
print(ans)

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

using namespace std;

int main(){
    string S;
    cin >> S;
    
    int Length = S.length();
    
    string ans = "";
    
    for(int i = 0; i < Length; ++i){
        if(i % 2 == 0){
            ans += S[i];
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    public static long gcd(long a,long b)
    {if (b == 0) 
        return a; 
    return gcd(b, a % b);  }
    public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		long a=s.nextLong();
		long b=s.nextLong();
		long k=gcd(a,b);
		System.out.println((a*b)/k);
	}}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,a[N],Max,Min,cnt,tot;
void GG(){ printf("No"); exit(0);}
int main()
{
	int i;
	scanf("%d",&n),Min=n+1;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>Max) Max=a[i];
		else if(a[i]==Max) tot++;
		if(a[i]<Min) Min=a[i],cnt=1;
		else if(a[i]==Min) cnt++;
	  }
	if(Max-Min>1) GG();
	if(Max-Min==1){
		if(Max<=cnt) GG();
		if(Max>cnt+(n-cnt)/2) GG();
	  }
	else
		if(Max>n/2&&Max!=n-1) GG();
	printf("Yes");
	return 0;
}


Measured memory_bytes: 640
def search(l, m):
    #dp = [[None for _ in range(len(l) + 1)] for __ in range(m + 1)]
    dp = [[False for _ in range(m+1)] for __ in range(len(l) + 1)]
    dp[0][0]= True
    for i in range(len(l)):
        for mi in range(m + 1):
            if l[i] <= mi:
                dp[i+1][mi] = dp[i][mi - l[i]] or dp[i][mi]
            else:
                dp[i+1][mi] = dp[i][mi]
    return dp[len(l)][m]


n = int(input())
l = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))

for m in ms:
    if search(l, m):
        print('yes')
    else:
        print('no')



Measured memory_bytes: 5952
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

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

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

P=[] # 5で割って1余る素数のリスト
for i in range(11,55556,10):
    p=1
    for j in range(2,int(i**0.5)+1):
        if i%j==0 :
            p=0
    if p==1 :
        P.append(i)

#print(P[:100])

s=""
for i in range(n-1):
    s+=str(P[i])+" "
s+=str(P[n-1])

print(s)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    ll A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    for (int n_posi = 0; n_posi < N; ++n_posi) {
        ll base = n_posi * C - (N - 1 - n_posi) * D;

        if (B - A >= base && B - A - base <= (N - 1) * (D - C)) {
            write("YES");
            return 0;
        }
    }

    write("NO");
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int s,i;
	scanf("%d", &s);
	if (s % 100 != 0 && s % 100 < 13) {
		if (s / 100 != 0 && s / 100 < 13) printf("AMBIGUOUS");
		else printf("YYMM");
	}
	else {
		if (s / 100 != 0 && s / 100 < 13) printf("MMYY");
		else printf("NA");
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define N 1001
void length(char*,char*);
int main(){
  char x[N],y[N];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",x,y);
    length(x,y);
  }
  return 0;
}
void length(char *x,char *y){
  int c[N][N];
  int i,j,n,m;

  m=strlen(x);
  n=strlen(y);
  for(i=1;i<=m;i++)
    c[i][0]=0;
    for(j=0;j<=n;j++)
      c[0][j]=0;
    for(i=1;i<=m;i++){
      for(j=1;j<=n;j++){
      if(x[i-1]==y[j-1])c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else  c[i][j]=c[i][j-1];
    }
  }
    printf("%d\n",c[m][n]);
  }




Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int N;
vector<int> len(3);
int ans=INF;
vector<pair<int,int>> now(4,pair<int,int>(0,0));
void dfs(int depth,vector<int> &l){
	if(depth<N){
		rep(i,4){
			now[i].first+=l[depth];
			now[i].second+=1;
			dfs(depth+1,l);
			now[i].first-=l[depth];
			now[i].second-=1;
		}
	}
	else{
		int tmp=0;
		rep(i,3){
			if(now[i].second==0) return;
			tmp+=abs(len[i]-now[i].first)+10*(now[i].second-1);
		}
		ans=min(ans,tmp);
	}
}


int main(){
	cin>>N;
	rep(i,3) cin>>len[i];
	vector<int> l(N);
	rep(i,N) cin>>l[i];
	dfs(0,l);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
inline int chk(string S)
{
	string T=S;
	reverse(T.begin(),T.end());
	return S==T;
}
int main()
{
	cin>>s;int n=s.size();string a,b;
	if(chk(s)==0) return puts("No"),0;
	for(int i=0;i<(n-1)/2;i++) a+=s[i];
	for(int i=(n+3)/2-1;i<n;i++) b+=s[i];
	if(chk(a)==0||chk(b)==0) puts("No");
	else puts("Yes");
}

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

int main() {
  int n, r, x;
  r = 3;
  for(;;) {
    cin >> n >> x;
    if (n == 0 && x == 0) return 0;
    if (n * (n + 1) / 2 < x) {
      cout << 0 << endl;
      continue;
    }

    int count = 0;

    vector<bool> v(n);
    fill(v.begin(), v.begin() + r, true);

    do {
      int sum = 0;
      for (int i = 0; i < n; ++i) {
        if (v[i]) {
          sum += i + 1;
        }
      }
      if (sum == x) {
        count++;
      }
    } while (prev_permutation(v.begin(), v.end()));
    cout << count << endl;
  }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll MIN(ll a,ll b){
	return a<b?a:b;
}

ll a,b,c,n;
ll *arr;
ll Synthetic(ll x,ll y,ll z,ll i){
	if(i == n){
		if(x<=0||y<=0||z<=0) return 1e12;
		
		return abs(a-x)+abs(b-y)+abs(c-z);
	}

	ll op1 = Synthetic(x,y,z,i+1);
	ll op2 = Synthetic(x+arr[i],y,z,i+1)+(x>0?10:0);
	ll op3 = Synthetic(x,y+arr[i],z,i+1)+(y>0?10:0);
	ll op4 = Synthetic(x,y,z+arr[i],i+1)+(z>0?10:0);
	return MIN(op1,MIN(op2,MIN(op3,op4)));
}

int main(){
	
	cin>>n>>a>>b>>c;
	arr = new ll[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<Synthetic(0,0,0,0);
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> pii;
typedef vector<pi> vpi;
typedef set<ll> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll INF = 1e18;
ll MOD = 1e9+7;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
int N,a,X,K,t,ans;

int main(){
  cin>>N>>K;
  cout<<(N+K-3)/(K-1);
  // for (int i=1;i<=N;++i){
  //   cin>>a;
  //   if (a == 1)X = i;
  // }
  // while (t < X){
  //   t += (K-1);
  //   ++ans;
  // }
  // t += K;
  // ++ans;
  // while (t < N){
  //   t += (K-1);
  //   ++ans;
  // }
  // cout<<ans;
}

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

int main()
{
     int n,i;
     cin>>n;
    
     int cnt[n+1];
     memset(cnt,0,sizeof cnt);
     for(i=0;i<n-1;i++)
     {
        int x;
        cin>>x;
        cnt[x]++;
     }
     for(i=1;i<=n;i++)
     {
         cout<<cnt[i]<<endl;
     }



}


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

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

A.sort(reverse=True)
ans = 0

ans += A[0]

cnt = 1
i = 1
#足せる回数はN-1回
while cnt < N-2:
    ans += A[i] * 2
    i += 1
    cnt += 2
if cnt == N-2:
    ans += A[i]

print(ans)


Measured memory_bytes: 105244
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<bool> ok(N, false);
  vector<int> cnt(N, 0);

  int p;
  string s;
  pair<int, int> ans = {0, 0};
  REP(i, M){
    cin >> p >> s;
    p--;
    if(ok[p]) continue;
    if(s == "WA") cnt[p]++;
    else{
      ans.first++;
      ans.second += cnt[p];
      ok[p] = true;
    }
  }

  cout << ans.first << " " << ans.second << "\n";

  return 0;
}

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

using namespace std;
int N;
int A[201], a[201];


int main(void) {
	int flag = 0;
	int cnt = 0;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		while(A[i] % 2 == 0 ) {
			A[i] = A[i] / 2;
			cnt++;
			
		}
		a[i] = cnt;
		cnt = 0;
		
	}
	sort(a, a + N);
	cout << a[0] << endl;
	return 0;
}

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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int d = a+b;//+1と0の合計枚数
  int e = d+c;//すべての合計枚数
  int f =0;
  for(int i=0;i<k;i++){
    if(i<a){
      f++;
    }
    if(d<=i){//カウント調整のため=追加
      f--;
    }
  }
 cout << f << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
int main(void)
{
	int x,y,n,i;
	int flg;
	char buf[1001];
	
	scanf("%s",buf);
	flg=0;
	
	while(flg==0){
		n=strlen(buf);
		y=0;
		for(i=0;i<n;i++){
		x=buf[i]-'0';
		y+=x;
		}
		if(y!=0){
				printf("%d\n",y);
				scanf("%s",buf);
		}
		else{
			flg=1;
		}
	}	
	return 0;
}	

Measured memory_bytes: 964
import math
X = int(input())

def is_prime(x):
	if x == 2:
		return True
	if x % 2 == 0:
		return False
	else:
		for i in range(3, int(math.sqrt(x))+1, 2):
			if x % i == 0:
				return False
		return True

a = X
if (X % 2 == 0) & (X > 2):
	a += 1
while 1:	
	if is_prime(a):
		print(a)
		break
	else:
		a += 2
			

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

ll h, w;
vll p(ll a){
  if((a/w)%2==0) return vll{(a/w), a%w};
  else return vll{a/w, w-1-(a%w)};
}
int main(int argc, char const *argv[]) {
  std::cin >> h >> w;
  ll n;std::cin >> n;
  vll a(n);
  multiset<ll> s;
  re(i, n) {
    std::cin >> a[i];
    re(j, a[i]) s.insert(i+1);
  }
  ll now = 0;
  vvl ans = vv(h, w, 0, ll);
  //std::cout << p(1)[0] << " " << p(1)[1] << '\n';
  for(auto itr=s.begin();itr!=s.end();itr++){
    vll tmp = p(now);
    ans[tmp[0]][tmp[1]] = *itr;
    now++;
  }
  re(i, h) re(j, w) std::cout << ans[i][j] << (j==w-1?"\n":" ");
  return 0;
}


Measured memory_bytes: 896
N = int(input())
a = [int(x) for x in input().split()]

d = []

# comparison list 
prev = 0
for i in range(N + 1) :
    if i == 0 : d.append(abs(a[i]))
    elif i == N : d.append(abs(a[i - 1]))
    else : d.append(abs(prev - a[i]))
    
    if i != N : prev = a[i]

totsum = sum(d)

for i in range(N) :
    # for first
    if i == 0 :
        x, y, z = 0, a[i], a[i + 1]
    elif i == N - 1 :
        x, y, z = a[i - 1], a[i], 0
    else :
        x, y, z = a[i - 1], a[i], a[i + 1]

    if x <= y <= z or x >= y >= z :
        print(totsum)
    else :
        print(totsum - abs(d[i] + d[i + 1]) + abs(d[i] - d[i + 1]))

Measured memory_bytes: 14164
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[10000];
int c[12];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	std::sort(b,b+a);
	int d=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(i==j)continue;
			int v=b[i];
			int w=b[j];
			while(w){
				w/=10;
				v*=10;
			}
			v+=b[j];
			c[d++]=v;
		}
	}
	std::sort(c,c+d);
	printf("%d\n",c[2]);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
    int goukei=0;
   for (int i = 0; i < N; i++) {
    goukei += vec.at(i);}
  
  int SA=0, SB, s=0;
   for (int i = 0; i < N; i++) {
     SA += vec.at(i);
     SB = goukei - SA;
     if(SA > SB){
       int p = SA - SB;
        if(p < s)
          s = p;
       else
         break;
     }
     else
       s = SB - SA;
   }
  cout << s << endl;
}


Measured memory_bytes: 3552
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  NAB := NextIntVec()
  N := NAB[0]
  A := NAB[1]
  B := NAB[2]
  if N + 1 < A + B {
    Write(-1)
  } else if A * B < N {
    Write(-1)
  } else {
    P := make([]string, N)
    pos := A
    for i := 0; i < A; i++ {
      P[i] = strconv.Itoa(N - A + i + 1)
    }
    if B > 1 {
      k := (N - A) / (B - 1)
      m := (N - A) % (B - 1)
      upper := N - A
      for i := 0; i < B - 1; i++ {
        _k := k
        if m > 0 {
          _k++
          m--
        }
        for j := 0; j < _k; j++ {
          P[pos] = strconv.Itoa(upper + 1 - _k + j)
          pos += 1
        }
        upper -= _k
      }
    }
    Write(strings.Join(P, " "))
  }
  Output()
}

Measured memory_bytes: 16000
import sys
from io import StringIO
import unittest


def resolve():
    K, N = [int(i) for i in input().split()]
    AA = [int(i) for i in input().split()]
    maxa = AA[0] + K - AA[-1]
    for i in range(N - 1):
        maxa = max(maxa, AA[i + 1] - AA[i])
    print(K - maxa)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """20 3
5 10 15"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """20 3
0 5 15"""
        output = """10"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 29032
// A.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 110, dx[2] = {0, 1}, dy[2] = {1, 0};

typedef pair<int, int> pii;

int n, m, idx[MAX_N][MAX_N], head[MAX_N * MAX_N], current, dist[MAX_N * MAX_N], start_pos;
char str[MAX_N][MAX_N];
bool vis[MAX_N * MAX_N];

struct edge
{
    int to, nxt, weight;
} edges[MAX_N * MAX_N << 3];

void addpath(int src, int dst, int weight)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    edges[current].weight = weight, head[src] = current++;
}

void shortestPath()
{
    memset(dist, 0x3f, sizeof(dist));
    priority_queue<pii> pq;
    pq.push(make_pair(0, start_pos)), dist[start_pos] = 0;
    while (!pq.empty())
    {
        int u = pq.top().second;
        pq.pop();
        if (vis[u])
            continue;
        vis[u] = true;
        for (int i = head[u]; i != -1; i = edges[i].nxt)
            if (dist[edges[i].to] > dist[u] + edges[i].weight)
                dist[edges[i].to] = dist[u] + edges[i].weight, pq.push(make_pair(-dist[edges[i].to], edges[i].to));
    }
}

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%s", str[i] + 1);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            idx[i][j] = m * (i - 1) + j;
    start_pos = n * m + 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            for (int d = 0; d < 2; d++)
            {
                int dstx = i + dx[d], dsty = j + dy[d];
                if (str[dstx][dsty] != 0)
                    if (str[i][j] == '.')
                        if (str[dstx][dsty] != str[i][j])
                            addpath(idx[i][j], idx[dstx][dsty], 1);
                        else
                            addpath(idx[i][j], idx[dstx][dsty], 0);
                    else
                        addpath(idx[i][j], idx[dstx][dsty], 0);
            }
    addpath(start_pos, idx[1][1], str[1][1] == '#');
    shortestPath(), printf("%d\n", dist[idx[n][m]]);
    return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    ll N, M, ret;
    cin >> N >> M;
    ret = abs(N - 2) * abs(M - 2);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100005];int k=0;
	scanf("%s",a);
	if(strlen(a)==1)
	{
		printf("0");
		return 0;
	}
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='0'&&a[i+1]=='0')
		{
			a[i+1]='1';
			k++;
		}
		if(a[i]=='1'&&a[i+1]=='1')
		{
			a[i+1]='0';
			k++;
		}
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 256
K=int(input())
a=[]
for i in range(1,K+1):
    a.append(i)

counter=0
if K>=2 and K<=100 :
    for x in range(len(a)):
        for j in range(x+1,len(a)):
            if a[x]&1==0 and a[j]&1==1 or a[x]&1==1 and a[j]&1==0:
                a[x]*a[j]%2==0
                if a[x]*a[j]%2==0:
                    counter+=1
            

    print(counter)            


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll n,k;
  cin>>n>>k;
  ll a[n];
  fo(i,n)
  cin>>a[i];
  sort(a,a+n);
  ll s=0;
  for(ll i=0;i<k;i++)
  	s=s+a[i];
  cout<<s;
  return 0;
}

Measured memory_bytes: 3656
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (isok).erase(unique(ALL((isok))),(isok).end())
# define LOWER(s)    transform(ALL((maze)),(maze).begin(),TL<char>)
# define UPPER(s)    transform(ALL((maze)),(maze).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b, x;

int main() {
	cin >> a >> b >> x;
	if (a <= x&&x <= a + b)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class OMatching {
        int n;
        int[][] arr;
        int mod = (int) 1e9 + 7;
        long[] memo;

        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            n = sc.nextInt();
            arr = new int[n][n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    arr[i][j] = sc.nextInt();
            memo = new long[1 << n];
            Arrays.fill(memo, -1);
            pw.println(dp(0, 0) % mod);
        }

        private long dp(int idx, int msk) {
            if (idx == n)
                return 1;
            if (memo[msk] != -1)
                return memo[msk];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                if ((msk & 1 << i) != 0)
                    continue;
                if (arr[idx][i] == 1)
                    sum += dp(idx + 1, msk | 1 << i);
                sum %= mod;
            }
            return memo[msk] = sum;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}



Measured memory_bytes: 41940
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll n;
ll a,b;
int a2[20]={},b2[20]={};
ll k=1;
int main() {
	string str;
	cin>>str;
	for(int i=0;i<str.size();++i){
		if(str[i]=='A')str[i]='T';
		else if(str[i]=='T')str[i]='A';

		if(str[i]=='C')str[i]='G';
		else if(str[i]=='G')str[i]='C';

	}
	cout<<str<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([int(i*(i-1)/2) for i in mods]))
main()

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

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

	set<char> st1;
	set<char> st2;
	for (int i = 0; i < s.size(); i++) {
		st1.insert(s[i]);
		st2.insert(t[i]);
	}

	if (st1.size() != st2.size()) {
		cout << "No" << endl;
		return 0;
	}

	vector<vector<int>> vs(30);
	vector<vector<int>> vt(30);

	for (auto it = st1.begin(); it != st1.end(); it++) {
		vector<bool> ch(30, false);
		int cnt = 0;
		for (int i = 0; i < s.size(); i++) {
			if (ch[s[i] - 'a']) continue;
			ch[s[i] - 'a'] = true;

			if (*it == s[i]) break;
			cnt++;
		}

		for (int i = 0; i < s.size(); i++) {
			if (s[i] == *it) {
				vs[cnt].push_back(i);
			}
		}
	}

	for (auto it = st2.begin(); it != st2.end(); it++) {
		vector<bool> ch(30, false);
		int cnt = 0;
		for (int i = 0; i < t.size(); i++) {
			if (ch[t[i] - 'a']) continue;
			ch[t[i] - 'a'] = true;

			if (*it == t[i]) break;
			cnt++;
		}

		for (int i = 0; i < t.size(); i++) {
			if (t[i] == *it) {
				vt[cnt].push_back(i);
			}
		}
	}

	for (int i = 0; i < st1.size(); i++) {
		if (vs[i].size() != vt[i].size()) {
			cout << "No" << endl;
			return 0;
		}
		for (int j = 0; j < vs[i].size(); j++) {
			if (vs[i][j] != vt[i][j]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}


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

int from_mcxi(string str)
{
	int num = 0;
	int temp = 1;

	for (unsigned int i = 0; i < str.size(); i++) {
		if (str.substr(i, 1) == "m") {
			num += temp * 1000;
			temp = 1;
		}
		else if (str.substr(i, 1) == "c") {
			num += temp * 100;
			temp = 1;
		}
		else if (str.substr(i, 1) == "x") {
			num += temp * 10;
			temp = 1;
		}
		else if (str.substr(i, 1) == "i") {
			num += temp;
			temp = 1;
		}
		else {
			temp = stoi(str.substr(i, 1));
		}
	}

	return num;
}

string to_mcxi(int x)
{
	string str;

	for (int i = 1000; i >= 1; i /= 10) {
		int temp = x / i;
		x %= i;
		if (temp == 0) {
			continue;
		}
		else if (temp >= 2) {
			str += to_string(temp);
		}

		switch (i) {
		case 1000:
			str += "m";
			break;
		case 100:
			str += "c";
			break;
		case 10:
			str += "x";
			break;
		case 1:
			str += "i";
			break;
		}
	}

	return str;
}

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

	for (int i = 0; i < n; i++) {
		string str1, str2;
		cin >> str1 >> str2;

		cout << to_mcxi(from_mcxi(str1) + from_mcxi(str2)) << endl;
	}

	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,q;
    ll k;
    cin >> n >> k >> q;
    int cnt[n] = {};
    int a;
    REP(i,q){
        cin >> a;
        a--;
        cnt[a]++;
    }
    REP(i,n){
        if(cnt[i] > q - k){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

#define sz(s) s.size()
#define pb push_back
#define fr first
#define sc second
#define int long long
#define mk make_pair
#define rinat puts("rinat");

using namespace std;

const int N = 1e5 + 5;
const int inf = 1e9 + 9;

int n, ar[N], a, b, q, dp[20][N], l, cnt = 0;

main()
{
    cin >> n;
    for( int i = 1; i <= n; i++ )
        scanf("%I64d", &ar[i]);

    scanf("%I64d", &l);

    for( int i = 1; i <= n; i++ )
    {
        dp[0][i] = upper_bound(ar, ar + n + 1, ar[i] + l) - ar - 1;
    }
    for( int i = 1; i <= 16; i++ )
        for( int j = 1; j <= n; j++ )
            dp[i][j] = dp[i - 1][dp[i - 1][j]];

    scanf("%I64d", &q);

    while( q-- )
    {
        scanf("%I64d%I64d", &a, &b );
        if( b < a )
            swap(a, b);
        int ans = 1;
        for( int i = 17; i >= 0; i-- )
        {
            if( dp[i][a] < b && dp[i][a])
            {
                a = dp[i][a];
                ans += (1 << i);
            }
        }
        printf("%I64d\n", ans);
    }
}























































Measured memory_bytes: 23040