akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll dp[105][2][2][2][2]; // [i:今いる桁][j:未満フラグ][s1][s2][s3]
void solve() {
  string N;
  cin >> N;
  int k;
  cin >> k;
  int len = N.size();
  dp[0][0][0][0][0] = 1;
  rep(i, len) rep(j, 2) rep(s1, 2) rep(s2, 2) rep(s3, 2) {
    int d = N[i] - '0';
    rep(x, 10) { // 0-9まで回して遷移をさせる
      int nj = j, ns1 = s1, ns2 = s2, ns3 = s3;
      if (!j && d < x) continue;
      if (x < d) nj = 1;
      if (!ns1 && !ns2 && !ns3 && x != 0) ns1 = 1, ns2 = 0, ns3 = 0;
      else if (ns1 && !ns2 && !ns3 && x != 0) ns1 = 0, ns2 = 1, ns3 = 0;
      else if (ns2 && !ns3 && x != 0) ns1 = 0, ns2 = 0, ns3 = 1;
      else if (ns3 && x != 0) continue;
      dp[i + 1][nj][ns1][ns2][ns3] += dp[i][j][s1][s2][s3];
    }
  }
  int ans = 0;
  if (k == 1) {
    rep(j, 2) ans += dp[len][j][1][0][0];
  } else if (k == 2) {
    rep(j, 2) ans += dp[len][j][0][1][0];
  } else {
    rep(j, 2) ans += dp[len][j][0][0][1];
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  string S;
  cin >> S;
  int N = S.length();
  bool a = true;
  rep(i, N / 2) {
    if (S[i] != S[N - i - 1]) a = false;
  }
  if (!a) {
    out("No");
    return 0;
  }
  a = true;
  rep(i, N / 2 / 2) {
    if (S[i] != S[N / 2 - i - 1]) a = false;
  }
  if (a) out("Yes") else out("No");
}


Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall ABC099D.cpp -o ./out/ABC099D.out
./out/ABC099D.out
*/

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

int main(){
//    freopen("./input/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    if (n <= 999) {
      printf("ABC\n");
    } else {
      printf("ABD\n");
    }
}


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main() {
    int N;
    cin >> N;
    ll X;
    cin >> X;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    ull sum = 0;
    for(int i = 0; i < N - 1; i++){
        if(A[i] + A[i + 1] > X){
            sum += A[i] + A[i + 1] - X;
            A[i + 1] -= (A[i] + A[i + 1] - X);
            if(A[i + 1] < 0){
                A[i] += A[i + 1];
                A[i + 1] = 0;
            }
        }
    }
    cout << sum << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, M;
            int[] S;
            int[] C;

            {
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                N = line[0];
                M = line[1];
            }
            S = new int[M];
            C = new int[M];

            for (int m = 0; m < M; m++)
            {
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                S[m] = line[0];
                C[m] = line[1];
            }

            int mn = new int[3] {0, 10, 100}[N - 1];
            int mx = new int[3] {9, 99, 999}[N - 1];
            int[] d = new int[N];
            for (int a = mn; a <= mx; a++)
            {
                bool flg = true;
                if (N == 1)
                {
                    d[0] = a;
                }
                if (N == 2)
                {
                    d[0] = a / 10;
                    d[1] = a % 10;
                }

                if (N == 3)
                {
                    d[0] = a / 100;
                    d[1] = (a / 10) % 10;
                    d[2] = a % 10;
                }

                for (int m = 0; m < M; m++)
                {
                    int s = S[m];
                    int c = C[m];
                    if (d[s - 1] != c) flg = false;
                }

                if (flg)
                {
                    Console.WriteLine(a);
                    return;
                }
                    
            }
            Console.WriteLine(-1);
            return;
        }
    }
}

Measured memory_bytes: 11220
package main
  
import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)
    vs := make([]int, n)
    for i := range vs {
        fmt.Scan(&vs[i])
    }
    sort.Sort(sort.IntSlice(vs))
    var ans float64
    ans = (float64(vs[0]) + float64(vs[1])) / 2.0
    for i := 2; i < n; i++ {
        ans = (ans + float64(vs[i])) / 2.0
    }
    fmt.Println(ans)
}


Measured memory_bytes: 512
using System;

class AOJ
{
	public static void Main()
	{
        int input = int.Parse(Console.ReadLine().Trim());
        int h = input / 3600;
        input = input % 3600;
        int m = input / 60;
        int s = input % 60;

        Console.WriteLine(string.Format("{0}:{1}:{2}", h, m, s));
	}
}

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

const int mod = 1e9 + 7;

int n;
string s, t, u;

unordered_map<int, int> memo[2];

int dfs(int p, bool up = false) {
	if (p == n) return !up;
	if (memo[up].count(p)) return memo[up][p];
	int id = n - 1 - p;
	int res = 0;
	for (int i = 0; i < 10; i++) if (s[id] == '?' || i == s[id] - '0') {
		for (int j = 0; j < 10; j++) if (t[id] == '?' || j == t[id] - '0') {
			int d = (i + j + up) % 10;
			bool nu = i + j + up >= 10;
			if (id == 0 && (i == 0 || j == 0 || d == 0)) continue;
			if (u[id] == '?' || d == u[id] - '0') {
				res = (res + dfs(p + 1, nu)) % mod;
			}
		}
	}
	return memo[up][p] = res;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	while (cin >> s, s != "0") {
		cin >> t >> u;
		n = s.size();
		cout << dfs(0) << endl;
		for (int i = 0; i < 2; i++) memo[i].clear();
	}
	return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
int main(void){
  int c = 0, i;
  long int X, y = 100;
  scanf("%ld", &X);

  for(i = 0; i < 5000; i++){
    y *= 1.01;
    if(y >= X) break;
  }

  printf("%d\n", i + 1);


  return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

int main()
{
	int i, j, k, s, t, a;

	while (1) {
		scanf("%d %d", &s, &t);
		if (s == 0 && t == 0) break;
		a = 0;
		for (i = 1; i <= s; i++) {
			for (j = i + 1; j <= s; j++) {
				for (k = j + 1; k <= s; k++) {
					if (i + j + k == t)
						a++;
				}
			}
		}
		printf("%d\n", a);
	}
		return 0;
	
}


Measured memory_bytes: 2088
from collections import deque
N=int(input())
A=list(map(int, input().split()))

# プラス　マイナス引いていく
plus=[]
minus=[]
zeros=[]
for a in A:
    if a==0:
        zeros.append(a)
    elif a>=1:
        plus.append(a)
    else:
        minus.append(a)
plus=sorted(plus)
minus=sorted(minus)
zeros=sorted(zeros)
ans=[]
if plus and minus:
    while len(plus)>1:
        now=plus.pop()
        ans.append((minus[0],now))
        minus[0]-=now
    while len(zeros)>0:
        now=zeros.pop()
        ans.append((plus[0],now))
    while len(minus)>1:
        now=minus.pop()
        ans.append((plus[0],now))
        plus[0]-=now
    ans.append((plus[0],minus[0]))
    ansnum=plus[0]-minus[0]
else:
    ansnum=0
    if len(plus)==0:
        if zeros:
            core=zeros.pop()
        else:
            core=minus.pop()
        while len(minus)>0:
            now=minus.pop()
            ans.append((core,now))
            core-=now
        ansnum=core
    else:
        if zeros:
            core=zeros.pop()
        else:
            plus=deque(plus)
            core=plus.popleft()
        while len(plus)>1:
            now=plus.pop()
            ans.append((core,now))
            core-=now
        ans.append((plus[0],core))
        ansnum=plus[0]-core
        core=ansnum
    while len(zeros)>0:
        now=zeros.pop()
        ans.append((core,now))
    
    

print(ansnum)
for t in ans:
    x,y=t
    print(x,y)

Measured memory_bytes: 101916
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
string s,t;
int count=0;
cin>>s;
cin>>t;
rep(i,3){
char a,b;
a=s.at(i);
b=t.at(i);
if(a==b)count++;
}
cout<<count;
}

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

int main(){
	float f;
	while( std::cin>>f, f>=0){
		int i=f;
		f=f-i;
		if( i>255 ){std::cout<<"NA"<<std::endl;continue;}
		int Fnum=(1<<4)*f;
		if( Fnum != (1<<4)*f ){std::cout<<"NA"<<std::endl;continue;}
		int count=8;
		while( count-- )
			std::cout<<((i&(1<<count))==0?'0':'1');
		std::cout<<'.';
		
		count=4;
		while( count-- )
			std::cout<<((Fnum&(1<<count))==0?'0':'1');
		
		std::cout<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int a[500],n,x,ans;
int main(){
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(x<=0)break;
        x-=a[i];
        ans++;
    }
    if(x!=0)ans--;
    cout<<ans<<endl;

}


Measured memory_bytes: 256
//31
#include<iostream>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n;){
    char s[1000001];
    int nx=0;
    int ans=0;
    int acm=0;
    cin>>s;
    for(int i=0;i<m;i++){
      const char *c="IO";
      if(s[i]!=c[nx]){
	acm=nx=0;
      }
      if(s[i]==c[nx]){
	acm++;
	if(acm==n*2+1){
	  ans++;
	  acm-=2;
	}
	nx^=1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2140
#include <stdio.h>

int main()
{
    int hotel[4][3][10],i,j,k,test,b,f,r,v;
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                hotel[i][j][k]=0;
            }
        }
    }
    scanf("%d",&test);
    for(i=0;i<test;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        hotel[b-1][f-1][r-1]+=v;
    }
    for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[0][j][k]);
            }
            printf("\n");
        }
    for(i=1;i<4;i++){
        printf("####################\n");
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",hotel[i][j][k]);
            }
            printf("\n");
        }
    }
    return 0;
}


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

int main(){
	int n,ans;

	while( cin >> n ){
		ans = 0;
		if(n<=36){
			for(int a=0 ; a<=9 ; a++){
				for(int b=0 ; b<=9 ; b++){
					for(int c=0 ; c<=9 ; c++){
						for(int d=0 ; d<=9 ; d++){
							if((a+b+c+d)==n){
								ans++;
							}
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}  

Measured memory_bytes: 2972
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main()
{
  int N;
  uint64_t ans = 1;
  uint64_t mm = pow(10, 18);

  cin >> N;
  vector<uint64_t> a(N);

  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }
  sort(a.rbegin(), a.rend());
  if (a.back() == 0)
  {
    cout << 0 << endl;
    return 0;
  }

  for (auto v : a)
  {
    if (v > mm / ans)
    {
      cout << -1 << endl;
      return 0;
    }
    ans *= v;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

int main()
{
	int32_t A, B, C;
	cin >> A >> B >> C;

	bool found = false;
	int32_t val = A;
	for (int32_t i = 0; i < 10000000; i++) {
		if (val % B == C) {
			found = true;
			break;
		}
		val += A;
	}

	cout << (found ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

        while (true) {
            int m = scanner.nextInt(), f = scanner.nextInt(), r = scanner.nextInt();

            if (m == -1 && f == -1 && r == -1) break;

            String score;
            if (m == -1 || f == -1 || m + f < 30) {
                score = "F";
            } else if (m + f < 50 && r < 50) {
                score = "D";
            } else if (m + f < 65 || (m + f < 50 && r >= 50)) {
                score = "C";
            } else if (m + f < 80) {
                score = "B";
            } else {
                score = "A";
            }

            System.out.println(score);
        }
    }
}


Measured memory_bytes: 26288
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>

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

using namespace std;
typedef long long int ll;
const int INF = 100000000;

// 組み合わせnCrを求める関数
int Combination(int n, int r) {
    int molecule = 1;
    int denominator = 1;
    for (int i = 0; i < r; i++) {
        molecule *= n - i;
        denominator *= r - i;
    }
    return (molecule / denominator);
}

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

    int ans = Combination(n, 2) + Combination(m, 2);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

int main()
{ 
    LL k,n;
    cin>>k>>n;
    LL ans=0;
    LL a[n];
    LL max=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>0){
            LL x=a[i]-a[i-1];
            if(max<x){max=x;}
        }
    }
    ans=a[n-1]-a[0];
    if(k-max<ans){ans=k-max;}
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
#define endl "\n"

const int MOD = 1e9 + 7;

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

    int h,a;
    cin >> h >> a;
    if(h % a == 0){
		cout << h / a << endl;
    } else
    cout << h / a + 1 << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const double EPS = 1e-9;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    int P, Q, R;
    cin >> P >> Q >> R;

    int t_min;
    t_min = min(min(P + Q, Q + R), R + P);
    cout << t_min << endl;

    return 0;
}

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

int main(){
 int h, w;
 vector<vector<char>> s;
 cin>>h>>w;
 s = vector<vector<char>>(h+2, vector<char>(w+2));
 for(int i=1;i<=h; i++)
  for(int j=1;j<=w; j++)cin>>s[i][j];
 for(int i=1; i<=h; i++)
  for(int j=1;j<=w; j++)
   if(s[i][j]=='#'&&s[i+1][j]!='#'&&
   s[i-1][j]!='#'&&s[i][j+1]!='#'&&s[i][j-1]!='#'){
    cout<<"No\n";
    return 0;
   }
 cout<<"Yes\n";
}


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

int main(){
    int r,g,b;
    cin>>r>>g>>b;
    
    int B=(100*r)+(10*g)+b;
     
    if(B%4==0){
        cout<<"YES"<<endl;
    }
    
    else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3520
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;
ll INF=1e10;

int main(){
    ll a; cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}





























































































Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, e;
	cin >> a >> b >> c;
	if (c * 2 >= b - a + 1) {
		for (long long h = a; h <= b; h++) {
			cout << h << endl;
		}
	}
	else {
		for (long long j = a; j <= a + c - 1; j++) {
			cout << j << endl;
		}
		for (long long k = b - c + 1; k <= b; k++) {
			cout << k << endl;
		}
	}
	cin >> e;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
const int INF=10000;
typedef pair<int,int> P;
char town[1001][1001];
int h,w,n;
int s;
int d[1001][1001];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char num='1';
int sx,sy,gx,gy;
int ans=0;

int bfs(){
queue<P> que;

 for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
     d[i][j]=INF;
   }
 }
 d[sy][sx]=0;
 que.push(P(sy,sx));

 while(que.size()){
   P p=que.front(); que.pop();
   
   if(town[p.first][p.second]==num){
     sy=p.first;
     sx=p.second;
     return d[p.first][p.second];
     break;
   }
   
   for(int i=0;i<4;i++){
     int ny=p.first + dy[i],nx=p.second+dx[i];
     
     if(0<=nx && nx<w && 0<=ny && ny<h && town[ny][nx]!='X' && d[ny][nx]==INF){
       que.push(P(ny,nx));
       d[ny][nx]=d[p.first][p.second]+1;
     }
   }
 }
}


int main(){
  cin>> h>> w>> n;
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>> town[i][j];
      if(town[i][j]=='S'){
	sy=i;
	sx=j;
      }
    }
  }

for(num='1';num<'1'+n;num++){
  ans+=bfs();
 }
  cout<< ans<< endl;
}

Measured memory_bytes: 6108
#include <string>
#include <iostream>
using namespace std;
int a, b;
pair<int, int> check(string s) {
	int xa = 0, xb = 0; bool flag = false;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'A') xa++;
		if(s[i] == 'B') xb++;
		if(xa == 4 && xb == 4) flag = true;
		if(!flag && (xa == 5 || xb == 5)) return make_pair(xa, xb);
	}
	return make_pair(xa, xb);
}
int main() {
	scanf("%d%d", &a, &b);
	for(int i = 0; i < 1 << (a + b); i++) {
		string s;
		for(int j = a + b - 1; j >= 0; j--) {
			if(i & (1 << j)) s += "B";
			else s += "A";
		}
		if(check(s) == make_pair(a, b)) cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3248
import java.util.*;

public class Main{
	public static int b[];
	public static int N;
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	N = sc.nextInt();
	int a[] = new int[N];
	for(int i=0;i<N;i++) a[i]=sc.nextInt();
	sc.close();
	b = new int[N];
	for(int i=0;i<N;i++) b[i]=0;//initialized
	
	for(int i=N;i>0;i--) {
			int cnt = 0;
			for(int j=2;j<=(N/(i));j++) {
				if(b[i*j-1]==1)cnt++;
			}
			if(cnt%2!=a[i-1])b[i-1]++;
	}
	
	StringBuilder sb = new StringBuilder();
	int cnt = 0;
	for(int i=0;i<N;i++) {
		if(b[i]==1) {
			sb.append(i+1+ " ");
			cnt ++;
		}
	}
	System.out.println(cnt);
	System.out.println(sb.toString());		
	}
}

Measured memory_bytes: 91408
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(3 * n);
  REP(i, m) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    REP(j, 3) {
      int ux = 3 * u + j;
      int vx = 3 * v + (j + 1) % 3;
      g[ux].push_back(vx);
    }
  }
  int vs, vt;
  cin >> vs >> vt;
  vs--;
  vt--;
  vs = 3 * vs;
  vt = 3 * vt;
  auto bfs = [&]() -> i64 {
    deque<tuple<int, i64>> q;
    vector<bool> done(3 * n);
    q.emplace_back(vs, 0);
    done[vs] = true;
    while (q.size()) {
      auto [v, d] = q.front();
      q.pop_front();
      if (v == vt) {
        assert(d % 3 == 0);
        return d / 3;
      }
      for (auto u : g[v]) {
        if (done[u]) continue;
        done[u] = true;
        q.emplace_back(u, d + 1);
      }
    }
    return -1;
  };
  cout << bfs() << endl;
}

Measured memory_bytes: 19444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int k;
    cin >> k;
    vector<ll> a;
    rrep(i,9)a.push_back(i);
    vector<ll>old;
    old = a;
    while(1){
        vector<ll> cur;
        if(a.size()>=k){
            cout<<a[k-1]<<endl;
            // rep(i,a.size())cout << a[i]<<" ";
            return 0;
        }
        for(auto m:old){
            int keta=0;
            ll mm = m%10;
            ll d;
            if(mm==0){
                for(int i=0;i<2;++i){
                    d = m*10+i;
                    cur.push_back(d);
                }
            }else if(mm==9){
                for(int i=-1;i<1;++i){
                    d = m*10+mm+i;
                    cur.push_back(d);
                }
            }else{
                for(int i = -1;i<2;++i){
                    d = m*10+mm+i;
                    cur.push_back(d);
                }    
            }
        }
        a.insert(a.end(),cur.begin(),cur.end());
        swap(old,cur);
    }
}

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

int main() {
    //freopen("../input.txt", "r", stdin);
    long long int N;
    cin >> N;
    map<string, int> freq;
    int highest = 0;
    for (int i = 0; i < N; ++i) {
        string input;
        cin >> input;
        freq[input]++;
        if(freq[input] > highest){
            highest = freq[input];
        }
    }
    //int highest = (*max_element(freq.begin(), freq.end())).second;
    for (auto it = freq.begin(); it != freq.end(); it++) {
        if (it->second == highest) {
            cout << it->first << "\n";
        }
    }
}

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

int main(){
 int H,N,c=0;
  cin >> H >> N;
  
  vector <int> A(N);
  
  rep(i,N){
    cin >> A.at(i);
    c+=A.at(i);
  }
  
  if(c>=H)
    cout << "Yes" << endl;
  else
    cout << "No" <<endl;
  

}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

const int sz = 2e5+20;
ll n,d,A;
ll dist[sz];

ll help(ll last){
	//~ put(last);
	ll left=0,right=n-1;
	ll ans=0;
	while(left<=right){
		ll mid=(left+right)/2;
		
		if(dist[mid]<=last){
			ans=mid;
			left=mid+1;
		}else{
			right=mid-1;
		}
	}
	return ans;
}

int main()
{
    fast;
    ll t;
    //~ cin>>t;
    t=1;
    while(t--){
			
			
			cin>>n>>d>>A;
			pair<ll,ll>a[n];
			for(int i=0;i<n;i++){
				cin>>a[i].xx>>a[i].yy;
			}
			
			sort(a,a+n);
			dist[0]=a[0].xx;
			for(int i=1;i<n;i++){
				dist[i]=a[i].xx;
			}
			//~ for(int i=0;i<n;i++)
				//~ cout<<dist[i]<<" ";
			//~ cout<<endl;
			
			ll ans=0;
			ll pre[n+10]={};
			
			for(int i=0;i<n;i++){
				if(i!=0)
					pre[i]+=pre[i-1];
					
				if(a[i].yy<=pre[i])
					continue;
				a[i].yy-=pre[i];
				ll tym = ceil((1.0*a[i].yy)/A);
				ans+=tym;
				pre[i]+=tym*A;
				ll last = help(a[i].xx+2*d);
				pre[last+1]-= tym*A;
				
				//~ int j=i+1;
				//~ while((a[j].xx-a[i].xx)<=2*d and j<n){
					//~ a[j].yy-=tym*A;
					//~ j++;
				//~ }
				//~ cout<<i<<" "<<last<<" "<<ans<<endl;
				
			}
			cout<<ans;
			
    }
    return 0;
}


Measured memory_bytes: 6528
import java.util.*;


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

		String s=sc.next();
		String y=s.split("/")[0];
		String m=s.split("/")[1];
		String d=s.split("/")[2];
		int year=Integer.parseInt(y);
		int month=Integer.parseInt(m)+10;
		int day=Integer.parseInt(d);
		if(year>=2020 || (year==2019 && month>=15)){
			System.out.println("TBD");
		}else if((year==2019 && month <=14 )|| year<=2018){
			System.out.println("Heisei");
		}


	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s,t;
    int ans=0;
    cin>>s>>t;
    rep(i,3) if(s[i]==t[i]) ans++;
    cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
d_l = list(map(int,input().split()))

count_dict = {}
for i in range(n):
    count_dict[i] = 0
for val in d_l:
    count_dict[val] += 1

if d_l[0] != 0 or count_dict[0] != 1:
    ans = 0
else:
    ans = 1

for i in range(1,n):
    ans = (ans*(count_dict[i-1]**count_dict[i])) %998244353
    if ans == 0:
        break

print(ans)

Measured memory_bytes: 20648
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

vector<int> color(1010), g[1010];
int l, r;

bool dfs(int v, int c) {
    color[v] = c;
    if (c)
        l++;
    else
        r++;
    for (int i = 0; i < g[v].size(); i++) {
        if (color[g[v][i]] == c) {
            return false;
        }
        if (color[g[v][i]] == -1 && !dfs(g[v][i], 1 - c)) {
            return false;
        }
    }
    return true;
}

int main() {
    int n, m;
    while (cin >> n >> m, n | m) {
        for (int i = 0; i < n; i++) {
            g[i].clear();
            color[i] = -1;
        }
        for (int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--;
            v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        l = r = 0;
        if (dfs(0, 1)) {
            vector<int> ans;
            if (l % 2 == 0) ans.push_back(l / 2);
            if (r % 2 == 0 && l != r) ans.push_back(r / 2);
            cout << ans.size() << endl;
            sort(ans.begin(), ans.end());
            for (int e : ans) cout << e << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}


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


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

    int A,B;
    cin >> A >> B;
    int ans=-1;

    rep(i,10000){
        int x=i*0.08;
        int y=i*0.1;
        if(x==A && B==y){
            ans=i;
            break;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[200007];
int main(){
    int n,a,b,c,d;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    int flag=0;
    int num=0;
    for(int i=min(a,b)+1;i<max(c,d);++i){
        if(s[i]=='#')
            num++;
        else
            num=0;
        if(num==2)
            flag=1;
    }
    if(flag){
        printf("No");
        return 0;
    }
    num=0;
    if(a<b&&c>d){
        if(s[d-1]!='.'){
            int tot=0;
            for(int i=b-1;i<d;++i){
                if(s[i]=='.')
                    num++;
                else
                    num=0;
                if(num==3)
                    tot=1;
            }
            if(tot){
                printf("Yes");
                return 0;
            }
        }
        else{
            printf("Yes");
            return 0;
        }
    }
    else if(a<b&&c<d||a>b&&c>d){
        printf("Yes");
        return 0;
    }
    else if(a>b&&c<d){
        if(s[c-1]!='.'){
            int tot=0;
            for(int i=a-1;i<c;++i){
                if(s[i]=='.')
                    num++;
                else
                    num=0;
                if(num==3)
                    tot=1;
            }
            if(tot){
                printf("Yes");
                return 0;
            }
        }
        else{
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
int main(){
    int i,b=0,n,k;
    scanf("%d",&n);
    int a[n];
    scanf("%d",&k);
    for (i=0;i<n;i++){
        scanf("%d",a+i);
        if (a[i]>=k)
            b++;
    }
    printf("%d",b);
    return 0;
}


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

using namespace std;

int main()
{
    int N;
    int L;
    string S;
    vector<string> v;

    cin >> N >> L;

    for (int i = 0; i < N + 1; i++)
    {
        string Si;
        cin >> Si;
        v.push_back(Si);
    }

    sort(v.begin(), v.end());

    for (int i = 0; i < N + 1; i++)
    {
        cout << v[i];
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    long long int a[4],n,x;
    cin >> n;
    x=1;
    a[0] = n % 10;
    a[1] = (n / 10) % 10;
    a[2] = (n / 100) % 10;
    a[3] = (n / 1000) % 10;
    for(int i=0;i<3;i++){
        if(a[i]==a[i+1])x=0;
    }
    if(x==0)cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

v = LIST()

c = LIST()

ans = 0
for i in range(n):
    if (v[i] >= c[i]):
        ans += v[i] - c[i]

print(ans)


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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline int read(){
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline ll readll(){
	ll f=1,x=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MOD=1e9+7;
inline int mod(int x){return x<MOD?x:x-MOD;}
int n,a[605],b[605],dp[605][305][305];
int main() {
	n=read();
	for(int i=1;i<=n*2;++i)a[i]=read();
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n*2;i+=2){
		if(a[i]==-1&&a[i+1]==-1)cnt1++;
		else if(a[i]==-1)b[a[i+1]]=2,cnt2++;
		else if(a[i+1]==-1)b[a[i]]=2,cnt2++;
		else b[a[i]]=3,b[a[i+1]]=3;
	}
	//for(int i=1;i<=n*2;++i)cout<<b[i]<<" ";cout<<endl;
	dp[n*2+1][0][0]=1;
	for(int i=n*2;i>=1;--i){
		if(b[i]==3){
			for(int j=0;j<=cnt2;++j)for(int k=0;k+j<=cnt1+cnt2;++k)dp[i][j][k]=dp[i+1][j][k];
		}
		else if(b[i]==2){
			for(int j=0;j<=cnt2;++j){
				for(int k=0;k+j<=cnt1+cnt2;++k){
					if(j)dp[i][j][k]=mod(dp[i][j][k]+dp[i+1][j-1][k]);
					if(k<cnt1+cnt2)dp[i][j][k]=mod(dp[i][j][k]+dp[i+1][j][k+1]);
				}
			}
		}
		else{
			for(int j=0;j<=cnt2;++j){
				for(int k=0;k+j<=cnt1+cnt2;++k){
					if(k)dp[i][j][k]=mod(dp[i][j][k]+dp[i+1][j][k-1]);
					if(k<cnt1+cnt2)dp[i][j][k]=mod(dp[i][j][k]+dp[i+1][j][k+1]);
					if(j<cnt2)dp[i][j][k]=mod(dp[i][j][k]+(ll)dp[i+1][j+1][k]*(j+1)%MOD);
				}
			}
		}
	}
	//int i,j,k;while(cin>>i>>j>>k)cout<<dp[i][j][k]<<endl;
	int t=1;
	for(int i=2;i<=cnt1;++i)t=(ll)t*i%MOD;
	cout<<(ll)dp[1][0][0]*t%MOD<<endl;
	return 0;
}

Measured memory_bytes: 219008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

map<ll,ll> mp;
ll N,A,B,C,D;
ll INF=1e18;

void solve(ll X);

void judge(ll X,ll Y){
  if(mp[X]>Y){
    mp[X]=Y;
    solve(X);
  }
}

void solve(ll X){
  if(X<2) return;
  if(D<=(INF-mp[X])/(X-1)){
    if(mp.find(1)==mp.end()) mp[1]=INF;
    mp[1]=min(mp[1],(X-1)*D+mp[X]);
  }
  int mo=X%2;
  if(mp.find(X/2)==mp.end()) mp[X/2]=INF;
  judge(X/2,mp[X]+A+D*mo);
  if(mo){
    ll Y=X+2-mo;
    if(mp.find(Y/2)==mp.end()) mp[Y/2]=INF;
    judge(Y/2,mp[X]+A+D);
  }
  
  if(mp.find(X/3)==mp.end()) mp[X/3]=INF;
  mo=X%3;
  judge(X/3,mp[X]+B+D*mo);
  if(mo){
    ll Y=X+3-mo;
    if(mp.find(Y/3)==mp.end()) mp[Y/3]=INF;
    judge(Y/3,mp[X]+B+D*(3-mo));
  }

  mo=X%5;
  if(mp.find(X/5)==mp.end()) mp[X/5]=INF;
  judge(X/5,mp[X]+C+D*mo);
  if(mo){
    ll Y=X+5-mo;
    if(mp.find(Y/5)==mp.end()) mp[Y/5]=INF;
    judge(Y/5,mp[X]+C+D*(5-mo));
  }
}

int main(){
  int T; cin>>T;
  while(T--){
    cin>>N>>A>>B>>C>>D;
    mp.clear();
    mp[N]=D;
    solve(N);
    cout<<mp[1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4504
#include <stdio.h>
int n, ret;
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		ret = 0;
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				int p = i * i * i + j * j * j;
				if (p <= n * n * n) {
					ret = ret > p ? ret : p;
				}
			}
		}
		printf("%d\n", n * n * n - ret);
	}
	return 0;
}

Measured memory_bytes: 2680
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    val c = b - a + 1
    val d = b + a - 1
    var i = c
    for (i in c..d){
        print(i)
        print(' ')
    }
}

Measured memory_bytes: 29344
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	
	int ave_1=sum/n;
	int ave_2=(sum+n-1)/n;
	
	int cost_1,cost_2;
	cost_1=cost_2=0;
	for(int i=0;i<n;i++){
		cost_1+=(ave_1-a[i])*(ave_1-a[i]);
		cost_2+=(ave_2-a[i])*(ave_2-a[i]);
	}
	int ans=min(cost_1,cost_2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b=0,i,c=0;
  for(i=0;i<4;i++){
    scanf("%d",&a);
    b+=a;
  }
  while(b>=60){
    b-=60;
    c++;
  }
  printf("%d\n%d\n",c,b);
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	ll dp[(int)s.size()+1][3];
	dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;ll ch=1;
	for(int i = 0; i < (int)s.size(); i++){
		if(s[i]=='A'){
			dp[i+1][0]=(dp[i][0]+ch)%mod;
			dp[i+1][1]=dp[i][1];
			dp[i+1][2]=dp[i][2];
		}
		else if(s[i]=='B'){
			dp[i+1][0]=dp[i][0];
			dp[i+1][1]=(dp[i][0]+dp[i][1])%mod;
			dp[i+1][2]=dp[i][2];
		}
		else if(s[i]=='C'){
			dp[i+1][0]=dp[i][0];
			dp[i+1][1]=dp[i][1];
			dp[i+1][2]=(dp[i][1]+dp[i][2])%mod;
		}
		else{
			dp[i+1][0]=(dp[i][0]*3+ch)%mod;
			dp[i+1][1]=(dp[i][0]+dp[i][1]*3)%mod;
			dp[i+1][2]=(dp[i][1]+dp[i][2]*3)%mod;
			ch*=3;ch%=mod;
		}
	}
	//for(int i = 0; i < 3; i++)cout << dp[(int)s.size()][i] << endl;
	cout << dp[(int)s.size()][2] << endl;
    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int k,x;
	cin>>k>>x;
	int ans=k*500;
	if(ans>=x)
	{
		cout<<"Yes"<<"\n";
	}
	else cout<<"No"<<"\n";
	return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string str;
    cin >> str;
    if(str[0]!=str[1]&&str[1]!=str[2]&&str[2]!=str[3]) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

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

inline long long read(){
	long long s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

bool flag = 0;
int main(){
	int n = read();
	for (int i = 1; i <= n; i++){
		int a = read();
		if (a % 2 == 0){
			if (a % 3 == 0 || a % 5 == 0){
				continue; 
			}
			flag = 1;
		}
	}
	if (flag){
		cout << "DENIED" << endl;
		return 0;
	}
	cout << "APPROVED" << endl;
	return 0;
}


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


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

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

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI s(m), c(m);
	
	rep(i, m) cin >>s[i] >>c[i];
	
	if(n==1 && m==0){puts("0"); return 0;}
	VI ans(n, -1);
	rep(i, m){
		if(n > 1 && s[i]==1 && c[i]==0){
			puts("-1"); return 0;
		}
		if(ans[s[i]-1] != -1 && ans[s[i]-1] != c[i]){
			puts("-1"); return 0;
		}
		ans[s[i]-1] = c[i];
	}
	//for(auto x :ans) cerr<<x<<" "; dbg("");
	rep(i, n){
		if(ans[i]==-1){
			if(i==0) ans[0] = 1;
			else ans[i] = 0;
		}
	}
	
	rep(i, n) cout <<ans[i];
	cout <<"\n";
	return 0;
}


Measured memory_bytes: 256
import sys

N, C, K = map(int ,input().split())
T = [int(input()) for _ in range(N)]
T.sort()

if C == 1:
	print(N)
	sys.exit()

cnt = 0
capacity = 0
time_limit = 0
for i in range(N):
	if capacity == 0:
		capacity += 1
		time_limit = T[i] + K
		continue
	if capacity > 0:
		if T[i] <= time_limit:
			capacity += 1
			if capacity == C:
				cnt += 1
				capacity = 0
				continue
		elif T[i] > time_limit:
			cnt += 1
			capacity = 1
			time_limit = T[i] + K


print(cnt+1)

Measured memory_bytes: 7384
#include<stdio.h>


int main(){
  int a,b;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
    	printf("%d\n",a+b);
    }else if(op == '-'){
    	printf("%d\n",a-b);
    }else if(op == '*'){
    	printf("%d\n",a*b);
    }else if(op == '/'){
    	printf("%d\n",a/b);
    }else{
        break;
    }
  }
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
int main(void){
    char S[5];
    for(int i=0; i<5;i++){
        S[i] = '\0';
    }

    //rewind(stdin);
    if(scanf("%s",&S[0])==EOF){
        printf("Error");
        return -1;
    }
    //大文字判定
    int oflg=0;
    for(int i=0;i<4;i++){
        if((S[i]>= 'A') && (S[i]<='Z')){
        
        }else{
            printf("No");
            return 0;
        }
    }


    //種類を数える
    char comp[5];
     for(int i=0; i<5;i++){
        comp[i] = '\0';
    }

    comp[0]=S[0];
    int complen=1;
    int cflg=0;
    for(int i=1;i<4;i++){
        for(int j=0; j<complen; j++){
            if(comp[j] == S[i]){
                cflg=1;
                break;    
            }
        }
        if(cflg==0){
            comp[complen]=S[i];
            complen++;
        }else{
            cflg=0;
        }
    }
 
    if(complen>2){
        printf("No");
        return 0;
    }
  
    //連続を探す
    int flg=0;
        
    if(S[0] == S[1] && S[1] != S[2] && S[2] == S[3])printf("Yes\n");
    else if(S[0] == S[2] && S[2] != S[1] && S[1] == S[3])printf("Yes\n");
    else if(S[0] == S[3] && S[3] != S[1] && S[1] == S[2])printf("Yes\n");
    else printf("No\n");
    
    return 0;
 }

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, T = MAP()
a = LIST()
ma = max(a)
left = sum(a)-ma
print(max(0, ma-left-1))


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define first fi
#define second se

ll gcd(ll c,ll d){
  if(d==0) return c;
  return gcd(d,c%d);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll lcm = (c*d) / gcd(c,d);

  ll diva = (a-1) / c;
  diva += (a-1) / d;
  diva -= (a-1) / lcm;
  ll nodiva = (a-1) - diva;

  ll divb = b / c;
  divb += b / d;
  divb -= b / lcm;
  ll nodivb = b - divb;

  ll ans = nodivb - nodiva;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>

typedef long long int64;

int main(void) {
  std::string s, t;
  int a, b;
  std::string u;
  std::cin >> s >> t;
  std::cin >> a >> b;
  std::cin >> u;

  if (s == u) {
    a--;
  }
  else if (t == u) {
    b--;
  }

  std::cout << a << " " << b << std::endl;

  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::{input, marker::{Isize1, Usize1, Bytes, Chars}};

#[proconio::fastout]
fn main() {
    input!(
        n: usize,
        arr: [u32; n],
    );
    let mut ones = Vec::with_capacity(32);
    for i in 0..32 {
        ones.push(arr.iter().copied().map(|a| (a >> i) & 1).sum::<u32>());
    }
    if arr.iter().copied().all(|a| a == 0) { println!("Yes"); }
    else if n % 3 != 0 { println!("No"); }
    else if ones.into_iter().all(|k| k == 0 || 2 * n / 3 == k as usize) { println!("Yes"); }
    else { println!("No"); }
}


Measured memory_bytes: 3196
gets
N = gets.strip.split(" ").map(&:to_i)

ans = 0

1.upto(N.size - 2) do |i|
  if N[i - 1] > N[i] && N[i + 1] < N[i] || N[i - 1] < N[i] && N[i + 1] > N[i]
    ans += 1
  end
end

puts ans


Measured memory_bytes: 1788