akhauriyash/Code-Regression huggingface dataset:
function main(input) {
  const is = input.split("\n");
  const n = parseInt(is[0].split(" ")[0]);
  const k = parseInt(is[0].split(" ")[1]);
  const s = is[1];

  const chars = s.split('');
  chars[k - 1] = chars[k - 1].toLowerCase();
  console.log(chars.join(''));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
import java.util.Scanner;
public class Main{
	
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int min = 0;
        if(a + b > n) {
        	min = a + b - n;
        }
        System.out.println(Math.min(a, b) + " " + min);
    }
}


Measured memory_bytes: 20692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int[][] C = new int[3][3];
            for (int r = 0; r < 3; r++) {
                for (int c = 0; c < 3; c++) {
                    C[r][c] = in.nextInt();
                }
            }

            int[] a = new int[3];
            int[] b = new int[3];
            int[][] a2 = new int[3][3];
            a[0] = 0;

            for (int c = 0; c < 3; c++) {
                b[c] = C[0][c] - a[0];
            }

            for (int r = 0; r < 3; r++) {
                for (int c = 0; c < 3; c++) {
                    a2[r][c] = C[r][c] - b[c];
                }
            }

            for (int r = 0; r < 3; r++) {
                for (int c = 1; c < 3; c++) {
                    if (a2[r][c - 1] != a2[r][c]) {
                        System.out.println("No");
                        return;
                    }
                }
            }
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 27060
#include <stdio.h>

int main(void)
{
    int a,b;
    int tmp;
    do
    {
        scanf("%d %d",&a,&b);
        tmp = b%2;
        int c = 1;
        if (a==0 && b==0)
        {
            break;
        }
        int i,j;
        for (i=a;i>0;i--)
        {
            for (j=b;j>0;j--)
            {
                if (c == 1)
                {
                    printf("#");
                    c = 0;
                }
                else
                {
                    printf(".");
                    c = 1;
                }
            }
            if (tmp == 0)
            {
                if (c){c=0;}
                else{c = 1;}
            }
            printf("\n");
        }
        printf("\n");

    }while (1);
    return 0;
}


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;

int main(){
	int N;
	cin>>N;
	
	int ans=0;
	REP(i,N){
		int x=i+1;
		int c=0;
		if(x%2==0)continue;
		REP(j,N){
			int y=j+1;
			if(x<y)continue;
			if(x%y==0)c++;
		}
		//cout<<c<<endl;
		if(c==8)ans++;
	}
	cout<<ans<<endl;
	
	return(0);
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(S: String){
    S.map{ if(it == '+') 1 else -1 }.sum().let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()
{
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n )
{
    for(int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


int gcd(int a,int b)
{
    return b ? gcd(b,a%b) : a;
}
int lcm(int a,int b)
{
    return (a*( b/ gcd(a,b)));
}

void f()
{
    int n,k,a;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>a;
    }
    cout<<ceil((n-1)*1.0/(k-1))<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >>  b2;
  ll dist1 = (t1*(a1-b1));
  ll dist2 = (t1*a1+t2*a2 - t1*b1 - t2*b2);
  if (dist2 == 0) {
    cout << "infinity" << endl; return 0;
  }
  if ((dist1 > 0 && dist2 > 0) || (dist1 <0 && dist2 < 0)) {
    cout << 0 << endl; return 0;
  }

  ll ans = (abs(dist1)-1)/abs(dist2) + 1;
  // cout << dist1 << " " << dist2 << endl;
  // cout << dist1 % dist2 << endl;
  ans *= 2;
  ans--;
  if (abs(dist1) % abs(dist2) == 0) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3672
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]


def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    # if sum(a)==0:
    #     print(*a)
    #     quit()
    while k:
        lst=[1]*n
        dic={}
        cnt=0
        for i in range(n):
            lst[i]+=cnt
            if i in dic:
                cnt-=dic[i]
            if a[i]>0:
                if not i+a[i] in dic:
                    dic[i+a[i]]=1
                else:
                    dic[i+a[i]]+=1
                cnt+=1

        dic={}
        cnt=0
        for i in range(n)[::-1]:
            lst[i]+=cnt
            if i in dic:
                cnt-=dic[i]
            if a[i]>0:
                if not i-a[i] in dic:
                    dic[i-a[i]]=1
                else:
                    dic[i-a[i]]+=1
                cnt+=1
        k-=1
        if sum(lst)==n*n:
            break
        # print(k)
        a=lst[:]

    print(*lst)

main()

Measured memory_bytes: 192276
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N, K;
vector<long long> a;

double solve() {
    vector<long long> s(N+1, 0);
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

    long long res = 0;
    for (int i = 0; i + K <= N; ++i) chmax(res, s[i+K] - s[i]);
    
    return (double)(res)/2;
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    while (cin >> N >> K) {
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i], ++a[i];
        cout << fixed << setprecision(10) << solve() << endl;
    }
}


















Measured memory_bytes: 3456
n = int(input())
a = 0
input_list = []
while a < n:
    ant = input()
    input_list.append(ant)
    a += 1
l={}
for i in range(len(input_list)):
    l[i] = list(input_list[i])
    l[i].sort()
l_dic = {}
ans = 0
for i in range(len(l)):
    try:
        ans += l_dic[str(l[i])]
        l_dic[str(l[i])] += 1
    except:
        l_dic[str(l[i])] = 1
print(ans)

Measured memory_bytes: 123104
#include"bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	string S;
	string ss,sf,sb;
	bool str = true;
	cin >> S;
	for (int i = S.size()-1; i > 1; i = i - 1) {
		if (i % 2 == 1)continue;
		ss = S.substr(0, i);
		//str = true;
		//	for (int i = 0; i < S.size() / 2; i++) {
		//		if (S[i] != S[i + S.size() / 2]) str = false;
		//	}
		sf = ss.substr(0, ss.size() / 2);
		sb = ss.substr(ss.size() / 2, ss.size() / 2);

			if (sf ==sb) {
				cout << i << endl;
				break;
			}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<vector<vector<int>>>>;


int main(){
int a,b;
  cin>>a>>b;
  if(a<b) rep(i,b) cout<<a;
  else if(b<a) rep(i,a) cout<<b;
  else rep(i,a) cout<<b; 
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}


int main() {
  string S;
  cin >> S;
  int n=0;
  rep2(i,1,S.size()) {
    if (S[i-1]!=S[i]) n++;
  }
  cout << n << endl;
}

Measured memory_bytes: 512
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    private int[] a;

    AtCoder(FastScanner sc) {
        a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }
    }

    void solve(PrintWriter out) {
        if (a[0] + a[1] + a[2] <= 21) {
            out.println("win");
        } else {
            out.println("bust");
        }
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


Measured memory_bytes: 22868
#include <stdio.h>

int main(void)
{
	int x, h, m, s;
	
	scanf("%d", &x);
	
	s = x % 60;
	m = (x / 60) % 60;
	h = x / 3600;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

char field[108][108];

int main() {
	while(true){
start:
		int h, w; cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				cin >> field[i][j];
			}
		}

		int x = 0, y = 0, c = 0;
		while (true){
			switch (field[y][x]){
			case '>':
				++x;
				break;
			case '<':
				--x;
				break;
			case '^':
				--y;
				break;
			case 'v':
				++y;
				break;
			default:
				printf("%d %d\n", x, y);
				goto start;
				break;
			}
			++c;
			if (c > w*h) {
				cout << "LOOP" << endl;
				goto start;
			}
		}
	}

	return 0;
}

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

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

  if((a - b) % 2 == 0) {
    cout << (a > b ? a : b) - abs(a - b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 256
N,W = map(int,input().split())
wv = [map(int,input().split()) for _ in range(N)]
w,v = [list(i) for i in zip(*wv)]
max_v,max_w = 0,0
for i,j in zip(w,v):
    max_w += i
    max_v += j
dp = [[float("inf")]*(max_v+1) for _ in range(N+1)]
dp[0][0] = 0#初期値
for i in range(1,N+1):
    for j in range(max_v+1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1])
        else:
            dp[i][j] = dp[i-1][j]
for i in range(1,max_v+2):
    if W >= dp[N][-i]:
        print(max_v+1-i)
        break

Measured memory_bytes: 308040
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

struct UnionFind {
  vector<int> par, rank, diff_weight;

  UnionFind(int n = 1, int SUM_UNITY = 0) {init(n, SUM_UNITY);}

  void init(int n = 1, int SUM_UNITY = 0) {
    par.resize(n); rank.resize(n); diff_weight.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }
  }

  int root(int x) {
    if (par[x] == x) return x;
    else {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  int weight(int x) {root(x); return diff_weight[x];}

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

  void unite(int x, int y, int w) {
    w += weight(x); w -= weight(y);
    x = root(x); y = root(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y), w = -w;
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return;
  }

  int diff(int x, int y) {return weight(y) - weight(x);}
};

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

  int n, m; cin >> n >> m;
  
  UnionFind u(n);

  for (int i = 0; i < m; ++i){
    int l, r, d; cin >> l >> r >> d;
    --l; --r;
    if (u.issame(l, r)){
      if (u.diff(l, r) != d){
        print("No"); return 0;
      }
    }
    else {
      u.unite(l, r, d);
    }
  }
  print("Yes");

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  string s; cin >>s;
  string t = "";
  rep(i, s.size()) if (s[i] != 'x') t.push_back(s[i]);
  string u = t; reverse(all(u));
  if (t != u){ cout <<-1 <<endl; return 0;}
  int ai = 0, bi = s.size()-1;
  int res = 0;
  while (ai < bi){
    if (s[ai] == s[bi]) ai++, bi--;
    else if (s[ai] == 'x'){
      ai++; res++;
    }else if (s[bi] == 'x'){
      bi--; res++;
    }else{
      res = -1; break;
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from collections import deque, defaultdict, Counter

S = input().rstrip()
L = len(S)

c = Counter(S)
if sum((x&1 for x in c.values())) >= 2:
    print(-1)
    exit()

alphabet_to_pos = defaultdict(deque)

for i,x in enumerate(S,1):
    alphabet_to_pos[x].append(i)

after = [None] * len(S)
n = 0
for i,x in enumerate(S,1):
    p = alphabet_to_pos[x]
    if not p:
        continue
    if len(p) == 1:
        p.pop()
        after[L//2] = i
        continue
    p.popleft()
    j = p.pop()
    after[n] = i
    after[L - n - 1] = j
    n += 1

def BIT_update(tree,x):
    while x <= L:
        tree[x] += 1
        x += x & (-x)

def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x & (-x)
    return s

answer = 0
tree = [0] * (L+1)
for i,x in enumerate(after):
    answer += i - BIT_sum(tree,x)
    BIT_update(tree,x)

print(answer)

Measured memory_bytes: 55372
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    string S;
    ll K;
    cin >> S >> K;
    for(ll i = 0; i < S.size(); i++){
        char c = S[i];
        if(c != '1' || i + 1 >= K){
            cout << c << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, M, A, ans;
    cin >> N >> M;
    int Sum = 0;
    REP(int,i,0,M){
        cin >> A;
        Sum += A;
    }
    ans = N - Sum;
    if ( ans < 0 ) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<vector<int>> rgb = {
  {0, 0, 0},
  {0, 0, 255},
  {0, 255, 0},
  {0, 255, 255},
  {255, 0, 0},
  {255, 0, 255},
  {255, 255, 0},
  {255, 255, 255}
};
vector<string> name = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  auto f = [&](string s) { return (isdigit(s[0]) ? s[0] - '0' : s[0] - 'a' + 10) * 16 + (isdigit(s[1]) ? s[1] - '0' : s[1] - 'a' + 10); };
  string s;
  while (cin >> s, s != "0") {
    int r = f(s.substr(1, 2)), g = f(s.substr(3, 2)), b = f(s.substr(5, 2));
    double d_min = 1e9;
    string ans = "";
    for (int i = 0; i < 8; i++) {
      double d = sqrt(pow(r - rgb[i][0], 2.0) + pow(g - rgb[i][1], 2.0) + pow(b - rgb[i][2], 2.0));
      if (d < d_min) {
        d_min = d;
        ans = name[i];
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    string s;
    cin >> s;
    ll n = s.size();
    if(n == 1) ANS("YES");
    if(n == 2 && s[0] != s[1]) ANS("YES");
    map<char, ll> mp;
    for(auto x: s) mp[x]++;
    if(mp.size() < 3) ANS("NO");
    ll mx = 0;
    itr(it, mp)
    {
        mx = max(mx, it->sd);
    }
    if(mx > (n+2)/3) cout << "NO";
    else cout << "YES";

}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 512
package main

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

func main() {
	sc := newScanner()
	N := sc.nextInt()
	K := sc.nextUint64()
	masks := make([]uint64, 0)
	masks = append(masks, K)

	var i uint
	for i = 30; i >= 0; i-- {
		if (1<<i)&K != 0 {
			mask := K &^ (1 << i)
			mask = mask | (1<<i - 1)
			masks = append(masks, mask)
		}
		if i == 0 {
			break
		}
	}
	// for _, m := range masks {
	// 	fmt.Printf("%b \n", m)
	// }
	a := make([]uint64, N)
	b := make([]uint64, N)
	for i := 0; i < N; i++ {
		a[i] = sc.nextUint64()
		b[i] = sc.nextUint64()
	}
	anss := make([]uint64, len(masks))
	for i := 0; i < N; i++ {
		// fmt.Scan(&a, &b)
		// a := sc.nextUint64()
		// b := sc.nextUint64()
		for idx, m := range masks {
			if m|a[i] == m {
				anss[idx] += b[i]
			}
		}
	}
	var ans uint64
	for _, a := range anss {
		if a > ans {
			ans = a
		}
	}
	fmt.Println(ans)
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) nextUint64() uint64 {
	v, _ := strconv.ParseUint(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
int Q;
long long a,b,c,d;
bool between(long long x1,long long y1,long long y2){
	if(y1>y2)
		swap(y1,y2);
	y1++;
	y2--;
	if(y1>y2)
		return false;
	while(x1>0){
		if(x1%3LL==1LL){
			if(y2-y1>3LL)
				return true;
			for(long long j=y1;j<=y2;j++)
				if(j%3LL==1LL)
					return true;
		}
		x1/=3LL;
		y1/=3LL;
		y2/=3LL;
	}
	return false;
}
long long get_detour(long long x1,long long y1,long long x2,long long y2){
	long long ans=0LL,tmp,p3=1LL;
	for(int i=0;i<35;i++){
		if(((x1/p3)==(x2/p3))&&between(x1/p3,y1/p3,y2/p3)){
			tmp=min(min(x1%p3,x2%p3)+1LL,p3-max(x1%p3,x2%p3));
			ans=max(ans,tmp);
		}
		p3*=3LL;
	}
	return ans;
}
long long get_path(long long x1,long long y1,long long x2,long long y2){
	return llabs(x1-x2)+llabs(y1-y2)+2LL*max(get_detour(x1,y1,x2,y2),get_detour(y1,x1,y2,x2));
}
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>Q;
	while(Q--){
		cin>>a>>b>>c>>d;
		a--,b--,c--,d--;
		cout<<get_path(a,b,c,d)<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0, sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI = acos(-1.0L);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int h, w;
  cin >> h >> w;
  int a[h][w], b[h][w];
  const int max_k = (h + w) * 80 + 5;
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) cin >> b[i][j];
  vector<vector<vector<bool>>> dp(h,
                                  vector<vector<bool>>(w, vector<bool>(max_k)));


  // bool dp[h][w][max_k];
  // memset(dp, false, sizeof(dp));
  const int dh[2] = {1, 0}, dw[2] = {0, 1};
  dp[0][0][abs(a[0][0] - b[0][0])] = true;
  rep(now_h, h) rep(now_w, w) {
    rep(i, 2) {
      int next_h = now_h + dh[i], next_w = now_w + dw[i];
      if (next_h >= h || next_w >= w)
        continue;
      int d = abs(a[next_h][next_w] - b[next_h][next_w]);
      rep(k, max_k) {
        if (!dp[now_h][now_w][k])
          continue;
        if (k + d < max_k)
          dp[next_h][next_w][k + d] = true;
        if (abs(k - d) < max_k)
          dp[next_h][next_w][abs(k - d)] = true;
      }
    }
  }
  int ans = max_k;
  rep(k, max_k) {
    if (dp[h - 1][w - 1][k])
      return cout << k << endl, 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10752
def solve(N, Q, S, LRs):
    Ts = [0 for _ in range(N)]
    tans = 0
    for i, (s1, s2) in enumerate(zip(S, S[1:])):
        if s1 == "A" and s2 == "C":
            tans += 1
        Ts[i + 1] = tans

    ans = []
    for l, r in LRs:
        ans.append(Ts[r - 1] - Ts[l - 1])
    return "\n".join(str(a) for a in ans)


if __name__ == "__main__":
    N, Q = tuple(map(int, input().split(" ")))
    S = input()
    LRs = [tuple(map(int, input().split(" "))) for __ in range(Q)]
    print(solve(N, Q, S, LRs))


Measured memory_bytes: 29820
#include <bits/stdc++.h>
 
using namespace std;
 
#define LL long long 
#define ULL unsigned long long 
#define LD long double 
 
const int INF = 1e9 + 4;
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int h[n];
	for(int i=0; i<n; i++) {
		cin>>h[i];
	}
	int mina = INF;
	for(int i=n-1; i>=0; i--) {
		if(h[i]-1>mina) {
			cout<<"No";
			return 0;
		}
		mina = min(mina, h[i]);
	}
	cout<<"Yes";
}


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

int main() {
    int N, M, i, j, lock;
    char U[300][11];
    char s[11];

    scanf("%d", &N);

    for (i = 0; i < N; i++) {
        scanf("%s", U[i]);
    }

    scanf("%d", &M);

    lock = 1;

    for (i = 0; i < M; i++) {
        scanf("%s", s);
        for (j = 0; j < N; j++) {
            if (strcmp(s, U[j]) == 0 && lock) {
                printf("Opened by %s\n", s);
                lock = 0;
                break;
            }
            else if (strcmp(s, U[j]) == 0 && !lock) {
                printf("Closed by %s\n", s);
                lock = 1;
                break;
            }
            if (j == N-1) {
                printf("Unknown %s\n", s);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2100
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B;
  cin >> A >> B;
  ll ans = max(A - B * 2, 0LL);
  cout << ans << endl;
  return 0;
}

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

int main () {
  ll a, b, x, ans = 0;
  cin >> a >> b >> x;
  
  ans = b/x-a/x;
  if (a%x == 0) {
    ans ++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cmath>

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


using namespace std;

int main(void){
    int a,b;
    
    while (cin>>a>>b){
        cout << a+b << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int M,N,L,cnt,ans;
int main(){
  while(cin>>L&&L){
    ans=cnt=0;
    for(int i=0;i<12;i++){
      cin>>M>>N;
      cnt+=(M-N);
      if(cnt>=L&&ans==0)ans=i+1;
    }
    if(ans==0)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define     ff first
#define     ss second
#define     ll long long
#define     ld long double
#define     pb push_back
#define     endl "\n"
#define     MOD 1000000007
#define     INF 1e18
#define     mod 998244353
#define     MAXN 10000001
#define     REP(i,n) for(ll i=0;i<(n);i++)
#define     PER(i,n) for(ll i=n-1;i>=0;i--)
#define     FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define     FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define     all(x) x.begin(),x.end()
#define     FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     BLOCK 555
mt19937     rng(chrono::steady_clock::now().time_since_epoch().count());
typedef     pair<ll, ll> pl;
typedef     vector<ll> vll;
typedef     vector<string> vs;
typedef     vector<pl> vp;
typedef     vector<vector<ll>> vvll;


/*      author:- Indrajit Sen
        Institution:- Jalpaiguri Government Engineering College
        id:- @Is97, @indra1997
                                                                
                                                                
*/


// directions for matrix movement
vll dir_x{0ll, 0ll, -1ll, 1ll};
vll dir_y{1ll, -1ll, 0ll, 0ll};

// log(y) power calculation
ll power_mod(ll x, ll y, ll m){
    ll arr = 1;
    x%=m;
    while(y){
        if(y&1){
            arr=(arr*x)%m;
        }
        y>>=1;
        x=(x*x)%m;
    }
    return arr;
}

ll power(ll x, ll y){
    ll arr = 1;
    while(y){
        if(y&1){
            arr*=x;
        }
        y>>=1;
        x = x*x;
    }
    return arr;
}


ll mod_inv(ll x,ll m){
    return power_mod(x,m-2,m);
}

bool comp(const pair<ll,pair<ll,ll>> &a, const pair<ll,pair<ll,ll>> &b) { 
    if(a.ff == b.ff){

        return (a.second < b.second); 
    }
    return (a.ff < b.ff); 
} 

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

bool isPalindrome(string s){
    bool flag = true;
    for(ll i=0;i<s.length()/2;i++){
        if(s[i]!=s[s.length()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}

bool isPerfectSquare(ll n){
    ld val = sqrt(n);
    return(val-floor(val) == 0);
}

bool isPrime(ll n){
    if(n<2){
        return false;
    }
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

ll NCR(ll n, ll k){ 
    ll res = 1;
    if ( k > n - k ){
        k = n - k;  
    }
    REP(i,k){
        res *= (n - i);  
        res /= (i + 1);  
    }  
    return res;  
} 

ll cntBits(ll n){
    ll cnt = 0;
    for(ll i=0;i<64;i++){
        if((1ll<<i)&n){
            cnt++;
        }
    }
    return cnt;
}



  
void solve(){

    ll n;
    cin>>n;
    if(n == 0){
        cout<<1<<endl;
    }
    else{
        cout<<0<<endl;
    }


}

int main(){

    FIO;
    // ll t;
    // cin>>t;
    // FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    // }
    return 0;
}


Measured memory_bytes: 3640
fun main() {
  val n = readLine()!!.toInt()
  val d = 2 * n
  var l = 1
  var r = n + 1
  val a = IntArray(n)
  for (i in 0 until n) {
    a[i] = 1 + i
  }
  println("? " + a.joinToString(" "))
  val f = readLine()!!
  while (r - l > 1) {
    val m = (l + r) / 2
    for (i in 0 until n) {
      a[i] = m + i
    }
    println("? " + a.joinToString(" "))
    if (f == readLine()!!) {
      l = m
    } else {
      r = m
    }
  }
  var c = "! "
  for (i in 1..d) {
    val fi = when {
      i == l -> f
      i == l + n -> if (f == "Red") "Blue" else "Red"
      i in l + 1 until l + n -> {
        a[0] = i
        for (j in 1 until n) {
          a[j] = if (n + l + j > d) -n + l + j else n + l + j
        }
        println("? " + a.joinToString(" "))
        readLine()!!
      }
      else -> {
        a[0] = i
        for (j in 1 until n) {
          a[j] = l + j
        }
        println("? " + a.joinToString(" "))
        readLine()!!
      }
    }
    c += fi[0]
  }
  println(c)
}

Measured memory_bytes: 41928
cnt=0
a,b=[],[]
l={}
while 1:
    try:
        n,k=map(int,raw_input().split(','))
        if l.has_key(n):
            l[n][0]+=1
            if cnt==1:
                l[n][1]=2
        elif cnt==0:
            l[n]=[1,1]
    except:
        cnt+=1
        if cnt>1:
            break
for i in l:
    if l[i][1]==2:
        a.append([i,l[i][0]])
a.sort()
for i in a:
    print i[0],i[1]

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

using namespace std;
using ll = long long;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;
 
struct MComb {
   std::vector<mint> fact;
   std::vector<mint> inversed;
   MComb(int n) { // O(n+log(mod))
       fact = std::vector<mint>(n+1,1);
       for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
       inversed = std::vector<mint>(n+1);
       inversed[n] = fact[n] ^ (MOD-2);
       for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
   }
   mint ncr(int n, int r) {
        if (n < r) return 0;
        if (n < 0 || r < 0) return 0;
       return (fact[n] * inversed[r] * inversed[n-r]);
   }
   mint npr(int n, int r) {
        if (n < r) return 0;
        if (n < 0 || r < 0) return 0;
       return (fact[n] * inversed[n-r]);
   }
   mint nhr(int n, int r) {
       assert(n+r-1 < (int)fact.size());
       return ncr(n+r-1, r);
   }
   mint fac(int n) {
       if(n < 0)return 0;
       return fact[n];
   }
};
MComb comb(200000);
 
mint ncr(int n, int r) {
   mint res = 1;
   for (int i = n - r + 1; i <= n; i++) res *= i;
   for (int i = 1; i <= r; i++) res /= i;
   return res;
}


int main()
{
    int n, k; cin >> n >> k;
    cout << ncr(n + k - 1, k - 1) << endl;
}


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

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)


int main(){
 long n,k;
   cin >> n >> k;
 vector<long> s(n+1,0),t(n+1,0);
  rep(i,0,n) {
    long a;
    cin >> a;
   s[i+1]=s[i]+a;
   t[i+1]=t[i]+max(long(0),a);
  
  }
 
  long res=0;
  rep(i,0,n-k+1){
   res=max(res,t[i]+max(s[i+k]-s[i],long(0))+(t[n]-t[i+k]));
  }
 
  cout << res << endl;
  
 
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int k;
	cin >> k;
	vector<lli> a(k);
	for(int i=0; i<k; i++){
		cin >> a[i];
	}
	
	lli ansmin=2, ansmax=2;
	for(int i=k-1; i>=0; i--){
		ansmin = (ansmin+a[i]-1)/a[i]*a[i];
		ansmax = ansmax/a[i]*a[i];
		if(ansmin>ansmax){
			ansmin=-1;
			break;
		}
		ansmax += a[i]-1;
	}
	
	if(ansmin==-1){
		cout << -1 << endl;
	}else{
		cout << ansmin << " " << ansmax << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;  
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int ans = 0;
  int memo = 1;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)) {
      memo++;
    }
    else {
      if (memo % 2 == 1) {
        ans++;
      }
      memo = 1;
    }
  }
  if (memo % 2 == 1) {
    ans++;
  } 
  cout << ans << endl;
}
     

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N,X;
int L[100];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>X;
    int cnt=1;
    int res=0;
    rep(i,0,N){
        cin>>L[i];
        res+=L[i];
        if(res<=X) cnt++;
    }
    cout <<cnt<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18


ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

ll modfact(ll n){
    ll ans = 1;
    for (ll i = 1; i <= n; i++){   
        ans *= i;
        ans %= MOD;
    }
    return ans;
}

ll modcomb(ll n, ll k){
    ll tmp = modfact(n);
    tmp *= modpow(modfact(n-k), MOD-2);
    tmp %= MOD;
    tmp *= modpow(modfact(k), MOD-2);
    tmp %= MOD;
    return tmp;
}

ll ans[100005];
ll dup[100005];

int main(){
    int n;
    cin >> n;
    int a[n+1];
    map<int,int> m;
    int d;

    rep(i, n+1){
        cin >> a[i];
        m[a[i]]++;
        if(m[a[i]]==2) d = a[i];
    }

    vector<int> v;
    rep(i, n+1){
        if(a[i]==d) v.emplace_back(i);
    }

    int lr = v[0] + n-v[1];

    ans[0] = 1;
    repr(i, 0, n){
        ans[i+1] = ans[i] * (n-i+1);
        ans[i+1] %= MOD;
        ans[i+1] *= modpow(i+1, MOD-2);
        ans[i+1] %= MOD; 
    }

    dup[0] = 1;
    repr(i, 0, lr-1){
        dup[i+1] = dup[i] * (lr-i);
        dup[i+1] %= MOD;
        dup[i+1] *= modpow(i+1, MOD-2);
        dup[i+1] %= MOD; 
    }

    // rep(i, n+2){
    //     printf("%d ", ans[i]);
    // }
    // printf("\n");

    // rep(i, lr+1){
    //     printf("%d ", dup[i]);
    // }
    // printf("\n");

    repr(i, 1, n+1){
        cout << (ans[i] - dup[i-1]+ MOD) % MOD << endl;
    }
    // printf("%d\n", N);
    return 0;
}

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

int main() {
    string str;
    cin >> str;

    int16_t l = str.length();
    bool n, w, s, e;
    n = w = s = e = false;

    for (int16_t i = 0; i < l; i++) {
        switch (str.at(i)) {
            case 'N':
                n = true;
                break;
            case 'W':
                w = true;
                break;
            case 'S':
                s = true;
                break;
            case 'E':
                e = true;
        }
    }
    if (n == s && w == e) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double angle;
    angle = abs((H * 60 + M) / 2. - (M * 6));
    angle = min(angle, 360 - angle);
    double ans;
    ans = sqrt((A * A) + (B * B) - (2 * A * B * cos(angle / 180 * M_PI)));
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}




Measured memory_bytes: 4224