akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
typedef complex<double> cd;
static const double pi = 3.141592653589793;

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

  string s; cin >> s;
  int n = s.size();
  ll k; cin >> k;

  int need = 0;
  for(int i = 1; i < n; ++i) {
    if(s[i] == s[i - 1]) {
      ++need;
      ++i;
    }
  }
  if(k == 1) {
    cout << need << endl;
    return 0;
  }

  bool only = 1;
  for(int i = 1; i < n; ++i) {
    if(s[i] != s[i - 1]) {
      only = 0;
      break;
    }
  }
  if(only) {
    ll cnt = n * k;
    ll ans = cnt / 2;
    cout << ans << endl;
    return 0;
  }

  s += s;
  n = s.size();
  int needTwice = 0;
  for(int i = 1; i < n; ++i) {
    if(s[i] == s[i - 1]) {
      ++needTwice;
      ++i;
    }
  }

  ll diff = needTwice - need;
  ll ans = need + (k - 1) * diff;
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

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

	w := make(map[string]string)
	for i := 0; i < len(s); i++ {
		for j := i + 1; j <= min(i+5, len(s)); j++ {
			t := s[i:j]
			w[t] = t
		}
	}

	k := make([]string, len(w))
	i := 0
	for _, c := range w {
		k[i] = c
		i++
	}

	sort.Strings(k)
	fmt.Println(k[K-1])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 3456
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

price = 0
num = 0
for i, line in enumerate(stdin, 1):
    p, n = (int(s) for s in line.split(','))
    price += p * n
    num += n

print(price)
print(int(num / i + 0.5))

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a;
	cin >> a;
	cout << a * a * a + a * a + a << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll ans = 0, x = 0;
  rep(i, n) {
    if(s[i] == 'I')
      x++;
    else
      x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
    int n,m;
    cin >> n >> m;
    VI a(n);
    REP(i,n) cin >> a[i];
    
    //総得票数b
    int b = 0;
    REP(i,n) b = b + a[i];
    // b/4mを求める
    int c;
    if(b % 4 * m == 0){
        c = b / (4 * m) - 1;
    }else{
        c = b / (4 * m);
    }

    //　1/4m未満のものを選ぶ
    int count = 0;
    REP(i,n){
        if(a[i] > c) count++;
    }

    if(count >= m){
        cout << "Yes";
    }else{
        cout <<"No";
    }
    cout << endl;
}

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

int main(void) {
  int n;
  cin >> n;
  
  long long ans = 1;
  bool zero_flag = false;
  bool over_flag = false;
  for(int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if(a == 0) {
      zero_flag = true;
    } else if(ans > (long long)1e18/a) {
      over_flag = true;
    } else {
      ans *= a;
    }
  }
  
  if(zero_flag) cout << "0" << endl;
  else if(over_flag) cout << "-1" << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll ans = 0;
int n,m;
ll x;
ll a[13][13];
ll c[13];

ll flag = false;

void rec(vector<ll> check, ll index, ll price) {
    if(index>=n) {
        rep(i, m) {
            if(check[i]<x) {
                return;
            }
        }
        flag = true;
        ans = min(ans, price);
        return;
    }

    rec(check, index+1, price);

    rep(i, m) {
        check[i] += a[index][i];
    }

    rec(check, index+1, price+c[index]);

    return;
}

int main() {
    
    cin >> n >> m >> x;
    
    
    rep(i, n) {
        cin >> c[i];
        ans += c[i];
        rep(j, m) {
            cin >> a[i][j];
        }
    }

    vector<ll> check;
    rep(i, m) {
        check.push_back(0);
    }
    rec(check, 0, 0);    
    
    if(!flag) {
        print(-1);
    } else {
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 3632
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var count = {};
  for(var i = 0; i < N; i++){
    if(count[list[i]] == null){
      count[list[i]] = 1;
    }else{
      count[list[i]]++;
    }
  }
  var keys = Object.keys(count);
  myerr(keys);
  if(keys.length > 3){
    myout("No");
  }else if(keys.length == 3){
    
    if((keys[0] ^ keys[1]) == keys[2] && count[keys[0]] == count[keys[1]] && count[keys[1]] == count[keys[2]]){
      myout("Yes");
    }else{
      myout("No");
    }
  }else if(keys.length == 2){
    if(keys.indexOf("0") != -1){
      
      var zeroCount = count["0"];
      var notZeroCount;
      if(keys[0] != 0){
         notZeroCount = count[keys[0]];
      }else{
         notZeroCount = count[keys[1]];
      }
      myerr(zeroCount);
      myerr(notZeroCount);
      if(notZeroCount / 2 == zeroCount){
        myout("Yes");
      }else{
        myout("No");
      }
    }else{
      myout("No");
    }
  }else{
    if(keys[0] == 0){
      myout("Yes");
    }else{
      myout("No");
    }
  }
}

Measured memory_bytes: 69120
#include <stdio.h>

int main(void){
  int n,count;
  char s[100001];
  scanf("%d %s",&n,s);
  count=n;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]) count--;
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1828
#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;
int main(void){
    
    char r[10];
    int flag = 1, count = 0;
    
    std::cin >> r;
    
    if(r[0] != 'A'){
        flag = 0;
    }
    
    if(isupper(r[1])) flag = 0;
    
    for(int i = 2; i < strlen(r) - 1; i++){
        if(r[i] == 'C'){
            count++;
        }
        else if(isupper(r[i])){
            flag = 0;
        }
    }
    
    if(count != 1){
        flag = 0;
    }
    
    if(isupper(r[strlen(r)-1])){
        flag = 0;
    }
    
    std::cout << ((flag)? "AC" : "WA" )<< std::endl;
    
    return 0;
    
}


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

namespace ABC096
{
    class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = input[0];
            int b = input[1];
            int result = 0;

            if(a == 1 && a < b) {
                result++;
            }
            else {
                if (a <= b) {
                    result = a;
                }
                else {
                    result = a - 1;
                }
            }
            

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std;
#define MAX 200005
#define MOD 998244353
#define EPS 0.00000000001
#define INF 998244353
int c[4];
char s[6];

int main()
{
    int n,i;
    scanf("%d ",&n);
    for(i=0;i<n;i++)
    {
        scanf("%c%c",&s[0],&s[1]);
        if(s[0]=='T')
        {
            scanf("%c",&s[2]);
        }
        scanf("%*c");
        if(s[0]=='A') c[0]++;
        else if(s[0]=='W') c[1]++;
        else if(s[0]=='T') c[2]++;
        else c[3]++;
    }
    printf("AC x %d\n",c[0]);
    printf("WA x %d\n",c[1]);
    printf("TLE x %d\n",c[2]);
    printf("RE x %d",c[3]);
    return 0;
}


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

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    vector<i64> a(n), b(n);
    for (i64 i = 0; i < n; i++) cin >> a[i] >> b[i];

    i64 cnt = 0;
    for (i64 i = n - 1; i >= 0; i--) cnt += (b[i] - (a[i] + cnt) % b[i]) % b[i];
    cout << cnt << endl;
}

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


Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
	char a[2];
	char sign='A';

	while(scanf("%c,%c",&a[0],&a[1]) != EOF){
		if(a[0] == sign)
			sign = a[1];
	        else if(a[1] == sign)
			sign = a[0];
	}
	printf("%c\n",sign);
	return 0;
}

Measured memory_bytes: 544
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for (v = 0; v < n; v++) {
    if (M[u][v] == 0) {
      continue;
    }
    if (color[v] == WHITE) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs() {
  int u;
  
  for (u = 0; u < n; u++) {
    color[u] = WHITE;
  }
  tt = 0;
  
  for (u = 0; u < n; u++) {
    if (color[u] == WHITE) {
      dfs_visit(u);
    }
  }
  for (u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k, i, j;
  
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      M[i][j] = 0;
    }
  }
  
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    u--;
    for (j = 0; j < k; j++) {
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  dfs();
  
  return 0;
}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll n; cin >> n;
	ll arr[n+5];
	rep(i,1,n) cin >> arr[i];
	
	ll ans = 0;
	ll curr = 1;
	
	rep(i,1,n){
	    if(arr[i] == curr){
	        curr++;
	    }
	    else{
	        ans++;
	    }
	}
	
	if(ans != n)
	cout << ans << endl;
	else
	cout << "-1\n";
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, x, y;

    cin >> n >> m >> x >> y;

    int a[n];
    int b[m];

    int i;

    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    sort(a, a + n);
    sort(b, b + m);

    n = max(x, a[n - 1]);
    m = min(y, b[0]);

    if (n < m) Out("No War");
    else Out("War");

    return 0;
}


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

#define int long long
int w,h;
int ans=INF;
signed main(){
  cin>>h>>w;
  //  if(w%3==0||h%3==0){
  //    cout<<0<<endl;
  //   return 0;
  //  }
  // if(w==2||h==2){
  //   cout<<1<<endl;
  //   return 0;
  // }

  for(int a=1;a<w;a++){
    int b=w-a;
    int temp=a*h;
    int kans=max(b*((h+1)/2),temp);
    int lans=min(temp,b*(h/2));
    //cout<<" "<<kans-lans<<endl;
    //大-小
    ans=min(kans-lans,ans);
  }
  //たて
  ans=min(ans,(((w+2)/3)-(w/3))*h);
  swap(h,w);

  for(int a=1;a<w;a++){
    int b=w-a;
    int temp=a*h;
    int kans=max(b*((h+1)/2),temp);
    int lans=min(temp,b*(h/2));
    //cout<<"kans"<<kans<<endl;
    //大-小
    ans=min(kans-lans,ans);
  }
  //たて
  ans=min(ans,(((w+2)/3)-(w/3))*h);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)

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


int n,m;
int max_m=300;
int a[300][300];
int ans=300;
bool used[300];
int pos[300];


int main(){
    cin>>n>>m;
    rep(i,0,n-1)rep(j,0,m-1){cin>>a[i][j];a[i][j]--;}
    memset(used,false,sizeof(used));
    int q=m;
    while(q--){
        int count[m];
        memset(count,0,sizeof(count));
        rep(i,0,n-1){
            count[a[i][pos[i]]]++;
        }
        int max=count[0],maxm=0;
        rep(i,1,m-1){
            if(count[i]>max){
                maxm=i;
                max=count[i];
            }
        }
        if(ans>max)ans=max;
        used[maxm]=true;
        rep(i,0,n-1){
            if(a[i][pos[i]]==maxm){
                pos[i]++;
                while(pos[i]<=m-1&&used[a[i][pos[i]]]==true){
                    pos[i]++;
                }
            }
        }
        
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(){
	char S[100000];
	scanf("%s",S);

	int length = strlen(S);
	int K = strlen(S);
	
	for ( int i=0; i<length-1 ; i++ ) {
		if ( S[i+1] != S[i] ) {
			if( 2*(i+1) < length) {
				K = length - (i+1) ;
			} else if ( i+1<K ) {
				K = i+1;
			}
		}
	}
	printf("%d",K); 
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int s;
  cin>>s;
  bool flag=0;
  int n=1;
  vector<int>a(n);
  a[0]=s;
  while(flag==0){
    if(a[n-1]%2==1){
 
      n++;
      a.resize(n);
      a[n-1]=a[n-2]*3+1;
    }
    else{
          
      n++;
      a.resize(n);
      a[n-1]=a[n-2]/2;
    }
    for(int i=0;i<=n-2;i++){
    
      if(a[i]==a[n-1]){
        
        flag=1;
        break;
      }
    }
  }
 /* for(int i=0;i<=n-1;i++){
  
    cout<<a[i]<<endl;
  }*/
  cout<<n;
  return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll dist(ll ji,ll t,ll x){
  if(ji>x&&t>x)return max(t,ji)-x;
  else if(ji<x&&t<x)return abs(min(t,ji)-x);
  else{
    if(abs(x-ji)>abs(x-t)){
      return abs(x-ji)+2*abs(x-t);
    }else{
      return abs(x-t)+2*abs(x-ji);
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,q;cin>>a>>b>>q;
  vi A(a);
  vi B(b);
  for(auto &aa:A)cin>>aa;
  for(auto &bb:B)cin>>bb;
  for(int i=0;i<q;i++){
    ll ans=0;
    ll x;cin>>x;
    auto ho = lower_bound(ALL(A),x);
    auto ho2 = lower_bound(ALL(B),x);
    ll num=*ho;
    ll num2=*ho;
    if(ho == A.begin()){
    }else if(ho == A.end()){
      --ho;
      num=*ho;
      num2=*ho;
    }else{
      ho--;
      num2=*ho;
    }
    ll numm=*ho2;
    ll numm2=*ho2;
    if(ho2 == B.begin()){
    }else if(ho2 == B.end()){
      --ho2;
      numm=*ho2;
      numm2=*ho2;
    }else{
      ho2--;
      numm2=*ho2;
    }
    //cout<<num<<" "<<num2<<" "<<numm<<" "<<numm2<<endl;
    cout<<min(min(dist(num2,numm,x),dist(num2,numm2,x)),min(dist(num,numm,x),dist(num,numm2,x)))<<endl;
  }
  return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s;
    ll n,a,b; cin >> n >> a >> b;
    ll ans = a * (n/(a+b));
    n %= (a+b);
    ans += min(a, n);
    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long lint;
typedef vector<lint> vl;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) REP(i,0,b)
#define maxn 100010

int n;

lint f(lint s, vl v){
	lint ans=0LL, x,t=0LL,y;
	REP(i,0,n){
		s*=(-1LL); 				//change sign
		if((s==-1LL&&(t+v[i])>=0)||(s==1LL&&(t+v[i])<=0)){
			x=s*(1LL)-t;
			y=abs(x-v[i]);
			v[i]=x;
			ans+=y;
		}
		t=t+v[i];
	}
	return ans;
}

int main(){
	while(scanf("%d",&n)==1){
		vl arr(maxn);
		lint a;
		rep(i,n){
			scanf("%lld",&arr[i]);
		}
		lint x=f(-1LL,arr);
		lint y=f(1LL,arr);
		lint ans=min(x,y);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	int t=1;
	//cin>>t;
	while(t--){
		//vector<int> v;map<int,int> mp;set<int> st;
		int ans=0;
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) if(i%3 and i%5) ans+=i;
		//int a[n];rep(i,n) cin>>a[i];
		cout<<ans;
	}
	return 0;
}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int a;
  cin >> a;
	string s;
  cin >> s;
  
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  
}

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

using namespace std;

int N, digit, counter;
bool ok = false;

int main()
{
        cin >> N;

        digit = N % 10;
        counter = 1;
        N /= 10;

        while (N > 0)
        {
                int currentDigit = N % 10;
                if (digit == currentDigit)
                {
                        ++counter;
                        if (counter == 3)
                                ok = true;
                }
                else
                {
                        digit = currentDigit;
                        counter = 1;
                }

                N /= 10;
        }

        if (ok == true)
                cout << "Yes";
        else
                cout << "No";

        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define lvi vector<long long>
#define pi pair<int,int>
#define lpi pair<long long ,long long>
#define mp make_pair
#define pb push_back
#define ll long long 
#define N 100005
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define mod1 1000000000000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>multiordered_set;
ll int pw(ll int a, ll int b,ll md) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2,md);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
vector<int> pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.push_back(p);
}
bool cmp(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}
ll int gcd(ll int a,ll int b)
{
    if(!a)return b;
    return gcd(b%a,a);
}
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
    return true; 
} 
map<int,int>pa;
int find(int i){
    if(pa[i]==i)return i;
    return pa[i]=find(pa[i]);
}     
void join(int i,int j){
    int a=find(i);
    int b=find(j);
    if(b>=a)pa[b]=a;
    else pa[a]=b;
}               
int ddx[]={-1,-1,-1,0,1,1,1,0};
int ddy[]={-1,0,1,1,1,0,-1,-1};
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int main()
{
    faltu;
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,cnt=0;
        cin>>n;
        int a[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                 int ab = a[i]+a[j];
                 int r = lower_bound(a,a+n,ab)-a;
                 int l = j+1;
                 cnt+= max(0,r-l);
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	char input[100001];
	long long n, m;
	string s, t;
	vector<long long> pos[26];
	vector<long long>::iterator ret;
	long long i, j;
	long long sol = 0;
	bool change = true;

	scanf("%s", input);
	s = input;
	n = s.size();
	scanf("%s", input);
	t = input;
	m = t.size();

	for (i = 0; i < n; i++)
	{
		pos[s[i] - 'a'].push_back(i);
	}

	j = 0;

	for (i = 0; i < m; i++)
	{
		ret = lower_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), j);

		if (ret == pos[t[i] - 'a'].end())
		{
			if (!change)
			{
				printf("-1\n");

				return 0;
			}

			j = 0;

			sol += n;

			i--;

			change = false;
		}

		else
		{
			change = true;

			j = *ret + 1;
		}
	}

	sol += j;

	printf("%lld\n", sol);

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
  using namespace std;
  int main()
  {
    int n, q, num, m;
    int A[2001]={1};
      cin>>n;
    for(int i=0; i<n; i++){
      cin>>num;
      for(int j=2000-num; j>=0; j--){
        if(A[j]) A[j+num] = 1;
      }
    }

      cin>>q;
    for(int i=0; i<q; i++){
      cin>>m;
      if(A[m])
        cout<<"yes"<<endl;
      else
        cout<<"no"<<endl;
    }

    return 0;
  }



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

void insertionSort(int a[],int n){
	int i,k;
	for(i=1; i<=n-1; i++){
		int v=a[i];
		int j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
			a[j+1]=v;
		}
		for(k=0; k<n; k++){
			cout<<a[k];
			if(k!=n-1) cout<<" ";
		}
		cout<<"\n";
	}
}

int main(){
	int n,i;
	cin>>n;
	int a[n];
	for(i=0; i<n; i++){
		cin>>a[i];
	}
	for(i=0; i<n; i++){
		cout<<a[i];
		if(i!=n-1) cout<<" ";
	}
	cout<<"\n";
	insertionSort(a,n);
	return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val k = sc.nextInt
  val q = sc.nextInt

  val v =  q - k

  val al = Seq.fill(q)(sc.nextInt)

  if(v < 0) (1 to n).foreach(_ =>println("Yes"))
  else {
    val m =
      al.zipWithIndex
        .groupBy(_._1)
        .mapValues{ a =>
          if(a.size > v) "Yes"
          else "No"
        }

    (1 to n).foreach{i =>
      println(m.getOrElse(i, "No"))
    }
  }
}

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

int main(){
  int n,k;
  cin >>n>>k;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin >>p.at(i);
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=p.at(i);
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 3624
program prob3
    implicit none
    character(len=105)::s
    integer::i, l, mode, cnt, tmp
    integer(16)::k
    read(*,*) s
    read(*,*) k
    l = len_trim(s)
    cnt = 0
    mode = 0
    do i = 1, l
        if(s(i:i) == "1" .and. mode == 0) then
            cnt = cnt + 1
        else
            mode = 1
            tmp = i
            exit
        end if
    end do
    if(cnt >= k) then
        write(*,'(a)') "1"
    else
        write(*,'(a)') trim(adjustl(s(tmp:tmp)))
    end if
    stop
end program

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int n, a[maxn];
bool dp[maxn][2];

bool dfs(int k, int num) {
    if (dp[k][num]) return dp[k][num];
    for (int i = 1; i <= n; i++) {
        if (k >= a[i]) {
            if (!dfs(k - a[i], !num)) {
                return dp[k][num] = true;
            }
        }
    }
    return dp[k][num] = false;
}

int main() {
    int k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    printf("%s\n", (dfs(k, 0) ? "First" : "Second"));
	return 0;
}


Measured memory_bytes: 5120
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<cctype>
#define INF 100000000
using namespace std;

struct  coor
{
	int x, y;
};

char map[1002][1002];
int tim[1002][1002];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int h, w, n;
coor s;
coor fac[10];
int phy;
int ans;


int bfs(coor fa)
{
	coor next;
	coor now;
	queue<coor>q;
	q.push(s);
	while (!q.empty())
	{
		now = q.front();
		q.pop();
		if (now.x == fa.x&&now.y == fa.y)
		{
			break;
		}
		for (int i = 0;i < 4;i++)
		{
			next.x = now.x + dx[i];
			next.y = now.y + dy[i];
			if (map[next.x][next.y] != 'X'&&next.x >= 0&& next.x < h &&next.y >= 0 && next.y < w && tim[next.x][next.y] ==INF)
			{
				tim[next.x][next.y] = tim[now.x][now.y] + 1;
				q.push(next);
			}
		}
	}
	return tim[fa.x][fa.y];
}

void timeinit(coor st)
{
	for (int i = 0;i < h;i++)
	{
		for (int j = 0;j < w;j++)
		{
			if (map[i][j] != 'X')
				tim[i][j] = INF;
		}
	}
	tim[st.x][st.y] = 0;

}
int main()
{
	while (~scanf("%d%d%d",&h,&w,&n))
	{
		getchar();
		for (int i = 0;i < h;i++)
		{
			for (int j = 0;j < w;j++)
			{
				scanf("%c", &map[i][j]);
				tim[i][j] = INF;
				if (map[i][j] == 'S') { map[i][j] = '.';s.x = i;s.y = j; }
				if (isdigit(map[i][j]))
				{
					fac[map[i][j] - '0'].x = i;
					fac[map[i][j] - '0'].y = j;
				}
			}
			getchar();
		}

		phy = 1;
		tim[s.x][s.y] = 0;
		ans = 0;
		for (int i = 1;i <= n ;i++)
		{
			ans += bfs(fac[i]);
			s.x = fac[i].x;
			s.y = fac[i].y;
			timeinit(s);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 7556
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main()
{
    int i = 1;
    int n;
    while (cin >> n) {
        if (n != 0) {
            cout << "Case " << i << ": " << n << endl;
            i++;
        } else {
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 3036
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

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

    int64_t rt, ra;
    rep(i, n)
    {
        int t, a;
        cin >> t >> a;

        if (i == 0) {
            rt = t;
            ra = a;
        } else {
            int64_t x = 0;
            x = max(x, dceil(rt, t));
            x = max(x, dceil(ra, a));
            rt = x * t;
            ra = x * a;
        }
    }
    int64_t result = rt + ra;
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#include<iomanip>
#define IO ios::sync_with_stdio(false)
#define eps 1e-7
#define int long long
using namespace std;
const int mod=1e9+7;
int d,t,s;
signed main()
{
	cin>>d>>t>>s;
	if(s*t>=d)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
 } 

Measured memory_bytes: 3628
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k, s = rm()
cnt = 0
for x in range(k, -1, -1):
    for y in range(k, -1, -1):
        if 0 <= s-x-y <= k:
            cnt += 1
print(cnt)















Measured memory_bytes: 27080
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=1e6+10,P=1e9+7;
int a,b,c,f[N],fac[N],ifac[N],inv[N],ff;
long long ans;
int C(int n,int k){
    if(n<k||k<0) return 0;
    return 1ll*fac[n]*ifac[k]%P*ifac[n-k]%P;
}
void pre(int n){
    fac[0]=1;rep(i,1,n) fac[i]=1ll*fac[i-1]*i%P;
    inv[1]=1;rep(i,2,n) inv[i]=1ll*(P-P/i)*inv[P%i]%P;
    ifac[0]=1;rep(i,1,n) ifac[i]=1ll*ifac[i-1]*inv[i]%P;
}
int main(){
    scanf("%d%d%d",&a,&b,&c);pre(a+b+c);f[0]=1;
    rep(i,1,b+c) f[i]=3ll*f[i-1]%P;
    if(b>c) swap(b,c);ff=1;
    rep(i,0,b+c){
        ans+=1ll*f[b+c-i]*C(a-1+i,i)%P*ff%P;
        ff=ff*2%P;
        if(i>=b) ff=(ff-C(i,b)+P)%P;
        if(i>=c) ff=(ff-C(i,c)+P)%P;
    }
    printf("%lld\n",ans%P);
    return 0;
}

Measured memory_bytes: 16720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
string s;
cin >> s;
int r=0,b=0;
rep(i,s.size()){
  if(s.at(i)=='0')r++;
  else b++;
}
int ans = min(r,b)*2;
cout << ans << endl;
}


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

string calcAddition( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "0", t = "0";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    for( int i = s.size() - 1; i >= 1; i-- )
    {
        s[i] += t[i] - '0';
        if( s[i] > '9' )
        {
            s[i] -= 10;
            s[i-1]++;
        }
    }
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

string calcSubtraction( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "", t = "";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    if( s < t )
    {
        string temp = s;
        s = t;
        t = temp;
    }

    for( int i = s.size() - 1; i >= 0; i-- )
    {
        if( s[i] < t[i] )
        {
            s[i] += 10;
            if( s[i-1] >= '1' )
                s[i-1]--;
            else
            {
                int j = i - 1;
                while( s[j] == '0' )
                    s[j--] += 9;
                s[j]--;
            }
        }
        s[i] -= ( t[i] - '0' );
    }
    if( s.size() == 1 )
        return s;
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

int main()
{
    string a, b;

    cin >> a >> b;

    int as = a.size(), bs = b.size();
    string s = a.substr( 1, as ), t = b.substr( 1, bs );
    int ss = s.size(), ts = t.size();

    if( a[0] == '-' && b[0] == '-' )
        cout << "-" << calcAddition( s, t ) << endl;
    else if( a[0] >= '0' && b[0] >= '0' )
        cout << calcAddition( a, b ) << endl;
    else if( a[0] == '-' )
    {
        if( ss > bs || ss == bs && s > b )
            cout << "-";
        cout << calcSubtraction( s, b ) << endl;
    }
    else
    {
        if( as < ts || as == ts && a < t )
            cout << "-";
        cout << calcSubtraction( a, t ) << endl;
    }
    return 0;
}



Measured memory_bytes: 3936
n, q = [int(i) for i in input().split() ]
s = input() #文字列
lr = list([])
count = [0 for i in range(n)]
for i in range(q):
    lr.append([int(i) for i in input().split() ])

ll = list([])
now = 0
for i, c in enumerate(s):
    if((c == "C") and (i>0) and (s[i-1] =="A")):
        now += 1
    count[i] = now

for i in range(q):
    ans = 0
    print(count[lr[i][1]-1] - count[lr[i][0]-1])

Measured memory_bytes: 24404
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
ll n;
vector<vl> adj;
vector<bool> visitedd;
void dfs(ll node)
{
	visitedd[node]=true;
	for(auto x: adj[node])
	{
		if(visitedd[x]==false)
		{
			dfs(x);
		}
	}
}
void solve()
{
	ll m;
    cin>>n>>m;
    visitedd.resize(n, false);
    adj.resize(n);
    forr(i, m)
    {
    	ll u, v;
    	cin>>u>>v;
    	--u, --v;
    	adj[u].pb(v), adj[v].pb(u);
    }
    ll ans=0;
    forr(i, n)
    {
    	if(visitedd[i]==false)
    	{
    		dfs(i);
    		ans++;
    	}
    }
    cout<<ans-1<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 10028
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
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 inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi  
    int n;
    cin>>n;
    int dp[n+5];
    for(int i=0;i<n+5;i++)
    dp[i]=0;
    dp[0]=1;
    for(int i=3;i<=n;i++)
    {   for(int j=3;j<=i;j++)
        dp[i]=((dp[i]%M)+(dp[i-j])%M)%M;
    }
    cout<<dp[n];
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  int x,a;
  cin>>x>>a;
  
  if(x<a) cout <<0<<endl;
  else cout<<10<<endl;
  
  
  return 0;
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int a, b, t;
int main() {
	std::cin >> a >> b >> t;

	std::cout << t / a * b << std::endl;
	return 0;
}


Measured memory_bytes: 256
/*
 * FileName:     partition
 * CreatedDate:  2020-08-13 01:31:30 +0900
 * LastModified: 2020-08-13 01:49:28 +0900
 */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;scanf("%d", &n);
    int *A = malloc(n*sizeof(int));
    for(int i=0; i<n; i++)scanf("%d", A+i);
    int swap_obj = 0;
    int pivot = A[n-1];
    for(int i=0; i<n-1; i++){
        if(pivot >= A[i]){
            int tmp = A[i];
            A[i] = A[swap_obj];
            A[swap_obj++] = tmp;
        }
    }
    int tmp = A[n-1];
    A[n-1] = A[swap_obj];
    A[swap_obj] = tmp;
    printf("%d", A[0]);
    for(int i=1; i<n; i++){
        if(i==swap_obj){
            printf(" [%d]", A[i]);
        }
        else{
            printf(" %d", A[i]);
        }
    }
    printf("\n");
    free(A);
    return 0;
}



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

vector<int> adj[15];

bool vis[15];
void dfs(int node){
	vis[node] = 1;
	for(int i=0;i<adj[node].size();++i){
		int c = adj[node][i];
		if(!vis[c]){
			dfs(c);
		}
	}
}
void solve(){
	for(int i=0;i<3;++i){
		int a,b;
		scanf("%d%d",&a,&b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(1);
	bool can = true;
	for(int i=1;i<=4;++i){
		if(!vis[i]){
			can = false;
		}
		if(adj[i].size()>2){
			can = false;
		}
	}
	if(can){
		printf("YES\n");
	} else {
		printf("NO\n");
	}

}
int main(){
	//freopen("input.txt","r",stdin);
	solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,r[1000],p,cnt1,cnt2;
    while(cin>>a>>b>>c)
    {
        int d;
        cnt1=0;
        cnt2=0;
        for(int j=0;j<=a;j++)
        {
            r[j]=0;
        }
        for(int j=1;j<=b;j++)
        {
            cin>>p;
            r[p]=1;
        }
        r[0]=0;
        r[c]=0;
        r[a]=0;
        for(int j=c;j<=a;j++)
        {
            if(r[j]==1)
            {
                cnt1++;
            }
        }
         for(int j=c;j>=0;j--)
        {
            if(r[j]==1)
            {
                cnt2++;
            }
        }


      if(cnt1<=cnt2)
      {
          cout<<cnt1<<endl;
      }
      else
      {
          cout<<cnt2<<endl;
      }

    }



    return 0;
}


Measured memory_bytes: 256