akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
using ld = long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class DFlippingSigns {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<ll> a(n), neg;
        int even = 0;
        ll asum = 0;
        for(int i=0; i<n; i++){
            in >> a[i];
            asum += abs(a[i]);
            if(a[i] <= 0) {
                even++;
            }
            neg.push_back(abs(a[i]));
        }

        if(even%2 == 0) out << asum << endl;
        else {
            sort(neg.begin(), neg.end());
            out << asum - neg[0]*2 << endl;
        }
	}
};


int main() {
	DFlippingSigns solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2168
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(c<=a&&b<=a)
	{
		cout<<c+b<<endl;
	}
	else if(a<=b&&c<=b)
	{
		cout<<c+a<<endl;
	}
	else if(a<=c&&b<=c)
	{
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
from array import*;R=range;T=[0]*28;N=int(input());S=[[ord(C)-95 for C in input()]for _ in[0]*N];U=N*26**2*array('i',[0]);V=N*[0];Q=int(input())
for X in S:
	P=0
	for C in X:
		if T[P+C]==0:T[P+C]=len(T);T+=[0]*28
		T[P]+=1;P=T[P+C]
	T[P]+=1;T[P+1]=1
for I in R(N):
	P=0
	for C in S[I]:
		for A in R(26):
			X=T[P+A+2]
			if(A!=C-2)*X:U[676*I+26*A+C-2]+=T[X]
		V[I]+=T[P+1]
		P=T[P+C]
while Q:
	K,P=input().split();K=int(K)-1;P=[ord(C)-97 for C in P];X=1+V[K]
	for A in R(26):
		for B in R(A+1,26):
			X+=U[676*K+26*P[A]+P[B]]
	print(X);Q-=1

Measured memory_bytes: 403644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cstdio>
#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
using namespace std;
int main()
{
	int e; while (cin >> e && e != 0)
	{
		int m = 214214, x = 0;
		rep(z, 111) rep(y, 1111)
		{
			x = e - (y * y + z * z * z);
			if (e == x + (y * y) + (z * z * z) && x >= 0 ) 
			{ m = min(x + y + z, m); }
		}
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    int n,d;cin>>n>>d;
    //d*=d;
    int cnt= 0;
    rep(i,1,n){
        ll x,y;
        cin>>x>>y;
        ll res = x*x+y*y;
        if(sqrt(res)<=d){
            ++cnt;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 3696
function main(input){
    input = input.split(' ');
    inputK = parseInt(input[0]);
    inputX = parseInt(input[1]);
    out = '';

    if(500*inputK>=inputX){
        out = 'Yes';
    }
    else if(500*inputK<inputX){
        out = 'No';
    }

    console.log(out);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> c(n), d(n);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> d[i];
    ans += d[i];
  }
  ans--;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += c[i] * d[i];
  }
  while (sum > 9) {
    ll cnt = sum / 10;
    ans += cnt;
    sum -= cnt * 9;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int A=0, B=0;
  for(int i=0; i<L; i++){
    if(S.at(i)=='0'){
      A++;
    }
    else{
      B++;
    }
  }
  cout << A+B-abs(A-B) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define N 305
using namespace std;
inline int rd() {
    int x=0,f=1;char ch=getchar();
    while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,a[N][N],vis[N],cnt[N];
int main() {
    n = rd(), m = rd();
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) a[i][j] = rd();
    for (int i=1;i<=m;i++) vis[i] = 1;
    int ans = n;
    for (int _=1;_<=m;_++) {
        memset(cnt,0,sizeof(cnt));
        for (int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
                if (vis[ a[i][j] ]) {
                    cnt[ a[i][j] ]++;
                    break;
                }
        int mx = 0, id = 0;
        for (int i=1;i<=m;i++)
            if (cnt[i] >= mx)
                mx = cnt[i], id = i;
        ans = min(ans, mx);
        vis[id] = 0;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,tmp;
    cin >> n;
    vector<int> x,cop;
    x.push_back(0);
    for(int i = 1;i <= n;i++){
        cin >> tmp;
        x.push_back(tmp);
    }
    cop = x;
    sort(cop.begin(),cop.end());
    for(int i = 1;i <= n;i++){
        if(x[i] <= cop[n/2]){
            cout << cop[n/2+1] << endl;
        }else if(x[i] >= cop[n/2+1]){
            cout << cop[n/2] << endl;
        }
    }
    return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define size_of(a) (int)(a).size()
#define allof(a) (a).begin(),(a).end()

void solve() {
	vector< int > p1(9), p2(9);
	
	for_(i,0,9) cin >> p1[i];
	for_(i,0,9) cin >> p2[i];
	
	sort(allof(p1));
	sort(allof(p2));
	
	int all = 0, w1 = 0, w2 = 0;
	
	do {
		int point1 = 0, point2 = 0;
		
		for_(i,0,9) {
			if (p1[i] > p2[i]) {
				point1 += p1[i] + p2[i];
			} else {
				point2 += p1[i] + p2[i];
			}
		}
		
		if (point1 > point2) ++w1;
		if (point2 > point1) ++w2;
		
		++all;
	} while (next_permutation(allof(p2)));
	
	double ans1 = (double)w1 / (double)all, ans2 = (double)w2 / (double)all;
	
	printf("%.5lf %.5lf\n", ans1, ans2);
}

int main() {
	int T; cin >> T;
	
	for_(case_num,0,T) {
		solve();
	}
}

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

typedef pair<int,int> pint;
typedef pair<pint,pint> ppint;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int> > a(H, vector<int>(W, 0));
    int odd = 0;
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) {
        cin >> a[i][j];
        if (a[i][j] & 1) ++odd;
    }
    
    vector<ppint> res;
    int num = 0;
    int x = 0, y = 0;
    for (int iter = 0; iter < W*H; ++iter) {
        if (a[x][y] & 1) ++num;
            
        int nx = x, ny = y;
        if (x % 2 == 0) {
            if (ny == W-1) ++nx;
            else ++ny;
        }
        else {
            if (ny == 0) ++nx;
            else --ny;
        }
        if (num & 1) if (num < odd) res.push_back(ppint(pint(x, y), pint(nx, ny)));
        x = nx, y = ny;
    }
        
    cout << res.size() << endl;
    for (auto p : res) {
        cout << p.first.first+1 << " " << p.first.second+1 << " " << p.second.first+1 << " " << p.second.second+1 << endl;
    }
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    vector<ll> s(N,0),ans(N,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
    
    ll tmp = sum;
    for(int i=1;i<N;i+=2){
        tmp -= (2 * A[i]);
    }
    ans[0] = tmp;
    cout << ans[0] << endl;
    for(int i=0;i<N-1;i++){
        ans[i+1] =  2 * A[i] - ans[i];
        cout << ans[i+1] << endl;
    }
}

Measured memory_bytes: 3712
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def getNodeToInsert(node:Node,keyNode:Node):Node =
    if(node.key > keyNode.key) {
      if(node.left == null) node
      else getNodeToInsert(node.left,keyNode)
    } else {
      if(node.right == null) node
      else getNodeToInsert(node.right,keyNode)
    }

  def insert(tree:Node, keyNode:Node) = {
    val target = getNodeToInsert(tree,keyNode)
    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 307388
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
a~>(f,x) = [a] ++ (null x)?([],f x)
half = flip div 2
aliq = ((0==).).mod

main = do
 [n] <- readLnInt
 print $ 2.0 * (fromIntegral n) * 3.14159265


Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string x,y;
cin>>x>>y;
ll int l1=x.length(),l2=y.length();
ll int dp[3002][3002];
memset(dp,0,sizeof dp);
for(ll int i=1;i<=l1;i++)
{for(ll int j=1;j<=l2;j++)
{if(x[i-1]==y[j-1])
  {dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
     
  }
dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));  
 }


}



//for(int i=0;i<=l1;i++)
//{for(int j=0;j<=l2;j++)
//cout<<dp[i][j]<<" ";
//cout<<endl;

//}
string fin="";
ll int i=l1,j=l2;
ll int ans=dp[l1][l2];
while(i>0&&j>0)
{if(dp[i][j]==ans && x[i-1]==y[j-1])
{//cout<<i<<" "<<j<<endl;
fin=x[i-1]+fin;
i--;
j--;
ans--;
}
else
{
if(dp[i-1][j]<dp[i][j-1])
j--;
else
i--;

}



}


cout<<fin<<endl;



}

Measured memory_bytes: 70656
A = int(input())
B = int(input())
C = int(input())
X = int(input())
L = []
answer = 0
for i in range(A+1) :
    for j in range(B+1) :
        for k in range(C+1) :
            L.append(500*i+100*j+50*k)
for l in range(len(L)) :
    if X-L[l] == 0 :
        answer += 1
print(answer)



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

int main(){
    int i,j,n;
    int a[10000];
    i=0;
    cin>>n;
    while(n!=0){
        a[i]=n;
        i=i+1;
        cin>>n;
    }
    for(j=0;j<i;j++){
        cout<<"Case "<<j+1<<": "<<a[j]<<endl;
    }
    return 0;
}






Measured memory_bytes: 3056
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    ll k;
    scanf("%lld", &k);

    ll m = k / 50;
    ll r = k % 50;

    printf("50\n");
    ll i;
    for(i=0; i<r; i++) {
        printf("%ld ", 49+m+50-(r-1));
    }
    for(i=r; i<50; i++) {
        printf("%ld ", 49+m-r);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main () {
    string s;
    cin >> s;
    int cnt = 1;
    int rcnt=0;
    for(int i=0; i<=2; i++) {
        if(s[i]=='R') rcnt++;
        if(s[i]=='R' && s[i+1]=='R' && i<2) cnt++;
    } 
    if(rcnt==0) cnt=0;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int times = B / A;
		int r = times < C ? times : C;
		System.out.println(r);
	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

using ll = long long int;

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

    ll ans = 0;

    bool kuriage = false;

    for(int i = n.size() - 1; 0 <= i; i--){
        ll c = n[i] - '0';
        if(c < 0 || 9 < c)
            continue;
        if(kuriage){
            c++;
        }

        if(c < 5){
            kuriage = false;
        }else if(c == 5){
            if(i == 0){
                kuriage = false;
            }else{
                ll pc = n[i - 1] - '0';
                if(pc < 5){
                    kuriage = false;
                }else{
                    kuriage = true;
                }
            }
        }else{
            kuriage = true;
        }

        if(kuriage){
            ans += 10 - c;
        }else {
            ans += c;
        }
    }

    if(kuriage)
        ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1412
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 100; const ll MOD = 1e9 + 7;
int N, M, a, b, f[maxn], F[maxn], q[maxn]; ll c, X; bool used[maxn], ok[maxn];
struct Edge
{
	int a, b; ll c;
	bool operator < (const Edge &B) { return c < B.c; }
}e[maxn];
int find(int x) { return (x==f[x]) ? x : (f[x]=find(f[x])); }
int Find(int x) { return (x==F[x]) ? x : (F[x]=Find(F[x])); }

ll pow(ll x, int n)
{
	if(!n) return 1ll;
	ll ret = pow(x, n>>1);
	ret = (ret * ret) % MOD;
	if(n & 1) ret = (ret * x) % MOD;
	return ret;
}

void work(int n)
{
	ll tot = 0ll;
	for(int i = 1; i <= N; ++i) f[i] = i;
	for(int i = 1; i <= M; ++i) used[i] = false;
	f[e[n].a] = e[n].b, tot = e[n].c, used[n] = true;
	for(int i = 1; i <= M; ++i)
	{
		a = find(e[i].a), b = find(e[i].b);
		if(a == b) continue; f[a] = b, tot += e[i].c, used[i] = true;
	}
	if(tot > X) return;
	if(tot < X)
	{
		int lst = 0;
		for(int i = 1; i <= M; ++i) if(used[i]) { lst = i; break; }
		for(int i = lst+1; i <= M; ++i)
		{
			if(!used[i]) continue;
			a = Find(lst), b = Find(i), lst = i;
			if(a != b) F[a] = b, ok[b] |= ok[a];
		}
		return;
	}
	for(int i = 1; i <= M; ++i)
		if(used[i]) ok[Find(i)] = true;
}

void Init()
{
	scanf("%d%d%lld", &N, &M, &X);
	for(int i = 1; i <= M; ++i)
	{
		scanf("%d%d%lld", &a, &b, &c);
		e[i] = (Edge) {a, b, c}, F[i] = i;
	}
	sort(e+1, e+M+1);
}

void Solve()
{
	for(int i = 1; i <= M; ++i) work(i);
	memset(used, 0, sizeof(used));
	int cnt = 0, n = 0;
	for(int i = 1; i <= M; ++i)
	{
		int x = Find(i); if(used[x]) continue;
		cnt++, used[x] = true; if(ok[x]) n++;
	}
	if(!n) { printf("0\n"); return; }
	printf("%lld\n", (pow(2ll, n)-2ll+MOD)%MOD*pow(2ll, cnt-n)%MOD);
}

int main()
{
	Init(), Solve();
}

Measured memory_bytes: 256
def city_savers(n, a, b)
  ans = 0
  (n - 1).downto(0) do |i|
    k = [a[i + 1], b[i]].min
    ans += k
    a[i + 1] -= k
    b[i] -= k

    k = [a[i], b[i]].min
    ans += k
    a[i] -= k
    b[i] -= k
  end
  ans
end

n = gets.chomp.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

puts city_savers(n, a, b)


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

int main(){
  int N;
  long int l, p1, p2;
  cin >> N;
  if(N == 1){
    l = 1;
  }
  else{
    p1 = 2, p2 = 1;
    for(int i = 2; i <= N; i++){
      l = p1 + p2;
      p1 = p2;
      p2 = l;
    }
  }
  cout << l << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  ll n,m;
  cin >> n >> m;
  if(n==1){
    if(m==1)
    cout << 1 << endl;
    else if(m==2)
    cout << 0 << endl;
    else
    cout << m-2 << endl;
    return 0;
  }
  else if(m==1){
    if(n==2)
    cout << 0 << endl;
    else
    cout << n-2 << endl;
    return 0;
  }
  else
  cout << (m-2)*(n-2) << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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 nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int jank(int a){
  char s[4]="spr";
  FOR(3)if(a==s[i])return i;
}

int main(void){
  int n,k;
  scanf(" %d %d",&n,&k);
  ll a[n],ans=0;
  FOR(n)scanf("%lld",&a[i]);
  qsort(a,n,sizeof(ll),usort);
  FOR(n-k)ans+=a[i];
  PRL(ans);
  return 0;
}


Measured memory_bytes: 3324
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();
    int c = sc.nextInt();

    if(1<=b && b<=a && a<=20 && 1<=c && c<=20){
      int x = a-b;
      int y = c-x;

      if(y<0){
        System.out.println(0);
      }else{
        System.out.println(y);
      }
    }

  }

}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

int main(){
 char c;
 cin >> c;
 c++;
 print(c);

}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int a, b;
  cin >> a >> b;
  cout << (a + b) % 24 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007LL
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;

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

	int n; cin >> n;
	int tmp = n;
	cout << n << ':';
	for(int i = 2; i*i <= tmp; i++){
		int cnt = 0;
		while(n % i == 0){
			cnt++; n /= i;
		}
		if(cnt > 0){
			REP(j, cnt) cout << ' ' << i;
		}
	}
	if(n != 1) cout << ' ' << n;
	cout << endl;

	return 0;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, 1, n+1){
        cin >> a[i];
    }
    
    vector<ll> ans(n+1, 0);

    ll m = 0;
    for(ll i=n; i>0; i--){
        ll cnt = 0;
        for(ll j=i; j<n+1; j+=i){
            cnt += ans[j]; 
        }
        if(cnt%2 == a[i]){
            ans[i] = 0;
        }else{
            ans[i] = 1;
            m++;
        } 
    }

    cout << m << endl;
    if(m != 0){
        rep(i, 1, n+1){
            if(ans[i] == 1) cout << i << " ";
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3968
N,M=map(int,input().split())
lr=[]
for _ in range(M):
    lr.append([int(i) for i in input().split()])

Nlist=[0 for i in range(N+2)]

for i in range(M):
    p=lr[i][0]
    q=lr[i][1]+1
    Nlist[p]+=1
    Nlist[q]-=1

for i in range(1,N+1):
    Nlist[i]+=Nlist[i-1]

num=Nlist.count(M)
if Nlist[N+1]==M:
    num-=1
print(num)


Measured memory_bytes: 25212
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    long long k;
    cin >> k;
    int firstnot1=-1;
    for(int i=0;i<s.size();i++){
        if(s.at(i) != '1'){
            firstnot1=i;
            break;
        }
    }
    if(firstnot1 == -1){
        cout << 1 << endl;
        return 0;
    }
    if(k >= firstnot1+1) cout << s.at(firstnot1) << endl;
    else cout << 1 << endl;
}

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

int main(){
     int x;
     cin>>x;
     if(x>=400&&x<=599) printf("8\n");
     if(x>=600&&x<=799) printf("7\n");
     if(x>=800&&x<=999) printf("6\n");
     if(x>=1000&&x<=1199) printf("5\n");
     if(x>=1200&&x<=1399) printf("4\n");
     if(x>=1400&&x<=1599) printf("3\n");
     if(x>=1600&&x<=1799) printf("2\n");
     if(x>=1800&&x<=1999) printf("1\n");
     return 0;
}


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

int main(){
	int n,a;
	cin >> n >> a;
	cout << n * n - a << endl;
}

Measured memory_bytes: 256
s = input()
ans = 0
l = len(s)
for i in range(2 ** (l-1)):
    p = s[0]
    for j in range(l-1):
        if ((i>>j)&1) == 1:
            p += "+"
        p += s[j+1]
    ans += sum(map(int, p.split("+")))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
cin>>x>>y>>z;
if((y*10+z)%4==0)cout<<"YES";
else cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)

/////////////////////////////////////////////////////////

void Main(){
  int N; cin >> N;
  vector<vector<int>> V(3);
  V.reserve(N);
  rep(i, 0, N){
    int A; cin >> A;
    auto tmp = find(all(V[A % 3]), A);
    if(tmp == V[A % 3].end()) V[A % 3].push_back(A);
    else V[A % 3].erase(tmp);
  }
  cout << V[0].size() + V[1].size() + V[2].size() << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {
	static boolean isPrime(int X){
		if(X == 1)return false;
		if(X == 2)return true;
		for(int i = 2 ; i * i <= X ; ++i){
			if(X % i == 0){
				return false;
			}
		}
		return true;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		for(int i = X ; ; ++i){
			if(isPrime(i)){
				System.out.println(i);
				break;
			}
		}
	}
}


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

int main()
{
    string s;
    cin >> s;
    int N = s.size();
    int start, end;
    for (int i = 0; i < N; ++i)
    {
        if (s[i] == 'A')
        {
            start = i;
            break;
        }
    }
    for (int i = 0; i < N; ++i)
    {
        if (s[N - 1 - i] == 'Z')
        {
            end = N - 1 - i;
            break;
        }
    }
    cout << end - start + 1 << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  for(int i=0;i<(tx-sx);i++){
    cout << "R";
  }
  for(int i=0;i<(ty-sy);i++){
    cout << "U";
  }
  for(int i=0;i<(tx-sx);i++){
    cout << "L";
  }
  for(int i=0;i<(ty-sy);i++){
    cout << "D";
  }
  
  cout << "D";
  for(int i=0;i<(tx-sx)+1;i++){
    cout << "R";
  }
  for(int i=0;i<(ty-sy)+1;i++){
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for(int i=0;i<(tx-sx)+1;i++){
    cout << "L";
  }
  for(int i=0;i<(ty-sy)+1;i++){
    cout << "D";
  }
  cout << "R" << endl;

  return 0;
}


Measured memory_bytes: 256
// failed to generate code

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

int main(){	
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int ans = 0;
	for(int i = 0 ; i < t.size() ; i++)
		if( s[i] != t[i] ) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    long a=gl();
	    long b=gl();
	    long c=gl();


        //System.out.println(n*n-a);
        if (a==b) {
        	System.out.print(c);
        }else if(a==c){
            System.out.print(b);
        } else {
        	System.out.print(a);
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35432
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin>>S;
    int N=S.size();
    int B[N];
    long long count=0;
    B[0]=0;
if(N>=1&&N<=2*100000){
    if(S[0]=='B'){
        B[0]+=1;
    }
    else{
        B[0]=0;
    }
    for(int i=1;i<N;i++){
        B[i]=B[i-1];
        if(S[i]=='B')
            B[i]+=1;
    }
    for(int i=0;i<N;i++){
        if(S[i]=='W'){
        count+=(i-1>=0?B[i-1]:0);
    }
    }
    cout<<count;
}
    return 0;
}

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

int main() {
	long long N, K;
	scanf("%lld %lld", &N, &K);

	if (K % 2 == 1) {
		cout << (N / K) * (N / K) * (N / K);
	} else {
		cout << (N / K) * (N / K) * (N / K) + (N / (K / 2) - N / K) *
		                                          (N / (K / 2) - N / K) *
		                                          (N / (K / 2) - N / K);
	}
	return 0;
}

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

using namespace std;
#define rep(j,n) for(int j=0;j<(n);j++)

using ll = long long;
using P = pair<int, int>;

int main(int, char**)
{
  int n;
  cin >> n;

  cout << (1000-n%1000)%1000 << endl;

  return 0;
}

Measured memory_bytes: 3620
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[100005]={};
  map<int,int> m;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(a[i]%2) {
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
}

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

using ll = long long;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	ll g = sqrt(n);
	while(g * g > n) g -= 1;
	while(g * g < n) g += 1;
	cout << 0 << " " << 0 << endl;
	if(n <= g * (g-1)){
		cout << g << " " << g*(g-1) - n << endl;
		cout << 1 << " " << g-1 << endl;
	} else {
		cout << g << " " << g*g - n << endl;
		cout << 1 << " " << g << endl;		
	}
}

Measured memory_bytes: 256
# coding: utf-8
s = input()
k = int(input())
sb_str = []
for i in range(len(s)+1):
    for j in range(1+i,len(s)+1):
        if len(s[i:j]) > 5:
            break
        if i < j:
            sb_str.append(s[i:j])

sb_str = list(set(sb_str))
sb_str.sort()
print(sb_str[k-1])

Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a , long long b){
  if (a < b) {
    swap(a, b);
  }
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  int N;
  cin >> N;
  vector <long long> T(N);
  for(int i = 0; i < N; i++){
    cin >> T.at(i);
  }
  long long ans = T.at(0);
  for (int i = 1; i < N; i++) {
    ans = ans / gcd(ans, T.at(i)) * T.at(i);
  }
  cout << ans << endl;
}


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

int main(){
    int n,x,ans=100000,t;
    cin>>n;
    while(n--){
        t=0;
        cin>>x;
        while(x%2==0){
            t++;
            x/=2;
        }
        ans=min(ans,t);
    }
    cout<<ans<<'\n';
}


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

    string as[n];
    vector<p> rl(n);

    rep(i,n){
        cin >> as[i];
    }

    rep(i,n){
        rep(j, as[i].size()){
            if (as[i][j] == ')'){
                if (rl[i].first > 0) rl[i].first -= 1;
                else rl[i].second += 1;
            } else if (as[i][j] == '('){
                rl[i].first += 1;
            }
        }
    }

    sort(rl.rbegin(), rl.rend());

    rep(i,n-1){
        int comp1, comp2, tmp1, tmp2;
        comp1 = abs(rl[i+1].second - rl[i].first) + rl[i+1].first + rl[i].second;
        comp2 = abs(rl[i+1].first - rl[i].second) + rl[i].first + rl[i+1].second;
        if (comp1<=comp2) {
            if (rl[i+1].second >= rl[i].first){
                tmp1 = rl[i+1].first;
                tmp2 = rl[i+1].second - rl[i].first + rl[i].second;
            } else{
                tmp1 = rl[i].first - rl[i+1].second + rl[i+1].first;
                tmp2 = rl[i].second;
            }
        } else{
            if (rl[i+1].first >= rl[i].second){
                tmp1 = rl[i+1].first - rl[i].second + rl[i].first;
                tmp2 = rl[i+1].second;
            } else{
                    tmp1 = rl[i].first;
                    tmp2 = rl[i].second - rl[i+1].first + rl[i+1].second;
            }
        }
        rl[i+1].first = tmp1;
        rl[i+1].second = tmp2;
    }

    if (rl[n-1].first + rl[n-1].second == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 42260
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		if(N.substring(0, 1).equals(N.substring(2, 3))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a[3];
	rep(i, 3) cin >> a[i];
	qsort(a, 3, sizeof(int), comp);
	cout << a[0] + a[1] << endl;
}

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

using namespace std;

int main()
{
    int a, b , c;
    cin >>a>>b;
    c=a+b;
    if((c>=0)&&(c<=23)){
        cout<<c;
    }
    else if (c>24){
        cout<<c-24;

    }else if(c=24){
    cout<<0;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

#define reps(i, f, n) for (int i = (f); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

void init()
{
}

void solve()
{
	int n;
	cin >> n;

	int ac = 0, tle = 0, wa = 0, re = 0;
	rep(i, n)
	{
		string s;
		cin >> s;

		if (s == "AC")
		{
			ac++;
			continue;
		}

		if (s == "WA")
		{
			wa++;
			continue;
		}

		if (s == "TLE")
		{
			tle++;
			continue;
		}

		if (s == "RE")
		{
			re++;
			continue;
		}
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3224
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i16 = read();
    let l: i16 = read();
    let eaten;
    if l - 1 < - n  {
        eaten = l + n - 1;
    } else if l > 0 {
        eaten = l + 1 - 1;
    } else {
        eaten = 0;
    }
    let mut sum = 0;
    for i in 1..n + 1 {
        sum += l + i - 1;
    }
    println!("{}", sum - eaten);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int main(){

	int N,K;
	scanf("%d %d",&N,&K);
	bool check[N+1][N+1],badTable[N+1];

	for(int i = 1; i <= N; i++){
		badTable[i] = false;
		for(int k = 1; k <= N; k++)check[i][k] = false;
	}

	int work[50],work_num;

	for(int loop = 0; loop < K; loop++){
		scanf("%d",&work_num);
		for(int i = 0; i < work_num;i++)scanf("%d",&work[i]);
		for(int i = 0; i < work_num;i++){
			for(int k = 0; k < work_num; k++){
				if(i != k){
					check[work[i]][work[k]] = true;
					check[work[k]][work[i]] = true;
				}
			}
		}
	}

	int R,left,right;

	scanf("%d",&R);

	for(int i = 0; i < R; i++){
		scanf("%d %d",&left,&right);
		if(check[left][right] == true){
			badTable[left] = true;
			badTable[right] = true;
		}
	}

	int count = 0;

	for(int i = 1; i <= N; i++){
		if(badTable[i])count++;
	}

	printf("%d\n",count);

	return 0;
}

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

def g(n, x):
    cnt = 0
    while True:
        n = n // x
        if x == 2:
            cnt += n
        else:
            cnt += n // 2
        if n == 0:
            break
    return cnt

if n % 2 != 0:
    print(0)
else:
    print(min(g(n, 2), g(n, 5)))

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

int n, m;
string b[500];
unsigned int nB[500][16];

int allSearch() {
	int i, j, k;
	int ans = 0;
	
	for (i = 0; i < (1 << n); i++) {
		bool used[25];
		int usedCnt = 0;
		for (j = 0; j < n; j++) {
			used[j] = ((i >> j) % 2);
			usedCnt += used[j];
		}
		
		unsigned int state[16] = {0};
		for (j = 0; j < n; j++) {
			if (!used[j]) continue;
			for (k = 0; k < 16; k++) {
				state[k] ^= nB[j][k];
			}
		}
		
		for (j = 0; j < 16; j++) { if (state[j] != 0) break; }
		if (j == 16) { ans = max(ans, usedCnt); }
	}
	return ans;
}

int bitDP() {
	static int dp[2][1 << 23];
	unsigned int i, j;
	int INF = 114514;
	
	for (i = 0; i < 2; i++) for (j = 0; j < (1 << m); j++) dp[i][j] = -INF;
	dp[0][0] = 0;
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < (1 << m); j++) {
			dp[1][j] = max(dp[1][j], dp[0][j]);
			dp[1][j ^ nB[i][0]] = max(dp[1][j ^ nB[i][0]], dp[0][j] + 1);
		}
		for (j = 0; j < (1 << m); j++) {
			dp[0][j] = dp[1][j];
			dp[1][j] = -INF;
		}
	}
	return dp[0][0];
}

void setNum(int id) {
	for (int i = 0; i < 16; i++) {
		nB[id][i] = 0;
	}
	
	for (int i = 0; ; i++) {
		for (int j = 0; j < 32; j++) {
			if (32 * i + j >= m) { return; }
			nB[id][i] += (b[id][32 * i + j] - '0') * ((unsigned int)1 << j);
		}
	}
}

int main() {
	while (cin >> n >> m) {
		if (!n) break;
		for (int i = 0; i < n; i++) cin >> b[i];
		for (int i = 0; i < n; i++) setNum(i);
		if (n <= m) { cout << allSearch() << endl; }
		else { cout << bitDP() << endl; }
	}
	return 0;
}

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

using namespace std;
using ll = long long;

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

    // 直前のやつ
    ll bt = 0;
    ll bx = 0;
    ll by = 0;

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

        ll p_delta = abs(bx-x) + abs(by-y);
        ll t_delta = t - bt;

        if (t_delta < p_delta ||
            (p_delta - t_delta) % 2 != 0) {
            cout << "No" << endl;
            exit(EXIT_SUCCESS);
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  
  vector<int>vec1(N);
  vector<int>vec2(M);
  
  for(int i=0;i<N;i++){
    cin>>vec1.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>vec2.at(i);
  }
  
  int S=0;
  

  for(int i=X+1;i<=Y;i++){
      
  int sumx=0;
  
  int sumy=0;
  
    
    for(int k=0;k<N;k++){
      if(i<=vec1.at(k)){
        sumx++;
      }
    }
    
    for(int l=0;l<M;l++){
      if(i>vec2.at(l)){
        sumy++;
      }
    }
    
    if(sumx==0&&sumy==0){
      cout<<"No War"<<endl;
      S++;
      break;
    }
    
    if(S==0&&i==Y){
      cout<<"War"<<endl;
    }
    
      
  }
}
   
    

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int H,W,i,j,c=0;
	
	scanf("%d%d",&H,&W);
	int ans[H*W][4];
	int a[H][W];
	for(i=0;i<H;i++){
		for(j=0;j<W;j++)scanf("%d",&a[i][j]);
	}
	
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(a[i][j]%2==0)continue;
			
			if(i>0 && a[i-1][j]%2==1){
				ans[c][0]=i;
				ans[c][1]=j;
				ans[c][2]=i-1;
				ans[c][3]=j;
				c++;
				a[i][j]--;
				a[i-1][j]++;
				continue;
			}
			
			if(j<W-1){
				ans[c][0]=i;
				ans[c][1]=j;
				ans[c][2]=i;
				ans[c][3]=j+1;
				a[i][j]--;
				a[i][j+1]++;
				c++;
				continue;
			}
			
			if(i<H-1){
				ans[c][0]=i;
				ans[c][1]=j;
				ans[c][2]=i+1;
				ans[c][3]=j;
				a[i][j]--;
				a[i+1][j]++;
				c++;
				continue;
			}
		}
	}
	
	printf("%d\n",c);
	for(i=0;i<c;i++)printf("%d %d %d %d\n",ans[i][0]+1,ans[i][1]+1,ans[i][2]+1,ans[i][3]+1);
	return 0;
}

Measured memory_bytes: 6784
/*input
3
4980
7980
6980
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll a[maxn];
ll ans=0;
int main(){
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	sort(a,a+n);
	REP(i,n) ans+=a[i];
	ans-=a[n-1]/2;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
clist=[-1]*n
ng=0

for i in range(m):
    s, c = map(int,input().split())
    if clist[s-1]==-1:
        clist[s-1]=c
    elif clist[s-1]!=c:
        ng=1

if ng==1:
    print(-1)
else:
    if clist[0]==0:
        if n==1:
            print(0)
        else:
            print(-1)
    else:
        for i in range(n):
            if clist[i]==-1:
                if i==0:
                    if n==1:
                        print(0)
                    else:
                        print(1, end="")
                else:
                    print(0, end="")
            else:
                print(clist[i], end="")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   int a, b;
   cin >> a >> b;

   if(a > b)swap(a, b);

   int mid = (a + b) / 2;

   if (abs(a - mid)== abs(b-mid)){
      cout<<mid;
      exit(0);
   }

   cout<<"IMPOSSIBLE";
   

   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[100000],order[100000];
char C[100000];

int Partition(int A[],char C[],int order[],int p,int r){
  int temp1,temp2,tempM,tempm,tempC,tempc;
  int i,j,x,stability,n;
  
  x = A[r];
  i = p-1;
  for(j = p ; j < r ; j++){
    if(A[j] <= x){
      i = i+1; 
      
      temp1 = A[i];
      tempM = C[i];
      tempC = order[i];
      
      A[i] = A[j];
      C[i] = C[j];
      order[i] = order[j];
      
      A[j] = temp1;
      C[j] = tempM;
      order[j] = tempC;
    }
  }
  temp2 = A[i+1];
  tempm = C[i+1];
  tempc = order[i+1];
  
  A[i+1] = A[r];
  C[i+1] = C[r];
  order[i+1] = order[r];
  
  A[r] = temp2;
  C[r] = tempm;
  order[r] = tempc;
  
  return i+1;
}

void Quicksort(int A[],char C[],int order[],int p,int r){
  int q;
  
  if(p < r){
    q = Partition(A,C,order,p,r);
    Quicksort(A,C,order,p,q-1);
    Quicksort(A,C,order,q+1,r);
  }
}

int main(void){
  int n,i,stability=0;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf(" %c%d",&C[i],&A[i]);
  }  
  for(i = 0 ; i < n ; i++){
    order[i] = i;
  }
  
  Quicksort(A,C,order,0,n-1);

  for(i = 0 ; i < n-1 ; i++){
    if(A[i] == A[i+1]){
      if(order[i] > order[i+1]){
	stability = 1;
	break;
      }
    }  
  }
  if(stability == 1){
    printf("Not stable\n");
  }
  else printf("Stable\n");
  
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n",C[i],A[i]);
  }
  
  return 0;
}

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

namespace ABC160C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] kn = Console.ReadLine().Split(' ');
            int K = int.Parse(kn[0]);
            int N = int.Parse(kn[1]);
            string[] Ainput = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Ainput[i]);
            }
            int[] B = new int[N];
            for (int i = 0; i < N - 1; i++)
            {
                B[i] = A[i + 1] - A[i];
            }
            B[N - 1] = K - A[N - 1] + A[0];
            Array.Sort(B);
            Console.WriteLine(K - B[N - 1]);
        }
    }
}


Measured memory_bytes: 43304