akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    ll x; cin >> x;
    ll q = x / 11, r = x % 11;
    ll ans = 2 * q;
    if (r > 6 && r) ans += 2;
    else if (r <= 6 && r) ans += 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
lis = list(input())
lit = list(input())

counts = {}
countt = {}

for i in lis:
    if i not in counts.keys():
        counts[i] = 0
    counts[i] += 1

for i in lit:
    if i not in countt.keys():
        countt[i] = 0
    countt[i] += 1


counts = sorted(counts.items(),key = lambda x: x[1])
countt = sorted(countt.items(),key = lambda x: x[1])

flag = "Yes"
count = 0

for i in range(len(counts)):
    if counts[i][1] != countt[i][1]:
        flag = "No"
        break
    count += 1

print(flag)


Measured memory_bytes: 6704
#include <stdio.h>

int main(void){
  int i,j,N,M,a[51],b[51],count[51]={};

  scanf("%d %d",&N,&M);

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

  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      if(a[j]==i){
        count[i]++;
      }
      if(b[j]==i){
        count[i]++;
      }
    }
  }

  for(i=0;i<N;i++){
    printf("%d\n",count[i]);
  }
  return 0;
}


Measured memory_bytes: 128
n = int(input())
s = list(map(int, input().strip().split(" ")))

flg = 0

for i in range(n-1):
    if s[i] - s[i+1] >= 2 or (s[i-1] ==  s[i] and s[i+1] - s[i] < 0):
        print("No")
        flg = 1
        break
    elif  s[i] - s[i+1] == 1:
        s[i] -= 1
    elif s[i] - s[i-1] >= 1:
        s[i] -= 1

if flg == 0:
    print("Yes")
        
        
        

Measured memory_bytes: 14396
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{ 
  IOS
  ll n,x;
  cin>>n>>x;
  vector<ll> v;
  v.pb(0);
  ll i,l=0;
  for(i=1;i<=n;i++)
  {
     ll y;
     cin>>y;
     l=l+y;
     v.pb(l);
  }
  ll lb=upper_bound(all(v),x)-v.begin();
  cout<<lb;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

int main(){

  long long int X;
  scanf("%lld", &X);

  std::vector<long long int> prime_table(2e5);
  prime_table[0] = 1;
  prime_table[1] = 1;
  for(long long int i = 2; i*i <= 2e5+1; i++){
    // if not prime
    if(prime_table[i] == 1){
      continue;
    }
    // if prime
    for(long long int j = 2*i; j <= 2e5; j += i){
      prime_table[j] = 1;
    }
  }

  long long int ans = X;
  while(prime_table[ans] == 1){
    ans++;
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
class UnionFind {
  constructor(n) {
    this.p = new Array(n).fill(null).map((_, i) => i)
    this.height = new Array(n).fill(0)
    this.size = new Array(n).fill(1)
  }

  unite(a, b) {
    this.link(this.findSet(a), this.findSet(b))
  }

  link(a, b) {
    if (a === b) return null

    if (this.height[a] > this.height[b]) {
      this.p[b] = a
      this.size[a] += this.size[b]
    } else {
      this.p[a] = b
      this.size[b] += this.size[a]

      if (this.height[a] === this.height[b]) {
        this.height[b]++
      }
    }
  }

  findSet(x) {
    if (this.p[x] === x) return x
    return this.findSet(this.p[x])
  }
}

const main = (input) => {
  input = input.trim().split('\n')
  const [n,] = input.shift().split(' ').map(Number)
  input = Array.from(new Set(input))

  const uf = new UnionFind(n+1)

  for (let i=0; i<input.length; i++) {
    const [a, b] = input[i].split(' ').map(Number)
    uf.unite(a, b)
  }

  // const ans = Math.max(...uf.size)
  let max = 0

  for (let i=0; i<uf.size.length; i++) max = Math.max(max, (uf.size[i]|| 0))
  return console.log(max)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 93288
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n){
    string s;
    cin >> s;
    mp[s] = 1;
  }
  cout << mp.size() << endl;
  return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;

int main(){
  cin >> N >> M;
  int A = 1, B = N;
  for (int i = 0; i < M; i++){
    int L, R; cin >> L >> R;
    A = max(A, L); B = min(B, R);
  }
  cout << max(0, B - A + 1) << endl;

  return 0;
}


Measured memory_bytes: 3628
w,h,n =map(int,input().split())
s =[list(map(int,input().split())) for _ in range(n)]
x =0;y =0;
for i in range(n):
  if s[i][2] ==1:
    if x < s[i][0]: x = s[i][0] 
  elif s[i][2] ==2:
    if w > s[i][0]: w = s[i][0]
  elif s[i][2] ==3:
    if y < s[i][1]: y = s[i][1]
  else:
    if h > s[i][1]: h = s[i][1]
print((w-x)*(h-y) if (w-x)>0 and (h-y)>0 else 0) 

Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


int SumNum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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


    int result = 100000000;
    for (int i = 1; i < N; i++) {
        int j = N - i;
        
        int mini = SumNum(i) + SumNum(j);
        result = min(result, mini);
        
    }
    cout << result << endl;
    
    return 0;
}

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

typedef long long ll;

int main()
{
	ll n,m;
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		if(n*2>=m)
		{
			printf("%lld\n",m/2);
		}
		else
		{
			printf("%lld\n",(m-n*2)/4+n);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  int res = INF;
  rep(i,int(s.size())-int(t.size())+1){
    int tmp = 0;
    rep(j,int(t.size())){
      if(s[i+j]=='?' || s[i+j]==t[j])tmp++;
    }
    if(tmp==int(t.size()))res = i;
  }
  if(res==INF)cout << "UNRESTORABLE\n";
  else{
    s.replace(res,int(t.size()),t);
    rep(i,int(s.size()))if(s[i]=='?')s[i] = 'a';
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
#define INF int(1e9 + 10)
#define MAX int(int(1e6))
ll V[MAX];
void solve() {
	var(int, n, W);
	fill(V, V + MAX, INF);
	V[0] = 0;
	ll w, v;
	rep(i, 0, n) {
		cin >> w >> v;
		rrep(j, 1e5 - 1, -1) {
			if (V[j] + w <= W) {
				chmin(V[j + v], V[j] + w);
			}
		}
	}
	rrep(i, 1e5, -1) {
		if (V[i] != INF) {
			print(i);
			break;
		}
	}
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define MAX 200
#define INF (1<<26)

int n,m,s,g1,g2,a,b,c;
int t[MAX][MAX];

void init(){
  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      t[i][j]=(i==j?0:INF);
}

int main(){
  while(1){
    cin>>n>>m>>s>>g1>>g2;
    if(n==0&&m==0&&s==0&&g1==0&&g2==0)break;
    s--,g1--,g2--;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      a--,b--;
      t[a][b]=c;
    }
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
    int ans=INF;
    for(int i=0;i<n;i++)
      ans=min(ans,t[s][i]+t[i][g1]+t[i][g2]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n, x, y;
bool inxy(int n) {
    return x <= n && n <= y;
}
int main() {
    cin >> n >> x >> y;
    x--; y--;
    vector<int> dist(n, 0);
    for (int i = 0; i < n-1; i++) {
        for (int j = i; j < n; j++) {
            int d;
            if (!inxy(i) && !inxy(j)) {
                if (j < x || y < i)
                    d = j - i;
                else
                    d = x - i + j - y + 1;
            }
            if (!inxy(i) && inxy(j)) {
                int d1 = j - i;
                int d2 = y - j + x - i + 1;
                d = min(d1, d2);
            }
            if (inxy(i) && !inxy(j)) {
                int d1 = j - i;
                int d2 = i - x + j - y + 1;
                d = min(d1, d2);
            }
            if (inxy(i) && inxy(j)) {
                int d1 = j - i;
                int d2 = i - x + y - j + 1;
                d = min(d1, d2);
            }
            dist[d]++;
        }
    }
    
    for (int i = 1; i < n; i++)
        cout << dist[i] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX 45
typedef long long ll;
  
int N, B[MAX], sum[MAX], mx;
ll ng[MAX];

void dfs(ll v, int strength, ll S)
{
    mx = max(mx, strength);
    
    if (v == N || sum[v] + strength <= mx) {
        return;
    }    
    dfs(v+1, strength, S);
    if (!(S >> v & 1) && (ng[v] & S) == 0) {
        dfs(v+1, strength + B[v], S|(1LL<<v));
    }
}
  
int main()
{
    while (cin >> N, N) {
        string A, D;
        int C;
        vector<string> DG[MAX];          
        map<string, int> s2i;
        
        for (int i = 0; i < N; i++) {
            cin >> A >> B[i] >> C;
            s2i[A] = i;
            for (int j = 0; j < C; j++) {
                cin >> D;
                DG[i].push_back(D);
            }
        }
        
        sum[N-1] = B[N-1];
        for (int i = N-2; i >= 0; i--) {
            sum[i] = sum[i+1] + B[i];
        }
        
        for (int i = 0; i < N; i++) {
            int len = DG[i].size();
            ng[i] = 0;
            for (int j = 0; j < len; j++) {
                ll t = s2i[DG[i][j]];
                ng[i] |= 1LL<<t;
            }
        }
        mx = 0;
        dfs(1, B[0], 1<<0);
        cout << mx << endl;
    }
    return 0;
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
 vi v(105,0);
 ll n;
 vi dabba(100002,-1);
 ll mexNumber(unordered_set<ll>&s)
 {
     ll mex=0;
     while(s.find(mex)!=s.end())
        mex++;
     return mex;
 }
 ll grundyNumber(ll k)
 {
  if(k==0)
        return 0;
        if(dabba[k]!=-1)
            return dabba[k];
  unordered_set<ll>s;
  for(ll i=0;i<n;i++)
  {
      if(k-v[i]>=0)
      s.insert(grundyNumber(k-v[i]));
  }
  return dabba[k]=mexNumber(s);
 }
int main()
{
   FASTIO
    ll k;
    cin>>n>>k;
    rep(i,0,n)
    cin>>v[i];
    ll ans=grundyNumber(k);
    if(ans!=0)
        cout<<"First";
    else
        cout<<"Second";
 return 0;
}


Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

map<int,int> problem;
int main(){
  int N,M;
  cin >> N;
  for(int i=0;i<N;++i){
    int d;
    cin >> d;
    problem[d]++;
  }
  cin >> M;
  for(int i=0;i<M;++i){
    int t;
    cin >> t;
    if(problem[t]==0){
      cout << "NO" << endl;
      return 0;
    }else{
      problem[t]--;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int c1,c2,c3;
  while(cin>>c1>>c2>>c3) {
    int a=0;
    for(int i=1; i<=10; i++) {
      if (i==c1||i==c2||i==c3) continue;
      if (c1+c2+i<=20) a++;
    }
    if (a>=4) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int ans,n,a[100010];

int main()
{
	cin>>n;
	for(int i=0; i<n; i++)
		cin>>a[i];
	for(int i=0; i<n; i++)
		for(int j=i+1;j<n;j++)
			ans+=a[i]*a[j];
	cout<<ans;
}

Measured memory_bytes: 256
// * template

#include <bits/stdc++.h>
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

// * solve


struct line {
	int a, b;
	line(int a_, int b_):a(a_), b(b_) {}
	int operator()(int x) const {
		return a * x + b;
	}
};

inline bool check(const line &f1, const line &f2, const line &f3) {
	return (f2.a - f1.a) * (f3.b - f2.b) >= (f2.b - f1.b) * (f3.a - f2.a);
}

int solve() {
	int s, n, m;
	cin >> s >> n >> m;
	if(n <= m) return 0;

	vector<int> x(s);
	for(auto &e : x) cin >> e;

	vector<int> a(n);
	for(auto &e : a) {
		int t, p;
		cin >> t >> p;
		e = t - x[p - 1];
	}

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

	vector<int> S{0};
	partial_sum(begin(a), end(a), back_inserter(S));

	/*
	 * dp[i][j] = min{dp[k][j-1] + (i-k)*a[i] - (S[i]-S[k]) | 0 <= k < i}
	 *          = a[i]*i - S[i] + min{dp[k][j-1] - k*a[i] + S[k] | 0 <= k < i}
	 * f_jk(x) = -k*x + dp[k][j-1] + S[k]
	 * dp[i][j] = a[i]*i - S[i] + min{f_jk(a[i]) | 0 <= k < i}
	 */
	constexpr int INF = (1 << 29);
	vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
	dp[0][0] = 0;

	const auto make_f = [&](int i, int j) -> line { return line(-i, dp[i][j] + S[i]); };
	vector<deque<line>> deq(n + 1);
	deq[0].emplace_back(make_f(0, 0));

	for(int i = 1; i <= n; ++i) {
		for(int j = i; j >= 1; --j) {
			auto &prev = deq[j - 1];
			auto &curr = deq[j];

			if(prev.empty()) continue;
			while(prev.size() > 1 && prev[0](a[i - 1]) >= prev[1](a[i - 1])) prev.pop_front();

			dp[i][j] = a[i - 1] * i - S[i] + prev.front()(a[i - 1]);
			dump(i, j, dp[i][j]);

			const auto f = make_f(i, j);
			while(curr.size() > 1 && check(curr[curr.size() - 2], curr.back(), f)) curr.pop_back();
			curr.emplace_back(move(f));
		}
	}

	return dp[n][m];
}

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

	cout << solve() << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 18184
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve() {
		char[] s = ns(6);
		out.println(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
	}
			
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <deque>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

ll n;
vector<int> vec;
deque<int> dq;

int main() {
    scanf("%lld",&n);
    while (n>0) {
    	if (n%2==1) {
    		vec.pb(1);
    		n=(n-1)/2;
    	} else {
    		vec.pb(0);
    		n--;
    	}
    }
    int len=vec.size();
    for (int i=len-1;i>=0;i--) {
    	if (vec[i]==0) {
    		dq.push_front(len-i);
    	} else {
    		dq.push_back(len-i);
    	}
    }
    printf("%d\n",2*len);
    for (int i=0;i<len;i++) {
    	printf("%d ",i+1);
    }
    for (int i:dq) printf("%d ",i);
    printf("\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------



int main() {
   int n,ans=0;
   cin>>n;
   vi a(n);
   rep(i,n)cin>>a.at(i);
   rep(i,n){
       if((i+1)%2==1&&a.at(i)%2==1)ans++;
   }
   cout<<ans<<endl;
}



Measured memory_bytes: 3596
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	N := getInt()
	S := make(map[string]int)
	for i := 0; i < N; i++ {
		s := getString()
		S[s]++
	}

	max := 0
	for _, n := range S {
		if max < n {
			max = n
		}
	}

	var results []string
	for s, n := range S {
		if n == max {
			results = append(results, s)
		}
	}

	sort.Strings(results)

	for _, r := range results {
		fmt.Println(r)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 32544
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 指定した値との差の絶対値が最小のvectorの番号を返します。
*/
long long int absmin(vector<int> a, long long int b) {
	int mini = 10000000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

//ここまでライブラリ
//ここから本文

long long int tpabsmin(vector<int> a, long long int b) {
	int mini = 10000000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b) && a.at(i) >= b) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


int main() {
	int n;
	cin >> n;
	vector<int> a(9);
	for (int i = 1; i <= 9; i++) {
		a.at(i-1) = i * 100 + i * 10 + i;
	}
	cout << a.at(tpabsmin(a, n)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int a[N][3];
  for (int i = 0; i < N; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
  int dp[N][3];
  dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2];
  for (int i = 1; i < N; i++) {
    dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] = a[i][1] + max(dp[i - 1][2], dp[i - 1][0]);
    dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max (dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;

int kaijou(int n) {
    int ans = 1;
    for(int i = 2; i <= n; i++) {
        ans *= i;
    }
    return ans;
}

double dis(vector<int> &x, vector<int> &y, vector<int> &visit) {
    double ans = 0;
    for(int i = 0; i < visit.size() - 1; i++) {
        ans += sqrt(pow(x.at(visit.at(i + 1)) - x.at(visit.at(i)), 2) +pow(y.at(visit.at(i + 1)) - y.at(visit.at(i)), 2));
    }
    return ans;
}

double AL(vector<int> &x, vector<int> &y, vector<int> &visit) {
    if(visit.size() == x.size()) {
        return dis(x, y, visit);
    }
    bool flg = true;
    double ans = 0;
    for(int i = 0; i < x.size(); i++) {
        for(int j = 0; j < visit.size(); j++) {
            if(i == visit.at(j)) {
                flg = false;
            }
        }
        if(flg) {
            visit.push_back(i);
            ans += AL(x, y, visit);
            visit.pop_back();
        } else {
            flg = true;
        }
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for(int i = 0; i < N; i++) {
        cin >> x.at(i) >> y.at(i);
    }
    vector<int> visit;
    cout << setprecision(14) << AL(x, y, visit) / kaijou(N) << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
       cin >> a[i][j];

  vector<int> x, y, d; // d==0> 1v
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w - 1; ++j) {
      if (a[i][j] & 1) {
        ++a[i][j + 1];
        y.push_back(i + 1);
        x.push_back(j + 1);
        d.push_back(0);
      }
    }
  }
  for (int i = 0; i < h - 1; ++i) {
    int j = w - 1;
    if (a[i][j] & 1) {
      ++a[i + 1][j];
      y.push_back(i + 1);
      x.push_back(j + 1);
      d.push_back(1);
    }
  }

  int n = d.size();
  cout << n << "\n";
  for (int i = 0; i < n; ++i) {
    if (d[i] == 0)
      cout << y[i] << " " << x[i] << " " << y[i] << " " << x[i] + 1 << "\n";
    else
      cout << y[i] << " " << x[i] << " " << y[i] + 1 << " " << x[i] << "\n";
  }

  return 0;
}


Measured memory_bytes: 4720
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    string S, T;
    cin>>S>>T;
    int DP[S.size()+1][T.size()+1];
    for(int i=0;i<=S.size();++i){
        for(int j=0;j<=T.size();++j){
            DP[i][j] = 0;
        }
    }
    DP[1][0] = 1;
    DP[0][1] = 1;
    for(int i=2;i<=S.size();++i){
        DP[i][0] = DP[i-1][0]+1;
    }
    for(int i=2;i<=T.size();++i){
        DP[0][i] += DP[0][i-1]+1;
    }
    for(int i=1;i<=S.size();++i){
        for(int j=1;j<=T.size();++j){
            if(S[i-1]==T[j-1]){
                DP[i][j] = min(DP[i-1][j-1], min(DP[i-1][j]+1, DP[i][j-1]+1));
            }
            else{
                DP[i][j] = min(DP[i-1][j-1]+1, min(DP[i-1][j]+1, DP[i][j-1]+1));
            }
        }
    }
    cout<<DP[S.size()][T.size()]<<endl;
}




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

using namespace std;
 
int main()
{
    int N;
    string S;
    cin >> N >> S;

    int ans=0;
    for (int i = 0; i < N - 2; i++) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
    }

    cout << ans << endl;;
}


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

int main()
{
	using namespace std;
	long long r,d,x;
	long long ans=0;
	cin >> r;
	cin >> d;
	cin >> x;	
	ans = (r * x) - d;
	cout << ans << endl;
	for (int i = 0; i < 9;i++) {
		ans = (ans * r) - d;
		cout << ans << endl;
	}
}

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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    string s;
    cin >> s;
    int n = s.size();

    int a = 0, b = 0;
    rep(i, n)
    {
        if (i % 2)
        {
            if (s[i] == '1')
            {
                a++;
            }
            else
            {
                b++;
            }
        }
        else
        {
            if (s[i] == '0')
            {
                a++;
            }
            else
            {
                b++;
            }
        }
    }
    cout << min(n - a, n - b) << endl;
    return 0;
}
//===========================================

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

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

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

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

    int N, N_sub;
    cin >> N;
    
    int ans = 0;
    bool flg = true;
    int pow10 = 10;
    for(int i = 1; i <= N; i++){
        if(i == pow10){
            flg = !flg;
            pow10 *= 10;
        }
        if(flg){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 384
n = int(input())
*A, = map(int, input().split())
maxA = max(A)
# C[a] = A内のaの個数
C = {a: 0 for a in A}
for a in A:
    C[a] += 1
# D[a]=1: Aにaより小さいaの約数が存在する
D = {a: 0 for a in A}
for a in A:
    if C[a] > 0:
        t = 2
        while a * t <= maxA:
            D[a * t] = 1
            t += 1
ans = 0
for a in A:
    if C[a] == 1 and D[a] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 104208
#include <bits/stdc++.h>
#define rup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int l = 0, r = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        r = max(r, a[i]);
    }
    
    int m = 0, ans = r;
    while (l <= r) {
        m = (l + r) / 2;
        if (m < 1) {
            ans = 1;
            break;
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            count += rup(a[i], m) - 1;
        }
        //cout << l << "," << r << "," << m << "," << count << endl;
        if (count <= k) {
            ans = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int n, k, i, j, tab[N], res[N];

int main() {
scanf("%d %d", &n, &k);
for (i=0;i<n;i++) scanf("%d", &tab[i]);
res[0] = 0;
for (i=1;i<=k;i++) {
	res[i] = 0;
	for (j=0;j<n;j++) if (tab[j] <= i && res[i - tab[j]] == 0) res[i] = 1;
}
if (res[k]) printf("First\n"); else printf("Second\n");
return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    string k;
    int s;
    cin >> s >> k;
    if (k.length() <= s) {
        cout << k << endl;
    }else{
        cout << k.substr(0, s) << "..." << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n, k, h[100000], dp[100000] = { 0 };

    cin >> n >> k;
    for (int i=0; i<n; i++) cin >> h[i];

    for (int i=1; i<n; i++) {
        int tmp = 2e+9;
        for (int j=1; j<=k; j++) {
            if (i-j < 0) break;
            tmp = min(tmp, dp[i-j] + abs(h[i]-h[i-j]));
        }
        dp[i] = tmp;
    }

    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <time.h>
#include <vector>
#include <stdio.h>
#include <queue>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
char s[500005];
int main()
{
	//std::ios::sync_with_stdio(false);
	cin>>s + 200000;
	//scanf("%s",s+10);
	int l = 200000;
	//cout<<strlen(s+200000)<<endl;
	int r = strlen(s+200000) + l;
	//cout<<l<<" "<<r<<endl;
	int q;
	cin>>q;
	int rev = 0;
	
	while(q--)
	{
		int op;
		cin>>op;
		if(op == 1)
		{
			if(rev == 0)
				rev = 1;
			else rev = 0;
		}
		else if(op == 2)
		{
			int f;
			char c;
			cin>>f>>c;
			if(f == 1)
			{
				if(rev == 1)
				{
					s[r++] = c;
				}
				else s[--l] = c;
			}
			else
			{
				if(rev == 1)
				{
					s[--l] = c;
				}
				else s[r++] = c;
			}
		}
	}
	if(rev == 0)
	for(int i=l;i<r;i++)
		cout<<s[i];
	else 
	{
		for(int i=r-1;i>=l;i--)
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N;
  cin >> N;
  vector<int> D(N);
  REP(i, N) cin >> D[i];

  int M;
  cin >> M;
  vector<int> T(M);
  REP(i, M) cin >> T[i];

  map<int, int> mp;
  REP(i, N) mp[D[i]]++;
  REP(i, M) {
    if (mp[T[i]] <= 0) {
      cout << "NO" << endl;
      return 0;
    }
    mp[T[i]]--;
  }
  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountll
#define m_p make_pair
#define infi 1e18+1
#define eps 0.000000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
//////////////
auto clk=clock();
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define sz(x) ((long long)x.size())
#define int long long  
#define f80 __float128
#define pii pair<int,int>
/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n,m;
	cin>>n>>m;
	if(n%2)
	{
		int x=1;
		while(m)
		{
			--m;
			cout<<x<<" "<<n-x+1<<"\n";
			x+=1;
		}
	}
	else
	{
		vector<int> ans;
		for(int i=n-1;i>n/2;i-=2)
		{
			ans.push_back(i);
		}
		for(int i=n/2-2+((n/2)%2);i>0;i-=2)
		{
			ans.push_back(i);
		}
		sort(all(ans),greater<int>());
		int v=1;
		for(int i=0;i<m;++i)
		{
			cout<<v<<" "<<v+ans[i]<<"\n";
			++v;
		}
	}
	#ifdef ANIKET_GOYAL
		cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
} 

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

int main()
{
    long long int a,b,x;
    cin >> a >> b >> x;
    if(a%x==0)
    {
        cout << (b/x - a/x) + 1;
    }
    else
    {
        cout << (b/x - a/x);
    }
    


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int Q;
    static int N;
    static int M;
    static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        a = new int[M];
        for (int i = 0; i < M; i++) {
            a[i] = sc.nextInt();
        }
        int[] dp = new int[N+10];
        dp[0] = 1;
        int index = 0;
        for(int i = 0; i < N+1; i++) {
            //index s.t. a[index] >= i
            while(index < M && a[index] < i) index++;
            if(index < M && i == a[index]) continue;
            dp[i+1] += dp[i];
            dp[i+1] %= MOD;
            dp[i+2] += dp[i];
            dp[i+2] %= MOD;
        }
        System.out.println(dp[N]);
    }

    //Copy & paste below codes
    public static final int MOD = 1_000_000_007;
    public static int[] fact;
    public static int[] invfact;

    /**
     * 
     * @param n Calculate factorials/inverse factorials for x = [0,n]
     */
    public static void preCalcFactorials(int n) {
        fact = new int[n + 1];
        invfact = new int[n + 1];
        fact[0] = 1;
        invfact[0] = 1;
        for (int i = 1; i < n + 1; i++) {
            fact[i] = modProd(i, fact[i-1]);
            int inv = invMod(i);
            invfact[i] = modProd(inv, invfact[i-1]);
        }
    }

    public static int properMod(int x) {
        int ans = x%MOD;
        if (ans < 0) ans += MOD;
        return ans;
    }

    /**
     * preCalcFactorials() should be executed beforehand.
     * Calculate nCm modulo to global MOD.
     * @param n
     * @param m
     * @return
     */
    public static int combMod(int n, int m) {
        int ans = modProd(fact[n], invfact[n-m]);
        ans = modProd(ans, invfact[m]);
        return ans;
    }
    /**
     * Calculate a product of 2 integers modulo to mod
     * @param x
     * @param y
     * @param mod modulo
     * @return
     */
    public static int modProd(int x, int y) {
        long ans = ((long) x) * ((long) y); //prevent overflow
        ans %= MOD;
        if (ans < 0) ans += MOD;
        return (int) ans;
    }
    /**
     * Calculate a power of integer modulo to mod
     * @param x
     * @param pow
     * @param mod
     * @return
     */
    public static int modPow(int x, int pow) {
        if (pow == 0) return 1;
        int y = modProd(x,x);
        int ans; 
        if (pow % 2 == 1) {
            ans = x;
        } else {
            ans = 1;
        }
        ans = modProd(ans, modPow(y, pow/2));
        return ans;
    }
    /**
     * Calculate a inverse of an integer modulo to mod, using Fermat's Theorem.
     * Assuming mod is a prime number.
     * @param x
     * @param mod
     * @return
     */
    public static int invMod(int x) {
        return modPow(x, MOD - 2);
    }

    /**
     * x / y modulo MOD global
     * @param x
     * @param y
     * @return
     */
    public static int modDivide(int x, int y) {
        return modProd(x, invMod(y));
    }

    //Copy & paste above code


}


Measured memory_bytes: 48624
[N,M] = list(map(int,input().split()))
s = 1
if N%2==0:
    t = N
    flag = 0
    for i in range(M):
        if (flag==0)and(s>N//4):
            s+=1
            flag =1
        print(s,t)
        s += 1
        t += -1
else:
    t = N-1
    for i in range(M):
        print(s,t)
        s += 1
        t += -1

Measured memory_bytes: 69500
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int N,M;
vector<string> A;
vector<string> B;

bool cal(int p,int q){
    bool ok = true;
    for(int i = 0;i < M;i++){
        for(int j = 0;j < M;j++){
            int a = p+i;
            int b = q+j;
            if(A[a][b] != B[i][j])ok = false;
        }
    }
    return ok;
}

int main() {
    cin >> N >> M;
    A.resize(N);
    B.resize(M);
    rep(i,N)cin >> A[i];
    rep(i,M)cin >> B[i];

    bool ans = false;
    for(int i = 0;i <= N - M;i++){
        for(int j = 0;j <= N - M;j++){
            if(cal(i,j))ans = true;
        }
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int A, B, C;
  int Ap,Bp,Cp;
  cin >> A >> B >> C;

  int cnt = 0;
  while (true){  
  	if(A%2==1 or B%2==1 or C%2==1){
      cout << cnt << endl;
      return 0;
    }else if(A==B and B==C){
      cout << -1 << endl;
      return 0;
    }
    Ap = (B+C)/2;
    Bp = (A+C)/2;
    Cp = (A+B)/2;
    A = Ap;
    B = Bp;
    C = Cp;
   
    cnt++;
  }

}

Measured memory_bytes: 256
//It is coded by ning-mew on 10.14
//Problem : arc 071 F
#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int maxn=1e6+7;
const LL mod=1e9+7;

LL n,dp[maxn],s[maxn],ans;

LL mul(LL A,LL B){return (A*B)%mod;}
LL add(LL A,LL B){return (A+B)%mod;}
int main(){
    scanf("%lld",&n);if(n==1){printf("1\n");return 0;}
    dp[0]=1;s[0]=1;
    ans=add(ans,mul(n-1,n-1));ans=add(ans,1);
    for(int i=1;i<=n;i++){
	dp[i]=dp[i-1];if(i>=3)dp[i]=add(dp[i],s[i-3]);
	s[i]=add(s[i-1],dp[i]);//s[1]=dp[1];
	//cout<<i<<' '<<dp[i]<<endl;
	if(i<n-1)ans=add(ans,mul(dp[i],mul(n-1,n-1)));
	if(i==n-1)ans=add(ans,mul(dp[i],n-1));
	if(i!=n&&i!=n-1)ans=add(ans,mul(dp[i],i+1));
    }
    //cout<<dp[n]<<endl;
    ans=add(ans,dp[n]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	int N, M, K;

	cin >> N >> M >> K;
	cout << (N / M) * K + (N % M != 0) * K << endl;


	return 0;
}


Measured memory_bytes: 3620
n, a, b = map(int, input().split())
s = input()

aac = 0
bac = 0

for i in s:
    if i == 'a' and aac + bac < a + b:
        print("Yes")
        aac += 1
    elif i == 'b' and aac + bac < a + b and bac < b:
        print("Yes")
        bac += 1
    else:
        print("No")


Measured memory_bytes: 4016
n, m = map(int, input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
elif n == 2 or m == 2:
    print(0)
else:
    print((n-2) * (m-2))


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

#define mem(arr,x) memset(arr,x,sizeof(arr))
#define pb push_back
#define ll long long
#define mp make_pair
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define all(x)   (x.begin(),x.end())

const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
const int inf = 1e9 + 7;

int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}
int main()
{
	
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string a,b;
cin>>a>>b;
int m=a.length();
int n=b.length();
int dp[m+1][n+1];
for(int i=0;i<=m;i++)
{
	for(int j=0;j<=n;j++)
	{
		if(i==0 || j==0)
			dp[i][j]=0;
		else if(a[i-1]==b[j-1])
		{
			dp[i][j]=1+dp[i-1][j-1];

		}
		else
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

		}

	}
}
//cout<<dp[m][n]<<'\n';
string ans=" ";
int i=m,j=n;
while(i>0 && j>0)
{   //checking if either left or upper value of dp match or not
	if(dp[i-1][j]==dp[i][j])
	{
		i--;
	}
	else if(dp[i][j-1]==dp[i][j])
	{
		j--;

	}
	else
	{
		ans=a[i-1]+ans;
		i--;
		j--;
	}
}
cout<<ans<<'\n';



}

Measured memory_bytes: 38844
use std::io::stdin;
fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let ints: Vec<i64> = buf
        .split_whitespace()
        .filter_map(|x| x.parse().ok())
        .collect();
    if let &[_n, k, ..] = ints.as_slice() {
        let mut ps: Vec<i64> = {
            let mut buf = String::new();
            stdin().read_line(&mut buf).unwrap();
            buf.split_whitespace()
                .filter_map(|x| x.parse().ok())
                .collect()
        };
        ps.sort();
        let ans: i64 = ps.iter().take(k.clone() as usize).sum();
        println!("{}", ans);
    }
}


Measured memory_bytes: 2144
package main

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

func main() {
	m := make(map[string]string, 3)
	m["a"] = getString()
	m["b"] = getString()
	m["c"] = getString()

	index := make(map[string]int, 3)
	index["a"] = 0
	index["b"] = 0
	index["c"] = 0

	turn := "a"
	ans := ""
	for {
		index[turn]++
		if index[turn] > len(m[turn]) {
			ans = turn
			break
		}

		turn = string(m[turn][index[turn]-1])
	}

	fmt.Println(strings.ToUpper(ans))
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640