akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
    
    while ( !PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        if (d[u] < f.first * (-1)) continue;
        
        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].second ) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main() {
    int k, u, v, c;
    
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    
    dijkstra();
    
    return 0;
}


Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int a,b,c;
  cin >> a >> b>>c;
  if((a==b && b!=c) || (b==c && c!=a) || (c==a && a!=b)){
    cout << "Yes"<<'\n';
  }
  else{
    cout<<"No\n";
  }
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class ETree {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        char C;
        string s;
        in>>s;
        n=s.length();
        s=' '+s;
        bool f=false;
        if(s[n]=='1'||s[1]=='0') f=true;
        Fr(i,n/2) if(s[i]!=s[n-i]) f=true;
        if(f){
            out<<-1<<endl;
            return;
        }

        int pa=1,nw=1;
        vector<int> m(n+1),c(n+1);
        Fr(i,n){
            m[i]=m[i-1];
            if(s[i-1]=='1') m[i]=i-1;
        }
        c[1]=n;
        vector<pair<int,int>> ans;
        Fr(i,n){
            if(c[i]==1) continue;
            c[++nw]=m[c[i]];ans.emplace_back(i,nw);
            c[i]-=m[c[i]];
            while(c[i]>1){
                c[++nw]=1;--c[i];
                ans.emplace_back(i,nw);
            }
        }
        for(auto p:ans) out<<p.first<<" "<<p.second<<endl;
    }
};

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


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

#define INF 1e9
#define MAX_V 1000
typedef pair<ll, int> P;  // (first,second) := (最短距離,頂点番号)

vector<int> G[MAX_V];

int d[MAX_V], pre[MAX_V];
int V, E;

// 頂点rからの最小距離
bool dijkstra(int r) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    que.push(P(0, r));
    d[r] = 0;

    while (que.size()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i];
            if (to == r) {
                pre[to] = v;
                return true;
            }
            if (d[v] + 1 < d[to]) {
                pre[to] = v;
                d[to] = d[v] + 1;
                que.push(P(d[to], to));
            }
        }
    }
    return false;
}

int main() {
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }
    for (int i = 0; i < V; i++) {
        fill(d, d + MAX_V, INF);
        fill(pre, pre + MAX_V, -1);
        if (dijkstra(i)) {
            int v = i, r = i, cnt = 0;
            vector<int> V1(V, -1);
            map<int, int> mp;
            do {
                V1[pre[v]] = v;
                v = pre[v];
            } while (v != r);
            do {
                mp[v] = cnt++;
                v = V1[v];
            } while (v != r);
            do {
                int max_b = -1, max_f = -1;
                int arg_mb, arg_mf;
                for (int j = 0; j < G[v].size(); j++) {
                    int to = G[v][j];
                    if (mp.find(to) != mp.end()) {
                        if (mp[to] < mp[v] && mp[to] > max_b) {
                            max_b = mp[to];
                            arg_mb = to;
                        } else if (mp[to] > mp[v] && mp[to] > max_f) {
                            max_f = mp[to];
                            arg_mf = to;
                        }
                    }
                }
                if (max_b != -1) {
                    r = arg_mb;
                    V1[v] = r;
                } else if (max_f != -1) {
                    V1[v] = arg_mf;
                }
                v = V1[v];
            } while (v != r);
            v = r;
            int V_size = 0;
            do {
                V_size++;
                v = V1[v];
            } while (v != r);
            cout << V_size << endl;
            do {
                cout << v + 1 << endl;
                v = V1[v];
            } while (v != r);
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define pb(n) push_back(n)
#define endl '\n'
#define P(x)  cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, count = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  vi a(3);
  VIN(a);
  sort(ALL(a));

  ans = abs(a[1]-a[0]) + abs(a[2]-a[1]);
  OUT(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

ul solve(int idx, vector< int > & v,
  vector< int > & x, vector< int > & y,
  unordered_map< int, vector< int > > & nx,
  unordered_map< int, vector< int > > & ny,
  set< int > & sx, set< int > & sy)
{
  if (v[idx]) return 0;
  v[idx] = true;
  sx.insert(x[idx]); sy.insert(y[idx]);
  ul n_cnt = 0;
  for (auto cx : nx[x[idx]]) {
    n_cnt += solve(cx, v, x, y, nx, ny, sx, sy);
  }
  for (auto cy : ny[y[idx]]) {
    n_cnt += solve(cy, v, x, y, nx, ny, sx, sy);
  }
  return n_cnt+1;
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< int > x(n), y(n);
  for (int i=0; i<n; ++i) cin >> x[i] >> y[i];
  unordered_map< int, vector< int > > nx, ny;
  for (int i=0; i<n; ++i) {
    if (nx.count(x[i]) > 0) nx[x[i]].push_back(i);
    else nx[x[i]] = vector< int >(1, i);
    if (ny.count(y[i]) > 0) ny[y[i]].push_back(i);
    else ny[y[i]] = vector< int >(1, i);
  }
  vector< int > v(n, false);
  ul ans = 0;
  for (int i=0; i<n; ++i) {
    if (v[i]) continue;
    set< int > sx, sy;
    ul cnt = solve(i, v, x, y, nx, ny, sx, sy);
    ans += sx.size() * sy.size() - cnt;
    //cerr << sx.size() << "*" << sy.size() << "-" << cnt << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27288
import java.util.Arrays;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int[] x = new int[N+1];
        int[] y = new int[M+1];

        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
        }
        x[N] = X;

        for (int i = 0; i < M; i++) {
            y[i] = sc.nextInt();
        }
        y[M] = Y;

        Arrays.sort(x);
        Arrays.sort(y);

        if (x[x.length - 1] < y[0]) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
}

Measured memory_bytes: 22996
N=int(input())
if N%2==0:
  print(N//2,N,N)
else:
  for i in range(1,3501):
    for j in range(1,3501):
      if 4*i*j-N*i-N*j!=0:
        w=(N*i*j)/(4*i*j-N*i-N*j)
        if w>0 and w.is_integer():
          print(i,j,int(w))
          exit()

Measured memory_bytes: 40556
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = scanner.nextInt();
        int e = scanner.nextInt();
        int t = 0;
        if (a < 0) {
            t = (-a * c) + d + (b * e);
        } else if (a == 0) {
            t = d + (b * e);
        } else {
            t = (b - a) * e;
        }
        System.out.println(t);

    }
}



Measured memory_bytes: 26140
import numpy as np

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

#def numsearch(list):
    #for i in list:
        #print(i)
        #if (i+1)/2 not in list:
            #list.remove(i)
    #return list

def main():
    Q = int(input())
    list = seachPrimeNum(100000)
    #フラグを立てるよ
    check = [0]*100001
    primeCheck = [0]*100001
    for i in list:
        primeCheck[i] = 1
    for i in list:
        if i == 2:
            continue
        tmp = int((i+1)/2)
        if primeCheck[tmp] == 1:
            check[i] = 1
    #答えを求めるための累積和
    c = [0]*100001
    c[0] = 0
    for i in range(1,100001,1):
        #print(i)
        if check[i] == 1:
            c[i] = c[i-1]+1
        else:
            c[i] = c[i-1]
    #print(c)
    for i in range(Q):
        l,r = map(int,input().split())
        print(c[r]-c[l-1])

main()


Measured memory_bytes: 32424
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int is_palindrome(char *s, int n) {
    int low, high;
    if (!n) n = strlen(s);
    low = 0;
    high = n - 1;
    while (low < high) {
        if (s[low++] != s[high--])
            return 0;
    }
    return 1;
}

int main() {
    char S[1000], *tmp;
    int len, index;
    fgets(S, 1000, stdin);
    len = strlen(S);
    S[--len] = 0;
    if (!is_palindrome(S, len)) {
        puts("No");
    } else if (!is_palindrome(S, len / 2)) {
        puts("No");
    } else if (!is_palindrome(S + len / 2 + 1, 0)) {
        puts("No");
    } else {
        puts("Yes");
    }
}


Measured memory_bytes: 128
#include <stdio.h>
#define A (80)
#define B (65)
#define C (50)
#define D (30)
int main (void) {
 int m, f, r; //入力
 int sum; // m + f
 while (1) { //ループ開始
  scanf ("%d %d %d", &m, &f, &r);
  if ((m==-1) && (f==-1) && (r==-1)) break;
  sum = m + f; //中間と期末の和
  if ((m==-1) || (f==-1)) {
   printf ("F\n");
   continue;
  }
  if (A<=sum) {
   printf ("A\n");
  }else if ((B<=sum) && (sum<A)){
   printf ("B\n");
  }else if ((C<=sum) && (sum<B)){
   printf ("C\n");
  }else if ((D<=sum) && (sum<C)){
   if (C<=r) {
    printf ("C\n");
   }else{
    printf ("D\n");
   }
  }else{
   printf ("F\n");
  }
 }
 return (0);
}





Measured memory_bytes: 2048
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

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

ll lcm(ll a, ll b){
	return a * b / gcd(a, b);
}

int main(){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	ll U = b-a+1;
	ll cdiv = b/c - (a-1)/c;
	ll ddiv = b/d - (a-1)/d;
	ll cd_lcm = lcm(c,d);
	ll candd = b/(cd_lcm) - (a-1)/(cd_lcm);
	ll ans = U - (cdiv+ddiv-candd);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3628
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _s(): return sys.stdin.readline().strip()


def main():
    if "7" in _s():
        ans = "Yes"
    else:
        ans = "No"
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 61664
s = open(0).read().rstrip()

import re

if len(s)>3 and re.fullmatch(r'A[a-z]+C[a-z]+',s):
    print('AC')
elif len(s) == 3 and re.fullmatch(r'A[a-z]?C[a-z]?',s):
    print('AC')
else:
    print('WA')

Measured memory_bytes: 70764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 85;

int main() {
   int n;
   cin >> n;
   vector <int> a(n);
   for(int i=0; i<n; i++) scanf("%d", &a[i]);
   ll cash = 1000;
   for(int i=1; i<n; i++) {
      if(a[i] > a[i-1]) {
         ll x = cash / a[i-1];
         cash += x * (a[i] - a[i-1]);
      }
   }
   cout << cash << endl;
}


Measured memory_bytes: 3636
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n;
    n = sc.nextInt();
    int v[] = new int[n];
    for(int i=0; i<n; i++) v[i] = sc.nextInt();
    Integer odd[] = new Integer[100010];
    Arrays.fill(odd,0);
    Integer even[] = new Integer[100010];
    Arrays.fill(even,0);
    int j=0;
    Integer total[] = new Integer[100010];
    Arrays.fill(total,0);
    for(int i=0; i<n; i++){
      total[v[i]]++;
    }
    for(int i=0; i<n/2; i++){
      odd[v[j]]++;
      even[v[j+1]]++;
      j+=2;
    }
    Arrays.sort(odd, Comparator.reverseOrder());
    Arrays.sort(even, Comparator.reverseOrder());
    Arrays.sort(total, Comparator.reverseOrder());
    int ans;
    if(odd[0] + even[0] == total[0]){
      ans = Math.min(n - odd[0] - even[1], n - odd[1] - even[0]);
    }else{
      ans = n - odd[0] - even[0];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 50732
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val inum = sc.nextInt()
    var flag = true

    for (i <- 1 to inum) {
      var num, numx, numy = sc.nextInt
      if (num >= (numx + numy) && flag) {
        if ((num % 2 == 0 && (numx + numy) % 2 == 0) | (num % 2 == 1 && (numx + numy) % 2 == 1)) flag=true else flag=false
      }else flag=false
    }

    if(flag)println("Yes") else println("No")
  }
}

Measured memory_bytes: 90972
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
                    str = br.readLine();
                    int N = Integer.parseInt(str);
                    str = br.readLine();
                    String[] strs = str.split("\\s");

                    int[] A = new int[N];//for boble
                    char[] I = new char[N];
                    for(int i=0;i<N;i++){
                        I[i] = strs[i].charAt(0);
                        A[i] = Character.getNumericValue(strs[i].charAt(1));
                    }

                    int[] As= Arrays.copyOf(A,A.length);//for selection
                    char[] Is = Arrays.copyOf(I,I.length);
                    
                    int[] OA= Arrays.copyOf(A,A.length);//for saving original array
                    char[] OI = Arrays.copyOf(I,I.length); 

                    String B = bobles(I,A);
                    String S = selects(Is,As);

                    System.out.println(B);
                    System.out.println("Stable");
                    System.out.println(S);
                    if(B.equals(S)){
                        System.out.println("Stable");
                    }else{
                        System.out.println("Not stable");
                    }
                    
                    br.close();
    }
    public static String bobles(char[] I,int[] A){
        for(int i = 0; i < A.length ;i++ ){
            for(int j =(A.length-1); j >= 1 ;j--){
                if(A[j] < A[j-1]){
                    int tmp = A[j];
                    char ti = I[j];

                    A[j] = A[j-1];
                    I[j] = I[j-1];

                    A[j-1] = tmp;
                    I[j-1] = ti;
                }
            }
        }

        StringBuffer sb = new StringBuffer();
        for(int i=0; i< A.length;i++){
            sb.append(I[i]);
            sb.append(A[i]);
            if(i != (A.length -1)){
                sb.append(" ");
            }
        }
        return sb.toString();
    }


    public static String selects(char[] I,int[] A){
        for(int i = 0;i < A.length;i++){
            int minj = i;
            for(int j= i;j < A.length;j++){
                if(A[j] < A[minj]){
                    minj = j;
                }
            }
            int tmp = A[i];
            char ti = I[i];

            A[i] = A[minj];
            I[i] = I[minj];

            A[minj] = tmp;
            I[minj] = ti;
        }

        StringBuffer sb = new StringBuffer();
        for(int i=0; i< A.length;i++){
            sb.append(I[i]);
            sb.append(A[i]);
            if(i != A.length -1){
                sb.append(" ");
            }
        }
        return sb.toString();
    }
}


Measured memory_bytes: 24400
#include<iostream>
using namespace std;
int main()
{
  string s,t;
  cin >> s >> t;
  for(int i=0; i<t.size(); i++){
    cout << s[i] << t[i];
  }
  if(s.size() > t.size())
    cout << s[s.size() - 1];
  cout << endl;
  
  return 0;
}

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

int main(){
    int k;
    string s,ans="";
    cin >> k >> s;

    if( s.size() > k ){
        rep(i,k){
            ans += s.at(i);
        }
        ans += "...";
    }else{
        ans = s;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long

const int N = 1000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
ll n,k;
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int x,y;
cin>>x>>y;
int z=max(-1000000,y-x+1);
int a=min(1000000,y+x-1);
for(int i=z;i<=a;i++)
cout<<i<<" ";

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD2;
        inv[i] = MOD2 - inv[MOD2%i] * (MOD2 / i) % MOD2;
        finv[i] = finv[i - 1] * inv[i] % MOD2;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD2) % MOD2;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M)%M;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans = 0;
    COMinit();
    rep(i,k+1){
        ans += m*COM(n-1,i)%MOD2*RepeatSquaring(m-1,n-i-1,MOD2);
        ans %= MOD2;
    }
    PRINT(ans);
}


Measured memory_bytes: 8348
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	string s; cin >> s;
	ll n = s.size();
	ll k = n;
	for(ll i = 0; i < n - 1; ++i){
		if(s[i] != s[i + 1]) k = min(k, max(i + 1, n - (i + 1)));
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> d(n);
  for(Int i=0;i<n;i++) cin>>d[i];
  map<Int, Int> r;
  for(Int i=0;i<n;i++) r[d[i]]=i;

  vector<vector<Int> > G(n);
  auto NO=[](){cout<<-1<<endl;exit(0);};
  auto add_edge=[&](Int x,Int y){
		  G[x].emplace_back(y);
		  G[y].emplace_back(x);
		};

  using P = pair<Int, Int>;
  priority_queue<P> pq;
  vector<Int> s(n,1),used(n,0);
  for(Int i=0;i<n;i++) pq.emplace(d[i],i);
  
  while(pq.size()>1u){
    Int x,v;
    tie(x,v)=pq.top();pq.pop();
    
    Int nd=x-(n-s[v])+s[v];
    if(!r.count(nd)) NO();
    
    Int u=r[nd];    
    if(used[u]) NO();
    
    add_edge(v,u);
    s[u]+=s[v];    
    used[v]=1;
  }

  vector<Int> sz(n,1),dp(n,0);
  function<Int(Int, Int)> dfs=
    [&](Int v,Int p){
      for(Int u:G[v]){
	if(u==p) continue;
	dp[v]+=dfs(u,v);
	dp[v]+=sz[u];
	sz[v]+=sz[u];
      }
      return dp[v];
    };
  
  if(d[0]!=dfs(0,-1)) NO();
  
  for(Int v=0;v<n;v++)
    for(Int u:G[v]) if(v<u) cout<<v+1<<" "<<u+1<<endl;
  return 0;
}


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

using namespace std;

int n;
int cost[100001];
int dp[100001];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> cost[i];
    }

    dp[0] = 0;
    dp[1] = abs(cost[1] - cost[0]);

    for(int i = 2; i < n; i++)
    {
        int x = dp[i-1] + abs(cost[i] - cost[i-1]);
        int y = dp[i-2] + abs(cost[i] - cost[i-2]);

        dp[i] = min(x, y);
    }
    
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Make Them Even
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 500;
const int MAX_W = 500;
const int MAX_HW = MAX_H * MAX_W;

/* typedef */

/* global variables */

int as[MAX_H][MAX_W], ops[MAX_HW][4];

/* subroutines */

inline void setop(int k, int y0, int x0, int y1, int x1) {
  ops[k][0] = y0, ops[k][1] = x0, ops[k][2] = y1, ops[k][3] = x1;
}

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      scanf("%d", &as[y][x]), as[y][x] &= 1;

  int m = 0;
  for (int y = 0; y < h;) {
    // ->
    if (y > 0 && as[y - 1][0]) {
      setop(m++, y - 1, 0, y, 0);
      as[y][0] ^= 1;
    }
    for (int x = 0; x < w - 1; x++)
      if (as[y][x]) {
	setop(m++, y, x, y, x + 1);
	as[y][x + 1] ^= 1;
      }
    if (++y >= h) break;

    // <-
    if (as[y - 1][w - 1]) {
      setop(m++, y - 1, w - 1, y, w - 1);
      as[y][w - 1] ^= 1;
    }
    for (int x = w - 1; x > 0; x--)
      if (as[y][x]) {
	setop(m++, y, x, y, x - 1);
	as[y][x - 1] ^= 1;
      }
    ++y;
  }

  printf("%d\n", m);
  for (int i = 0; i < m; i++)
    printf("%d %d %d %d\n",
	   ops[i][0] + 1, ops[i][1] + 1, ops[i][2] + 1, ops[i][3] + 1);
  return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    ll x;
    REP(i,m)
    {
        cin>>x;
        sum+=x;
    }
    if(sum<=n)
    cout<<n-sum;
    else cout<<-1;   
  }  
  return 0;
}

Measured memory_bytes: 3668
use proconio::input;

fn main() {
    input! {
        k: u32,
        a: u32,
        b: u32,
    }

    let multiplicand = (a + (k-1)) / k;
    let num = k * multiplicand;
    if num <= b {
        println!("OK");
    } else {
        println!("NG");
    }
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	double n, ans = 0;
	cin >>n ;
	const double PI = acos(-1);
	
	printf("%.13f\n", 2.0*PI*n);
	return 0;
}


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

using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define fill(a, x) memset(a, x, sizeof(a))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;


int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int i,a,b;
	for(i=1;i<=5;i++){
		cin>>a;
		if(a==0) b=i;
	}
	cout<<b;
	}



Measured memory_bytes: 3632
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var N, K int
	fmt.Scanf("%d %d\n", &N, &K)

	cnt := 0
	for i := 0; i < N; i++ {
		var h int
		fmt.Scan(&h)
		if h >= K {
			cnt++
		}
	}
	fmt.Println(cnt)

}


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int d[1010][1010];
char a[1010][1010];

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int h = 0, w = 0;
queue<pair<int, int>> que;

int  bfs() {
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();

		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (1 <= nx && nx <= w && 1 <= ny && ny <= h && a[ny][nx] != '#'&& d[ny][nx] == INF) {
				que.push(pair<int, int>(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}

	int ans = 0;
	
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			ans = max(ans,d[i][j]);
		}
	}

	return ans;

}



int main() {

	cin >> h >> w;
	string s;

	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= w; j++) {
			d[i][j] = INF;
		}
	}
	for (int i = 1; i <= h; i++) {
		cin >> s;
		for (int j = 1; j <= w; j++) {
			a[i][j] = s[j - 1];
			if (a[i][j] == '#') {
				que.push(pair<int, int>(i, j));
				d[i][j] = 0;
			}
		}
	}

	int res = bfs();
	cout << res << endl;
}

Measured memory_bytes: 13328
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

int main() {
	
	int n, a[105];

	cin >> n;
	for (int i = 0; i < n; i++) {

		cin >> a[i];

	}
	for (int i = n - 1; i >= 1; i--) {

		cout << a[i] << " ";

	}
	cout << a[0] << endl;

	return 0;
}

Measured memory_bytes: 3116
#include<iostream>
using namespace std;
const int INF = 999999999;
const int MAX = 500000;
int cnt = 0;
int A[MAX], L[MAX], R[MAX];
void merge(int A[], int left, int mid, int right)
{
	int ln = mid - left;
	int rn = right - mid;
	for (int i = 0; i < ln; i++)
		L[i] = A[left + i];
	for (int i = 0; i < rn; i++)
		R[i] = A[mid + i];
	L[ln] = R[rn] = INF;
	int i = 0, j = 0;
	for (int k = left; k < right; k++)
	{
		cnt++;
		if (L[i] <= R[j])
		{
			A[k] = L[i];
			i++;
		}
		else
		{
			A[k] = R[j];
			j++;
		}
	}
}
void mergeSort(int A[], int left, int right)
{
	if (left+1 >= right)
		return;
	int mid = (left + right) / 2;
	mergeSort(A, left, mid);
	mergeSort(A, mid, right);
	merge(A, left, mid, right);
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	mergeSort(A, 0, n);
	for (int i = 0; i < n; i++)
		if (i != n - 1)
			cout << A[i] << " ";
		else
			cout << A[i] << endl;
	cout << cnt << endl;
}


Measured memory_bytes: 6980
#include <cstdio>
#include <algorithm>
#include <queue>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 1000100;

int x[N], n, e, t;
LL f[N];


int main()
{
	scanf("%d%d%d", &n, &e, &t);
	Rep(i, n) scanf("%d", &x[i]);
	
	int j = 0;
	LL tmp = 1e18;
	Rep(i, n) {
		f[i] = 1e18;
        while (t <= (x[i] - x[j + 1]) * 2){
            tmp = min(tmp, f[j] - 2 * x[j + 1]);
        	j ++;	
		}
        if(j < i) f[i] = min(f[i], f[j] + t);
        f[i] = min(f[i], tmp + 2 * x[i]);
    }
    printf("%lld\n", f[n] + e);
	
	return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

#define READ first
#define WRITE second

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

	for(int n; cin >> n, n;) {
		vector<pair<int, int> > book(n);
		for(int i = 0; i < n; ++i)
			cin >> book[i].READ >> book[i].WRITE;

		sort(book.begin(), book.end());
		int sum = 0;
		for(int i = 0; i < n - 1; ++i)
			sum += book[i].READ;

		int ans = sum + book[n - 1].READ;
		for(int i = 0; i < n; ++i)
			ans += book[i].WRITE;

		if(sum < book[n - 1].READ) {
			int rest = book[n - 1].READ - sum;
			vector<bool> dp(rest + 1, false);
			dp[rest] = true;

			for(int i = 0; i < n - 1; ++i) {
				for(int j = book[i].WRITE; j <= rest; ++j) {
					if(dp[j])
						dp[j - book[i].WRITE] = true;
				}
			}

			for(int i = 0; i <= rest; ++i)
				if(dp[i]) {
					ans += i;
					break;
				}

		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1212
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        double res = 0;
        for (int i = 1; i <= n; i++)
        {
            int count = 0;
            while (i << count < k) count++;
            res += Pow(0.5, count);
        }
        res /= n;
        Console.WriteLine(res);
    }

}


Measured memory_bytes: 11348
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    tmp = input.split(" ");
    tmp = tmp.map(Number);
    N = tmp[1] - tmp[0];
    h = 0;
    for(i =1; i < N ;i++){
        h += i;
    }
    
    console.log(h-tmp[0]);


    //console.log(answer);
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int n; cin >> n;
    vector<int> l;
    rep(i, n) {
        int tmp; cin >> tmp;
        l.push_back(tmp);
    }
    sort(l.begin(), l.end());
    ll ans = 0;
    for(int i = 0; i < n-2; i++) {
        for(int j = i+1; j< n-1; j++) {
            auto it = lower_bound(l.begin(), l.end(), l[i] + l[j]);
            int diff = it - l.begin()-1;
            // cout << diff << " " << diff-j << endl;
            ans += diff-j;
        }
    }
    cout << ans << endl;
}


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

int main(){
	int n,x,i,j,k,s;
 	
 	while(1){
		cin>>n>>x;
		if(n==0&&x==0){
			break;
		}
		
		s=0;
		for(i=1;i<=n-2;i++){
			for(j=i+1;j<=n-1;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x){
						s++;
					}
				}
			}
		}
		cout<<s<<endl;
 	}
  	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

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 << "{";
    typename vector< T > :: const_iterator it;
    for( 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 << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( 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 << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

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

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;

// TEMPLATE DEFINITIONS END

unordered_map<string, int> m;
string s;

void read_input(){
    
    cin >> s;
}

void solve(){

    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;

    cout << m[s] << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

int main() {
  int n; cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  rep(b, n) rep(a, b) {
    int ab = l[a] + l[b];
    int R = lower_bound(l.begin(), l.end(), ab) - l.begin();
    int L = b + 1;
    ans += max(0, R - L);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	R int sum=1,res=0;
	while(sum<b)sum+=a-1,++res;
	printf("%d\n",res);
	return 0;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    ll n, ma, mb;
    cin >> n >> ma >> mb;
    vector<tuple<ll,ll,ll>> v(n);
    for(auto &e: v) {
        ll a, b, c;
        cin >> a >> b >> c;
        e = make_tuple(a, b, c);
    }
    
    auto f = [&](ll a, ll b) {
        return mb * a - ma * b;
    };

    map<ll, ll> mp;
    for(ll i=0; i<n/2; i++) {
        map<ll, ll> pre = mp;
        pre[0] = 0;
        ll a, b, c;
        tie(a, b, c) = v[i];
        for(auto &t: pre) {
            ll k = t.first + f(a, b);
            if(mp.count(k)) mp[k] = min(mp[k], t.second + c);
            else mp[k] = t.second + c;
        }
    }

    map<ll, ll> mq;
    for(ll i=n/2; i<n; i++) {
        map<ll, ll> pre = mq;
        pre[0] = 0;
        ll a, b, c;
        tie(a, b, c) = v[i];
        for(auto &t: pre) {
            ll k = t.first + f(a, b);
            if(mq.count(k)) mq[k] = min(mq[k], t.second + c);
            else mq[k] = t.second + c;
        }
    }

    ll r = 1e18;
    for(auto &t: mp) {
        ll k, c;
        tie(k, c) = t;
        if(mq.count(-k))
            r = min(r, c + mq[-k]);
    }
    if(mp.count(0)) r = min(r, mp[0]);
    if(mq.count(0)) r = min(r, mq[0]);
    cout << (r == 1e18 ? -1 : r) << endl;
}


Measured memory_bytes: 384
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Thu Dec  6 23:54:39 2018
//
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	var K string
	fmt.Scan(&S, &K)

	if len(K) <= 3 {
		k, _ := strconv.Atoi(K)
		if k <= len(S) {
			all1 := true
			for i := 0; i < k; i++ {
				if S[i] != '1' {
					all1 = false
				}
			}
			if all1 {
				fmt.Println(1)
				return
			}
		}
	}

	for i := 0; i < len(S); i++ {
		if S[i] != '1' {
			fmt.Println(string(S[i]))
			return
		}
	}

	fmt.Println(1)
}


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

int main(void){
	string s;
	cin >> s;
	int ans = 0;
	ans += s[0] == '1';
	ans += s[1] == '1';
	ans += s[2] == '1';
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
    string a;
    cin >> a;
    int A = 0, B = 0;
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i] == 'A')
            A++;
        else if(a[i] == 'B')
            B++;
    }
    if(A == 0 || B == 0)
        cout << "No" << endl;
    else
        cout <<"Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

// Input string
func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := scanString()

	for _, c := range input {
		if c == '7' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 1760
n = int(input())
s = input()

pins = [str(i).zfill(3) for i in range(1000)]

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    if (index > 0):
      ans += 1;
      
print(ans)


Measured memory_bytes: 3060