akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stdlib.h>
#include <time.h> 
#include <assert.h>

#define nmax 500010
#define eps 1e-8
#define MOD 998244353

#define P1 25671
#define P2 191
#define MOD1 666013
#define MOD2 1000000007
#define B_SIZE 315

#define SZ(x) ((int)(x.size()))

#define fst first
#define snd second
#define pb push_back
#define mp make_pair

using namespace std;

int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); }

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n, m;
bool fr[nmax];
int dp[nmax];
vector <int> graph[nmax];

void dfs(int node)
{
	fr[node] = true;

	for (int i = 0; i < SZ(graph[node]); i++)
		if (!fr[graph[node][i]]) {

			dfs(graph[node][i]);

			dp[node] = max(dp[node], dp[graph[node][i]] + 1);
		}
		else
			dp[node] = max(dp[node], dp[graph[node][i]] + 1);
}

int main()
{
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++) {

		int x, y;

		scanf("%d %d", &x, &y);

		graph[x].pb(y);
	}

	for (int i = 1; i <= n; i++)
		if (!fr[i]) dfs(i);

	int answer = 0;

	for (int i = 1; i <= n; i++) answer = max(answer, dp[i]);

	printf("%d", answer);

	return 0;
}

Measured memory_bytes: 17792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int H;

void maxHeapify(int *A, int i) {
  int l = 2 * i;
  int r = 2 * i + 1;
  // ????????????????????????????????§???????????§????????????????????¶
  int largest = -11111;
  if (l <= H && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if (r <= H && A[r] > A[largest]) {
    largest = r;
  }

  if (largest != i) {// i ???????????????????????§????????´???
    int t = A[i];
    A[i] = A[largest];
    A[largest] = t;

    maxHeapify(A, largest); // ?????°??????????????????
  }
}

void buildMaxHeap(int *A) {
  for (int i = H / 2; i >= 1; i--) {
    maxHeapify(A, i);
  }
}

int main() {
  cin >> H;

  int A[H + 10];
  FOR(i, 1, H + 1) {
    cin >> A[i];
  }

  buildMaxHeap(A);
  FOR(i, 1, H + 1) {
    cout << " " << A[i];
  }
  cout << endl;


  return 0;
}

Measured memory_bytes: 5016
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s; cin >> s;
  ll ans = 0;
  string anss = "CODEFESTIVAL2016";
  REP(i, 16) if (s[i] != anss[i]) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N,C = map(int,input().split())
D = []
for i in range(C):
    d = list(map(int,input().split()))
    D.append(d)
A = []
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a)

X0,X1,X2 = [],[],[]
for i in range(N):
    for j in range(N):
        if (i+j)%3 == 0:
            X0.append(A[i][j])
        elif (i+j)%3 == 1:
            X1.append(A[i][j])
        else:
            X2.append(A[i][j])

# それぞれの集合を塗り替える場合のコストを計算
Xn = [X0,X1,X2]
cost = [[0 for _ in range(C)] for _ in range(3)]
for i in range(3):
    for c in range(1,C+1):
        Ans = 0
        for x in Xn[i]:
            if x != c:
                Ans += D[x-1][c-1]
        cost[i][c-1] = Ans

Y0 = cost[0]
Y1 = cost[1]
Y2 = cost[2]
Ans = 1000000000000000
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and j != k and k != i:
                Ans = min(Ans, Y0[i]+Y1[j]+Y2[k])

print(Ans)


Measured memory_bytes: 58332
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int H,W; cin>>H>>W;
	int cnt[H+2][W+2] = {};
	vector<pair<int,int>> dir = {{-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}};
	string s[H];
	rep(i,0,H){
		cin>>s[i];
		rep(j,0,W){
			if(s[i][j] == '.') continue;
			rep(k,0,8) cnt[i + dir[k].first + 1][j + dir[k].second + 1]++;
		}
	}
	rep(i,0,H){
		rep(j,0,W){
			if(s[i][j] == '#') cout<<"#";
			else cout<<cnt[i+1][j+1];
		}cout<<endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  
  int n = N % 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
    cout << "hon" << endl;
  } else if ( n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon" << endl;
  } else {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<complex>
#include<cmath>
#include <iomanip>
#define PI 3.1415926535
#define eps 1.0e-18
using namespace std;
int main()
{
     int a,b,h,m;
     long double s,c,x;
    cin >> a >> b >> h >> m;
    s=(h*60+m)/360.0-m/30.0;
    x=abs(a*a+b*b-2*a*b*cos(s*PI));
    c=sqrtl(x);
    cout << fixed << setprecision(10) << c;
    return 0;
}

Measured memory_bytes: 4160
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>

// graph by adjacency list
template <typename T>
struct Edge {
  int src, dst;
  T weight;
  Edge(const int src, const int dst, const T weight)
      : src(src), dst(dst), weight(weight) {}
  Edge(const int dst, const T weight) : src(-1), dst(dst), weight(weight) {}
  bool operator<(const Edge<T> &e) const { return weight > e.weight; }
};

template <typename T>
struct Graph {
  int V;
  std::vector<std::vector<Edge<T>>> E;
  Graph(const int V) : V(V) { E.resize(V); }
  void add_edge(const int src, const int dst, const T weight) {
    E[src].emplace_back(src, dst, weight);
  }
};

template <typename T>
struct Node {
  int v;
  T dist;
  Node(int v, T dist) : v(v), dist(dist){};
  bool operator<(const Node<T> &n) const {
    return dist > n.dist;  // reverse
  }
};

template <typename T>
struct ShortestPath {
  Graph<T> g;
  std::vector<T> dist;
  std::vector<int> prev;
  T inf;

  ShortestPath(const Graph<T> g, T inf = std::numeric_limits<T>::max())
      : g(g), dist(g.V), prev(g.V), inf(inf) {}

  void run(int start, int goal = -1) {
    std::priority_queue<Node<T>> que;
    std::fill(dist.begin(), dist.end(), inf);

    dist[start] = 0;
    que.emplace(start, 0);
    prev[0] = -1;

    while (!que.empty()) {
      Node<T> n = que.top();
      que.pop();
      int v = n.v;
      if (v == goal) return;
      T cost = n.dist;
      if (dist[v] < cost) continue;
      for (Edge<T> e : g.E[v]) {
        if (dist[v] < dist[e.dst] - e.weight) {
          dist[e.dst] = dist[v] + e.weight;
          prev[e.dst] = v;
          que.emplace(e.dst, dist[e.dst]);
        }
      }
    }
  }

  std::vector<int> build_path(int goal) {
    std::vector<int> path;
    for (int v = goal; v != -1; v = prev[v]) {
      path.emplace_back(v);
    }
    std::reverse(path.begin(), path.end());
    return path;
  }
};

void aoj() {
  // https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_1_A

  int V, E, r;
  std::cin >> V >> E >> r;
  Graph<int> g(V);
  for (int i = 0; i < E; i++) {
    int s, t, d;
    std::cin >> s >> t >> d;
    g.add_edge(s, t, d);
  }
  ShortestPath<int> sp(g);
  sp.run(r);
  for (int i = 0; i < g.V; i++) {
    if (sp.dist[i] == sp.inf) {
      std::cout << "INF" << std::endl;
    } else {
      std::cout << sp.dist[i] << std::endl;
    }
  }
}

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

  aoj();
  return 0;
}



Measured memory_bytes: 33344
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    ll minv = INF, maxv = -INF;
    rep(i, 0, n) {
        ll a; cin >> a;
        if (a - minv > maxv) maxv = a - minv;
        if (minv > a) minv = a;
    }
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	printf("%d\n",(n-a)%b);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int k,i,j,n,num1[200],num2[200],num3[200],sum[200];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&num1[i],&num2[i],&num3[i]);
  }

  for(i=0;i<n-1;i++){

    if(num1[i]==0)continue;

    k=num1[i];

      for(j=i+1;j<n;j++){
	if(k==num1[j]){
	  num1[j]=0;
	  num1[i]=0;
	}
      }
  }


   for(i=0;i<n-1;i++){

    if(num2[i]==0)continue;

    k=num2[i];

      for(j=i+1;j<n;j++){
	if(k==num2[j]){
	  num2[j]=0;
	  num2[i]=0;
	}
      }
  }


   for(i=0;i<n-1;i++){

    if(num3[i]==0)continue;

    k=num3[i];

      for(j=i+1;j<n;j++){
	if(k==num3[j]){
	  num3[j]=0;
	  num3[i]=0;
	}
      }
  }

   for(i=0;i<n;i++){
     printf("%d\n",num1[i]+num2[i]+num3[i]);
   }

   return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int main()
{
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);
  
  int n=0;
  
  while(1)
  {
    if(y*n+z*(n+1)>x)
    {
      n=n-1;
      break;
    }
    n++;
  }
  
  printf("%d\n",n);
  return 0;
}

Measured memory_bytes: 128
fist = list(map(int, input().split()))
N = fist[0]
X = fist[1]
DList=[]
kosu=0
for i in range(N):
    DList.append(int(input()))
X -= sum(DList)
kosu += len(DList)

sD = min(DList)

while X >= sD:
    X -= sD
    kosu += 1
print(kosu)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

static int cnt;

void InsertionSort(int a[], int n, int g) {
    int i, j, v;
    
    for (i = g; i < n; i++) {
        v = a[i];
        j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void ShellSort(int a[], int n) {
    int m, i;
    int gs[100];
    
    gs[0] = 0;
    for (i = 1; i <= n; i++) {
        gs[i] = 3 * gs[i-1] + 1;
        if (gs[i] >= n / 3) {
            m = i;
            break;
        }
    }
    cnt = 0;
    printf("%d\n", m);
    for (i = 0; i < m; i++) {
        if (i == 0)
            printf("%d", gs[m-i]);
        else
            printf(" %d", gs[m-i]);
        InsertionSort(a, n, gs[m-i]);
    }
    printf("\n");
    printf("%d\n", cnt);
    for (i = 0; i < n; i++) {
        printf("%d\n", a[i]);
    }
}

int main(void) {
    int n, i, j, key;
    int *a;
    
    scanf("%d", &n);
    a = (int *)malloc(sizeof(int) * n);
    for (i = 0; i < n; i++) scanf("%d", &a[i]);

    ShellSort(a, n);
    
    free(a);

    return 0;
}



Measured memory_bytes: 5156
#include <cstdio>
#define MX (200000 + 230)

#define LL long long
#define MOD (1000000007LL)

LL sum(LL l ,LL r){
	return ((l + r) * (r - l + 1) / 2) % MOD;
}

int main(){
	LL n ,k; scanf("%lld%lld" ,&n ,&k);
	LL Ans = 0;
	for(int i = k ; i <= n + 1 ; ++i){
		Ans = (Ans + sum(n - i + 1 ,n) - sum(0 ,i - 1) + 1 + MOD) % MOD;
	}printf("%lld\n" ,Ans);
	return 0;
}

Measured memory_bytes: 3228
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[0]
dp.append(abs(h[1]-h[0]))

for i in range(2,n):
    tmp_lst=[]
    for j in range(1,i+1):
        if j <= k:
            tmp=dp[i-j]+abs(h[i]-h[i-j])
            tmp_lst.append(tmp)
        else:
            break
    dp.append(min(tmp_lst))
print(dp[-1])

Measured memory_bytes: 58336
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine().trim());
        int a = N;
        int sumdigit = 0;
        while(a != 0){
            sumdigit += a % 10;
            a /= 10;
        }
        if(N % sumdigit == 0) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22484
#include<iostream>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  char c = s[0];
  int t = 0;
  rep(i, n-1) {
    if(s[i+1] == c) t++;
    else c = s[i+1];
  }
  cout << min(t + 2 * k, n-1) << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int n,d,x;
int a[100];
int kq = 0;
int main()
{
    cin >> n >> d >> x;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++)
    {
        if (d % a[i] == 0) kq = kq + d/a[i];
        else kq = kq + d/a[i] + 1;
    }
    cout << kq + x;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

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

  cout << (a>=2*b-1?"YES":"NO") <<endl;
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  while(cin>>n>>m,n||m) {
    int H[n+1], W[m+1];
    H[0] = 0, W[0] = 0;
    FOR(i,0,n) {
      int in; cin >> in;
      H[i+1] = H[i] + in;
    }
    FOR(i,0,m) {
      int in; cin >> in;
      W[i+1] = W[i] + in;
    }
    map<int, int> MAP;
    FOR(i,0,n+1) {
      FOR(j,i+1,n+1) {
        MAP[H[j]-H[i]]++;
      }
    }
    int ans = 0;
    FOR(i,0,m+1) {
      FOR(j,i+1,m+1) {
        if(MAP.count(W[j]-W[i])) ans += MAP[W[j]-W[i]];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 16564
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BlACK 2

void visit(int);
void dfs(void);

int n,M[N][N];
int color[N],d[N],f[N],t;

int main() {

  int u,v,k,i,j;

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

  for(i=0;i<n;i++) {
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++) {
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;

}

void visit(int u) {

  int v;
  color[u] = GRAY;
  d[u] = ++t;
  for(v=0;v<n;v++) {
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE) visit(v);
  }

  color[u] = BlACK;
  f[u] = ++t;

}

void dfs() {

  int u;
  for(u=0;u<n;u++) color[u] = WHITE;
  t = 0;

  for(u=0;u<n;u++) {
    if(color[u] == WHITE) visit(u);
  }

  for(u=0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);

}



Measured memory_bytes: 2056
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while(scanf("%d ",&n), n){
    char m[128],a,b;
    REP(i,128) m[i] = i;
    REP(i,n){
      scanf("%c %c ",&a,&b);
      m[a] = b;
    }
    scanf("%d ",&n);
    REP(i,n){
      scanf("%c ",&a);
      putchar(m[a]);
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 0
// C.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[])
{
	LL N, A, dp[51][5000] = {};
	cin >> N >> A;
	dp[0][2500] = 1;
	for (int i = 0; i < N; ++i) {
		LL x;
		cin >> x;
		memcpy(dp + i + 1, dp + i, sizeof(dp[0]));
		for (int j = 0; j < 5000; ++j) {
			int k = j - x + A;
			if (k >= 0 && k < 5000 && dp[i][k]) {
				dp[i + 1][j] += dp[i][k];
			}
		}
	}
	cout << dp[N][2500] - 1 << endl;
	return 0;
}


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

int main() {
	int k;
	std::string s;

	std::cin >> s >> k;

	for (int i = 0; i < s.length(); i++) {
		int dist_a = (26 - (s[i] - 'a')) % 26;
		if (dist_a <= k) {
			k -= dist_a;
			s[i] = 'a';
		}
		//std::cout << dist_a << std::endl;
	}

	if (k > 0) {
		s[s.length() - 1] = static_cast<char>(((s[s.length() - 1] - 'a') + k) % 26 + 'a');
	}

	std::cout << s << std::endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int mod = 1e9 + 7;
const long double PI = 3.141592653589793;

void solve(){
  ull k;
  cin >> k;
  string s;
  cin >> s;
  if(s.length() > k){
    for(ull i = 0;i<k;i++)cout << s[i];
    cout << "...";
  }
  else{
    cout << s;
  }
  cout << endl;
  return;
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
vector<int> G[100000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  rep(i, N) {
    int s = G[i].size();
    if (s % 2 != 0) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}


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

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

    if (n%2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    string t1, t2;
    t1 = s.substr(0,n/2);
    t2 = s.substr(n/2);

    if (t1 == t2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

double dist(vector<int> x, vector<int> y, int i, int j)
{
	return sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
}

int main()
{
	ll n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(){
	int i, count = 0;
	char ch, moji[1200];
	while(1){
		scanf("%c", &ch);
		if(ch == '\n') break;
		if(islower(ch)){
			moji[count] = toupper(ch);
		}else if(isupper(ch)){
			moji[count] = tolower(ch);
		} else {
			moji[count] = ch;
		}
		count++;
	}
	for(i = 0; i < count; i++){
		printf("%c", moji[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include <cstdio>
#include <algorithm>

constexpr int mod = 1000000007;
int dp[1000000] = {};

int main() {
  int N, H, D;
  scanf("%d %d %d", &N, &H, &D);
  long long coeff = 0;
  long long fact = 1;
  for (int i = 1; i <= N; ++i) {
    if ((coeff += ((fact *= i) %= mod)) >= mod) coeff -= mod;
  }
  std::fill(dp, dp + D, fact);
  int sum = dp[0];
  for (int i = 1; i < H; ++i) {
    if ((dp[i] += (coeff * sum) % mod) >= mod) dp[i] -= mod;
    if ((sum += dp[i]) >= mod) sum -= mod;
    if (i >= D) if ((sum -= dp[i - D]) < 0) sum += mod;
  }
  printf("%d\n", dp[H - 1]);
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,k,mp[12][1002],pos[12],cnt,ans,cut[1002];
char s[12][1002];
inline int calc(){
	re int lst=1,aa=0;
	for(re int i=1;i<=m;++i){
		for(re int j=1;j<=cnt;++j){
		re int x=pos[j-1]+1,y=pos[j];
	//	printf("%d %d\n",x,y);
		if(mp[y][i]-mp[y][i-1]-mp[x-1][i]+mp[x-1][i-1]>k)return 1e7;
		if(mp[y][i]-mp[y][lst-1]-mp[x-1][i]+mp[x-1][lst-1]>k)cut[i]=1;	
		}
		if(cut[i]){
			++aa;
			lst=i;
		}
	}
	return aa;
}
inline void work(re int x,re int y){
	if(x==n){
		memset(cut,0,sizeof(cut));
	//	printf("%d\n",y);
		pos[++cnt]=n;y+=calc();--cnt;
	//	printf("%d\n\n",y);
		ans=min(ans,y);
		return;
	}
	work(x+1,y);
	pos[++cnt]=x;
	work(x+1,y+1);
	--cnt;
}
signed main(){
	n=read(),m=read(),k=read();ans=1e9;
	for(re int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(re int i=1;i<=n;++i){
		for(re int j=1;j<=m;++j){
			mp[i][j]=s[i][j]-'0';
			mp[i][j]+=mp[i-1][j]+mp[i][j-1]-mp[i-1][j-1];
		}
	}
	pos[0]=0;pos[1]=n;
	work(1,0);
	printf("%d",ans);
}


Measured memory_bytes: 256
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

#N = ii()
#ss = [sys.stdin.readline().rstrip() for i in range(2*N)]
#for i in range(N):
S = input()
T = input()
#S = ss[2*i]
#T = ss[2*i+1]

ls, lt = len(S), len(T)
dp = dp2(0, ls+1, lt+1)
#if S[0] == T[0]:
    #dp[1][1] = 1

for i in range(lt+1):
    for j in range(ls+1):
        if (i < lt and j < ls) and S[j] == T[i]:
            dp[i+1][j+1] = dp[i][j] + 1
        if j < ls:
            dp[i][j+1] = max(dp[i][j], dp[i][j+1])
        if i < lt:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])
if not dp[lt][ls]:
    dp[lt][ls] = max(dp[lt-1][ls], dp[lt][ls-1])

#print(dp[lt][ls])


i, j = lt, ls
ans = ''

while dp[i][j] != 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += S[j-1]
        i -= 1
        j -= 1

print(ans[::-1])

Measured memory_bytes: 117340
N,M,X,Y = map(int,input().split(" "))
list1 = list(map(int,input().split(" ")))
list2 = list(map(int,input().split(" ")))
list1.sort(reverse=True)
list2.sort()
while(True):
    if list1[0] >= Y:
        print("War")
        break
    if list2[0] <= X:
        print("War")
        break
    if list1[0] >= list2[0]:
        print("War")
        break
    else:
        print("No War")
        break



Measured memory_bytes: 3064
for _ in range(int(input())):
    xa, ya, ra, xb, yb, rb = list(map(float,input().split()))
    dAB = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
    if ra + rb < dAB:
        print('0')
    elif dAB + rb < ra:
        print('2')
    elif dAB + ra < rb:
        print('-2')
    else:
        print('1')

Measured memory_bytes: 7656
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <iostream>


using namespace std;

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    long n;
    cin >> n;
    long long x[n];
    long long plus_sum = 0;
    long long minus_sum = 0;
    long long a;
    for (long i = 0; i < n; i++) {
        cin >> x[i];
        // scanf("%lld", &x[i]);
        x[i] -= (i + 1);
        // if (x[i] >= 0) {
        //     plus_sum +=x[i] - (i + 1);
        // } else {
        //     minus_sum +=x[i] - (i + 1);
        // }
    }
    sort(x, x + n);
    long center = n / 2;
    long long res = 0;
    long long b;
    if (n % 2) {
        b = x[center];
    } else {
        b = static_cast<long long int>(round((x[center - 1] + x[center]) / 2));
    }

    for (long i = 0; i < n; i++) {
        res += abs(x[i] - b);
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int A,B,C;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	if(A==5&&B==5&&C==7)
	{printf("YES");}
	else if(A==5&&B==7&&C==5)
		{printf("YES");}
		else if(A==7&&B==5&&C==5)
		{printf("YES");}
	else { 
			printf("NO");} 
	return 0;
 } 

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)
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 (b < a) { a = b; return 1; } return 0; }

int main()
{
	int r;

	cin >> r;

	cout << fixed << setprecision(10) << 2 * r * M_PI << endl;


	return 0;
}

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

int main(){
    while(1){
        int m,f,r;
        cin>>m>>f>>r;
        if((m==-1)&&(f==-1)&&(r==-1))break;
        if((m==-1)||(f==-1)){
            cout<<"F"<<endl;
            continue;
        }
        if((m+f>=80)){
            cout<<"A"<<endl;
            continue;
        }
        if((m+f>=65)){
            cout<<"B"<<endl;
            continue;
        }
        if((m+f>=50)||((m+f>=30)&&(r>=50))){
            cout<<"C"<<endl;
            continue;
        }
        if(m+f>=30){
            cout<<"D"<<endl;
            continue;
        }
        cout<<"F"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3048
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    l=[int(input()) for i in range(5)]
    k=int(input())
    f=True
    for i in l:
        for j in l:
            if abs(i-j) >k:
                f=False      
    print('Yay!' if f == True else ':(')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
N=int(input())
ss=[2,3,5]
ans=[]
for i in range(7,55555):
    for j in ss:
        if i%j==0:
            break
        if j>i**(0.5):
            ss.append(i)
            if i%5==1:
                ans.append(i)
            break
    if len(ans)==N:
        break
for i in range(N):
    print(ans[i],end=" ")

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

int main() {
    int a, b , c, k;
    cin >> a >> b >> c >> k;
    int max_num = max(a, max(b, c));
    int sum_rest = a + b + c - max_num;
    cout << 1ll  * max_num * pow(2ll, k) + sum_rest << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

void update(int i, int x);
int query(int x, int y, int k, int l, int r);

int n=3e5+1, k;
vector<int> a;

int main(){

    int tmpn;
    cin >> tmpn >> k;

    rep(i, 30) {
        if ((n - 1) < 1 << i) {
            n = 1 << i;
            break;
        }
    }

    rep(i, 2 * n - 1) { a.push_back(0); }

    rep(i, tmpn) {
        int x;
        cin >> x;
        update(x, query(max(0, x-k), min(n, x+k+1), 0, 0, n)+1);
    }

    cout << a[0] << endl;

    return 0;
}

void update(int i, int x) {
  i += n - 1;
  a[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    a[i] = max(a[i * 2 + 1], a[i * 2 + 2]);
  }
}

int query(int x, int y, int k, int l, int r) {
  if (r <= x || y <= l) return 0;
  if (x <= l && r <= y)
    return a[k];
  else {
    int vl = query(x, y, k * 2 + 1, l, (l + r) / 2);
    int vr = query(x, y, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    map<ll, ll> MA;

    REP(i, M){
        ll a, b;
        cin >> a >> b;
        if(a == 1){
            MA[b]++;
        }
        if(b == N){
            MA[a]++;
        }
    }

    for(auto iter=MA.begin(); iter!=MA.end(); iter++){
        // cout << iter->first << endl;
        if(iter->second == 2){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 16104
# -*- coding: utf-8 -*-
#D - Static Sushi 
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))

right = 0
ans = 0
total = 0
#尺取法 閉区間
for left in range(N):
    while right < N and (total ^ A[right]) == (total + A[right]):
        total += A[right]
        right += 1
    ans += right-left
    if left == right:
        right += 1
    else:
        total -= A[left]
print(ans)

Measured memory_bytes: 95560
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
#define mod 1000000007
#define pb push_back;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll n,k;
    cin>>n>>k;
    ll sm=0;
    ll mn=LLONG_MAX;
    ll x;
    ll i;
    vector<ll> v;
    for(i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    if(v[n-1]==0)
    {
        if(k&1)
        {
            cout<<0;
        }
        else
        {
            ll prod=1;
            for(i=0;i<k;i++)
            {
                prod=((prod*v[i])%mod+mod)%mod;
            }
            cout<<prod;
        }
    }
    else if(v[n-1]<0)
    {
        if(k&1)
        {
            reverse(v.begin(),v.end());
            ll prod=1;
            for(i=0;i<k;i++)
            {
                prod=((prod*v[i])%mod+mod)%mod;
            }
            cout<<prod;
        }
        else
        {
            ll prod=1;
            for(i=0;i<k;i++)
            {
                prod=((prod*v[i])%mod+mod)%mod;
            }
            cout<<prod;
        }
    }
    else
    {
        if(k&1)
        {
            ll prod=v[n-1];
            k--;
            ll j=n-2;
            ll i=0;
            while(k>0)
            {
                ll x=v[j]*v[j-1];
                ll y=v[i]*v[i+1];
                if(x>y)
                {
                    x%=mod;
                    prod=((prod*x)%mod+mod)%mod;
                    j-=2;
                }
                else
                {
                    y%=mod;
                    prod=((prod*y)%mod+mod)%mod;
                    i+=2;
                }
                k-=2;
            }
            cout<<prod;
        }
        else
        {
            ll prod=1;
            ll j=n-1;
            ll i=0;
            while(k>0)
            {
                ll x=v[j]*v[j-1];
                ll y=v[i]*v[i+1];
          //      cout<<x<<" "<<y<<" "<<i<<" "<<j<<endl;
                if(x>y)
                {
                    x%=mod;
                    prod=((prod*x)%mod+mod)%mod;
                    j-=2;
                }
                else
                {
                    y%=mod;
                    prod=((prod*y)%mod+mod)%mod;
                    i+=2;
                }
             //   cout<<prod<<endl;
                k-=2;
            }
            cout<<prod;
        }
    }
}

Measured memory_bytes: 5364
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	char c,map[10000][22];
	int w,h,i,j,a,b;
	cin>>w>>h>>c;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			map[i][j]='.';
			if(i==0 || i==h-1){
				map[i][j]='-';
			}
			if(j==0 || j==w-1){
				map[i][j]='|';
			}
			if(i==0&&j==0) map[i][j]='+';
			if(i==0&&j==w-1) map[i][j]='+';
			if(i==h-1&&j==0) map[i][j]='+';
			if(i==h-1&&j==w-1) map[i][j]='+';
		}
	}
	a=h/2;
	b=w/2;
	map[a][b]=c;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cout<<map[i][j];
		}
		cout<<endl;	
	}
	
	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
 
using namespace std;
 
int main() {
    long a,v;
    cin>>a>>v;
    long b,w;
    cin>>b>>w;
    long t;
    cin >>t;
    long k = abs(a-b);
    long h = v-w;
    h = h*t;
    if(k <= h){
      cout<<"YES";
    }
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 3100
A = []

for i in range(3):
  p, q, r = map(int, input().split())
  A.append(p)
  A.append(q)
  A.append(r)
N = int(input())
c = [0] * 9
for i in range(N):
  B = int(input())
  if B in A:
    position = A.index(B)
    c[position] = 1
if c[0]==c[4]==c[8]==1 or c[2]==c[4]==c[6]==1 or c[0]==c[1]==c[2]==1 or c[3]==c[4]==c[5]==1 or c[6]==c[7]==c[8]==1 or c[0]==c[3]==c[6]==1 or c[1]==c[4]==c[7]==1 or c[2]==c[5]==c[8]==1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9244
#include<iostream>
using namespace std;
const int N=1e5+10;
long long a[N];
int main(){
	int n;
	cin>>n;
	long long ans=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0) return cout<<0,0;
	}
	for(int i=0;i<n;i++){
		if(a[i]>1000000000000000000/ans) return cout<<-1,0;
		ans*=a[i];
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4512
#include<bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
 
typedef pair<long long int,long long int>pa;
#define resize(A) A.resize(unique(A.begin(), A.end()) - A.begin())
#define pb push_back
 
# define  MAX 200005
long long int MOD=1e9+7;
long long int INF=1e18;
 
int main()
{
    
       ios_base::sync_with_stdio(false); 
       cin.tie(NULL);
     cout.tie(NULL);
      long long int i,j,k=0,l=0,r=0,m=0,n,p=0,cnt=0,cnt1=0,x,y,z=0,a,b,low,mid,high,ans=0,maxi=0,mini=INF,t;
    cin>>n;
    long long int A[n];
    map<long long int,long long int>ma;
    map<long long int,long long int>::iterator it;
    for(i=0;i<n;i++)
    {
        cin>>A[i];
        ma[A[i]]++;
         if(A[i]==0)
             cnt++;
    }
    if(cnt==n)
        cout<<"Yes\n";
    else if(n%3==0)
    {
        if(ma.size()==2)
        {
          r=n/3;
            vector<pa>V;
            for(it=ma.begin();it!=ma.end();it++)
            {
                V.push_back({it->second,it->first});
            }
            sort(V.begin(),V.end());
            if(V[1].first==2*r && V[0].second==0)
            {
                cout<<"Yes\n";
            }
            else
                cout<<"No\n";
            
        }
        else if(ma.size()==3)
        {
            r=n/3;
            vector<pa>V;
            for(it=ma.begin();it!=ma.end();it++)
            {
                V.push_back({it->second,it->first});
            }
            sort(V.begin(),V.end());
            k=0;
            k=k^V[0].second^V[1].second^V[2].second;
            if(V[0].first==r && V[1].first==r && V[2].first==r && k==0 )
            {
                cout<<"Yes\n";
            }
            else
                cout<<"No\n";
        }
        else
            cout<<"No\n";
    }
    else
        cout<<"No\n";

}

Measured memory_bytes: 5760
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
c=[0]*(n+1)
flg=True
ans=0
if a[n]>2**n:
  print(-1)
else:
  b[n]=a[n]
  c[0]=1
  for i in range(n-1,-1,-1):
    b[i]=b[i+1]+a[i]
  for i in range(1,n+1):
    
    c[i]=2*(c[i-1]-a[i-1])
  
  for i in range(n+1):
    if c[i]<=0:
      flg=False
  if c[n]-a[n]<0:
    flg=False
  
  for i in range(n+1):
    ans+=min(b[i],c[i])
  if flg:
    
    print(ans)
  else:
    print(-1)





Measured memory_bytes: 680004
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

map<int, bool> mp;
bool f(int n){
    while(n > 0){
        if(mp[n%10]) return false;
        n /= 10;
    }
    return true;
}


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

    int n, k;
    cin >> n >> k;

    vector<int> d(k);
    REP(i, k) cin >> d[i];

    REP(i, k) mp[d[i]] = true;

    while(1){
        if(f(n)){
            break;
        }
        n++;
    }
    cout << n << endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = in.nextLongArray(n);

			long ans = 0;

			if (a[0] != 0) {
				out.println(-1);
				return;
			}

			for (int i = 1; i < n; i++) {
				long sa = a[i] - a[i-1];
				if (sa > 1) {
					out.println(-1);
					return;
				}
			}

			for (int i = 1; i < n; i++) {
				long sa = a[i] - a[i-1];
				if (sa == 1) {
					ans++;
				} else {
					ans += a[i];
				}
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

#define LEN 100001

typedef struct pp{
  char name[11];
  int time;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P a)
{
    Q[tail] = a;
    tail = (++tail)%LEN;
}

P dequeue()
{
    P a = Q[head];
    head = (++head)%LEN;
    return a;
}

int main()
{
    int cal=0,c;
    int q;
    P aa;
    cin >> n >> q;
    for(int i=1;i <= n;i++){
        cin >> Q[i].name >> Q[i].time;
    }
    head = 1;
    tail = n+1;
    
    while(head != tail){
        aa = dequeue();
        c = min(q, aa.time);
        aa.time -= c;
        cal += c;
        if(aa.time > 0) enqueue(aa);
        else{
            cout << aa.name << " " << cal << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4668
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;string S;
    cin >> N >> S;
    int cnt = 0;
    REP(i,N-2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<58;
const ll mod=1e9+7;


int main(){
  int i,j;
  int n;
  cin>>n;
  ll a[n];
  ll all=0;
  for(i=0;i<n;i++){
    cin>>a[i];
    all+=a[i];
  }
  ll ab=INF;
  ll sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
    ab=min(ab,abs(2*sum-all));
  }
  cout<<ab<<endl;
}

Measured memory_bytes: 1792
//mOzis_
/////*31022618*/////
//****//MONU KUMAR\****//
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define lp(i,l,r) for (long long int i = l; i < r; i++)
#define mem(a,x) memset(a,x,sizeof(a))              //set elements of array to some value
#define pi 3.1415926535897932384626
#define mod 1000000007
#define pb(x) push_back(x)
#define ff first
#define ss second
#define siz 256                        //characters are stored using 8 bit and there can be
bool anagram(char *s1, char *s2)     //256 possible characters only in lowercase alphabet
{
	ll count[siz];
    mem(count,0) ;
    ll i;
    for (i = 0; s1[i] && s2[i];  i++)
    {
        count[s1[i]]++;
        count[s2[i]]--;
    }
    if (s1[i] || s2[i])
    {
      return false;
    }
    lp(i,0,siz)
    {
    	 if (count[i])
    	 {
    	 	 return false;
    	 }
    }
     return true;

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

	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for (int i = 0; i < n; ++i)
	{
		if (i==(k-1))
		{
			if (s[i]=='A')
			{
				s[i]='a';
			}
			if (s[i]=='B')
			{
				s[i]='b';
			}
			if (s[i]=='C')
			{
				s[i]='c';
			}
		}
		cout<<s[i];
	}

	return 0;
}
//////////*********************end of program*********************//////////




Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    inf = 10 ** 16
    n, k = map(int, input().split())
    hh = [0] + list(map(int, input().split()))
    dp = [[0] * (k + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        h = hh[i]
        for j in range(k + 1):
            v = inf
            for nd in range(k + 1):
                if i - 1 - nd < 0 or j - nd < 0: break
                v = min(v, dp[i - 1 - nd][j - nd] + max(0, h - hh[i - 1 - nd]))
            dp[i][j] = v
    print(min(dp[n-d][k-d] for d in range(min(n+1,k+1))))

main()


Measured memory_bytes: 43244