akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A_array(N), B_array(N), C_array(N - 1);
  for (int i = 0; i < N; ++i) {
    std::cin >> A_array.at(i);
  }
  for (int i = 0; i < N; ++i) {
    std::cin >> B_array.at(i);
  }
  for (int i = 0; i < N - 1; ++i) {
    std::cin >> C_array.at(i);
  }

  int prev_index = -100;
  int sum_point = 0;
  for (int i = 0; i < N; ++i) {
    const int index = A_array.at(i) - 1;
    const int point = B_array.at(index);
    sum_point += point;
    if (prev_index + 1 == index) {
      const int bonus = C_array.at(prev_index);
      sum_point += bonus;
    }
    prev_index = index;
  }
  std::cout << sum_point << std::endl;
  return 0;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    ans = 0
    if n == 0:
        break
    count = n
    for i in range(1, n):
        a = 0
        for j in range (i, n):
            a += j
            if a == n:
                ans += 1
                break
            if a > n:
                break
    print(ans)




Measured memory_bytes: 5584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while(true){
        int n = sc.nextInt();
        int x = sc.nextInt();
            if(n == 0 && x == 0) break;
            
        int p = 0;
        
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x) p++;
                }
            }
        }
        System.out.println(p);
        }
    }
}



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

int X;

bool is_expo(int x) {
	int n[1001] = { 0 };
	for (int i = 2; i <= 1000; i++) {
		while (x % i == 0) {
			x = x / i;
			n[i]++;
		}
	}

	int tmp = 0;
	for (int i = 0; i <= 1000; i++) {
		if (n[i] == 1) {
			return false;
		}

		if (n[i] >= 2) {
			if (tmp == 0) {
				tmp = n[i];
			}else{
				if (n[i] != tmp) {
					return false;
				}
			}
		}
	}

	return true;
}

int main() {
	cin >> X;
	while (X > 1) {
		if (is_expo(X)) {
			cout << X << endl;
			return 0;
		}
		X--;
	}
	cout << X << endl;
}

Measured memory_bytes: 256
N, K = map(int,input().split())
List = []
mod = 10 ** 9 + 7
for i in range(1,K+1):
    List.append(pow(K//i,N,mod))
for i in range(K-1,-1,-1):
    List[i] -= sum(List[i::i+1]) - List[i]
ans = 0
for i in range(K):
    ans += ((i+1) * List[i]) % mod
print(ans % mod)

Measured memory_bytes: 73756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  
  int j;
  char A;
  char B;
  char C;
  
  j = 0;
  
  for (int i = 0; i < N-2; i++){
    if (S.at(i) == 'A'){
      if (S.at(i + 1) == 'B'){
        if (S.at(i + 2) == 'C'){
          j++;
        }
      }
    }
  }
  
  cout << j << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int sum=0;
	map<string,int>m;
	while(n--){
		string s;
		cin >> s;
		if(m[s]==0){m[s]=1;sum++;}
	}
	cout << sum << endl;
	return 0;
} 

Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H, W;
    cin >> H >> W;
    string str(W+2, '#');
    vector<string> ans(H);
    
    cout << str << endl;
    for (int i = 0; i < H; i++){
        cin >> ans[i];
        cout << '#' << ans[i] << '#' << endl;
    }
    cout << str << endl;
    
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var a = new[] { 1, 3, 5, 7, 8, 10, 12 };
        var b = new[] { 4, 6, 9, 11 };
        var c = new[] { 2 };

        var s = Console.ReadLine().Split(' ');
        var x = int.Parse(s[0]);
        var y = int.Parse(s[1]);

        if (m1(a, x) && m1(a, y))
        {
            Console.WriteLine("Yes");
        }
        else if (m1(b, x) && m1(b, y))
        {
            Console.WriteLine("Yes");
        }
        else if (m1(c, x) && m1(c, y))
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }

    static bool m1(int[] a, int x)
    {
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == x) return true;
        }
        return false;
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,k;
    scanf("%d %d",&n,&m);
    long long x[n+10],y[m+10],d,p=1000000007;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&x[i]);
    }
    for(i=1;i<=m;i++)
    {
        scanf("%lld",&y[i]);
    }
    long long ans1=0,ans2=0,ans;
    for(i=1;i<n;i++)
    {
        d=(abs(x[i+1]-x[i]))%p;
        ans1+=((d%p)*(n-i)%p*(i%p))%p;

    }
    for(i=1;i<m;i++)
    {
        d=(abs(y[i+1]-y[i]))%p;
        ans2+=((d%p)*(m-i)%p*(i%p))%p;

    }
    ans=((ans1%p)*(ans2%p))%p;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
/*
  I used a template program in C.
*/

#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){


}
 
Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){ /*find*/

  /*my code beginning*/
  if ( u == NIL || k == u->key ){
    return u;
  }
  if ( k < u->key ){ 
    return treeSearch(u->left,k);
  } else { 
    return treeSearch(u->right,k);
  }
  /*my code end*/

}
 
Node treeSuccessor(Node x){

 
}
 
Node treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y


}
 
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  /*my code beginning*/
  while ( x != NIL ){
    y = x;
    if ( z->key < x->key ){ 
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if ( y == NIL ){ 
    root = z;
  } else if ( z->key < y->key ){
    y->left = z;
  } else {
    y->right = z;
  }
  /*my code end*/

}
 
void inorder(Node u){

  /*my code beginning*/
  if ( u != NIL ){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  /*my code end*/

}
void preorder(Node u){

  /*my code beginning*/
  if ( u != NIL ){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
  /*my code end*/

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  /*my code beginning*/
  root=NIL;
  /*my code end*/

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 19364
// atcoder/abc123/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int x, y, z;
  lli w;
  while (cin >> x >> y >> z >> w) {
    vector<lli> a(x);
    vector<lli> b(y);
    vector<lli> c(z);
    cin >> a >> b >> c;
    sort(begin(a), end(a));
    sort(begin(b), end(b));
    sort(begin(c), end(c));
    reverse(begin(a), end(a));
    reverse(begin(b), end(b));
    reverse(begin(c), end(c));

    vector<lli> d;
    each (i, a) each (j, b) d.push_back(i + j);
    sort(begin(d), end(d));
    reverse(begin(d), end(d));

    priority_queue<lli, vector<lli>, greater<lli>> q;
    each (i, d) {
      each (j, c) {
        if (q.size() < w) q.push(i + j);
        else {
          if (i + j < q.top()) break;
          q.push(i + j);
        }
        if (w < q.size()) q.pop();
      }
    }

    vector<lli> v;
    while (q.size()) {
      v.push_back(q.top());
      q.pop();
    }
    sort(begin(v), end(v));
    reverse(begin(v), end(v));
    each (i, v) cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 10480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
//ノードの数の変化がないのでleft-child,right-sibling representationによって木を表す

struct Node{ll parent,left,right;};
struct Node T[MAX];
ll D[MAX],N;


//あるノードの親があるか(NILはnotNode)でふかさを測る
ll getDepth(ll u){
    ll d = 0;
    while(T[u].parent!=NIL){
        u = T[u].parent;
        d++;
        }
    return d;
}
//下の方が高速
//u:ノード番号　D:各ノードの深さ 右の兄弟の深さと、最左のこの深さを探索　
void setDepth(ll u,ll p){
    D[u] = p;
    if(T[u].right != NIL){
        setDepth(T[u].right,p);
    }
    if(T[u].left != NIL){
        setDepth(T[u].left,p+1);
    }
}

void printChildren(ll u){
    ll i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";

    if(T[u].parent == NIL)cout << "root, ";
    else if(T[u].left == NIL)cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for(ll i = 0,c = T[u].left;c != NIL;i++,c = T[c].right){
        if(i)cout <<", ";
        cout << c;
    }
    cout << "]" << endl;
    // ll c = T[u].left;
    // while(c != NIL){
    //     cout << c;
    //     c = T[c].right;
    // }
}


int main(){
    ll i,j,d,v,c,left,right;
    cin >> N;
    //初期化
    REP(i,N){
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    REP(i,N){
        cin >> v >> d;
        REP(j,d){
            cin >> c;
            if(j==0)T[v].left = c;
            else T[left].right = c;
            left = c;
            T[c].parent =v;
        }
    }
    REP(i,N){
        if(T[i].parent == NIL)right = i;
    }
    setDepth(right,0);
    REP(i,N)printChildren(i);
    return 0;
}


Measured memory_bytes: 9388
#include<iostream>
#include <algorithm>
#include<string>
using namespace std;
 
int main(void) {
	int r[100] = { 0 };
	int A,B,X;
	cin >> A>>B>>X;
	if(A > X  || A+B < X)
		cout << "NO"<< endl;
	else 
		cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
N,T = map(int,input().split())

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

nmin = float("inf")
nsub = 0
ans = 0

Acopy = A.copy()
Acopy.sort()

for i in Acopy:

    if A[-1] == i:
        del A[-1]
    else:
        break


for i in range(len(A)):

    nmin = min(nmin , A[i])

    if nsub < A[i] - nmin:
        nsub = A[i] - nmin
        ans = 1

    elif nsub == A[i] - nmin:
        ans += 1

print (ans)


Measured memory_bytes: 14252
from collections import defaultdict

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

S = [0] * (N+1)
for i in range(1, N+1):
  S[i] = S[i-1] + A[i-1]

d = defaultdict(int)
for i in range(len(S)):
  d[S[i]] += 1

ans = 0
for key, val in d.items():
  ans += val * (val-1) // 2
print(ans)

Measured memory_bytes: 41760
object Main extends App {
  val line1 = io.StdIn.readLine

  var flag = false
  var cnt = 0
  var max = Int.MinValue

  for (c <- line1) {
    c match {
      case 'A' | 'C' | 'G' | 'T' => {
        flag = true
        cnt += 1
      }
      case _ if flag => {
        max = if (cnt > max) cnt else max
        flag = false
        cnt = 0
      }
      case _ =>
    }
  }
  max = if (cnt > max) cnt else max
  println(max)
}


Measured memory_bytes: 25412
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

string S;

int main() {
	cin >> S;
	REP(i, S.length()) {
		if (i % 2 == 0) {
			if (S[i] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (S[i] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

int amount[101];
int num[101];
int dp[101][1001];

int main(){
	string str;
	vector<string> data;
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		memset(amount,0,sizeof(amount));
		memset(num,0,sizeof(num));
		memset(dp,0,sizeof(dp));

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

		dp[0][0] = 1;


		for(int i=0;i<n;i++){		
				for(int j=0;j<=amount[i];j++){
					for(int k=0;k<=1000;k++){
					if(k - num[i]*j >= 0){
						dp[i+1][k] += dp[i][k-num[i]*j];
					}
				}
			}
		}

		int g;
		scanf("%d",&g);
		for(int i=0;i<g;i++){
			int c;
			scanf("%d",&c);
			printf("%d\n",dp[n][c]);
		}
	}
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	struct R
	{
		public int P;
		public bool Odd;
	}

	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var map = new int[n + 1].Select(_ => new List<R>()).ToArray();
		foreach (var r in new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()))
		{
			map[r[0]].Add(new R { P = r[1], Odd = r[2] % 2 == 1 });
			map[r[1]].Add(new R { P = r[0], Odd = r[2] % 2 == 1 });
		}

		var cs = new bool[n + 1];
		var q = new Queue<int>();
		q.Enqueue(1);
		while (q.Any())
		{
			var p = q.Dequeue();
			foreach (var r in map[p])
			{
				cs[r.P] = cs[p] ^ r.Odd;
				map[r.P].RemoveAll(x => x.P == p);
				q.Enqueue(r.P);
			}
		}
		foreach (var c in cs.Skip(1)) Console.WriteLine(c ? 1 : 0);
	}
}


Measured memory_bytes: 30680
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=100000;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
    ll lower_bound(ll X){
        if(sum(N)<X||X<=0) return -1;
        ll ret=0,memo=1,sum=0;
        while(memo*2<=N) memo*=2;
        while(memo>0){
            if(memo+ret<=N&&sum+bit[memo+ret]<X){
                sum+=bit[memo+ret];
                ret+=memo;
            }
            memo/=2;
        }
        return ret+1;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y,ll mod){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=mod;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=mod;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string S; cin>>S;
    rep(i,0,S.size()){
        if(S[i]=='?') S[i]='D';
    }
    cout<<S<<endl;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#include<cstdio>
 
using namespace std;
 
typedef long long int ll;
 
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; }
 
typedef pair<int,int> pair;
 
int main(){
    int n; cin >> n;
    vector<int> a(n); for(int i=0;i<n;i++) cin >> a[i];

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

    for(int i=1;i<n;i++){
        if(a[i-1]==a[i]){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String args[] ){
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int b = sc.nextInt();
	    if(a < b){
	        System.out.println("a < b");
	    }else if(a > b){
	        System.out.println("a > b");
	    }else if(a == b){
	        System.out.println("a == b");
	    }
	}
}



Measured memory_bytes: 26184
#include<iostream>
#include<vector>
#include<algorithm>
#include <string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>

#define ok printf("ok\n");
#define MAX 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define pb push_back

using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	int a,b;
	cin >> a >> b;
	if(a*b%2 == 1)
		cout << "Odd";
	else
		cout << "Even";


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll res = min(N, M / 2);
    cout << res + (M - res * 2) / 4 << endl;
    return 0;
}


Measured memory_bytes: 256
/*D - Knapsack 1*/

#include <bits/stdc++.h>
using namespace std;
using Long = long long;

vector <Long> peso;
vector <Long> valor;
vector < vector <Long> > memo;

Long sumaMax(Long W, Long tam);

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int items;
	int W;

	cin >> items >> W;

	peso = vector <Long>(items);
	valor = vector <Long>(items);
	memo = vector <vector <Long> >(W + 1, vector<Long> (items, -1));

	for (int i = 0; i < items; ++i)
		cin >> peso[i] >> valor[i];
	

	Long ans = 0;

	ans = sumaMax(W, items - 1);

	cout << ans;

	return 0;
}

Long sumaMax(Long W, Long tam){

	if(W == 0ll or tam < 0){
		return 0ll;
	}

	Long ans;

	if(memo[W][tam] != -1)
		return memo[W][tam];

	ans = sumaMax(W, tam - 1);

	if(W - peso[tam] >= 0)
		ans = max(ans, valor[tam] + sumaMax(W - peso[tam], tam - 1));

	memo[W][tam] = ans;

	return ans;
}

Measured memory_bytes: 82304
# # もし修行により消化コストが全て0になる場合
# if sum(a_list) <= k:
#     print(0)
#     exit()

# # 更新メソッド
# def update_cost(max_idx, result_cost, a_list, f_list):

#     result_cost[max_idx] = a_list[max_idx] * f_list[max_idx]

#     if max_idx == 0:
#         pass
#     else:
#         result_cost[max_idx-1] = a_list[max_idx-1] * f_list[max_idx-1]

#     return result_cost

# # ソート
# a_list.sort()
# f_list.sort(reverse=True)

# # コストリストinit
# result_cost = [a_list[idx] * f_list[idx] for idx in range(len(a_list))]


# # 修行する
# while k > 0:
#     # 現状で最もコストが大きいものについて考える
#     max_idx = result_cost.index(max(result_cost))

#     # 修行実行
#     a_list[max_idx] -= 1
#     a_list.sort()

#     # コストリスト更新
#     result_cost = update_cost(max_idx, result_cost, a_list, f_list)

#     # 修行数減らす
#     k -= 1

# print(max(result_cost))

import numpy as np
n, k = map(int, input().split())

A = np.array(input().split(), np.int)
F = np.array(input().split(), np.int)

A.sort()
F.sort()
F = F[::-1]

left = -1 
right = (A * F).sum()

while (right-left) > 1:
    # print(left, right)
    split_line = (left + right) // 2
    r = np.maximum(0, A-split_line // F).sum() <= k
    if r:
        right = split_line
    else:
        left = split_line

print(right)



Measured memory_bytes: 37236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define rev(a,b,c) for(int a=b;a>=c;a--)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define F first
#define S second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define get(a) cin>>a
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n";
const ll mod = 1000000007;
const ll maxn = 500005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
ll ncr(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%mod;
    }
    return C[k];
}
void solve()
{
    int n;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    rep0(i,n){
        cout<<s1[i]<<s2[i];
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
       // nextl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

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

  REP(i, 9 * n + 1){
    ostringstream oss;
    oss << n + i;
    string sn = oss.str();
    bool f = true;
    REP(j, sn.size()){
      REP(k, d.size()){
        char c = sn[j];
        f = (atoll(&c)  ==  d[k]);
        if(f) break;
      }
      if(f) break;
    }
    if(!f){
      cout << n + i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}

		int count = 0;
		while(true) {
			for(int i = 0; i < a.length; i++) {	
				if(a[i] % 2 == 0) {
					a[i] /= 2;
				}else {
					System.out.println(count);
					return;
				}
			}
			count++;
		}
		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(ll i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    ll n;cin>>n;
    if(n%2==1)cout<<"0"<<endl;
    else if(n==0) cout<<"0"<<endl;
    else{
        ll ans=0;
        for(ll go=10;go<=n;go*=5) ans+=n/go;
        cout<<ans<<endl;
    }
    return 0;
}

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

const int64_t MOD= 1000000007;
const int Nfac= 2000007;
#define MEMORY 0 // 1/0: 階乗を配列に格納をする前処理をする/しない
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};

/* 階乗,二項係数 */
#if (MEMORY==1)
// 前処理として,階乗を配列に格納をするver.
vector<mint> mfac(Nfac+1), ifac(Nfac+1);
void fact_modp_init(int N= Nfac){
  mfac.at(0)= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    mfac.at(i)= mfac.at(i-1)* buf;
  }

  ifac.at(N)= mfac.at(N).inv();
  for(int i=N; i>0; i--){
    buf= i;
    ifac.at(i-1)= ifac.at(i)* buf;
  }
}
#else
// 前処理を回避するver.
void fact_modp_init(int N= Nfac){}
mint mfac(int N){
  mint ans= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    ans*= buf;
  }

  return ans;
}
#endif
// ^^^ テンプレここまで ^^^
mint binom_modp(int n, int k){
  k= min(k, n-k);
  if(n < 0 || k < 0) return 0;
  
  mint ans= 1;
  for(int i=1; i<=k; i++){
    mint num= n-i+1;
    mint den= i;
    ans*= num*den.inv();
  }
  return ans;
}

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

  mint t= 2;
  
  cout << t.pow(N)- 1- binom_modp(N, a)- binom_modp(N, b) << endl;
}

Measured memory_bytes: 256
// PCK2018 Yosen Q7 Warp machine
// YAMADA Terushige 2018.9.30.

#include <iostream>
#include <string>

using namespace std;

int main(){
  const int m=1000000007;
  int N;
  string s,t;
  cin >> N >> s >> t;
  int c[26] = {};// path count of entrance 'x' cities. 'x'='a'~'z'
  c[s[0]-'a']=1;

  for(int i=1;i<N-1;i++){
    c[s[i]-'a']+=c[t[i]-'a'];
    c[s[i]-'a']%=m;
    //    cout << "c[" << s[i] << "] = " << c[s[i]-'a'] << endl;
  }
  cout << c[t[N-1]-'a'] << endl;
  return 0;
}



Measured memory_bytes: 3364
#include <stdio.h>
#include <stdlib.h>
#include <float.h>

#define _max(_x, _y) ((_x)>(_y)?(_x):(_y))
#define _min(_x, _y) ((_x)>(_y)?(_y):(_x))

int main(void)
{
  int A,B,K, i, start;
  int count=0;

  scanf("%d %d %d", &A,&B,&K);
  start = _max(A,B);
  for (i=start; i>0; --i) {
    if ((A%i==0) && (B%i==0)) {
      ++count;
      if (count == K) {
        printf("%d\n", i);
        break;
      }
    }
  }  
  return 0;
}

Measured memory_bytes: 128
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    two_sat ts(n);
    int d; cin >> d;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    rep(i, n) {
        for(int j = i + 1; j < n; ++ j) {
            if(abs(x[i] - x[j]) < d) {
                ts.add_clause(i, false, j, false);
            }
            if(abs(x[i] - y[j]) < d) {
                ts.add_clause(i, false, j, true);
            }
            if(abs(y[i] - x[j]) < d) {
                ts.add_clause(i, true, j, false);
            }
            if(abs(y[i] - y[j]) < d) {
                ts.add_clause(i, true, j, true);
            } 
        }
    }
    if(!ts.satisfiable()) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    auto ans = ts.answer();
    rep(i, n) {
        if(ans[i]) cout << x[i] << endl;
        else cout << y[i] << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector <string> a(N);
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sort(a[i].begin(), a[i].end());
    }

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

    int i, j;
    for (i = 0; i < N; i=j) {
        ll tmp = 0;
        for (j = i + 1; j < N; j++) {
            if (a[i] != a[j]) break;
            tmp++;
        }
        cnt += (tmp+1)*(tmp)/2;
    }

    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 7296
#include <stdio.h>
 
int main (void) {
  int x, y, z;
  int i, N, count;
  
  scanf("%d", &N);

  for(i=1; i<N+1; i++) {
    count = 0;
    for(x=1; x*x<i+1; x++) {
      for(y=1; x*x + y*y + x*y<i+1; y++) {
        for(z=1; x*x + y*y + z*z + x*y + y*z + z*x<i+1; z++) {
          if(x*x + y*y + z*z + x*y + y*z + z*x == i) count +=1;
        }
      }
    }
    
  printf("%d\n", count);


  }

  
  return 0;
}

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

typedef long long ll;

ll N,K;
ll ans = 0;

int main()
{
    scanf("%lld%lld",&N,&K);
    ll a = 0,b = 0;
    for(int i = 1; i <= N; i++)if(i % K == 0)a++;
    for(int i = 1; i <= N; i++)if(i % K == K / 2)b++;
    ans = a * a * a;
    if(K % 2 == 0)ans += b * b * b;

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2000 + 5;

int n, m;
char a[maxn][maxn];

int U[maxn][maxn], D[maxn][maxn], L[maxn][maxn], R[maxn][maxn];

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(a[i][j] == '.'){
				L[i][j] = 1 + L[i][j - 1];
				U[i][j] = 1 + U[i - 1][j];
			}
		}
	}
	
	for(int i = n; i >= 1; i--){
		for(int j = m; j >= 1; j--){
			if(a[i][j] == '.'){
				R[i][j] = 1 + R[i][j + 1];
				D[i][j] = 1 + D[i + 1][j];
			}
		}
	}
	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(a[i][j] == '.')
				ans = max(ans, U[i][j] + R[i][j] + D[i][j] + L[i][j] - 3);
	
	cout << ans << endl;

	return 0;
}


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

using namespace std;

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

#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

ll next(){ll x; cin >> x; return x;}
const int maxn = 1e5 + 3, intf = 2e9;
const ll inf = 2e18, mod = 998244353;
const ld eps = 1e-6;


void solve(){
	int a , b , c , d; cin >> a >> b >> c >> d;
	swap(a , b);
	swap(c , d);
	if ((b + c - 1) / c < (d + a - 1) / a){
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
}


signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
    
    for (int t = 1; t--;) {
    	solve();
    }

	return 0;
}
/*


*/



Measured memory_bytes: 3612
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
dic_A = {}
for i in a_list:
    if i in dic_A:
        dic_A[i] += 1
    else:
        dic_A[i] = 1
ans = 0
cnt = len(dic_A)
for k, v in sorted(dic_A.items(), key=lambda x: x[1]):
    if cnt <= K:
        break
    ans += v
    cnt -= 1
print(ans)

Measured memory_bytes: 40092
package main

import (
	"fmt"
)

func main() {
	var S, w string
	var K, cnt int
	fmt.Scan(&S, &K)
	for _, v := range S {
		if v == '1' {
			cnt++
		} else {
			w = string(v)
			break
		}
	}
	if K <= cnt {
		fmt.Println(1)
	} else {
		fmt.Println(w)
	}
}


Measured memory_bytes: 512
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

N = int(input())
S = input()
N = len(S)

ans = 0
for i in range(N):
    if S[i:i+3] == "ABC":
        ans += 1
print(ans)

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    ll N,K;
    cin >> N >> K;
    
    vector<ll> A_i(N);
    
    REP(i,N)
    {
        cin >> A_i.at(i);
    }
    
    //テレポート回数が多いので、正直にシミュレーションするとTLE
    //町の数は最大で200000個なので、どこかでループになるはず
    ll count = 0;
    ll place = 1;

    vector<ll> A_bit(N);
    vector<ll> A_count_log(N);
    REP(i,N)
    {
        A_bit.at(i) = 0;
        A_count_log.at(i) = 0;
    }

    while(1)
    {
        place = A_i.at(place-1);
        if( A_bit.at(place-1) == 1)
        {
            //既に通った場所（ループ開始場所）
            //MODになるまでスキップする
            ll skip_count = (count - A_count_log.at(place-1));
            ll tmp_mod = ( (K - (count+1)) % skip_count );

            // cout << "skip_count:" << skip_count << endl;
            // cout << "tmp_mod:" << tmp_mod << endl;

            //場所特定
            ll count2 = 0;
            while(1)
            {
                if(count2 == tmp_mod)
                {
                    //debug
                    // cout << "kotti" << endl;
                    
                    //modが0なら今の場所に戻ってくる
                    break;
                }

                place = A_i.at(place-1);
                count2 ++;
            }
            
            count = K-1;
        }
        else
        {
            //bit on
            A_bit.at(place-1) = 1;
            A_count_log.at(place-1) = count;
        }
        count ++;

        if( count == K ) break;
    }

    cout << place << endl;

    return 0;
}

Measured memory_bytes: 8008
from collections import Counter as C
n=int(input())
a=sorted(C(list(map(int,input().split()))).items())
d=0
if a[-1][0]%2==0:
    d=1
q=1
for i in range(len(a)-1,-1,-1):
    if d:
        if a[i][0]==a[-1][0]//2 and a[i][1]!=1:
            q=0
            break
        elif a[i][0]<a[-1][0]//2:
            q=0
            break
        elif a[i][0]!=a[-1][0]+i-len(a)+1:
            q=0
            break
        elif a[i][1]<2 and i!=0:
            q=0
            break
    else:
        if a[i][0]<(a[-1][0]+1)//2:
            q=0
            break
        elif a[i][0]!=a[-1][0]+i-len(a)+1:
            q=0
            break
        elif a[i][0]==(a[-1][0]+1)//2 and a[i][1]!=2:
            q=0
            break
        elif a[i][1]<2:
            q=0
            break
if q:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    string s;
    cin >> s;
    int l = s.size();
    string a = s.substr(0, (l - 1) / 2);
    string b = s.substr((l + 1) / 2);
    string c = s.substr((l + 1) / 2);
    reverse(c.begin(), c.end());
    string ans = (a == b && a == c) ? "Yes" : "No";
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e,AC=0,TLE=0,WA=0,RE=0;
    cin>>a;
    string A;
    for(b=0;b<a;b++)
    {
        cin>>A;
        if(A=="AC") AC++;
        else if(A=="WA") WA++;
        else if(A=="TLE") TLE++;
        else RE++;
    }
    cout<<"AC x "<<AC<<endl;
    cout<<"WA x "<<WA<<endl;
    cout<<"TLE x "<<TLE<<endl;
    cout<<"RE x "<<RE<<endl;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll tmp;
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (i == j) continue;
			tmp = abs(a[j] - a[i]);
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
}


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

bool judge(string a,string b){
  for(int i=0;i<a.size();i++){
    bool f=true;
    for(int j=0;j<b.size();j++){
      if(!(i+j<a.size())){
        f=false;
        break;
      }
      if(a[i+j]!=b[j]){
        if(b[j]!='_'){
          f = false;
        }
      }
    }
    if(f)return true;
  }
  return false;
}
int main(){
  string a,b;
  cin>>a>>b;
  if(judge(a,b))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
    
 
    int K,T;
    cin>>K>>T;
    vector<int> S(T);
    int m=0;
    for(int i=0;i<T;i++){
        cin>>S.at(i);
        m=max(m,S.at(i));
    }
    int ans=max(0,m-1-(K-m));
    cout<<ans<<endl;
}


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

int main()
{
   char s[20], r[20];
   int n, c, d;
   gets(s);

   n = strlen(s);

   for (c=n-1,d=0;c>=0;c--,d++)
      r[d] = s[c];

   r[d] = '\0';

   printf("%s\n", r);

   return 0;
}

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

int main(){
  char c;
  string vowel = "aeiou";
  int d = 0;
  cin >> c;
  rep(i,vowel.size()){
    if(c==vowel.at(i))
      d++;
  }
  if(d==0)
    cout << "consonant" << endl;
  else
    cout << "vowel" << endl;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 'N':
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 'S':
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 'W':
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

a,b,c,d,e,f = map(int,input().split())
dice1 = Dice(a,b,c,d,e,f)

l_order = list(input())
for i in range(len(l_order)):
    dice1.roll(l_order[i])

print(dice1.above_face())


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
using namespace std;

int main(){
  int a, b; cin >> a >> b;
  if (a + b == 15) {
    cout << "+" << endl;
  } else if (a * b == 15) {
    cout << "*" << endl;
  } else {
    cout << "x" << endl;
  }
}


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

int main(){
  int l[200];
  int m[200];
  int k=-1;
  for(int i=0;!cin.eof();i++,k++){
    cin >> l[i];
    cin >> m[i];
  }

  for(int j=0;j<k;j++){
  cout<< (int)log10(l[j]+m[j])+1 << endl;
  }
  return 0;
}  

Measured memory_bytes: 1204