akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int len = s.size();
    
    string result1;
    string result2;
    result1.resize(len, '0');
    result2.resize(len, '0');
    for (int i = 0; i < len; i++) {
        if (i%2==0) {
            result1[i] = '0';
            result2[i] = '1';
        } else {
            result1[i] = '1';
            result2[i] = '0';
        }
    }
    
    int count1 = 0;
    int count2 = 0;
    for (int i = 0; i < len; i++) {
        if (s[i] != result1[i]) {
            count1++;
        }
        if (s[i] != result2[i]) {
            count2++;
        }
    }
    
    int ans = min(count1, count2);
    
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	cout << (A[N - 1] - A[0]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807int
#define I64_MAX2 1223372036854775807int
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION  
 
//solve

void solve(void)
{
  double N,M;
  cin>>N>>M;
  double X = 1900*M + 100*(N-M);
  double ANS = 0;
  double P = pow(0.5,M);
  double Q = 1-P;
  for (int i = 0; i < 10000; i++)
  {
  ANS += X*(1+i)*P*pow(Q,i);
    // DEBUG(ANS);
  }
  ANS += 0.01;
  cout<<(int)ANS<<endl;
  


  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int x,n;
    cin >> x >> n;
    vector <int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));

    //ans>x
    int big;
    for(int i=x; i<=101; i++){
        int tmp = count(all(p),i);
        if(tmp == 0){
            big = i;
            break;
        }
    }

    int small;
    for(int i=x; i>=-1; i--){
        int tmps = count(all(p),i);
        if(tmps == 0){
            small = i;
            break;
        }
    }
    int b=abs(x-big), s=abs(x-small);
    if(b >= s){
        cout << small << endl;
    }
    else{
        cout << big << endl;
    }
    
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
    double x1,x2,y1,y2;
    scanf("%lf %lf %lf %lf",&x1,&x2,&y1,&y2);
    double x=(x1-y1)*(x1-y1)+(x2-y2)*(x2-y2);
    printf("%f\n",sqrt(x));
    return 0;
}

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

int main(){
    char a[1200] = {0};
    string b;
    getline(cin,b);
    b.copy(a,b.size());
    a[b.size()]='\0';
    for(int i = 0; a[i] != '\0'; ++i){
        if(islower(a[i])){
            a[i] = toupper(a[i]);
        }else if(isupper(a[i])){
            a[i] = tolower(a[i]);
        }
    }

    cout << a<<endl;
}

Measured memory_bytes: 3132
N = int(input())
A = [a for a in range(2, N+1)]
T = 1
while len(A)>0:
  X = A[0]
  T *= sum(N//(X**i) for i in range(1, 11))+1
  A = [a for a in A if a%A[0]]
print(T%(10**9+7))

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<ll> a(n);
    vector<ll> d(100001,0);
    rep(i,n) cin >> a[i];
    rep(i,n){
        d[a[i]]++;
        ans+=a[i];
    }
    ll q;
    cin >> q;
    for(ll i=0;i<q;i++){
        ll b,c;
        cin >> b >> c;
        ll kazu=d[b];
        ans+=kazu*(c-b);
        cout << ans << endl;
        d[b]=0;
        d[c]+=kazu;
    }
    
    
    return 0;
}











Measured memory_bytes: 4768
function Main(input) {
	input = input.split("\n");
    s = input[0];
    t = input[1];
    
    let cnt = 0;
    for(let i = 0; i < s.length; i++ ){
        if(s[i] !== t[i]){
            cnt++;
        }
    }

    console.log(cnt);

}

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


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

int main() {
	int n, k, m = 0;
	cin >> n >> k;
	int v[55];
	for (int i = 0; i < n; i++)
		cin >> v[i];
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n + 1; j++) {
			if (i + n - j > k) continue;
			vector<int> u;
			for (int l = 0; l < i; l++)
				u.push_back(v[l]);
			for (int l = j; l < n; l++)
				u.push_back(v[l]);
			sort(u.begin(), u.end());
			int s = 0;
			for (int x : u) s += x;
			for (int l = 0; l < min((int)u.size(), k - (i + n - j) + 1); l++)
				m = max(m, s), s -= u[l];
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;


namespace AtCoder_ABC_A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            //int n = int.Parse(Console.ReadLine());　
            //List<int> intNumsList = new List<int>();          //リストintNumsを初期化
            //int[] intNumsArray = new int[n];                        //配列intNumsを初期化

            //intNumsList = inputAndSetNumsToList(n);             //IF YOU WANT TO USE LIST, CHOOSE THIS
            //intNumsArray = inputAndSetNumsToArray(n);       ////IF YOU WANT TO USE ARRAY, CHOOSE THIS

            String strLine = Console.ReadLine();        //入力を受けとりString型に代入
            String[] strSplited = strLine.Split(' ');       //Stringを数字ごとに分割しString配列に代入
            int n = int.Parse(strSplited[0]);
            int l = int.Parse(strSplited[1]);
            int[] ajiScore = new int[n];
            int totalAjiScore = 0;
            int eatedApple = 0;        //Absが最も小さいりんご
            int ans;

            for (int i = 0; i < n; i++)
            {
                ajiScore[i] = l + i ;
                if(i == 0)
                {
                    eatedApple = i;
                }else if(Math.Abs(ajiScore[eatedApple]) > Math.Abs(ajiScore[i])) {
                    eatedApple = i;
                }
                totalAjiScore += ajiScore[i];
            }

            ans = totalAjiScore - ajiScore[eatedApple];
            Console.WriteLine(ans);
        }


        
        public static  List<int> inputAndSetNumsToList(int n)
        {
            List<int> getIntNums = new List<int>();     //リストgetIntNumsを初期化
            
            String strLine = Console.ReadLine();        //入力を受けとりString型に代入
            String[] strSplited = strLine.Split(' ');       //Stringを数字ごとに分割しString配列に代入

            for (int i = 0; i < n; i++)
            {
                getIntNums.Add(int.Parse(strSplited[i]));   //リストintNumsにString配列の中身を代入
            }
            return getIntNums;
        }

        

        public static int[] inputAndSetNumsToArray(int n)
        {
            int[] getIntNums = new int[n];      //配列getIntNumsを初期化

            String strLine = Console.ReadLine();        //入力を受けとりString型に代入
            String[] strSplited = strLine.Split(' ');       //Stringを数字ごとに分割しString配列に代入

            for (int i = 0; i < n; i++)
            {
                getIntNums[i] = int.Parse(strSplited[i]);   //リストintNumsにString配列の中身を代入
            }
            return getIntNums;
        }

    }
}


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

typedef long long lli;

lli dupPerm(int n, int k){ // select k items from {1,2,...,n}
  lli ans = 1;
  for (int i=0; i<k; i++){
    ans *= n;
  }
  return ans;
}

int main(void){
  int n,k;
  lli ans;
  cin >> n >> k;
  
  // %k = 0
  ans = dupPerm(n/k, 3);
  // %k = k/2
  if (k%2 == 0){
    ans += dupPerm((n+k/2)/k, 3);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let bd: Vec<Vec<char>> = (0..n)
        .map(|_| sc.next::<String>().chars().collect())
        .collect();

    // let mut all_same = true;
    // 'outer: for i in 0..n {
    //     for j in 0..n {
    //         if bd[0][0] != bd[i][j] {
    //             all_same = false;
    //             break 'outer;
    //         }
    //     }
    // }

    // if all_same {
    //     println!("{}", n * n);
    //     return;
    // }

    let mut nbd: Vec<Vec<char>> = vec![vec![' '; 2 * n]; 2 * n];
    for i in 0..2 * n {
        for j in 0..2 * n {
            nbd[i][j] = bd[j % n][i % n];
        }
    }

    let mut rbd: Vec<Vec<char>> = vec![vec![' '; 2 * n]; 2 * n];

    for i in 0..2 * n {
        for j in 0..2 * n {
            rbd[i][j] = nbd[j][i];
        }
    }

    let mut ans = 0;
    for a in 0..n {
        for b in 0..n {
            let mut ok = true;
            for i in 0..n {
                let r1 = &nbd[(i + a) % n];
                let r2 = &rbd[(i + b) % n];

                if &r1[b..b + i] != &r2[a..a + i] {
                    ok = false;
                    break;
                }

                // unsafe {
                //     for j in 0..i {
                //         if *r1.get_unchecked(j + b) != *r2.get_unchecked(j + a) {
                //             ok = false;
                //         }
                //     }
                // }
            }

            if ok {
                ans += 1;
            }
        }

        if n >= 250 && ans >= n * n / 2 && ans == (a + 1) * n {
            ans = n * n;
            break;
        }
    }

    println!("{:?}", ans);
}

//-----

pub mod io {
    use std;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T>(&mut self) -> T
        where
            T: std::str::FromStr,
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            let s = self.iter.next().unwrap();
            s.parse::<T>().unwrap()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 6524
#include<bits/stdc++.h>
using namespace std;
const int N=222;
char s[N][N];
int n;
int dis[N];
void bfs(int f){
	memset(dis,0x3f,sizeof(dis));
	queue<int> q;
	q.push(f);
	dis[f]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<n;i++){
			if(s[x][i]=='1'&&dis[x]+1<dis[i]){
				dis[i]=dis[x]+1;
				q.push(i);
				// cerr<<i<<" "<<dis[i]<<endl;
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			while(!isdigit(s[i][j]=getchar()))
				;
		}
	}
	bfs(0);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(s[i][j]=='1'&&!((dis[i]^dis[j])&1)){
				// cerr<<i<<" "<<j<<endl;
				puts("-1");
				exit(0);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		bfs(i);
		for(int j=0;j<n;j++){
			ans=max(ans,dis[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
	int i, n;
	int max_count;
	int max_len;
	int flag;
	int count[2][1000];
	char data[1000][33];
	char str[33];
	
	n = 0;
	max_len = 0;
	max_count = 0;
	memset(count, 0, sizeof(count));
	while (scanf("%s", str) != EOF){
		flag = 0;
		for (i = 0; i < n; i++){
			if (!strcmp(data[i], str)){
				count[1][i]++;
				flag = 1;
				
				if (count[1][max_count] < count[1][i]){
					max_count = i;
				}
			}
		}
		
		if (!flag){
			strcpy(data[++n], str);
			count[0][n] = strlen(str);
			
			if (count[0][n] > count[0][max_len]){
				max_len = n;
			}
		}
	}
	
	printf("%s %s\n", data[max_count], data[max_len]);
	
	return (0);
}

Measured memory_bytes: 576
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int k = 7;
int a[7];

int read() {
  for (int i = 0; i < k; ++i) {
    if (scanf("%d", a + i) < 1) {
      return 0;
    }
  }
  return 1;
}

void solve() {
  long long res = a[1];
  res += a[0];
  res += a[3];
  res += a[4];

  int best = (a[0] & 1) + (a[3] & 1) + (a[4] & 1);
  if (a[0] && a[3] && a[4]) {
    best = min(best, 3 - best);
  }
  res -= best;
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main() {
  int a, b;
  string n;
  cin >> a >> b;
  
  int cnt = 0;
  for (int i = a; i <= b; ++i) {
    n = to_string(i);
    if (n.at(0) == n.at(4) && n.at(1) == n.at(3)) { ++cnt; }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3660
while True:
    n, p = map(int, input().split())
    if n == 0 and p == 0:
        break
    originalP = p
    stone = [0 for i in range(n)]
    i = 0
    while True:
        if p != 0:
            stone[i] += 1
            p -= 1
        elif p == 0 and stone[i] > 0:
            p += stone[i]
            stone[i] = 0
        if stone[i] == originalP:
            break
        i += 1
        if i >= n:
            i = 0
    print(i)


Measured memory_bytes: 5600
M=10**9+7
n,k,*a=map(int,open(y:=0).read().split())
a.sort()
x=s=1
r=k
while r>1:
 if(t:=a[y]*a[y+1])>a[-x]*a[~x]:s=s*t%M;y+=2;r-=2
 else:s=s*a[-x]%M;x+=1;r-=1
if r:s*=a[-x]
if a[-1]<0<k%2:
 s=1
 for i in a[-k:]:s=s*i%M
print(s%M)

Measured memory_bytes: 31764
#include <stdio.h>

int main(){
  int a;
  scanf("%d",&a);
  int b1, b2, b3;
  b1 = a % 10;
  b2 = (int)(a / 10) % 10;
  b3 = (int)(a / 100);
  if(b1 == 7 || b2 == 7 || b3 == 7){
    printf("Yes");
  }else{
    printf("No");
  }
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll A, B; cin >> A >> B;
  string s = ".#";
  //A>Bなら白黒の役割入れ替える
  if(A>B){
    swap(A,B);
    s = "#.";
  }
  //以下，A<=B
  //Aの方にs[0],Bの方にs[1]を割り当てる
  vector<string> grid(100);
  REP(i,100) REP(j,100) grid[i].push_back(s[0]);

  //左上(x,y)として黒の連結成分つくる
  auto create_black = [&](ll x, ll y){
    REP(i,3) REP(j,3) if(i!=1||j!=1){
      grid[x+i][y+j] = s[1];
    }
  };

  //黒の連結成分B個つくる
  ll yoko = B%25;
  ll tate = B/25+1;
  REP(i,tate){
    ll L = (i==tate-1) ? yoko : 25;
    REP(j,L){
      create_black(4*i,4*j);
    }
  }
  //このとき白の連結成分B+1個できている
  //A個に減らすため，B-A+1個塗りつぶす
  yoko = (B-A+1)%25;
  tate = (B-A+1)/25+1;
  REP(i,tate){
    ll  L = (i==tate-1) ? yoko : 25;
    REP(j,L){
      grid[1+4*i][1+4*j] = s[1];
    }
  }

  cout << 100 << " " << 100 << endl;
  REP(i,100) cout << grid[i] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

void ushiro(char *c){
  int i;
  for(i=0; i<12; i++){
    if(c[i]=='\0'){
      break;
    }
  }
  for(int j=0; j<=i; j++){
    c[11-i+j]=c[j];
  }
  for(int j=0; j<11-i; j++){
    c[j]='0';
  }
  return;
}

int main(){
  
  int a, b;
  scanf("%d %d", &a,&b);
  char x[11], y[11];
  char x2[11], y2[11];
  
  for(int i=0; i<=a; i++){
    x[i] = (char)'0'+(char)b;
    if(i==a) x[i]='\0';
  }
  for(int i=0; i<=b; i++){
    y[i] = (char)'0'+(char)a;
    if(i==b) y[i]='\0';
  }
  if(a==0){
    x[0]='0';
    x[1]='\0';
  }
  if(b==0){
    y[0]='0';
    y[1]='\0';
  }
  strcpy(x2,x);
  strcpy(y2,y);
  ushiro(x);
  ushiro(y);
  if(strcmp(x,y)>0){
    for(int i=0; i<a; i++){
      printf("%c", x2[i]);
    }
  }else{
    //printf("a");
    for(int i=0; i<b; i++){
      printf("%c", y2[i]);
    }
  }
  
  return 0;
}

Measured memory_bytes: 128
fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }

    val lm = mutableMapOf<Int, Long>()
    val rm = mutableMapOf<Int, Long>()

    for (i in a.indices) {
        val l = i + a[i]
        lm[l] = (lm[l] ?: 0) + 1
        val r = i - a[i]
        rm[r] = (rm[r] ?: 0) + 1
    }

    var ans = 0L
    for (l in lm.keys) {
        if (rm.containsKey(l)) ans += lm[l]!! * rm[l]!!
    }
    println(ans)
}


Measured memory_bytes: 85180
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int n;
  cin >> n;
  vint to(n);
  int d;
  cin >> d;
  to[d]++;
  bool flag = true;
  if(d != 0) flag = false;
  rep(i,n-1){
    int d;
    cin >> d;
    to[d]++;
  }
  int ans = 1;
  bool flag2 = true;
  for(int i = 1;i < n;i++){
    if(to[i] == 0) flag2 = false; 
    if(flag2){
      //cout << pow(to[i-1],to[i]) << endl;
      int count = to[i];
      while(count--){
        ans *= to[i-1];
        ans %= 998244353;
      }
    }
    else{
      if(to[i] > 0) flag = false;
    }
    //cout << ans << endl;
  }
  if(flag && to[0] == 1) cout << ans << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 1024
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


const ll MOD = 1e9 + 7;
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

const int MX = 250000;

ll fc[MX];
ll bfc[MX];

ll cnk(int n, int k) {
	if (n < k)
		return 0;
	return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD;
}


void add(ll &a, ll b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int n, m;
ll dp[1 << 16];
ll dp2[1 << 16];
int go[1 << 16];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	fc[0] = 1;
	for (int i = 1; i < MX; ++i)
		fc[i] = (fc[i - 1] * i) % MOD;
	for (int i = 0; i < MX; ++i)
		bfc[i] = pw(fc[i], MOD - 2);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int x;
		cin >> x;
		--x;
		go[x] = 1;
	}
	dp[0] = 1;
	int cnt = 0;
	for (int i = (1 << n) - 1; i > 0; --i) {
		++cnt;
		if (!go[i])
			continue;
		copy(dp, dp + (1 << n), dp2);
		for (int j = 0; j < (1 << n); ++j) {
			int av = cnt - j;
			for (int k = 0; (1 << k) <= av; ++k) {
				if (((j >> k) & 1))
					continue;
				add(dp2[j ^ (1 << k)], dp[j] * (MOD - cnk(av - 1, (1 << k) - 1)) % MOD);
			}
		}
		copy(dp2, dp2 + (1 << n), dp);
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < (1 << n); ++j) {
			if (!((j >> i) & 1)) {
				add(dp[j ^ (1 << i)], dp[j] * cnk((1 << n) - 1 - j, (1 << i)) % MOD);
				dp[j] = 0;
			}
		}
	}
	ll ans = dp[(1 << n) - 1];
	for (int i = 0; i < n; ++i)
		ans = (ans * fc[(1 << i)]) % MOD;
	ans = (ans * pw(2, n)) % MOD;
	cout << ans << "\n";
	return 0;
}




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

using namespace std;

int main(){
	
	int k;
	
	cin>>k;
	long long int p = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int t = 1; t <= k; t++){
				p += __gcd(i,__gcd(j,t));
			}
		}
	}
	cout<<p<<"\n";
				
}


Measured memory_bytes: 3636
using System;
using System.Linq;

namespace ABC125_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var V = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var C = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ans = 0;
            for (int i = 0; i < N; i++)
            {
                var val = V[i] - C[i];
                if (val > 0) ans += val;
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for (int64_t i = 0; i < n; i++) {
        int64_t ai;
        cin >> ai;
        a[i] = ai - (i + 1);
    }

    sort(begin(a), end(a));
    int64_t ans = 0;
    for (auto& e : a) ans += abs(e - a[n/2]);
    cout << ans << endl;
}


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


Measured memory_bytes: 640
#include<iostream>

using namespace std;

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

  int l[N];
  int max = 0;
  for (int i = 0; i < N; i++) {
    int length;
    cin >> length;

    l[i] = length;
    if (max < length) {
      max = length;
    }
  }

  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += l[i];
  }
  sum -= max;

  if (max < sum) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    ll w[n+1];
    w[0]=0;
    rep(0,i,n){
        ll nw;
        cin>>nw;
        w[i+1]=w[i]+nw;
    }
    ll ans=1000000;
    rep(1,i,n+1){
        ans=min(abs(w[n]-2*w[i]),ans);
    }
    cout<<ans;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]

count = 0

for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        if a[i+1] < b[i]:
            count += a[i+1]
            a[i+1] = 0
        else:
            count += b[i]
            a[i+1] -= b[i]
    else:
        count += b[i]
        a[i] -= b[i]

print(count)
        

Measured memory_bytes: 18624
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
ans=0
flag=0
for i in range(n):
    d1,d2=get_ints()
    if d1==d2:
        ans=ans+1
        if ans>=3:
            flag=1
    else:
        ans=0
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62196
#include <iostream>
int main()
{
    int ans, a, b, c, d;
    std::cin >> a >> b >> c >> d;
    if(c >= b){
        ans = 0;
    }if(a <= c && c <= b && b <= d){
        ans = b - c;
    }if(c <= a && a <= b && b <= d){
        ans = b - a;
    }if(c <= a && a <= d && d <= b){
        ans = d - a;
    }if(c <= d && d <= a && a <= b){
        ans = 0;
    }if(c <= a && a <= d && d <= b){
        ans = d - a;
    }if(a <= c && c <= d && d <= b){
        ans = d - c;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = [0]*(n+1)
l[0]=2
l[1]=1
def lucas_number(n):
    global l
    if l[n]!=0:
        return l[n]
    l[n] = lucas_number(n-1)+lucas_number(n-2)
    return l[n]
print(lucas_number(n))


Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
typedef long long ll;
int inf=10000000000007;
void war(vector<vector<int>> &map,int n){
  rep1(k,n){
    rep1(i,n){
      rep1(j,n){
        map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
      }
    }
  }
}
signed main(){
  int n,m,l;cin>>n>>m>>l;
  vector<vector<int>> map(n+1,vector<int> (n+1,inf));
  rep1(i,n)map[i][i]=0;
  vector<vector<int>> map2(map);
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;
    map[a][b]=c;
    map[b][a]=c;
  }
  war(map,n);
  rep1(i,n){
    rep1(j,n){
      if(map[i][j]<=l)map2[i][j]=1;
    }
  }
  war(map2,n);
  int q;cin>>q;
  vector<int> s(q);vector<int> t(q);
  rep(i,q){
    cin>>s[i]>>t[i];
  }
  rep(i,q){
    if(map2[s[i]][t[i]]==inf){
      cout<<-1<<endl;
      continue;
    }
    cout<<map2[s[i]][t[i]]-1<<endl;
  }
  return 0;
}


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

int main(){
	int m,f,b;
	cin >> m >> f >> b;

		if( m >= b )
		{
		cout << "0" << endl;
		
		}else{
			if( m + f >= b)
			{
			cout << b-m << endl;
			}else{
			cout << "NA" << endl;
			}
		}

}


Measured memory_bytes: 3096
import math
N,M = map(int,input().split())

if abs(N-M) > 1:    print(0)
elif N == M:
    print( (2*(math.factorial(N)**2)) % (10**9+7) )
else:
    if N < M:   N,M = M,N
    print( ((math.factorial(M)**2)*N) % (10**9+7) )

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,l,r,c;
    cin>>n;
    string s;
    cin>>s;
    l=0;
    r=n-1;
    c=0;
    while(l<=r)
    {
        if(s[r]=='R')
        {
            if(s[l]=='W')
            {
                swap(s[l],s[r]);
                l++;
                r--;
                c++;
            }
            else
            {
                l++;
            }
        }
        else
        {

            r--;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3720
import sys
mod = pow(10, 9) + 7
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = (10**2)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


def erabu(aW):
    r = 0
    for i in range(aW // 2 + 1 + 1):
        sp = aW - (2*i -1)
        r += cmb(sp+i+1-1, sp, mod)
    return r

N, W, K = [int(x) for x in input().strip().split(" ")]
hasi = 0
cc = []
if W == 1:
    if K == 1:
        print(1)
    else:
        print(0)
    sys.exit()
elif W == 2:
    cccl = [1, 1]
    cc = [1, 1]
elif W == 3:
    cccl = [1, 1, 1]
    cc = [2, 1, 2]
elif W >= 4:
    aW = W - 1
    hW = aW - 2
    nhW = aW - 3
    cc = []
    cccl = []
    for w in range(W):
        nn = max(W - 1 - w - 1, 0)
        nnn = max((W - 1) - nn - 2, 0)
        if w == W -1:
            nnn += 1
        cc.append(erabu(nn) * erabu(nnn))
        cccl.append(erabu(nn) * erabu(nnn-1))

cccl[0] = 0
cccr = cccl[::-1]
d = [1] + [0 for x in range(W-1)]
for i in range(N):
    newd = []
    for j in range(W):
        newd.append(0)
        if j != 0:
            newd[j] = (newd[j] + (d[j-1] * cccl[j]) )% mod
        if j != W-1:
            newd[j] = (newd[j] + (d[j+1] * cccr[j])) % mod
        newd[j] = (newd[j] + (d[j] * cc[j])) % mod
    d = newd[:]

print(d[K-1])


Measured memory_bytes: 38384
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
Amax = 1
for a in A:
    Amax = Amax*a//gcd(Amax, a)
Amax -= 1
ans = 0
for a in A:
    ans += (Amax % a)
print(ans)


Measured memory_bytes: 5344
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

class Edge {
public:
  ll t, w;
  Edge() {}
  Edge(ll t, ll w): t(t), w(w) {}
};


ll N, M;
vector<Edge> g[MAX*3];
ll d[MAX*3];

void dijkstra(ll S) {
  ll clr[MAX*3]={};
  ll i, u;
  for(i=0; i<MAX*3; i++) d[i]=INF;
  d[S]=0;
  
  priority_queue<P> q;
  q.push({0, S});
  
  while(q.size()) {
    P p=q.top(); q.pop();
    ll u=p.sc;
    
    clr[u]=1;
    if(-p.ft>d[u]) continue;
    
    for(i=0; i<g[u].size(); i++) {
      Edge &e=g[u][i];
      if(clr[e.t]==0 && d[e.t]>d[u]+e.w) {
        d[e.t]=d[u]+e.w;
        q.push(P(-d[e.t], e.t));
      }
    }
  }
  
}

int main(void) {
  cin >> N >> M;
  ll i, j;
  ll S, T;
  
  for(i=0; i<M; i++) {
    ll u, v;
    cin >> u >> v;
    u--; v--;
    g[u      ].pb(Edge(v+MAX  , 1));
    g[u+MAX  ].pb(Edge(v+MAX*2, 1));
    g[u+MAX*2].pb(Edge(v      , 1));
  }
  
  cin >> S >> T;
  S--; T--;
  
  dijkstra(S);
  
  if(d[T]==INF) pt(-1);
  else pt(d[T]/3);
  
}














Measured memory_bytes: 21376
#include <bits/stdc++.h>
const int maxn=1e5+10,mod=1e9+7;
typedef long long ll;
using namespace std;
int n,m,k,t;
ll fac[maxn],inv[maxn];
ll qpow(ll x,ll y)
{
    ll ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ret;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++)
        fac[i]=fac[i-1]*i%mod;
    inv[maxn-1]=qpow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
    {
        inv[i]=(i+1)*inv[i+1]%mod;
    }
}
int a[maxn];
ll C(int x,int y)
{
    if(x<0||y<0||x<y)return 0;
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    init();
    scanf("%d%d",&n,&k);
    ll ret=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        //i~j-1
        for(j=i;j<=n&&a[i]==a[j];j++);
        int cnt=j-i;
        (ret+=(a[i]%mod+mod)*(C(j-1,k)-C(i-1,k)-C(n-i+1,k)+C(n-j+1,k)+2*mod)%mod)%=mod;
        i=j-1;
    }
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 2176
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);
		
		//数列の長さ
		int n=sc.nextInt();
		int[] afterNumber=new int[n];
		int[] beforeNumber=new int[n*2];
		Arrays.fill(beforeNumber,(int)Math.pow(10,10));
		
		//数列
		for(int i=1;i<=n;i++) {
			afterNumber[i-1]=sc.nextInt();
			if(n%2==0) {
				if(i%2==0) {
					beforeNumber[n-i]=afterNumber[i-1];
				}else {
					beforeNumber[n+i]=afterNumber[i-1];
				
				}
			}else {
				if(i%2==0) {
					beforeNumber[n+i]=afterNumber[i-1];
				}else {
					beforeNumber[n-i]=afterNumber[i-1];

				}
			}
		}

		for(int i=0;i<beforeNumber.length;i++) {
			if(beforeNumber[i]!=(int)Math.pow(10,10)) {
			System.out.print(beforeNumber[i]+" ");
			}
		}
	}
}

Measured memory_bytes: 94144
#include <stdio.h>

int predA (
  const char  * s
  )
{
  int n = 0;

  if ( *( s++ ) != '>' )  return ( 0 );
  if ( *( s++ ) != '\'' ) return ( 0 );
  if ( *s       != '=' )  return ( 0 );

  for ( ; *s == '='; ++s )  ++n;
  if ( *( s++ ) != '#' )  return ( 0 );
  for ( ; *s == '='; ++s )  --n;
  if ( n )                return ( 0 );
  if ( *( s++ ) != '~' )  return ( 0 );
  if ( *( s++ ) != '\0' ) return ( 0 );

  return ( 1 );
}

int predB (
  const char  * s
  )
{
  if ( *( s++ ) != '>' )  return ( 0 );
  if ( *( s++ ) != '^' )  return ( 0 );

  for ( ; s[ 0 ] == 'Q' && s[ 1 ] == '='; s += 2 ) ;

  if ( s[ -2 ]  != 'Q' )  return ( 0 );
  if ( s[ -1 ]  != '=' )  return ( 0 );
  if ( *( s++ ) != '~' )  return ( 0 );
  if ( *( s++ ) != '~' )  return ( 0 );
  if ( *( s++ ) != '\0' ) return ( 0 );

  return ( 1 );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );

  while ( n-- )
  {
    char s[ 256 ] = { 0 };

    scanf ( " %s", s );

    puts ( predA ( s ) ? "A"
         : predB ( s ) ? "B"
         :               "NA" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  cin>>x>>y;
  bool A=false;
  for(int i=0;i<=x;i++){
  for(int j=0;j<=x;j++){
  if(i+j ==x && 2*i+4*j==y){A=true;break;}
  }
    if(A)break;
  }
  if(A) cout<<"Yes"<<endl;
  else cout<< "No"<<endl;
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define debug(elem) foreach(e, elem){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define MOD 100000009
using ll = long long;
using ull = unsigned long long;

int wa[100010];
bool ac[100010];

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

    rep(i, 100010){
        wa[i] = 0;
        ac[i] = false;
    }

    int ok = 0, ng = 0;
    int pn; string sn;
    rep(i, m){
        cin >> pn >> sn;

        // すでにACしている場合
        if(ac[pn]){
            continue;
        }

        if(sn == "AC"){
            ac[pn] = true;   // その問題がACされた
            ok++;
            ng += wa[pn];    // その問題の間違えた数
        }else{
            wa[pn]++;
        }
    }

    cout << ok << sp << ng << next;
}

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

using namespace std;

const int maxn = 100005;

long long a[maxn];
long long b[maxn];
int n;
int main() {
    scanf("%d",&n);
    for(int i = 0; i < n; i++) {
        scanf("%d%d",&a[i],&b[i]);
    }
    long long ans = 0;
    for(int i = n - 1; i >= 0; i--) {
        a[i] += ans;
        if(a[i] % b[i] == 0) continue;
        else if(a[i] > b[i]) {
            long long tmp = a[i] / b[i];
            ans += (tmp + 1) * b[i] - a[i];
        }else {
            ans += b[i] - a[i];
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<LL, LL> PII;

struct edge {
  LL to, cost;
};

const long long INF = 1LL << 60;
const int MAX_V = 2100000;

int V = MAX_V;
vector<edge> G[MAX_V];
LL d[MAX_V];

void dijkstra(int s) {
  priority_queue<PII, vector<PII>, greater<PII>> que;

  fill(d, d + V, INF);
  d[s] = 0;

  que.push(PII(0, s));

  while (!que.empty()) {
    PII p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(PII(d[e.to], e.to));
      }
    }
  }
}

void add_edge(int from, int to, LL cost) {
  G[from].push_back((edge){to, cost});
}
int main() {
  int N, M;
  cin >> N >> M;

  for (int i = 0; i < N - 1; i++) add_edge(i + 1, i, 0);
  for (int i = 0; i < M; i++) {
    LL l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;

    add_edge(l, r, c);
  }

  dijkstra(0);
  LL ans = d[N - 1];
  if (ans ==  INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 72696
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "container/heap"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Item struct {
  Day int
  Step int
  Break int
  x int
  y int
}
func less(a, b *Item) bool {
  if a.Day != b.Day {
    return a.Day < b.Day
  } else if a.Step != b.Step {
    return a.Step < b.Step
  } else {
    return a.Break < b.Break
  }
}
type PriorityQueue []*Item
func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
  return less(pq[i], pq[j])
}
func (pq PriorityQueue) Swap(i, j int) {
  pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Pop() interface{} {
  old := *pq
  n := len(old)
  item := old[n - 1]
  *pq = old[0:n - 1]
  return item
}
func (pq *PriorityQueue) Push(x interface{}) {
  item := x.(*Item)
  *pq = append(*pq, item)
}

func drill(PQ *PriorityQueue, A *[]string, B *[][]Item, x, y, a, b, K int) {
  var C Item
  C = (*B)[x][y]
  C.x = a
  C.y = b
  if (*A)[a][b] == '.' {
    C.Step += 1
  } else {
    C.Break += 1
    if C.Day <= (C.Break - 1) / K + 1 {
      C.Day = (C.Break - 1) / K + 2
      C.Step = 1
    } else {
      C.Step += 1
    }
  }
  if C.Step > K {
    C.Day += 1
    C.Step -= K
  }
  if less(&C, &(*B)[a][b]) {
    (*B)[a][b] = C
    heap.Push(PQ, &C)
  }
}

func main() {
  HWK := NextIntVec()
  H := HWK[0]
  W := HWK[1]
  K := HWK[2]
  A := make([]string, H)
  B := make([][]Item, H)
  var PQ PriorityQueue
  for i := range A {
    A[i] = NextLine()
    B[i] = make([]Item, W)
    for j := range B[i] {
      B[i][j] = Item{H * W, 0, 0, i, j}
      if A[i][j] == 'S' {
        B[i][j].Day = 1
        heap.Push(&PQ, &B[i][j])
      }
    }
  }
  for {
    q := heap.Pop(&PQ).(*Item)
    if q.x == 0 || q.x == H - 1 || q.y == 0 || q.y == W - 1 {
      Write(q.Day)
      break
    }
    drill(&PQ, &A, &B, q.x, q.y, q.x - 1, q.y, K)
    drill(&PQ, &A, &B, q.x, q.y, q.x, q.y - 1, K)
    drill(&PQ, &A, &B, q.x, q.y, q.x + 1, q.y, K)
    drill(&PQ, &A, &B, q.x, q.y, q.x, q.y + 1, K)
  }
  Output()
}

Measured memory_bytes: 56320
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=sc.nextInt();
    int cnt=0;
    for(int ia=0;ia<=a;ia++)
      for(int ib=0;ib<=b;ib++)
        for(int ic=0;ic<=c;ic++)
          if(500*ia+100*ib+50*ic==d)cnt++;
    System.out.println(cnt);
  }
}

Measured memory_bytes: 21844
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int u = min(511, n);
    vi v(n), w(n);
    rep(i, n) {
        cin >> v[i] >> w[i];
    }
    int q;
    cin >> q;
    ll ma = 0;
    vi vv(q), l(q);
    rep(i, q) {
        cin >> vv[i] >> l[i];
        --vv[i];
        ma = max(ma, l[i]);
    }

    vvi d(u, vi(ma+1));
    rep(i, u) {
        if(!i) {
            rep(j, ma+1) {
                if(j >= w[0]) d[0][j] = v[0];
            }
        } else {
            int ch = (i-1)/2;
            rep(j, ma+1) {
                if(j >= w[i]) {
                    d[i][j] = max(d[ch][j], d[ch][j-w[i]]+v[i]);
                } else {
                    d[i][j] = d[ch][j];
                }
            }
        }
    }

    rep(i, q) {
        if(vv[i] < u) {
            cout << d[vv[i]][l[i]] << '\n';
        } else {
            int p = vv[i];
            vector<P> se(1, P(0, 0));
            while(p >= u) {
                int si = se.size();
                rep(j, si) {
                    se.emplace_back(se[j].first+w[p], se[j].second+v[p]);
                }
                p = (p-1)/2;
            }
            ll ans = 0;
            rep(j, se.size()) {
                if(se[j].first > l[i]) continue;
                ans = max(ans, se[j].second + d[p][l[i]-se[j].first]);
            }
            cout << ans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 410296
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    REP(i,N) A[i] %= M;

    Rep(i, 1, N){
        A[i] += A[i-1];
        A[i] %= M;
    }

    A.insert(A.begin(), 0);N++;

    map<ll, int> m;
    REP(i, N){
        m[A[i]]++;
    }

    ll ans = 0;
    REP(i, N){
        ans += (m[A[i]]-1);
        m[A[i]]--;
    }
    pr(ans);
}

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

int main(){
  string s;
  long long int k;
  cin >> s >> k;
  string ans = "1";
  for(int i = 0; i < k; i++){
    if(s[i] != '1'){
      ans = s[i];
      break;
    }
    if(i + 1 == s.size()) break;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d1(n);
  vector<int> d2(n);
  for (int i = 0; i < n; ++i) {
    cin >> d1[i] >> d2[i];
  }
  bool ans = false;
  for (int i = 0; i + 2 < n; ++i) {
    if (d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2]) {
      ans = true;
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3628
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        l: usize,
        r: usize,
        d: usize,
    }
    let mut ans = 0;
    for i in l..(r + 1) {
        if i % d == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    vector<int>a(1000000);
    a[1]=s;

    rep2(i,2,1000000){
        if(a[i-1]%2==0){
            a[i]=a[i-1]/2;
        }
        else {
            a[i]=a[i-1]*3+1;
        }
    }

    rep2(i,1,1000000){
        if(a[i]==1||a[i]==2||a[i]==4){
            cout<<i+3<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4096
function main()
  
  (N, Y) = map(x -> parse(Int, x), split(readline()))
  Y = div(Y, 1000)
  
  ans = []
  check = false
  
  for i in 0:N
    for j in 0:N-i
      if 10i + 5j + (N-j-i) == Y
        ans = [i, j, N-j-i]
        check = true
      end
    end
  end
  
  if check
    println(ans[1], " ", ans[2], " ", ans[3])
  else
    println("-1 -1 -1")
  end
  
end

main()

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int A, B, C;
    cin >> A >> B >> C;
    swap(A, B);
    swap(A, C);
    cout << A << ' ' << B << ' ' << C << endl;


    return 0;
}

Measured memory_bytes: 384